Merge vk-gl-cts/master into aosp/deqp-dev
[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 = "tesselation control";
2412                 break;
2413         case TESS_EVAL:
2414                 result = "tesselation evaluation";
2415                 break;
2416         case GEOMETRY:
2417                 result = "geomtery";
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 tesselation_control_shader    Tesselation control shader source code
2625  * @param tesselation_evaluation_shader Tesselation 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& tesselation_control_shader,
2633                                    const std::string& tesselation_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, tesselation_control_shader);
2647         m_tess_eval.Init(Shader::TESS_EVAL, tesselation_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, tesselation_control_shader,
2675                                                          tesselation_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 tesselation_control_shader    Tesselation control shader source code
2685  * @param tesselation_evaluation_shader Tesselation 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& tesselation_control_shader,
2691                                    const std::string& tesselation_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, tesselation_control_shader, tesselation_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 tesselation control stage
3096  * @param tess_eval_shader Source code for tesselation 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         /* Tesselation 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                         test_case_result = false;
6144                 }
6145         }
6146         else /* Draw */
6147         {
6148                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6149                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6150                 bool                       is_build_error         = false;
6151                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6152                 Utils::Program   program(m_context);
6153                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6154                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6155                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6156
6157                 try
6158                 {
6159                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6160                 }
6161                 catch (Utils::Shader::InvalidSourceException& exc)
6162                 {
6163                         if (false == is_failure_expected)
6164                         {
6165                                 m_context.getTestContext().getLog()
6166                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6167                                 exc.log(m_context);
6168                         }
6169
6170 #if DEBUG_NEG_LOG_ERROR
6171
6172                         else
6173                         {
6174                                 m_context.getTestContext().getLog()
6175                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6176                                         << tcu::TestLog::EndMessage;
6177                                 exc.log(m_context);
6178                         }
6179
6180 #endif /* DEBUG_NEG_LOG_ERROR */
6181
6182                         is_build_error = true;
6183                 }
6184                 catch (Utils::Program::BuildException& exc)
6185                 {
6186                         if (false == is_failure_expected)
6187                         {
6188                                 m_context.getTestContext().getLog()
6189                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6190                                 exc.log(m_context);
6191                         }
6192
6193 #if DEBUG_NEG_LOG_ERROR
6194
6195                         else
6196                         {
6197                                 m_context.getTestContext().getLog()
6198                                         << tcu::TestLog::Message
6199                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6200                                 exc.log(m_context);
6201                         }
6202
6203 #endif /* DEBUG_NEG_LOG_ERROR */
6204
6205                         is_build_error = true;
6206                 }
6207
6208                 if (is_build_error != is_failure_expected)
6209                 {
6210                         test_case_result = false;
6211                 }
6212         }
6213
6214         return test_case_result;
6215 }
6216
6217 /* Constants used by TextureTestBase */
6218 const glw::GLuint TextureTestBase::m_width  = 16;
6219 const glw::GLuint TextureTestBase::m_height = 16;
6220
6221 /** Constructor
6222  *
6223  * @param context          Test context
6224  * @param test_name        Name of test
6225  * @param test_description Description of test
6226  **/
6227 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6228         : TestBase(context, test_name, test_description)
6229 {
6230 }
6231
6232 /** Get locations for all inputs with automatic_location
6233  *
6234  * @param program           Program object
6235  * @param program_interface Interface of program
6236  **/
6237 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6238 {
6239         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6240
6241         Utils::Variable::PtrVector& inputs = si.m_inputs;
6242
6243         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6244         {
6245                 /* Test does not specify location, query value and set */
6246                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6247                 {
6248                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6249                         GLint  location = 0;
6250
6251                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6252
6253                         (*it)->m_descriptor.m_expected_location = location;
6254                 }
6255         }
6256 }
6257
6258 /** Verifies contents of drawn image
6259  *
6260  * @param ignored
6261  * @param color_0 Verified image
6262  *
6263  * @return true if image is filled with 1, false otherwise
6264  **/
6265 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6266 {
6267         static const GLuint size                   = m_width * m_height;
6268         static const GLuint expected_color = 1;
6269
6270         std::vector<GLuint> data;
6271         data.resize(size);
6272
6273         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6274
6275         for (GLuint i = 0; i < size; ++i)
6276         {
6277                 const GLuint color = data[i];
6278
6279                 if (expected_color != color)
6280                 {
6281                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6282                                                                                                 << tcu::TestLog::EndMessage;
6283                         return false;
6284                 }
6285         }
6286
6287         return true;
6288 }
6289
6290 /** Execute dispatch compute for 16x16x1
6291  *
6292  * @param ignored
6293  **/
6294 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6295 {
6296         const Functions& gl = m_context.getRenderContext().getFunctions();
6297
6298         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6299         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6300 }
6301
6302 /** Execute drawArrays for single vertex
6303  *
6304  * @param ignored
6305  **/
6306 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6307 {
6308         const Functions& gl = m_context.getRenderContext().getFunctions();
6309
6310         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6311         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6312 }
6313
6314 /** Prepare code snippet that will pass in variables to out variables
6315  *
6316  * @param ignored
6317  * @param varying_passthrough Collection of connections between in and out variables
6318  * @param stage               Shader stage
6319  *
6320  * @return Code that pass in variables to next stage
6321  **/
6322 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6323                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6324 {
6325         static const GLchar* separator = "\n    ";
6326
6327         /* Skip for compute shader */
6328         if (Utils::Shader::COMPUTE == stage)
6329         {
6330                 return "";
6331         }
6332
6333         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6334
6335         std::string result   = Utils::g_list;
6336         size_t          position = 0;
6337
6338         for (GLuint i = 0; i < vector.size(); ++i)
6339         {
6340
6341                 Utils::VaryingConnection& connection = vector[i];
6342
6343                 Utils::Variable* in  = connection.m_in;
6344                 Utils::Variable* out = connection.m_out;
6345
6346                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6347                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6348
6349                 const std::string passthrough =
6350                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6351
6352                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6353         }
6354
6355         Utils::endList("", position, result);
6356
6357         return result;
6358 }
6359
6360 /** Basic implementation of method getProgramInterface
6361  *
6362  * @param ignored
6363  * @param ignored
6364  * @param ignored
6365  **/
6366 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6367                                                                                   Utils::ProgramInterface& /* program_interface */,
6368                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6369 {
6370 }
6371
6372 /** Prepare code snippet that will verify in and uniform variables
6373  *
6374  * @param ignored
6375  * @param program_interface Interface of program
6376  * @param stage             Shader stage
6377  *
6378  * @return Code that verify variables
6379  **/
6380 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6381                                                                                                         Utils::ProgramInterface& program_interface,
6382                                                                                                         Utils::Shader::STAGES   stage)
6383 {
6384         static const GLchar* separator = " ||\n        ";
6385
6386         std::string verification = "if (LIST)\n"
6387                                                            "    {\n"
6388                                                            "        result = 0u;\n"
6389                                                            "    }\n";
6390
6391         /* Get flavour of in and out variables */
6392         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6393
6394         /* Get interface for shader stage */
6395         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6396
6397         /* There are no varialbes to verify */
6398         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6399         {
6400                 return "";
6401         }
6402
6403         /* For each in variable insert verification code */
6404         size_t position = 0;
6405
6406         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6407         {
6408                 const Utils::Variable& var                              = *si.m_inputs[i];
6409                 const std::string&       var_verification = getVariableVerifcation("", var.m_data, var.m_descriptor, in_flavour);
6410
6411                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6412         }
6413
6414         /* For each unifrom variable insert verification code */
6415         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6416         {
6417                 const Utils::Variable& var = *si.m_uniforms[i];
6418                 const std::string&       var_verification =
6419                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6420
6421                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6422         }
6423
6424         /* For each ssb variable insert verification code */
6425         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6426         {
6427                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6428                 const std::string&       var_verification =
6429                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6430
6431                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6432         }
6433
6434         Utils::endList("", position, verification);
6435
6436 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6437
6438         {
6439                 GLchar buffer[16];
6440                 sprintf(buffer, "%d", stage + 10);
6441                 Utils::replaceToken("0u", position, buffer, verification);
6442         }
6443
6444 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6445
6446         if (Utils::Shader::VERTEX == stage)
6447         {
6448                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6449         }
6450         else
6451         {
6452                 Utils::replaceToken("0u", position, "31u", verification);
6453         }
6454
6455 #endif
6456
6457         /* Done */
6458         return verification;
6459 }
6460
6461 /** Selects if "compute" stage is relevant for test
6462  *
6463  * @param ignored
6464  *
6465  * @return true
6466  **/
6467 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6468 {
6469         return true;
6470 }
6471
6472 /** Selects if "draw" stages are relevant for test
6473  *
6474  * @param ignored
6475  *
6476  * @return true
6477  **/
6478 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6479 {
6480         return true;
6481 }
6482
6483 /** Prepare code that will do assignment of single in to single out
6484  *
6485  * @param in_parent_name  Name of parent in variable
6486  * @param in_variable     Descriptor of in variable
6487  * @param in_flavour      Flavoud of in variable
6488  * @param out_parent_name Name of parent out variable
6489  * @param out_variable    Descriptor of out variable
6490  * @param out_flavour     Flavoud of out variable
6491  *
6492  * @return Code that does OUT = IN
6493  **/
6494 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6495                                                                                                         const Utils::Variable::Descriptor& in_variable,
6496                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6497                                                                                                         const std::string&                                 out_parent_name,
6498                                                                                                         const Utils::Variable::Descriptor& out_variable,
6499                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6500 {
6501         bool                             done             = false;
6502         GLuint                           index            = 0;
6503         GLuint                           member_index = 0;
6504         size_t                           position        = 0;
6505         std::string                      result           = Utils::g_list;
6506         static const GLchar* separator  = ";\n    ";
6507
6508         /* For each member of each array element */
6509         do
6510         {
6511                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6512                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6513                 std::string               passthrough;
6514
6515                 /* Prepare verification */
6516                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6517                 {
6518                         size_t pass_position = 0;
6519
6520                         passthrough = "OUT = IN;";
6521
6522                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6523                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6524
6525                         /* Increment index */
6526                         ++index;
6527                 }
6528                 else
6529                 {
6530                         const Utils::Interface* in_interface  = in_variable.m_interface;
6531                         const Utils::Interface* out_interface = out_variable.m_interface;
6532
6533                         if ((0 == in_interface) || (0 == out_interface))
6534                         {
6535                                 TCU_FAIL("Nullptr");
6536                         }
6537
6538                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6539                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6540
6541                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6542                                                                                                  Utils::Variable::BASIC);
6543
6544                         /* Increment member_index */
6545                         ++member_index;
6546
6547                         /* Increment index and reset member_index if all members were processed */
6548                         if (in_interface->m_members.size() == member_index)
6549                         {
6550                                 ++index;
6551                                 member_index = 0;
6552                         }
6553                 }
6554
6555                 /* Check if loop should end */
6556                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6557                 {
6558                         done = true;
6559                 }
6560
6561                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6562
6563         } while (true != done);
6564
6565         Utils::endList("", position, result);
6566
6567         /* Done */
6568         return result;
6569 }
6570
6571 /** Get verification of single variable
6572  *
6573  * @param parent_name Name of parent variable
6574  * @param data        Data that should be used as EXPECTED
6575  * @param variable    Descriptor of variable
6576  * @param flavour     Flavour of variable
6577  *
6578  * @return Code that does (EXPECTED != VALUE) ||
6579  **/
6580 std::string TextureTestBase::getVariableVerifcation(const std::string& parent_name, const GLvoid* data,
6581                                                                                                         const Utils::Variable::Descriptor& variable,
6582                                                                                                         Utils::Variable::FLAVOUR                   flavour)
6583 {
6584         static const GLchar* logic_op   = " ||\n        ";
6585         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6586         size_t                           position   = 0;
6587         std::string                      result         = Utils::g_list;
6588         GLint                            stride         = variable.m_expected_stride_of_element;
6589
6590         /* For each each array element */
6591         for (GLuint element = 0; element < n_elements; ++element)
6592         {
6593                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6594
6595                 /* Calculate data pointer */
6596                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6597
6598                 /* Prepare verification */
6599                 if (Utils::Variable::BUILTIN == variable.m_type)
6600                 {
6601                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6602                         std::string                verification;
6603                         size_t                     verification_position = 0;
6604
6605                         verification = "(EXPECTED != NAME)";
6606
6607                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6608                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6609
6610                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6611                 }
6612                 else
6613                 {
6614                         const Utils::Interface* interface = variable.m_interface;
6615
6616                         if (0 == interface)
6617                         {
6618                                 TCU_FAIL("Nullptr");
6619                         }
6620
6621                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6622
6623                         /* for each member */
6624                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6625                         {
6626                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6627
6628                                 /* Get verification of member */
6629                                 const std::string& verification =
6630                                         getVariableVerifcation(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6631
6632                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6633                         }
6634                 }
6635         }
6636
6637         Utils::endList("", position, result);
6638
6639         return result;
6640 }
6641
6642 /** Prepare attributes, vertex array object and array buffer
6643  *
6644  * @param test_case_index   Index of test case
6645  * @param program_interface Interface of program
6646  * @param buffer            Array buffer
6647  * @param vao               Vertex array object
6648  **/
6649 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6650                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6651 {
6652         bool use_component_qualifier = useComponentQualifier(test_case_index);
6653
6654         /* Get shader interface */
6655         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6656
6657         /* Bind vao and buffer */
6658         vao.Bind();
6659         buffer.Bind();
6660
6661         /* Skip if there are no input variables in vertex shader */
6662         if (0 == si.m_inputs.size())
6663         {
6664                 return;
6665         }
6666
6667         /* Calculate vertex stride and check */
6668         GLint vertex_stride = 0;
6669
6670         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6671         {
6672                 Utils::Variable& variable = *si.m_inputs[i];
6673
6674                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6675
6676                 GLint ends_at = variable_size + variable.m_descriptor.m_offset;
6677
6678                 vertex_stride = std::max(vertex_stride, ends_at);
6679         }
6680
6681         /* Prepare buffer data and set up vao */
6682         std::vector<GLubyte> buffer_data;
6683         buffer_data.resize(vertex_stride);
6684
6685         GLubyte* ptr = &buffer_data[0];
6686
6687         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6688         {
6689                 Utils::Variable& variable = *si.m_inputs[i];
6690
6691                 memcpy(ptr + variable.m_descriptor.m_offset, variable.m_data, variable.m_data_size);
6692
6693                 if (false == use_component_qualifier)
6694                 {
6695                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6696                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6697                                                   variable.GetStride(), (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6698                 }
6699                 else if (0 == variable.m_descriptor.m_expected_component)
6700                 {
6701                         /* Components can only be applied to vectors.
6702                          Assumption that test use all 4 components */
6703                         const Utils::Type& type =
6704                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6705
6706                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6707                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6708                                                   (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6709                 }
6710         }
6711
6712         /* Update buffer */
6713         buffer.Data(Utils::Buffer::StaticDraw, vertex_stride, ptr);
6714 }
6715
6716 /** Get locations for all outputs with automatic_location
6717  *
6718  * @param program           Program object
6719  * @param program_interface Interface of program
6720  **/
6721 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6722 {
6723         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6724         Utils::Variable::PtrVector& outputs = si.m_outputs;
6725
6726         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6727         {
6728                 /* Test does not specify location, query value and set */
6729                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6730                 {
6731                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6732                         GLint  location = 0;
6733
6734                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6735
6736                         (*it)->m_descriptor.m_expected_location = location;
6737                 }
6738         }
6739 }
6740
6741 /** Prepare framebuffer with single texture as color attachment
6742  *
6743  * @param framebuffer     Framebuffer
6744  * @param color_0_texture Texture that will used as color attachment
6745  **/
6746 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6747 {
6748         /* Prepare data */
6749         std::vector<GLuint> texture_data;
6750         texture_data.resize(m_width * m_height);
6751
6752         for (GLuint i = 0; i < texture_data.size(); ++i)
6753         {
6754                 texture_data[i] = 0x20406080;
6755         }
6756
6757         /* Prepare texture */
6758         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6759                                                  &texture_data[0]);
6760
6761         /* Prepare framebuffer */
6762         framebuffer.Init();
6763         framebuffer.Bind();
6764         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6765
6766         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6767         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6768 }
6769
6770 /** Prepare iamge unit for compute shader
6771  *
6772  * @param location      Uniform location
6773  * @param image_texture Texture that will used as color attachment
6774  **/
6775 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6776 {
6777         static const GLuint image_unit = 0;
6778
6779         std::vector<GLuint> texture_data;
6780         texture_data.resize(m_width * m_height);
6781
6782         for (GLuint i = 0; i < texture_data.size(); ++i)
6783         {
6784                 texture_data[i] = 0x20406080;
6785         }
6786
6787         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6788                                            &texture_data[0]);
6789
6790         const Functions& gl = m_context.getRenderContext().getFunctions();
6791
6792         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6793                                                 GL_WRITE_ONLY, GL_R32UI);
6794         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6795
6796         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6797 }
6798
6799 /** Basic implementation
6800  *
6801  * @param ignored
6802  * @param si        Shader interface
6803  * @param program   Program
6804  * @param cs_buffer Buffer for ssb blocks
6805  **/
6806 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6807                                                                   Utils::Buffer& buffer)
6808 {
6809         /* Skip if there are no input variables in vertex shader */
6810         if (0 == si.m_ssb_blocks.size())
6811         {
6812                 return;
6813         }
6814
6815         /* Calculate vertex stride */
6816         GLint ssbs_stride = 0;
6817
6818         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6819         {
6820                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6821
6822                 if (false == variable.IsBlock())
6823                 {
6824                         continue;
6825                 }
6826
6827                 GLint variable_stride = variable.GetStride();
6828
6829                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6830
6831                 ssbs_stride = std::max(ssbs_stride, ends_at);
6832         }
6833
6834         /* Set active program */
6835         program.Use();
6836
6837         /* Allocate */
6838         buffer.Bind();
6839         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6840
6841         /* Set up uniforms */
6842         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6843         {
6844                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6845
6846                 /* prepareUnifor should work fine for ssb blocks */
6847                 prepareUniform(program, variable, buffer);
6848         }
6849 }
6850
6851 /** Basic implementation
6852  *
6853  * @param test_case_index   Test case index
6854  * @param program_interface Program interface
6855  * @param program           Program
6856  * @param cs_buffer         Buffer for compute shader stage
6857  **/
6858 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6859                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6860 {
6861         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6862
6863         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6864
6865         prepareSSBs(test_case_index, cs, program, cs_buffer);
6866
6867         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6868 }
6869
6870 /** Basic implementation
6871  *
6872  * @param test_case_index   Test case index
6873  * @param program_interface Program interface
6874  * @param program           Program
6875  * @param fs_buffer         Buffer for fragment shader stage
6876  * @param gs_buffer         Buffer for geometry shader stage
6877  * @param tcs_buffer        Buffer for tesselation control shader stage
6878  * @param tes_buffer        Buffer for tesselation evaluation shader stage
6879  * @param vs_buffer         Buffer for vertex shader stage
6880  **/
6881 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6882                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6883                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6884 {
6885         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6886         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6887         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6888         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6889         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6890
6891         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6892         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6893         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6894         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6895         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6896
6897         prepareSSBs(test_case_index, fs, program, fs_buffer);
6898         prepareSSBs(test_case_index, gs, program, gs_buffer);
6899         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
6900         prepareSSBs(test_case_index, tes, program, tes_buffer);
6901         prepareSSBs(test_case_index, vs, program, vs_buffer);
6902
6903         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
6904         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
6905         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
6906         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
6907         vs_buffer.BindBase(Utils::Shader::VERTEX);
6908 }
6909
6910 /** Updates buffer data with variable
6911  *
6912  * @param program  Program object
6913  * @param variable Variable
6914  * @param buffer   Buffer
6915  **/
6916 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
6917 {
6918         const Functions& gl = m_context.getRenderContext().getFunctions();
6919
6920         GLsizei count = variable.m_descriptor.m_n_array_elements;
6921         if (0 == count)
6922         {
6923                 count = 1;
6924         }
6925
6926         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
6927         {
6928                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
6929                                                 variable.m_data);
6930         }
6931         else
6932         {
6933                 const bool is_block = variable.IsBlock();
6934
6935                 if (false == is_block)
6936                 {
6937                         TCU_FAIL("Not implemented");
6938                 }
6939                 else
6940                 {
6941                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
6942                                                    variable.m_data);
6943                 }
6944         }
6945 }
6946
6947 /** Basic implementation
6948  *
6949  * @param ignored
6950  * @param si        Shader interface
6951  * @param program   Program
6952  * @param cs_buffer Buffer for uniform blocks
6953  **/
6954 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6955                                                                           Utils::Buffer& buffer)
6956 {
6957         /* Skip if there are no input variables in vertex shader */
6958         if (0 == si.m_uniforms.size())
6959         {
6960                 return;
6961         }
6962
6963         /* Calculate vertex stride */
6964         GLint uniforms_stride = 0;
6965
6966         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6967         {
6968                 Utils::Variable& variable = *si.m_uniforms[i];
6969
6970                 if (false == variable.IsBlock())
6971                 {
6972                         continue;
6973                 }
6974
6975                 GLint variable_stride = variable.GetStride();
6976
6977                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6978
6979                 uniforms_stride = std::max(uniforms_stride, ends_at);
6980         }
6981
6982         /* Set active program */
6983         program.Use();
6984
6985         /* Allocate */
6986         buffer.Bind();
6987         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
6988
6989         /* Set up uniforms */
6990         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6991         {
6992                 Utils::Variable& variable = *si.m_uniforms[i];
6993
6994                 prepareUniform(program, variable, buffer);
6995         }
6996 }
6997
6998 /** Basic implementation
6999  *
7000  * @param test_case_index   Test case index
7001  * @param program_interface Program interface
7002  * @param program           Program
7003  * @param cs_buffer         Buffer for compute shader stage
7004  **/
7005 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7006                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7007 {
7008         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7009
7010         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7011
7012         prepareUniforms(test_case_index, cs, program, cs_buffer);
7013
7014         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7015 }
7016
7017 /** Basic implementation
7018  *
7019  * @param test_case_index   Test case index
7020  * @param program_interface Program interface
7021  * @param program           Program
7022  * @param fs_buffer         Buffer for fragment shader stage
7023  * @param gs_buffer         Buffer for geometry shader stage
7024  * @param tcs_buffer        Buffer for tesselation control shader stage
7025  * @param tes_buffer        Buffer for tesselation evaluation shader stage
7026  * @param vs_buffer         Buffer for vertex shader stage
7027  **/
7028 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7029                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7030                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7031 {
7032         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7033         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7034         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7035         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7036         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7037
7038         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7039         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7040         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7041         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7042         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7043
7044         prepareUniforms(test_case_index, fs, program, fs_buffer);
7045         prepareUniforms(test_case_index, gs, program, gs_buffer);
7046         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7047         prepareUniforms(test_case_index, tes, program, tes_buffer);
7048         prepareUniforms(test_case_index, vs, program, vs_buffer);
7049
7050         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7051         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7052         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7053         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7054         vs_buffer.BindBase(Utils::Shader::VERTEX);
7055 }
7056
7057 /** Basic implementation
7058  *
7059  * @param test_case_index   Test case index
7060  * @param program_interface Program interface
7061  * @param program           Program
7062  * @param fs_buffer         Buffer for fragment shader stage
7063  * @param gs_buffer         Buffer for geometry shader stage
7064  * @param tcs_buffer        Buffer for tesselation control shader stage
7065  * @param tes_buffer        Buffer for tesselation evaluation shader stage
7066  * @param vs_buffer         Buffer for vertex shader stage
7067  **/
7068 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7069                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7070                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7071                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7072                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7073 {
7074         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7075         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7076         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7077         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7078         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7079
7080         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7081         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7082         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7083         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7084         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7085
7086         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7087         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7088
7089         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7090         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7091
7092         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7093         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7094
7095         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7096         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7097
7098         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7099         vs_buffer.BindBase(Utils::Shader::VERTEX);
7100 }
7101
7102 /** Prepare source for shader
7103  *
7104  * @param test_case_index     Index of test case
7105  * @param program_interface   Interface of program
7106  * @param varying_passthrough Collection of connection between in and out variables
7107  * @param stage               Shader stage
7108  *
7109  * @return Source of shader
7110  **/
7111 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7112                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7113                                                                                          Utils::Shader::STAGES          stage)
7114 {
7115         /* Get strings */
7116         const GLchar*     shader_template  = getShaderTemplate(stage);
7117         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7118
7119         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7120
7121         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7122
7123         const GLchar* per_vertex = "";
7124
7125         std::string source   = shader_template;
7126         size_t          position = 0;
7127
7128         /* Replace tokens in template */
7129         if (Utils::Shader::GEOMETRY == stage)
7130         {
7131                 if (false == useMonolithicProgram(test_case_index))
7132                 {
7133                         per_vertex = "out gl_PerVertex {\n"
7134                                                  "vec4 gl_Position;\n"
7135                                                  "};\n"
7136                                                  "\n";
7137                 }
7138
7139                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7140         }
7141
7142         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7143         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7144
7145         if (false == verification.empty())
7146         {
7147                 Utils::replaceAllTokens("ELSE", "    else ", source);
7148         }
7149         else
7150         {
7151                 Utils::replaceAllTokens("ELSE", "", source);
7152         }
7153
7154         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7155
7156         /* Done */
7157         return source;
7158 }
7159
7160 /** Returns template of shader for given stage
7161  *
7162  * @param stage Shade stage
7163  *
7164  * @return Proper template
7165  **/
7166 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7167 {
7168
7169         static const GLchar* compute_shader_template =
7170                 "#version 430 core\n"
7171                 "#extension GL_ARB_enhanced_layouts : require\n"
7172                 "\n"
7173                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7174                 "\n"
7175                 "writeonly uniform uimage2D uni_image;\n"
7176                 "\n"
7177                 "INTERFACE"
7178                 "\n"
7179                 "void main()\n"
7180                 "{\n"
7181                 "    uint result = 1u;\n"
7182                 "\n"
7183                 "    VERIFICATION"
7184                 "\n"
7185                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7186                 "}\n"
7187                 "\n";
7188
7189         static const GLchar* fragment_shader_template = "#version 430 core\n"
7190                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7191                                                                                                         "\n"
7192                                                                                                         "flat in  uint gs_fs_result;\n"
7193                                                                                                         "     out uint fs_out_result;\n"
7194                                                                                                         "\n"
7195                                                                                                         "INTERFACE"
7196                                                                                                         "\n"
7197                                                                                                         "void main()\n"
7198                                                                                                         "{\n"
7199                                                                                                         "    uint result = 1u;\n"
7200                                                                                                         "\n"
7201                                                                                                         "    if (1u != gs_fs_result)\n"
7202                                                                                                         "    {\n"
7203                                                                                                         "         result = gs_fs_result;\n"
7204                                                                                                         "    }\n"
7205                                                                                                         "ELSEVERIFICATION"
7206                                                                                                         "\n"
7207                                                                                                         "    fs_out_result = result;\n"
7208                                                                                                         "    PASSTHROUGH\n"
7209                                                                                                         "}\n"
7210                                                                                                         "\n";
7211
7212         static const GLchar* geometry_shader_template =
7213                 "#version 430 core\n"
7214                 "#extension GL_ARB_enhanced_layouts : require\n"
7215                 "\n"
7216                 "layout(points)                           in;\n"
7217                 "layout(triangle_strip, max_vertices = 4) out;\n"
7218                 "\n"
7219                 "     in  uint tes_gs_result[];\n"
7220                 "flat out uint gs_fs_result;\n"
7221                 "\n"
7222                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7223                 "INTERFACE"
7224                 "\n"
7225                 "void main()\n"
7226                 "{\n"
7227                 "    uint result = 1u;\n"
7228                 "\n"
7229                 "    if (1u != tes_gs_result[0])\n"
7230                 "    {\n"
7231                 "         result = tes_gs_result[0];\n"
7232                 "    }\n"
7233                 "ELSEVERIFICATION"
7234                 "\n"
7235                 "    gs_fs_result = result;\n"
7236                 "    PASSTHROUGH\n"
7237                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7238                 "    EmitVertex();\n"
7239                 "    gs_fs_result = result;\n"
7240                 "    PASSTHROUGH\n"
7241                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7242                 "    EmitVertex();\n"
7243                 "    gs_fs_result = result;\n"
7244                 "    PASSTHROUGH\n"
7245                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7246                 "    EmitVertex();\n"
7247                 "    gs_fs_result = result;\n"
7248                 "    PASSTHROUGH\n"
7249                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7250                 "    EmitVertex();\n"
7251                 "}\n"
7252                 "\n";
7253
7254         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7255                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7256                                                                                                          "\n"
7257                                                                                                          "layout(vertices = 1) out;\n"
7258                                                                                                          "\n"
7259                                                                                                          "in  uint vs_tcs_result[];\n"
7260                                                                                                          "out uint tcs_tes_result[];\n"
7261                                                                                                          "\n"
7262                                                                                                          "INTERFACE"
7263                                                                                                          "\n"
7264                                                                                                          "void main()\n"
7265                                                                                                          "{\n"
7266                                                                                                          "    uint result = 1u;\n"
7267                                                                                                          "\n"
7268                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7269                                                                                                          "    {\n"
7270                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7271                                                                                                          "    }\n"
7272                                                                                                          "ELSEVERIFICATION"
7273                                                                                                          "\n"
7274                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7275                                                                                                          "\n"
7276                                                                                                          "    PASSTHROUGH\n"
7277                                                                                                          "\n"
7278                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7279                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7280                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7281                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7282                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7283                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7284                                                                                                          "}\n"
7285                                                                                                          "\n";
7286
7287         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7288                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7289                                                                                                          "\n"
7290                                                                                                          "layout(isolines, point_mode) in;\n"
7291                                                                                                          "\n"
7292                                                                                                          "in  uint tcs_tes_result[];\n"
7293                                                                                                          "out uint tes_gs_result;\n"
7294                                                                                                          "\n"
7295                                                                                                          "INTERFACE"
7296                                                                                                          "\n"
7297                                                                                                          "void main()\n"
7298                                                                                                          "{\n"
7299                                                                                                          "    uint result = 1u;\n"
7300                                                                                                          "\n"
7301                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7302                                                                                                          "    {\n"
7303                                                                                                          "         result = tcs_tes_result[0];\n"
7304                                                                                                          "    }\n"
7305                                                                                                          "ELSEVERIFICATION"
7306                                                                                                          "\n"
7307                                                                                                          "    tes_gs_result = result;\n"
7308                                                                                                          "\n"
7309                                                                                                          "    PASSTHROUGH\n"
7310                                                                                                          "}\n"
7311                                                                                                          "\n";
7312
7313         static const GLchar* vertex_shader_template = "#version 430 core\n"
7314                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7315                                                                                                   "\n"
7316                                                                                                   "out uint vs_tcs_result;\n"
7317                                                                                                   "\n"
7318                                                                                                   "INTERFACE"
7319                                                                                                   "\n"
7320                                                                                                   "void main()\n"
7321                                                                                                   "{\n"
7322                                                                                                   "    uint result = 1u;\n"
7323                                                                                                   "\n"
7324                                                                                                   "    VERIFICATION\n"
7325                                                                                                   "\n"
7326                                                                                                   "    vs_tcs_result = result;\n"
7327                                                                                                   "\n"
7328                                                                                                   "    PASSTHROUGH\n"
7329                                                                                                   "}\n"
7330                                                                                                   "\n";
7331
7332         const GLchar* result = 0;
7333
7334         switch (stage)
7335         {
7336         case Utils::Shader::COMPUTE:
7337                 result = compute_shader_template;
7338                 break;
7339         case Utils::Shader::FRAGMENT:
7340                 result = fragment_shader_template;
7341                 break;
7342         case Utils::Shader::GEOMETRY:
7343                 result = geometry_shader_template;
7344                 break;
7345         case Utils::Shader::TESS_CTRL:
7346                 result = tess_ctrl_shader_template;
7347                 break;
7348         case Utils::Shader::TESS_EVAL:
7349                 result = tess_eval_shader_template;
7350                 break;
7351         case Utils::Shader::VERTEX:
7352                 result = vertex_shader_template;
7353                 break;
7354         default:
7355                 TCU_FAIL("Invalid enum");
7356         }
7357
7358         return result;
7359 }
7360
7361 /** Runs test case
7362  *
7363  * @param test_case_index Id of test case
7364  *
7365  * @return true if test case pass, false otherwise
7366  **/
7367 bool TextureTestBase::testCase(GLuint test_case_index)
7368 {
7369         try
7370         {
7371                 if (true == useMonolithicProgram(test_case_index))
7372                 {
7373                         return testMonolithic(test_case_index);
7374                 }
7375                 else
7376                 {
7377                         return testSeparable(test_case_index);
7378                 }
7379         }
7380         catch (Utils::Shader::InvalidSourceException& exc)
7381         {
7382                 exc.log(m_context);
7383                 TCU_FAIL(exc.what());
7384         }
7385         catch (Utils::Program::BuildException& exc)
7386         {
7387                 TCU_FAIL(exc.what());
7388         }
7389 }
7390
7391 /** Runs "draw" test with monolithic program
7392  *
7393  * @param test_case_index Id of test case
7394  **/
7395 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7396 {
7397         Utils::ProgramInterface   program_interface;
7398         Utils::VaryingPassthrough varying_passthrough;
7399
7400         /* */
7401         const std::string& test_name = getTestCaseName(test_case_index);
7402
7403         /* */
7404         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7405
7406         bool result = true;
7407         /* Draw */
7408         if (true == isDrawRelevant(test_case_index))
7409         {
7410                 Utils::Buffer     buffer_attr(m_context);
7411                 Utils::Buffer     buffer_ssb_fs(m_context);
7412                 Utils::Buffer     buffer_ssb_gs(m_context);
7413                 Utils::Buffer     buffer_ssb_tcs(m_context);
7414                 Utils::Buffer     buffer_ssb_tes(m_context);
7415                 Utils::Buffer     buffer_ssb_vs(m_context);
7416                 Utils::Buffer     buffer_u_fs(m_context);
7417                 Utils::Buffer     buffer_u_gs(m_context);
7418                 Utils::Buffer     buffer_u_tcs(m_context);
7419                 Utils::Buffer     buffer_u_tes(m_context);
7420                 Utils::Buffer     buffer_u_vs(m_context);
7421                 Utils::Framebuffer framebuffer(m_context);
7422                 Utils::Program   program(m_context);
7423                 Utils::Texture   texture_fb(m_context);
7424                 Utils::VertexArray vao(m_context);
7425
7426                 /* */
7427                 const std::string& fragment_shader =
7428                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7429                 const std::string& geometry_shader =
7430                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7431                 const std::string& tess_ctrl_shader =
7432                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7433                 const std::string& tess_eval_shader =
7434                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7435                 const std::string& vertex_shader =
7436                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7437
7438                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7439                                          vertex_shader, false /* is_separable */);
7440
7441                 /* */
7442                 prepareAttribLocation(program, program_interface);
7443                 prepareFragmentDataLoc(program, program_interface);
7444
7445                 /* */
7446                 std::stringstream stream;
7447                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7448                 {
7449                         m_context.getTestContext().getLog()
7450                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7451                                 << ". Inspection of draw program interface failed:\n"
7452                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7453                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7454                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7455
7456                         return false;
7457                 }
7458
7459                 /* */
7460                 program.Use();
7461
7462                 /* */
7463                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7464                 vao.Init();
7465                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7466
7467                 /* */
7468                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7469                                                 buffer_u_tes, buffer_u_vs);
7470
7471                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7472                                         buffer_ssb_tes, buffer_ssb_vs);
7473
7474                 /* */
7475                 prepareFramebuffer(framebuffer, texture_fb);
7476
7477                 /* Draw */
7478                 executeDrawCall(test_case_index);
7479
7480 #if USE_NSIGHT
7481                 m_context.getRenderContext().postIterate();
7482 #endif
7483
7484                 /* Check results */
7485                 if (false == checkResults(test_case_index, texture_fb))
7486                 {
7487                         m_context.getTestContext().getLog()
7488                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7489                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7490                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7491                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7492
7493                         result = false;
7494                 }
7495         }
7496
7497         /* Compute */
7498         if (true == isComputeRelevant(test_case_index))
7499         {
7500                 Utils::Buffer     buffer_ssb_cs(m_context);
7501                 Utils::Buffer     buffer_u_cs(m_context);
7502                 Utils::Program   program(m_context);
7503                 Utils::Texture   texture_im(m_context);
7504                 Utils::VertexArray vao(m_context);
7505
7506                 /* */
7507                 const std::string& compute_shader =
7508                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7509
7510                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7511                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7512
7513                 /* */
7514                 {
7515                         std::stringstream stream;
7516
7517                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7518                         {
7519                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7520                                                                                                         << ". Inspection of compute program interface failed:\n"
7521                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7522
7523                                 return false;
7524                         }
7525                 }
7526
7527                 /* */
7528                 program.Use();
7529
7530                 /* */
7531                 vao.Init();
7532                 vao.Bind();
7533
7534                 /* */
7535                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7536
7537                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7538
7539                 /* */
7540                 GLint image_location = program.GetUniformLocation("uni_image");
7541                 prepareImage(image_location, texture_im);
7542
7543                 /* Draw */
7544                 executeDispatchCall(test_case_index);
7545
7546 #if USE_NSIGHT
7547                 m_context.getRenderContext().postIterate();
7548 #endif
7549
7550                 /* Check results */
7551                 if (false == checkResults(test_case_index, texture_im))
7552                 {
7553                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7554                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7555                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7556
7557                         result = false;
7558                 }
7559         }
7560
7561         return result;
7562 }
7563
7564 /** Runs "draw" test with separable program
7565  *
7566  * @param test_case_index Id of test case
7567  **/
7568 bool TextureTestBase::testSeparable(GLuint test_case_index)
7569 {
7570         Utils::ProgramInterface   program_interface;
7571         Utils::VaryingPassthrough varying_passthrough;
7572
7573         /* */
7574         const std::string& test_name = getTestCaseName(test_case_index);
7575
7576         /* */
7577         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7578
7579         bool result = true;
7580         /* Draw */
7581         if (true == isDrawRelevant(test_case_index))
7582         {
7583                 Utils::Buffer     buffer_attr(m_context);
7584                 Utils::Buffer     buffer_u_fs(m_context);
7585                 Utils::Buffer     buffer_u_gs(m_context);
7586                 Utils::Buffer     buffer_u_tcs(m_context);
7587                 Utils::Buffer     buffer_u_tes(m_context);
7588                 Utils::Buffer     buffer_u_vs(m_context);
7589                 Utils::Framebuffer framebuffer(m_context);
7590                 Utils::Pipeline pipeline(m_context);
7591                 Utils::Program   program_fs(m_context);
7592                 Utils::Program   program_gs(m_context);
7593                 Utils::Program   program_tcs(m_context);
7594                 Utils::Program   program_tes(m_context);
7595                 Utils::Program   program_vs(m_context);
7596                 Utils::Texture   texture_fb(m_context);
7597                 Utils::VertexArray vao(m_context);
7598
7599                 /* */
7600                 const std::string& fs =
7601                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7602                 const std::string& gs =
7603                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7604                 const std::string& tcs =
7605                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7606                 const std::string& tes =
7607                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7608                 const std::string& vs =
7609                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7610
7611                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7612                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7613                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7614                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7615                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7616
7617                 /* */
7618                 prepareAttribLocation(program_vs, program_interface);
7619                 prepareFragmentDataLoc(program_vs, program_interface);
7620
7621                 /* */
7622                 std::stringstream stream;
7623                 if ((false ==
7624                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7625                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7626                                                                                                                                 stream)) ||
7627                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7628                                                                                                                                 stream)) ||
7629                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7630                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7631                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7632                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7633                 {
7634                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7635                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7636                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7637                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7638                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7639                                                                                                 << tcu::TestLog::KernelSource(fs);
7640
7641                         return false;
7642                 }
7643
7644                 /* */
7645                 pipeline.Init();
7646                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7647                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7648                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7649                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7650                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7651                 pipeline.Bind();
7652
7653                 /* */
7654
7655                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7656                 vao.Init();
7657                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7658
7659                 /* */
7660                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7661                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7662
7663                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7664
7665                 /* */
7666                 prepareFramebuffer(framebuffer, texture_fb);
7667
7668                 /* Draw */
7669                 executeDrawCall(test_case_index);
7670
7671 #if USE_NSIGHT
7672                 m_context.getRenderContext().postIterate();
7673 #endif
7674
7675                 /* Check results */
7676                 if (false == checkResults(test_case_index, texture_fb))
7677                 {
7678                         m_context.getTestContext().getLog()
7679                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7680                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7681                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7682
7683                         result = false;
7684                 }
7685         }
7686
7687         /* Compute */
7688         if (true == isComputeRelevant(test_case_index))
7689         {
7690                 Utils::Buffer     buffer_u_cs(m_context);
7691                 Utils::Program   program(m_context);
7692                 Utils::Texture   texture_im(m_context);
7693                 Utils::VertexArray vao(m_context);
7694
7695                 /* */
7696                 const std::string& compute_shader =
7697                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7698
7699                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7700                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7701
7702                 /* */
7703                 {
7704                         std::stringstream stream;
7705
7706                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7707                         {
7708                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7709                                                                                                         << ". Inspection of compute program interface failed:\n"
7710                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7711
7712                                 return false;
7713                         }
7714                 }
7715
7716                 /* */
7717                 program.Use();
7718
7719                 /* */
7720                 vao.Init();
7721                 vao.Bind();
7722
7723                 /* */
7724                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7725
7726                 /* */
7727                 GLint image_location = program.GetUniformLocation("uni_image");
7728                 prepareImage(image_location, texture_im);
7729
7730                 /* Draw */
7731                 executeDispatchCall(test_case_index);
7732
7733 #if USE_NSIGHT
7734                 m_context.getRenderContext().postIterate();
7735 #endif
7736
7737                 /* Check results */
7738                 if (false == checkResults(test_case_index, texture_im))
7739                 {
7740                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7741                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7742                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7743
7744                         result = false;
7745                 }
7746         }
7747
7748         return result;
7749 }
7750
7751 /** Basic implementation
7752  *
7753  * @param ignored
7754  *
7755  * @return false
7756  **/
7757 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7758 {
7759         return false;
7760 }
7761
7762 /** Basic implementation
7763  *
7764  * @param ignored
7765  *
7766  * @return true
7767  **/
7768 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7769 {
7770         return true;
7771 }
7772
7773 /** Constructor
7774  *
7775  * @param context Test framework context
7776  **/
7777 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7778         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7779 {
7780         /* Nothing to be done here */
7781 }
7782
7783 /** Execute test
7784  *
7785  * @return tcu::TestNode::STOP otherwise
7786  **/
7787 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7788 {
7789         static const GLuint expected_comp = 64;
7790         static const GLuint expected_xfb  = 4;
7791         static const GLuint expected_sep  = 4;
7792         GLint                           max_comp          = 0;
7793         GLint                           max_xfb           = 0;
7794         GLint                           max_sep           = 0;
7795         bool                            test_result   = true;
7796
7797         const Functions& gl = m_context.getRenderContext().getFunctions();
7798
7799         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7800         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7801         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7802         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7803         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7804         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7805
7806         if (expected_xfb > (GLuint)max_xfb)
7807         {
7808                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7809                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7810                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7811
7812                 test_result = false;
7813         }
7814
7815         if (expected_comp > (GLuint)max_comp)
7816         {
7817                 m_context.getTestContext().getLog()
7818                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7819                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7820
7821                 test_result = false;
7822         }
7823
7824         if (expected_sep > (GLuint)max_sep)
7825         {
7826                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7827                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7828                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7829
7830                 test_result = false;
7831         }
7832
7833         /* Set result */
7834         if (true == test_result)
7835         {
7836                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7837         }
7838         else
7839         {
7840                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7841         }
7842
7843         /* Done */
7844         return tcu::TestNode::STOP;
7845 }
7846
7847 /** Constructor
7848  *
7849  * @param context Test framework context
7850  **/
7851 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7852         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7853 {
7854         /* Nothing to be done here */
7855 }
7856
7857 /** Execute test
7858  *
7859  * @return tcu::TestNode::STOP otherwise
7860  **/
7861 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7862 {
7863         GLint              length = 0;
7864         GLchar             name[64];
7865         GLint              param = 0;
7866         Utils::Program program(m_context);
7867         bool               test_result = true;
7868
7869         const Functions& gl = m_context.getRenderContext().getFunctions();
7870
7871         try
7872         {
7873                 program.Init("" /* cs */, "#version 430 core\n"
7874                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7875                                                                   "\n"
7876                                                                   "in  vec4 vs_fs;\n"
7877                                                                   "out vec4 fs_out;\n"
7878                                                                   "\n"
7879                                                                   "void main()\n"
7880                                                                   "{\n"
7881                                                                   "    fs_out = vs_fs;\n"
7882                                                                   "}\n"
7883                                                                   "\n" /* fs */,
7884                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7885                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7886                                                                                                                           "\n"
7887                                                                                                                           "in  vec4 in_vs;\n"
7888                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7889                                                                                                                           "\n"
7890                                                                                                                           "void main()\n"
7891                                                                                                                           "{\n"
7892                                                                                                                           "    vs_fs = in_vs;\n"
7893                                                                                                                           "}\n"
7894                                                                                                                           "\n" /* vs */,
7895                                          false /* separable */);
7896         }
7897         catch (Utils::Shader::InvalidSourceException& exc)
7898         {
7899                 exc.log(m_context);
7900                 TCU_FAIL(exc.what());
7901         }
7902         catch (Utils::Program::BuildException& exc)
7903         {
7904                 TCU_FAIL(exc.what());
7905         }
7906
7907         /*
7908          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
7909          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
7910          * following:
7911          *   * MAX_NAME_LENGTH,
7912          *   * MAX_NUM_ACTIVE_VARIABLES;
7913          */
7914         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
7915         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
7916                            test_result);
7917
7918         /*
7919          * - GetProgramResourceIndex should generate INVALID_ENUM when
7920          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7921          */
7922         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
7923         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7924         /*
7925          * - GetProgramResourceName should generate INVALID_ENUM when
7926          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7927          */
7928         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
7929                                                           name);
7930         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7931
7932         /* Set result */
7933         if (true == test_result)
7934         {
7935                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7936         }
7937         else
7938         {
7939                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7940         }
7941
7942         /* Done */
7943         return tcu::TestNode::STOP;
7944 }
7945
7946 /** Check if error is the expected one.
7947  *
7948  * @param expected_error Expected error
7949  * @param message        Message to log in case of error
7950  * @param test_result    Test result, set to false in case of invalid error
7951  **/
7952 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
7953 {
7954         const Functions& gl = m_context.getRenderContext().getFunctions();
7955
7956         GLenum error = gl.getError();
7957
7958         if (error != expected_error)
7959         {
7960                 m_context.getTestContext().getLog()
7961                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
7962                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
7963
7964                 test_result = false;
7965         }
7966 }
7967
7968 /** Constructor
7969  *
7970  * @param context Test framework context
7971  **/
7972 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
7973         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
7974 {
7975         /* Nothing to be done here */
7976 }
7977
7978 /** Source for given test case and stage
7979  *
7980  * @param test_case_index Index of test case
7981  * @param stage           Shader stage
7982  *
7983  * @return Shader source
7984  **/
7985 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
7986 {
7987         static const GLchar* cs = "#version 430 core\n"
7988                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7989                                                           "\n"
7990                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7991                                                           "\n"
7992                                                           "writeonly uniform uimage2D uni_image;\n"
7993                                                           "\n"
7994                                                           "void main()\n"
7995                                                           "{\n"
7996                                                           "    uint result = 1u;\n"
7997                                                           "    CONSTANT = 3;\n"
7998                                                           "\n"
7999                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8000                                                           "}\n"
8001                                                           "\n";
8002         static const GLchar* fs = "#version 430 core\n"
8003                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8004                                                           "\n"
8005                                                           "in  vec4 gs_fs;\n"
8006                                                           "out vec4 fs_out;\n"
8007                                                           "\n"
8008                                                           "void main()\n"
8009                                                           "{\n"
8010                                                           "ASSIGNMENT"
8011                                                           "    fs_out = gs_fs;\n"
8012                                                           "}\n"
8013                                                           "\n";
8014         static const GLchar* gs = "#version 430 core\n"
8015                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8016                                                           "\n"
8017                                                           "layout(points)                           in;\n"
8018                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8019                                                           "\n"
8020                                                           "in  vec4 tes_gs[];\n"
8021                                                           "out vec4 gs_fs;\n"
8022                                                           "\n"
8023                                                           "void main()\n"
8024                                                           "{\n"
8025                                                           "ASSIGNMENT"
8026                                                           "    gs_fs = tes_gs[0];\n"
8027                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8028                                                           "    EmitVertex();\n"
8029                                                           "    gs_fs = tes_gs[0];\n"
8030                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8031                                                           "    EmitVertex();\n"
8032                                                           "    gs_fs = tes_gs[0];\n"
8033                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8034                                                           "    EmitVertex();\n"
8035                                                           "    gs_fs = tes_gs[0];\n"
8036                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8037                                                           "    EmitVertex();\n"
8038                                                           "}\n"
8039                                                           "\n";
8040         static const GLchar* tcs = "#version 430 core\n"
8041                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8042                                                            "\n"
8043                                                            "layout(vertices = 1) out;\n"
8044                                                            "\n"
8045                                                            "in  vec4 vs_tcs[];\n"
8046                                                            "out vec4 tcs_tes[];\n"
8047                                                            "\n"
8048                                                            "void main()\n"
8049                                                            "{\n"
8050                                                            "\n"
8051                                                            "ASSIGNMENT"
8052                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8053                                                            "\n"
8054                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8055                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8056                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8057                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8058                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8059                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8060                                                            "}\n"
8061                                                            "\n";
8062         static const GLchar* tes = "#version 430 core\n"
8063                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8064                                                            "\n"
8065                                                            "layout(isolines, point_mode) in;\n"
8066                                                            "\n"
8067                                                            "in  vec4 tcs_tes[];\n"
8068                                                            "out vec4 tes_gs;\n"
8069                                                            "\n"
8070                                                            "void main()\n"
8071                                                            "{\n"
8072                                                            "ASSIGNMENT"
8073                                                            "    tes_gs = tcs_tes[0];\n"
8074                                                            "}\n"
8075                                                            "\n";
8076         static const GLchar* vs = "#version 430 core\n"
8077                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8078                                                           "\n"
8079                                                           "in  vec4 in_vs;\n"
8080                                                           "out vec4 vs_tcs;\n"
8081                                                           "\n"
8082                                                           "void main()\n"
8083                                                           "{\n"
8084                                                           "ASSIGNMENT"
8085                                                           "    vs_tcs = in_vs;\n"
8086                                                           "}\n"
8087                                                           "\n";
8088
8089         std::string source;
8090         testCase&   test_case = m_test_cases[test_case_index];
8091
8092         if (Utils::Shader::COMPUTE == test_case.m_stage)
8093         {
8094                 size_t position = 0;
8095
8096                 source = cs;
8097
8098                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8099         }
8100         else
8101         {
8102                 std::string assignment = "    CONSTANT = 3;\n";
8103                 size_t          position   = 0;
8104
8105                 switch (stage)
8106                 {
8107                 case Utils::Shader::FRAGMENT:
8108                         source = fs;
8109                         break;
8110                 case Utils::Shader::GEOMETRY:
8111                         source = gs;
8112                         break;
8113                 case Utils::Shader::TESS_CTRL:
8114                         source = tcs;
8115                         break;
8116                 case Utils::Shader::TESS_EVAL:
8117                         source = tes;
8118                         break;
8119                 case Utils::Shader::VERTEX:
8120                         source = vs;
8121                         break;
8122                 default:
8123                         TCU_FAIL("Invalid enum");
8124                 }
8125
8126                 if (test_case.m_stage == stage)
8127                 {
8128                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8129                 }
8130                 else
8131                 {
8132                         assignment = "";
8133                 }
8134
8135                 position = 0;
8136                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8137         }
8138
8139         return source;
8140 }
8141
8142 /** Get description of test case
8143  *
8144  * @param test_case_index Index of test case
8145  *
8146  * @return Constant name
8147  **/
8148 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8149 {
8150         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8151
8152         return result;
8153 }
8154
8155 /** Get number of test cases
8156  *
8157  * @return Number of test cases
8158  **/
8159 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8160 {
8161         return static_cast<GLuint>(m_test_cases.size());
8162 }
8163
8164 /** Selects if "compute" stage is relevant for test
8165  *
8166  * @param test_case_index Index of test case
8167  *
8168  * @return true when tested stage is compute
8169  **/
8170 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8171 {
8172         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8173 }
8174
8175 /** Prepare all test cases
8176  *
8177  **/
8178 void GLSLContantImmutablityTest::testInit()
8179 {
8180         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8181         {
8182                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8183                 {
8184                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8185
8186                         m_test_cases.push_back(test_case);
8187                 }
8188         }
8189 }
8190
8191 /** Get name of glsl constant
8192  *
8193  * @param Constant id
8194  *
8195  * @return Name of constant used in GLSL
8196  **/
8197 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8198 {
8199         const GLchar* name = "";
8200
8201         switch (constant)
8202         {
8203         case GL_ARB_ENHANCED_LAYOUTS:
8204                 name = "GL_ARB_enhanced_layouts";
8205                 break;
8206         case GL_MAX_XFB:
8207                 name = "gl_MaxTransformFeedbackBuffers";
8208                 break;
8209         case GL_MAX_XFB_INT_COMP:
8210                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8211                 break;
8212         default:
8213                 TCU_FAIL("Invalid enum");
8214         }
8215
8216         return name;
8217 }
8218
8219 /** Constructor
8220  *
8221  * @param context Test framework context
8222  **/
8223 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8224         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8225 {
8226 }
8227
8228 /** Selects if "compute" stage is relevant for test
8229  *
8230  * @param ignored
8231  *
8232  * @return false
8233  **/
8234 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8235 {
8236         return false;
8237 }
8238
8239 /** Prepare code snippet that will verify in and uniform variables
8240  *
8241  * @param ignored
8242  * @param ignored
8243  * @param stage   Shader stage
8244  *
8245  * @return Code that verify variables
8246  **/
8247 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8248                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8249                                                                                                                   Utils::Shader::STAGES stage)
8250 {
8251         /* Get constants */
8252         const Functions& gl = m_context.getRenderContext().getFunctions();
8253
8254         GLint max_transform_feedback_buffers                            = 0;
8255         GLint max_transform_feedback_interleaved_components = 0;
8256
8257         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8258         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8259         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8260         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8261
8262         std::string verification;
8263
8264         if (Utils::Shader::VERTEX == stage)
8265         {
8266                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8267                                            "    {\n"
8268                                            "        result = 0;\n"
8269                                            "    }\n"
8270                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8271                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8272                                            "    {\n"
8273                                            "        result = 0;\n"
8274                                            "    }\n"
8275                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8276                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8277                                            "    {\n"
8278                                            "        result = 0;\n"
8279                                            "    }\n";
8280
8281                 size_t position = 0;
8282                 GLchar buffer[16];
8283
8284                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8285                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8286
8287                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8288                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8289         }
8290         else
8291         {
8292                 verification = "";
8293         }
8294
8295         return verification;
8296 }
8297
8298 /** Constructor
8299  *
8300  * @param context Test framework context
8301  **/
8302 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8303         : TextureTestBase(context, "glsl_constant_integral_expression",
8304                                           "Test verifies that symbols can be used as constant integral expressions")
8305 {
8306 }
8307
8308 /** Get interface of program
8309  *
8310  * @param ignored
8311  * @param program_interface Interface of program
8312  * @param ignored
8313  **/
8314 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8315                                                                                                                          Utils::ProgramInterface& program_interface,
8316                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8317 {
8318         /* Get constants */
8319         const Functions& gl = m_context.getRenderContext().getFunctions();
8320
8321         GLint max_transform_feedback_buffers                            = 0;
8322         GLint max_transform_feedback_interleaved_components = 0;
8323
8324         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8325         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8326         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8327         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8328
8329         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8330         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8331
8332         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8333         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8334
8335         /* Globals */
8336         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8337                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8338                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8339
8340         size_t position = 0;
8341         GLchar buffer[16];
8342
8343         sprintf(buffer, "%d", gohan_div);
8344         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8345
8346         sprintf(buffer, "%d", goten_div);
8347         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8348
8349         program_interface.m_vertex.m_globals    = globals;
8350         program_interface.m_tess_ctrl.m_globals = globals;
8351         program_interface.m_tess_eval.m_globals = globals;
8352         program_interface.m_geometry.m_globals  = globals;
8353         program_interface.m_fragment.m_globals  = globals;
8354         program_interface.m_compute.m_globals   = globals;
8355 }
8356
8357 /** Prepare code snippet that will verify in and uniform variables
8358  *
8359  * @param ignored
8360  * @param ignored
8361  * @param ignored
8362  *
8363  * @return Code that verify variables
8364  **/
8365 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8366                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8367                                                                                                                                            Utils::Shader::STAGES /* stage */)
8368 {
8369         std::string verification = "{\n"
8370                                                            "        uint goku_sum = 0;\n"
8371                                                            "        uint gohan_sum = 0;\n"
8372                                                            "        uint goten_sum = 0;\n"
8373                                                            "\n"
8374                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8375                                                            "        {\n"
8376                                                            "            goku_sum += goku[i];\n"
8377                                                            "        }\n"
8378                                                            "\n"
8379                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8380                                                            "        {\n"
8381                                                            "            gohan_sum += gohan[i];\n"
8382                                                            "        }\n"
8383                                                            "\n"
8384                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8385                                                            "        {\n"
8386                                                            "            goten_sum += goten[i];\n"
8387                                                            "        }\n"
8388                                                            "\n"
8389                                                            "        if ( (1u != goku_sum)  &&\n"
8390                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8391                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8392                                                            "        {\n"
8393                                                            "            result = 0u;\n"
8394                                                            "        }\n"
8395                                                            "    }\n";
8396
8397         size_t position = 0;
8398         GLchar buffer[16];
8399
8400         sprintf(buffer, "%d", m_gohan_length);
8401         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8402
8403         sprintf(buffer, "%d", m_goten_length);
8404         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8405
8406         return verification;
8407 }
8408
8409 /** Prepare unifroms
8410  *
8411  * @param ignored
8412  * @param ignored
8413  * @param program Program object
8414  * @param ignored
8415  **/
8416 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8417                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8418                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8419 {
8420         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8421
8422         const Functions& gl = m_context.getRenderContext().getFunctions();
8423
8424         GLint goku_location  = program.GetUniformLocation("goku");
8425         GLint gohan_location = program.GetUniformLocation("gohan");
8426         GLint goten_location = program.GetUniformLocation("goten");
8427
8428         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8429         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8430         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8431 }
8432
8433 /** Prepare unifroms
8434  *
8435  * @param test_case_index   Pass as param to first implemetnation
8436  * @param program_interface Pass as param to first implemetnation
8437  * @param program           Pass as param to first implemetnation
8438  * @param ignored
8439  * @param ignored
8440  * @param ignored
8441  * @param ignored
8442  * @param vs_buffer         Pass as param to first implemetnation
8443  **/
8444 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8445                                                                                                                  Utils::ProgramInterface& program_interface,
8446                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8447                                                                                                                  Utils::Buffer& /* gs_buffer */,
8448                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8449                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8450 {
8451         /* Call first implementation */
8452         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8453 }
8454
8455 /** Constructor
8456  *
8457  * @param context Test framework context
8458  **/
8459 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8460         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8461                                           "Test verifies offsets and alignment of uniform buffer members")
8462 {
8463 }
8464
8465 /** Get interface of program
8466  *
8467  * @param test_case_index     Test case index
8468  * @param program_interface   Interface of program
8469  * @param varying_passthrough Collection of connections between in and out variables
8470  **/
8471 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8472                                                                                                                            Utils::ProgramInterface&   program_interface,
8473                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8474 {
8475         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8476                                                   "const int type_align = TYPE_ALIGN;\n"
8477                                                   "const int type_size  = TYPE_SIZE;\n";
8478
8479         Utils::Type  type                = getType(test_case_index);
8480         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8481         const GLuint base_align  = type.GetBaseAlignment(false);
8482         const GLuint array_align = type.GetBaseAlignment(true);
8483         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8484         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8485
8486         /* Calculate offsets */
8487         const GLuint first_offset  = 0;
8488         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8489
8490 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8491
8492         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8493         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8494         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8495         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8496         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8497         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8498
8499 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8500
8501         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8502         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
8503         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8504         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8505         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8506         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
8507
8508 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8509
8510         /* Prepare data */
8511         const std::vector<GLubyte>& first  = type.GenerateData();
8512         const std::vector<GLubyte>& second = type.GenerateData();
8513         const std::vector<GLubyte>& third  = type.GenerateData();
8514         const std::vector<GLubyte>& fourth = type.GenerateData();
8515
8516         m_data.resize(eigth_offset + base_stride);
8517         GLubyte* ptr = &m_data[0];
8518         memcpy(ptr + first_offset, &first[0], first.size());
8519         memcpy(ptr + second_offset, &second[0], second.size());
8520         memcpy(ptr + third_offset, &third[0], third.size());
8521         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8522         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8523         memcpy(ptr + sixth_offset, &third[0], third.size());
8524         memcpy(ptr + seventh_offset, &second[0], second.size());
8525         memcpy(ptr + eigth_offset, &first[0], first.size());
8526
8527         /* Prepare globals */
8528         size_t position = 0;
8529         GLchar buffer[16];
8530
8531         sprintf(buffer, "%d", basic_size);
8532         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8533
8534         sprintf(buffer, "%d", type_align);
8535         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8536
8537         sprintf(buffer, "%d", base_stride);
8538         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8539
8540         /* Prepare Block */
8541         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8542
8543         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8544                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8545                                                  first_offset);
8546
8547         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8548                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8549                                                  0 /* n_array_elements */, base_stride, second_offset);
8550
8551         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8552                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8553                                                  third_offset);
8554
8555         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8556                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8557                                                  fourth_offset);
8558
8559         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8560                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8561
8562         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8563                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8564
8565         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8566                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8567                                                  eigth_offset);
8568
8569         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8570
8571         /* Add globals */
8572         vs_si.m_globals = globals;
8573
8574         /* Add uniform BLOCK */
8575         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8576                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8577
8578         /* */
8579         program_interface.CloneVertexInterface(varying_passthrough);
8580 }
8581
8582 /** Get type name
8583  *
8584  * @param test_case_index Index of test case
8585  *
8586  * @return Name of type test in test_case_index
8587  **/
8588 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8589 {
8590         return getTypeName(test_case_index);
8591 }
8592
8593 /** Returns number of types to test
8594  *
8595  * @return Number of types, 34
8596  **/
8597 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8598 {
8599         return getTypesNumber();
8600 }
8601
8602 /** Prepare code snippet that will verify in and uniform variables
8603  *
8604  * @param ignored
8605  * @param ignored
8606  * @param stage   Shader stage
8607  *
8608  * @return Code that verify variables
8609  **/
8610 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8611         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8612 {
8613         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8614                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8615                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8616                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8617                                                            "    {\n"
8618                                                            "        result = 0;\n"
8619                                                            "    }";
8620
8621         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8622
8623         Utils::replaceAllTokens("PREFIX", prefix, verification);
8624
8625         return verification;
8626 }
8627
8628 /** Constructor
8629  *
8630  * @param context Test framework context
8631  **/
8632 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8633         : NegativeTestBase(
8634                   context, "uniform_block_layout_qualifier_conflict",
8635                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8636 {
8637         /* Nothing to be done here */
8638 }
8639
8640 /** Source for given test case and stage
8641  *
8642  * @param test_case_index Index of test case
8643  * @param stage           Shader stage
8644  *
8645  * @return Shader source
8646  **/
8647 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8648                                                                                                                                          Utils::Shader::STAGES stage)
8649 {
8650         static const GLchar* cs = "#version 430 core\n"
8651                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8652                                                           "\n"
8653                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8654                                                           "\n"
8655                                                           "LAYOUTuniform Block {\n"
8656                                                           "    layout(offset = 16) vec4 boy;\n"
8657                                                           "    layout(align  = 64) vec4 man;\n"
8658                                                           "} uni_block;\n"
8659                                                           "\n"
8660                                                           "writeonly uniform image2D uni_image;\n"
8661                                                           "\n"
8662                                                           "void main()\n"
8663                                                           "{\n"
8664                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8665                                                           "\n"
8666                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8667                                                           "}\n"
8668                                                           "\n";
8669         static const GLchar* fs = "#version 430 core\n"
8670                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8671                                                           "\n"
8672                                                           "LAYOUTuniform Block {\n"
8673                                                           "    layout(offset = 16) vec4 boy;\n"
8674                                                           "    layout(align  = 64) vec4 man;\n"
8675                                                           "} uni_block;\n"
8676                                                           "\n"
8677                                                           "in  vec4 gs_fs;\n"
8678                                                           "out vec4 fs_out;\n"
8679                                                           "\n"
8680                                                           "void main()\n"
8681                                                           "{\n"
8682                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8683                                                           "}\n"
8684                                                           "\n";
8685         static const GLchar* gs = "#version 430 core\n"
8686                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8687                                                           "\n"
8688                                                           "layout(points)                           in;\n"
8689                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8690                                                           "\n"
8691                                                           "LAYOUTuniform Block {\n"
8692                                                           "    layout(offset = 16) vec4 boy;\n"
8693                                                           "    layout(align  = 64) vec4 man;\n"
8694                                                           "} uni_block;\n"
8695                                                           "\n"
8696                                                           "in  vec4 tes_gs[];\n"
8697                                                           "out vec4 gs_fs;\n"
8698                                                           "\n"
8699                                                           "void main()\n"
8700                                                           "{\n"
8701                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8702                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8703                                                           "    EmitVertex();\n"
8704                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8705                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8706                                                           "    EmitVertex();\n"
8707                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8708                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8709                                                           "    EmitVertex();\n"
8710                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8711                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8712                                                           "    EmitVertex();\n"
8713                                                           "}\n"
8714                                                           "\n";
8715         static const GLchar* tcs =
8716                 "#version 430 core\n"
8717                 "#extension GL_ARB_enhanced_layouts : require\n"
8718                 "\n"
8719                 "layout(vertices = 1) out;\n"
8720                 "\n"
8721                 "LAYOUTuniform Block {\n"
8722                 "    layout(offset = 16) vec4 boy;\n"
8723                 "    layout(align  = 64) vec4 man;\n"
8724                 "} uni_block;\n"
8725                 "\n"
8726                 "in  vec4 vs_tcs[];\n"
8727                 "out vec4 tcs_tes[];\n"
8728                 "\n"
8729                 "void main()\n"
8730                 "{\n"
8731                 "\n"
8732                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8733                 "\n"
8734                 "    gl_TessLevelOuter[0] = 1.0;\n"
8735                 "    gl_TessLevelOuter[1] = 1.0;\n"
8736                 "    gl_TessLevelOuter[2] = 1.0;\n"
8737                 "    gl_TessLevelOuter[3] = 1.0;\n"
8738                 "    gl_TessLevelInner[0] = 1.0;\n"
8739                 "    gl_TessLevelInner[1] = 1.0;\n"
8740                 "}\n"
8741                 "\n";
8742         static const GLchar* tes = "#version 430 core\n"
8743                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8744                                                            "\n"
8745                                                            "layout(isolines, point_mode) in;\n"
8746                                                            "\n"
8747                                                            "LAYOUTuniform Block {\n"
8748                                                            "    layout(offset = 16) vec4 boy;\n"
8749                                                            "    layout(align  = 64) vec4 man;\n"
8750                                                            "} uni_block;\n"
8751                                                            "\n"
8752                                                            "in  vec4 tcs_tes[];\n"
8753                                                            "out vec4 tes_gs;\n"
8754                                                            "\n"
8755                                                            "void main()\n"
8756                                                            "{\n"
8757                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8758                                                            "}\n"
8759                                                            "\n";
8760         static const GLchar* vs = "#version 430 core\n"
8761                                                           "#extension GL_ARB_enhanced_layouts : require\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 in_vs;\n"
8769                                                           "out vec4 vs_tcs;\n"
8770                                                           "\n"
8771                                                           "void main()\n"
8772                                                           "{\n"
8773                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8774                                                           "}\n"
8775                                                           "\n";
8776
8777         std::string   layout    = "";
8778         size_t            position  = 0;
8779         testCase&        test_case = m_test_cases[test_case_index];
8780         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8781         std::string   source;
8782
8783         if (0 != qualifier[0])
8784         {
8785                 size_t layout_position = 0;
8786
8787                 layout = "layout (QUALIFIER) ";
8788
8789                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8790         }
8791
8792         switch (stage)
8793         {
8794         case Utils::Shader::COMPUTE:
8795                 source = cs;
8796                 break;
8797         case Utils::Shader::FRAGMENT:
8798                 source = fs;
8799                 break;
8800         case Utils::Shader::GEOMETRY:
8801                 source = gs;
8802                 break;
8803         case Utils::Shader::TESS_CTRL:
8804                 source = tcs;
8805                 break;
8806         case Utils::Shader::TESS_EVAL:
8807                 source = tes;
8808                 break;
8809         case Utils::Shader::VERTEX:
8810                 source = vs;
8811                 break;
8812         default:
8813                 TCU_FAIL("Invalid enum");
8814         }
8815
8816         if (test_case.m_stage == stage)
8817         {
8818                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8819         }
8820         else
8821         {
8822                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8823         }
8824
8825         return source;
8826 }
8827
8828 /** Get description of test case
8829  *
8830  * @param test_case_index Index of test case
8831  *
8832  * @return Qualifier name
8833  **/
8834 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8835 {
8836         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8837
8838         return result;
8839 }
8840
8841 /** Get number of test cases
8842  *
8843  * @return Number of test cases
8844  **/
8845 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8846 {
8847         return static_cast<GLuint>(m_test_cases.size());
8848 }
8849
8850 /** Selects if "compute" stage is relevant for test
8851  *
8852  * @param test_case_index Index of test case
8853  *
8854  * @return true when tested stage is compute
8855  **/
8856 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8857 {
8858         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8859 }
8860
8861 /** Selects if compilation failure is expected result
8862  *
8863  * @param test_case_index Index of test case
8864  *
8865  * @return false for STD140 cases, true otherwise
8866  **/
8867 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8868 {
8869         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8870 }
8871
8872 /** Prepare all test cases
8873  *
8874  **/
8875 void UniformBlockLayoutQualifierConflictTest::testInit()
8876 {
8877         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8878         {
8879                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8880                 {
8881                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8882
8883                         m_test_cases.push_back(test_case);
8884                 }
8885         }
8886 }
8887
8888 /** Get name of glsl constant
8889  *
8890  * @param Constant id
8891  *
8892  * @return Name of constant used in GLSL
8893  **/
8894 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8895 {
8896         const GLchar* name = "";
8897
8898         switch (qualifier)
8899         {
8900         case DEFAULT:
8901                 name = "";
8902                 break;
8903         case STD140:
8904                 name = "std140";
8905                 break;
8906         case SHARED:
8907                 name = "shared";
8908                 break;
8909         case PACKED:
8910                 name = "packed";
8911                 break;
8912         default:
8913                 TCU_FAIL("Invalid enum");
8914         }
8915
8916         return name;
8917 }
8918
8919 /** Constructor
8920  *
8921  * @param context Test framework context
8922  **/
8923 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
8924         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
8925                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
8926 {
8927         /* Nothing to be done here */
8928 }
8929
8930 /** Constructor
8931  *
8932  * @param context     Test framework context
8933  * @param name        Test name
8934  * @param description Test description
8935  **/
8936 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
8937         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
8938         : NegativeTestBase(context, name, description)
8939 {
8940         /* Nothing to be done here */
8941 }
8942
8943 /** Source for given test case and stage
8944  *
8945  * @param test_case_index Index of test case
8946  * @param stage           Shader stage
8947  *
8948  * @return Shader source
8949  **/
8950 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
8951                                                                                                                                                   Utils::Shader::STAGES stage)
8952 {
8953         static const GLchar* cs = "#version 430 core\n"
8954                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8955                                                           "\n"
8956                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8957                                                           "\n"
8958                                                           "layout (std140) uniform Block {\n"
8959                                                           "    layout (offset = OFFSET) TYPE member;\n"
8960                                                           "} block;\n"
8961                                                           "\n"
8962                                                           "writeonly uniform image2D uni_image;\n"
8963                                                           "\n"
8964                                                           "void main()\n"
8965                                                           "{\n"
8966                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
8967                                                           "\n"
8968                                                           "    if (TYPE(1) == block.member)\n"
8969                                                           "    {\n"
8970                                                           "        result = vec4(1, 1, 1, 1);\n"
8971                                                           "    }\n"
8972                                                           "\n"
8973                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8974                                                           "}\n"
8975                                                           "\n";
8976         static const GLchar* fs = "#version 430 core\n"
8977                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8978                                                           "\n"
8979                                                           "in  vec4 gs_fs;\n"
8980                                                           "out vec4 fs_out;\n"
8981                                                           "\n"
8982                                                           "void main()\n"
8983                                                           "{\n"
8984                                                           "    fs_out = gs_fs;\n"
8985                                                           "}\n"
8986                                                           "\n";
8987         static const GLchar* fs_tested = "#version 430 core\n"
8988                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
8989                                                                          "\n"
8990                                                                          "layout (std140) uniform Block {\n"
8991                                                                          "    layout (offset = OFFSET) TYPE member;\n"
8992                                                                          "} block;\n"
8993                                                                          "\n"
8994                                                                          "in  vec4 gs_fs;\n"
8995                                                                          "out vec4 fs_out;\n"
8996                                                                          "\n"
8997                                                                          "void main()\n"
8998                                                                          "{\n"
8999                                                                          "    if (TYPE(1) == block.member)\n"
9000                                                                          "    {\n"
9001                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9002                                                                          "    }\n"
9003                                                                          "\n"
9004                                                                          "    fs_out += gs_fs;\n"
9005                                                                          "}\n"
9006                                                                          "\n";
9007         static const GLchar* gs = "#version 430 core\n"
9008                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9009                                                           "\n"
9010                                                           "layout(points)                           in;\n"
9011                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9012                                                           "\n"
9013                                                           "in  vec4 tes_gs[];\n"
9014                                                           "out vec4 gs_fs;\n"
9015                                                           "\n"
9016                                                           "void main()\n"
9017                                                           "{\n"
9018                                                           "    gs_fs = tes_gs[0];\n"
9019                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9020                                                           "    EmitVertex();\n"
9021                                                           "    gs_fs = tes_gs[0];\n"
9022                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9023                                                           "    EmitVertex();\n"
9024                                                           "    gs_fs = tes_gs[0];\n"
9025                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9026                                                           "    EmitVertex();\n"
9027                                                           "    gs_fs = tes_gs[0];\n"
9028                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9029                                                           "    EmitVertex();\n"
9030                                                           "}\n"
9031                                                           "\n";
9032         static const GLchar* gs_tested = "#version 430 core\n"
9033                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9034                                                                          "\n"
9035                                                                          "layout(points)                           in;\n"
9036                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9037                                                                          "\n"
9038                                                                          "layout (std140) uniform Block {\n"
9039                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9040                                                                          "} block;\n"
9041                                                                          "\n"
9042                                                                          "in  vec4 tes_gs[];\n"
9043                                                                          "out vec4 gs_fs;\n"
9044                                                                          "\n"
9045                                                                          "void main()\n"
9046                                                                          "{\n"
9047                                                                          "    if (TYPE(1) == block.member)\n"
9048                                                                          "    {\n"
9049                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9050                                                                          "    }\n"
9051                                                                          "\n"
9052                                                                          "    gs_fs += tes_gs[0];\n"
9053                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9054                                                                          "    EmitVertex();\n"
9055                                                                          "    gs_fs += tes_gs[0];\n"
9056                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9057                                                                          "    EmitVertex();\n"
9058                                                                          "    gs_fs += tes_gs[0];\n"
9059                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9060                                                                          "    EmitVertex();\n"
9061                                                                          "    gs_fs += tes_gs[0];\n"
9062                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9063                                                                          "    EmitVertex();\n"
9064                                                                          "}\n"
9065                                                                          "\n";
9066         static const GLchar* tcs = "#version 430 core\n"
9067                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9068                                                            "\n"
9069                                                            "layout(vertices = 1) out;\n"
9070                                                            "\n"
9071                                                            "in  vec4 vs_tcs[];\n"
9072                                                            "out vec4 tcs_tes[];\n"
9073                                                            "\n"
9074                                                            "void main()\n"
9075                                                            "{\n"
9076                                                            "\n"
9077                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9078                                                            "\n"
9079                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9080                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9081                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9082                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9083                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9084                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9085                                                            "}\n"
9086                                                            "\n";
9087         static const GLchar* tcs_tested = "#version 430 core\n"
9088                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9089                                                                           "\n"
9090                                                                           "layout(vertices = 1) out;\n"
9091                                                                           "\n"
9092                                                                           "layout (std140) uniform Block {\n"
9093                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9094                                                                           "} block;\n"
9095                                                                           "\n"
9096                                                                           "in  vec4 vs_tcs[];\n"
9097                                                                           "out vec4 tcs_tes[];\n"
9098                                                                           "\n"
9099                                                                           "void main()\n"
9100                                                                           "{\n"
9101                                                                           "    if (TYPE(1) == block.member)\n"
9102                                                                           "    {\n"
9103                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9104                                                                           "    }\n"
9105                                                                           "\n"
9106                                                                           "\n"
9107                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9108                                                                           "\n"
9109                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9110                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9111                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9112                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9113                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9114                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9115                                                                           "}\n"
9116                                                                           "\n";
9117         static const GLchar* tes = "#version 430 core\n"
9118                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9119                                                            "\n"
9120                                                            "layout(isolines, point_mode) in;\n"
9121                                                            "\n"
9122                                                            "in  vec4 tcs_tes[];\n"
9123                                                            "out vec4 tes_gs;\n"
9124                                                            "\n"
9125                                                            "void main()\n"
9126                                                            "{\n"
9127                                                            "    tes_gs = tcs_tes[0];\n"
9128                                                            "}\n"
9129                                                            "\n";
9130         static const GLchar* tes_tested = "#version 430 core\n"
9131                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9132                                                                           "\n"
9133                                                                           "layout(isolines, point_mode) in;\n"
9134                                                                           "\n"
9135                                                                           "layout (std140) uniform Block {\n"
9136                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9137                                                                           "} block;\n"
9138                                                                           "\n"
9139                                                                           "in  vec4 tcs_tes[];\n"
9140                                                                           "out vec4 tes_gs;\n"
9141                                                                           "\n"
9142                                                                           "void main()\n"
9143                                                                           "{\n"
9144                                                                           "    if (TYPE(1) == block.member)\n"
9145                                                                           "    {\n"
9146                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9147                                                                           "    }\n"
9148                                                                           "\n"
9149                                                                           "    tes_gs += tcs_tes[0];\n"
9150                                                                           "}\n"
9151                                                                           "\n";
9152         static const GLchar* vs = "#version 430 core\n"
9153                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9154                                                           "\n"
9155                                                           "in  vec4 in_vs;\n"
9156                                                           "out vec4 vs_tcs;\n"
9157                                                           "\n"
9158                                                           "void main()\n"
9159                                                           "{\n"
9160                                                           "    vs_tcs = in_vs;\n"
9161                                                           "}\n"
9162                                                           "\n";
9163         static const GLchar* vs_tested = "#version 430 core\n"
9164                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9165                                                                          "\n"
9166                                                                          "layout (std140) uniform Block {\n"
9167                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9168                                                                          "} block;\n"
9169                                                                          "\n"
9170                                                                          "in  vec4 in_vs;\n"
9171                                                                          "out vec4 vs_tcs;\n"
9172                                                                          "\n"
9173                                                                          "void main()\n"
9174                                                                          "{\n"
9175                                                                          "    if (TYPE(1) == block.member)\n"
9176                                                                          "    {\n"
9177                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9178                                                                          "    }\n"
9179                                                                          "\n"
9180                                                                          "    vs_tcs += in_vs;\n"
9181                                                                          "}\n"
9182                                                                          "\n";
9183
9184         std::string source;
9185         testCase&   test_case = m_test_cases[test_case_index];
9186
9187         if (test_case.m_stage == stage)
9188         {
9189                 GLchar                     buffer[16];
9190                 const GLuint       offset       = test_case.m_offset;
9191                 size_t                     position  = 0;
9192                 const Utils::Type& type          = test_case.m_type;
9193                 const GLchar*     type_name = type.GetGLSLTypeName();
9194
9195                 sprintf(buffer, "%d", offset);
9196
9197                 switch (stage)
9198                 {
9199                 case Utils::Shader::COMPUTE:
9200                         source = cs;
9201                         break;
9202                 case Utils::Shader::FRAGMENT:
9203                         source = fs_tested;
9204                         break;
9205                 case Utils::Shader::GEOMETRY:
9206                         source = gs_tested;
9207                         break;
9208                 case Utils::Shader::TESS_CTRL:
9209                         source = tcs_tested;
9210                         break;
9211                 case Utils::Shader::TESS_EVAL:
9212                         source = tes_tested;
9213                         break;
9214                 case Utils::Shader::VERTEX:
9215                         source = vs_tested;
9216                         break;
9217                 default:
9218                         TCU_FAIL("Invalid enum");
9219                 }
9220
9221                 Utils::replaceToken("OFFSET", position, buffer, source);
9222                 Utils::replaceToken("TYPE", position, type_name, source);
9223                 Utils::replaceToken("TYPE", position, type_name, source);
9224         }
9225         else
9226         {
9227                 switch (stage)
9228                 {
9229                 case Utils::Shader::FRAGMENT:
9230                         source = fs;
9231                         break;
9232                 case Utils::Shader::GEOMETRY:
9233                         source = gs;
9234                         break;
9235                 case Utils::Shader::TESS_CTRL:
9236                         source = tcs;
9237                         break;
9238                 case Utils::Shader::TESS_EVAL:
9239                         source = tes;
9240                         break;
9241                 case Utils::Shader::VERTEX:
9242                         source = vs;
9243                         break;
9244                 default:
9245                         TCU_FAIL("Invalid enum");
9246                 }
9247         }
9248
9249         return source;
9250 }
9251
9252 /** Get description of test case
9253  *
9254  * @param test_case_index Index of test case
9255  *
9256  * @return Type name and offset
9257  **/
9258 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9259 {
9260         std::stringstream stream;
9261         testCase&                 test_case = m_test_cases[test_case_index];
9262
9263         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9264
9265         return stream.str();
9266 }
9267
9268 /** Get number of test cases
9269  *
9270  * @return Number of test cases
9271  **/
9272 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9273 {
9274         return static_cast<GLuint>(m_test_cases.size());
9275 }
9276
9277 /** Selects if "compute" stage is relevant for test
9278  *
9279  * @param test_case_index Index of test case
9280  *
9281  * @return true when tested stage is compute
9282  **/
9283 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9284 {
9285         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9286 }
9287
9288 /** Selects if compilation failure is expected result
9289  *
9290  * @param test_case_index Index of test case
9291  *
9292  * @return should_fail field from testCase
9293  **/
9294 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9295 {
9296         return m_test_cases[test_case_index].m_should_fail;
9297 }
9298
9299 /** Checks if stage is supported
9300  *
9301  * @param stage ignored
9302  *
9303  * @return true
9304  **/
9305 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9306 {
9307         return true;
9308 }
9309
9310 /** Prepare all test cases
9311  *
9312  **/
9313 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9314 {
9315         const Functions& gl               = m_context.getRenderContext().getFunctions();
9316         GLint                    max_size = 0;
9317         const GLuint     n_types  = getTypesNumber();
9318         bool                     stage_support[Utils::Shader::STAGE_MAX];
9319
9320         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9321         {
9322                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9323         }
9324
9325         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9326         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9327
9328         for (GLuint i = 0; i < n_types; ++i)
9329         {
9330                 const Utils::Type& type           = getType(i);
9331                 const GLuint       alignment  = type.GetBaseAlignment(false);
9332                 const GLuint       type_size  = type.GetSize();
9333                 const GLuint       sec_to_end = max_size - 2 * type_size;
9334
9335                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9336                 {
9337                         if (false == stage_support[stage])
9338                         {
9339                                 continue;
9340                         }
9341
9342                         for (GLuint offset = 0; offset <= type_size; ++offset)
9343                         {
9344                                 const GLuint modulo              = offset % alignment;
9345                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9346                                 const bool   should_fail = !is_aligned;
9347
9348                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9349
9350                                 m_test_cases.push_back(test_case);
9351                         }
9352
9353                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9354                         {
9355                                 const GLuint modulo              = offset % alignment;
9356                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9357                                 const bool   should_fail = !is_aligned;
9358
9359                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9360
9361                                 m_test_cases.push_back(test_case);
9362                         }
9363                 }
9364         }
9365 }
9366
9367 /** Constructor
9368  *
9369  * @param context Test framework context
9370  **/
9371 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9372         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9373                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9374 {
9375         /* Nothing to be done here */
9376 }
9377
9378 /** Constructor
9379  *
9380  * @param context Test framework context
9381  * @param name        Test name
9382  * @param description Test description
9383  **/
9384 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9385                                                                                                                                                                    const glw::GLchar* name,
9386                                                                                                                                                                    const glw::GLchar* description)
9387         : NegativeTestBase(context, name, description)
9388 {
9389         /* Nothing to be done here */
9390 }
9391
9392 /** Source for given test case and stage
9393  *
9394  * @param test_case_index Index of test case
9395  * @param stage           Shader stage
9396  *
9397  * @return Shader source
9398  **/
9399 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9400                                                                                                                                           Utils::Shader::STAGES stage)
9401 {
9402         static const GLchar* cs = "#version 430 core\n"
9403                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9404                                                           "\n"
9405                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9406                                                           "\n"
9407                                                           "layout (std140) uniform Block {\n"
9408                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9409                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9410                                                           "} block;\n"
9411                                                           "\n"
9412                                                           "writeonly uniform image2D uni_image;\n"
9413                                                           "\n"
9414                                                           "void main()\n"
9415                                                           "{\n"
9416                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9417                                                           "\n"
9418                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9419                                                           "        (MAN_TYPE(0) == block.man) )\n"
9420                                                           "    {\n"
9421                                                           "        result = vec4(1, 1, 1, 1);\n"
9422                                                           "    }\n"
9423                                                           "\n"
9424                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9425                                                           "}\n"
9426                                                           "\n";
9427         static const GLchar* fs = "#version 430 core\n"
9428                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9429                                                           "\n"
9430                                                           "in  vec4 gs_fs;\n"
9431                                                           "out vec4 fs_out;\n"
9432                                                           "\n"
9433                                                           "void main()\n"
9434                                                           "{\n"
9435                                                           "    fs_out = gs_fs;\n"
9436                                                           "}\n"
9437                                                           "\n";
9438         static const GLchar* fs_tested = "#version 430 core\n"
9439                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9440                                                                          "\n"
9441                                                                          "layout (std140) uniform Block {\n"
9442                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9443                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9444                                                                          "} block;\n"
9445                                                                          "\n"
9446                                                                          "in  vec4 gs_fs;\n"
9447                                                                          "out vec4 fs_out;\n"
9448                                                                          "\n"
9449                                                                          "void main()\n"
9450                                                                          "{\n"
9451                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9452                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9453                                                                          "    {\n"
9454                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9455                                                                          "    }\n"
9456                                                                          "\n"
9457                                                                          "    fs_out += gs_fs;\n"
9458                                                                          "}\n"
9459                                                                          "\n";
9460         static const GLchar* gs = "#version 430 core\n"
9461                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9462                                                           "\n"
9463                                                           "layout(points)                           in;\n"
9464                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9465                                                           "\n"
9466                                                           "in  vec4 tes_gs[];\n"
9467                                                           "out vec4 gs_fs;\n"
9468                                                           "\n"
9469                                                           "void main()\n"
9470                                                           "{\n"
9471                                                           "    gs_fs = tes_gs[0];\n"
9472                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9473                                                           "    EmitVertex();\n"
9474                                                           "    gs_fs = tes_gs[0];\n"
9475                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9476                                                           "    EmitVertex();\n"
9477                                                           "    gs_fs = tes_gs[0];\n"
9478                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9479                                                           "    EmitVertex();\n"
9480                                                           "    gs_fs = tes_gs[0];\n"
9481                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9482                                                           "    EmitVertex();\n"
9483                                                           "}\n"
9484                                                           "\n";
9485         static const GLchar* gs_tested = "#version 430 core\n"
9486                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9487                                                                          "\n"
9488                                                                          "layout(points)                           in;\n"
9489                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9490                                                                          "\n"
9491                                                                          "layout (std140) uniform Block {\n"
9492                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9493                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9494                                                                          "} block;\n"
9495                                                                          "\n"
9496                                                                          "in  vec4 tes_gs[];\n"
9497                                                                          "out vec4 gs_fs;\n"
9498                                                                          "\n"
9499                                                                          "void main()\n"
9500                                                                          "{\n"
9501                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9502                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9503                                                                          "    {\n"
9504                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9505                                                                          "    }\n"
9506                                                                          "\n"
9507                                                                          "    gs_fs += tes_gs[0];\n"
9508                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9509                                                                          "    EmitVertex();\n"
9510                                                                          "    gs_fs += tes_gs[0];\n"
9511                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9512                                                                          "    EmitVertex();\n"
9513                                                                          "    gs_fs += tes_gs[0];\n"
9514                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9515                                                                          "    EmitVertex();\n"
9516                                                                          "    gs_fs += tes_gs[0];\n"
9517                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9518                                                                          "    EmitVertex();\n"
9519                                                                          "}\n"
9520                                                                          "\n";
9521         static const GLchar* tcs = "#version 430 core\n"
9522                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9523                                                            "\n"
9524                                                            "layout(vertices = 1) out;\n"
9525                                                            "\n"
9526                                                            "in  vec4 vs_tcs[];\n"
9527                                                            "out vec4 tcs_tes[];\n"
9528                                                            "\n"
9529                                                            "void main()\n"
9530                                                            "{\n"
9531                                                            "\n"
9532                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9533                                                            "\n"
9534                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9535                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9536                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9537                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9538                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9539                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9540                                                            "}\n"
9541                                                            "\n";
9542         static const GLchar* tcs_tested = "#version 430 core\n"
9543                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9544                                                                           "\n"
9545                                                                           "layout(vertices = 1) out;\n"
9546                                                                           "\n"
9547                                                                           "layout (std140) uniform Block {\n"
9548                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9549                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9550                                                                           "} block;\n"
9551                                                                           "\n"
9552                                                                           "in  vec4 vs_tcs[];\n"
9553                                                                           "out vec4 tcs_tes[];\n"
9554                                                                           "\n"
9555                                                                           "void main()\n"
9556                                                                           "{\n"
9557                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9558                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9559                                                                           "    {\n"
9560                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9561                                                                           "    }\n"
9562                                                                           "\n"
9563                                                                           "\n"
9564                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9565                                                                           "\n"
9566                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9567                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9568                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9569                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9570                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9571                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9572                                                                           "}\n"
9573                                                                           "\n";
9574         static const GLchar* tes = "#version 430 core\n"
9575                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9576                                                            "\n"
9577                                                            "layout(isolines, point_mode) in;\n"
9578                                                            "\n"
9579                                                            "in  vec4 tcs_tes[];\n"
9580                                                            "out vec4 tes_gs;\n"
9581                                                            "\n"
9582                                                            "void main()\n"
9583                                                            "{\n"
9584                                                            "    tes_gs = tcs_tes[0];\n"
9585                                                            "}\n"
9586                                                            "\n";
9587         static const GLchar* tes_tested = "#version 430 core\n"
9588                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9589                                                                           "\n"
9590                                                                           "layout(isolines, point_mode) in;\n"
9591                                                                           "\n"
9592                                                                           "layout (std140) uniform Block {\n"
9593                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9594                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9595                                                                           "} block;\n"
9596                                                                           "\n"
9597                                                                           "in  vec4 tcs_tes[];\n"
9598                                                                           "out vec4 tes_gs;\n"
9599                                                                           "\n"
9600                                                                           "void main()\n"
9601                                                                           "{\n"
9602                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9603                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9604                                                                           "    {\n"
9605                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9606                                                                           "    }\n"
9607                                                                           "\n"
9608                                                                           "    tes_gs += tcs_tes[0];\n"
9609                                                                           "}\n"
9610                                                                           "\n";
9611         static const GLchar* vs = "#version 430 core\n"
9612                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9613                                                           "\n"
9614                                                           "in  vec4 in_vs;\n"
9615                                                           "out vec4 vs_tcs;\n"
9616                                                           "\n"
9617                                                           "void main()\n"
9618                                                           "{\n"
9619                                                           "    vs_tcs = in_vs;\n"
9620                                                           "}\n"
9621                                                           "\n";
9622         static const GLchar* vs_tested = "#version 430 core\n"
9623                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9624                                                                          "\n"
9625                                                                          "layout (std140) uniform Block {\n"
9626                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9627                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9628                                                                          "} block;\n"
9629                                                                          "\n"
9630                                                                          "in  vec4 in_vs;\n"
9631                                                                          "out vec4 vs_tcs;\n"
9632                                                                          "\n"
9633                                                                          "void main()\n"
9634                                                                          "{\n"
9635                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9636                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9637                                                                          "    {\n"
9638                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9639                                                                          "    }\n"
9640                                                                          "\n"
9641                                                                          "    vs_tcs += in_vs;\n"
9642                                                                          "}\n"
9643                                                                          "\n";
9644
9645         std::string source;
9646         testCase&   test_case = m_test_cases[test_case_index];
9647
9648         if (test_case.m_stage == stage)
9649         {
9650                 GLchar                     buffer[16];
9651                 const GLuint       boy_offset   = test_case.m_boy_offset;
9652                 const Utils::Type& boy_type              = test_case.m_boy_type;
9653                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9654                 const GLuint       man_offset   = test_case.m_man_offset;
9655                 const Utils::Type& man_type              = test_case.m_man_type;
9656                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9657                 size_t                     position              = 0;
9658
9659                 switch (stage)
9660                 {
9661                 case Utils::Shader::COMPUTE:
9662                         source = cs;
9663                         break;
9664                 case Utils::Shader::FRAGMENT:
9665                         source = fs_tested;
9666                         break;
9667                 case Utils::Shader::GEOMETRY:
9668                         source = gs_tested;
9669                         break;
9670                 case Utils::Shader::TESS_CTRL:
9671                         source = tcs_tested;
9672                         break;
9673                 case Utils::Shader::TESS_EVAL:
9674                         source = tes_tested;
9675                         break;
9676                 case Utils::Shader::VERTEX:
9677                         source = vs_tested;
9678                         break;
9679                 default:
9680                         TCU_FAIL("Invalid enum");
9681                 }
9682
9683                 sprintf(buffer, "%d", boy_offset);
9684                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9685                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9686                 sprintf(buffer, "%d", man_offset);
9687                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9688                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9689                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9690                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9691         }
9692         else
9693         {
9694                 switch (stage)
9695                 {
9696                 case Utils::Shader::FRAGMENT:
9697                         source = fs;
9698                         break;
9699                 case Utils::Shader::GEOMETRY:
9700                         source = gs;
9701                         break;
9702                 case Utils::Shader::TESS_CTRL:
9703                         source = tcs;
9704                         break;
9705                 case Utils::Shader::TESS_EVAL:
9706                         source = tes;
9707                         break;
9708                 case Utils::Shader::VERTEX:
9709                         source = vs;
9710                         break;
9711                 default:
9712                         TCU_FAIL("Invalid enum");
9713                 }
9714         }
9715
9716         return source;
9717 }
9718
9719 /** Get description of test case
9720  *
9721  * @param test_case_index Index of test case
9722  *
9723  * @return Type name and offset
9724  **/
9725 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9726 {
9727         std::stringstream stream;
9728         testCase&                 test_case = m_test_cases[test_case_index];
9729
9730         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9731                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9732
9733         return stream.str();
9734 }
9735
9736 /** Get number of test cases
9737  *
9738  * @return Number of test cases
9739  **/
9740 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9741 {
9742         return static_cast<GLuint>(m_test_cases.size());
9743 }
9744
9745 /** Selects if "compute" stage is relevant for test
9746  *
9747  * @param test_case_index Index of test case
9748  *
9749  * @return true when tested stage is compute
9750  **/
9751 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9752 {
9753         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9754 }
9755
9756 /** Checks if stage is supported
9757  *
9758  * @param stage ignored
9759  *
9760  * @return true
9761  **/
9762 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9763 {
9764         return true;
9765 }
9766
9767 /** Prepare all test cases
9768  *
9769  **/
9770 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9771 {
9772         const GLuint n_types = getTypesNumber();
9773         bool             stage_support[Utils::Shader::STAGE_MAX];
9774
9775         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9776         {
9777                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9778         }
9779
9780         for (GLuint i = 0; i < n_types; ++i)
9781         {
9782                 const Utils::Type& boy_type = getType(i);
9783                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9784
9785                 for (GLuint j = 0; j < n_types; ++j)
9786                 {
9787                         const Utils::Type& man_type  = getType(j);
9788                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9789                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9790
9791                         const GLuint boy_offset           = lcm(boy_size, man_size);
9792                         const GLuint man_after_start  = boy_offset + 1;
9793                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9794                         const GLuint man_before_start = boy_offset - man_align;
9795                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9796
9797                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9798                         {
9799                                 if (false == stage_support[stage])
9800                                 {
9801                                         continue;
9802                                 }
9803
9804                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9805                                 {
9806                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9807                                                                                    (Utils::Shader::STAGES)stage };
9808
9809                                         m_test_cases.push_back(test_case);
9810                                 }
9811
9812                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9813                                 {
9814                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9815                                                                                    (Utils::Shader::STAGES)stage };
9816
9817                                         m_test_cases.push_back(test_case);
9818                                 }
9819
9820                                 /* Boy offset, should be fine for both types */
9821                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9822
9823                                 m_test_cases.push_back(test_case);
9824                         }
9825                 }
9826         }
9827 }
9828
9829 /** Find greatest common divisor for a and b
9830  *
9831  * @param a A argument
9832  * @param b B argument
9833  *
9834  * @return Found gcd value
9835  **/
9836 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9837 {
9838         if ((0 != a) && (0 == b))
9839         {
9840                 return a;
9841         }
9842         else
9843         {
9844                 GLuint greater = std::max(a, b);
9845                 GLuint lesser  = std::min(a, b);
9846
9847                 return gcd(lesser, greater % lesser);
9848         }
9849 }
9850
9851 /** Find lowest common multiple for a and b
9852  *
9853  * @param a A argument
9854  * @param b B argument
9855  *
9856  * @return Found gcd value
9857  **/
9858 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9859 {
9860         return (a * b) / gcd(a, b);
9861 }
9862
9863 /** Constructor
9864  *
9865  * @param context Test framework context
9866  **/
9867 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9868         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9869                                            "Test verifies that align qualifier requires value that is a power of 2")
9870 {
9871         /* Nothing to be done here */
9872 }
9873
9874 /** Constructor
9875  *
9876  * @param context Test framework context
9877  * @param name        Test name
9878  * @param description Test description
9879  **/
9880 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9881                                                                                                                                                            const glw::GLchar* name,
9882                                                                                                                                                            const glw::GLchar* description)
9883         : NegativeTestBase(context, name, description)
9884 {
9885         /* Nothing to be done here */
9886 }
9887
9888 /** Source for given test case and stage
9889  *
9890  * @param test_case_index Index of test case
9891  * @param stage           Shader stage
9892  *
9893  * @return Shader source
9894  **/
9895 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
9896 {
9897         static const GLchar* cs = "#version 430 core\n"
9898                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9899                                                           "\n"
9900                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9901                                                           "\n"
9902                                                           "layout (std140) uniform Block {\n"
9903                                                           "    vec4 boy;\n"
9904                                                           "    layout (align = ALIGN) TYPE man;\n"
9905                                                           "} block;\n"
9906                                                           "\n"
9907                                                           "writeonly uniform image2D uni_image;\n"
9908                                                           "\n"
9909                                                           "void main()\n"
9910                                                           "{\n"
9911                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9912                                                           "\n"
9913                                                           "    if (TYPE(0) == block.man)\n"
9914                                                           "    {\n"
9915                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
9916                                                           "    }\n"
9917                                                           "\n"
9918                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9919                                                           "}\n"
9920                                                           "\n";
9921         static const GLchar* fs = "#version 430 core\n"
9922                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9923                                                           "\n"
9924                                                           "in  vec4 gs_fs;\n"
9925                                                           "out vec4 fs_out;\n"
9926                                                           "\n"
9927                                                           "void main()\n"
9928                                                           "{\n"
9929                                                           "    fs_out = gs_fs;\n"
9930                                                           "}\n"
9931                                                           "\n";
9932         static const GLchar* fs_tested = "#version 430 core\n"
9933                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9934                                                                          "\n"
9935                                                                          "layout (std140) uniform Block {\n"
9936                                                                          "    vec4 boy;\n"
9937                                                                          "    layout (align = ALIGN) TYPE man;\n"
9938                                                                          "} block;\n"
9939                                                                          "\n"
9940                                                                          "in  vec4 gs_fs;\n"
9941                                                                          "out vec4 fs_out;\n"
9942                                                                          "\n"
9943                                                                          "void main()\n"
9944                                                                          "{\n"
9945                                                                          "    if (TYPE(0) == block.man)\n"
9946                                                                          "    {\n"
9947                                                                          "        fs_out = block.boy;\n"
9948                                                                          "    }\n"
9949                                                                          "\n"
9950                                                                          "    fs_out += gs_fs;\n"
9951                                                                          "}\n"
9952                                                                          "\n";
9953         static const GLchar* gs = "#version 430 core\n"
9954                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9955                                                           "\n"
9956                                                           "layout(points)                           in;\n"
9957                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9958                                                           "\n"
9959                                                           "in  vec4 tes_gs[];\n"
9960                                                           "out vec4 gs_fs;\n"
9961                                                           "\n"
9962                                                           "void main()\n"
9963                                                           "{\n"
9964                                                           "    gs_fs = tes_gs[0];\n"
9965                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9966                                                           "    EmitVertex();\n"
9967                                                           "    gs_fs = tes_gs[0];\n"
9968                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9969                                                           "    EmitVertex();\n"
9970                                                           "    gs_fs = tes_gs[0];\n"
9971                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9972                                                           "    EmitVertex();\n"
9973                                                           "    gs_fs = tes_gs[0];\n"
9974                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9975                                                           "    EmitVertex();\n"
9976                                                           "}\n"
9977                                                           "\n";
9978         static const GLchar* gs_tested = "#version 430 core\n"
9979                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9980                                                                          "\n"
9981                                                                          "layout(points)                           in;\n"
9982                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9983                                                                          "\n"
9984                                                                          "layout (std140) uniform Block {\n"
9985                                                                          "    vec4 boy;\n"
9986                                                                          "    layout (align = ALIGN) TYPE man;\n"
9987                                                                          "} block;\n"
9988                                                                          "\n"
9989                                                                          "in  vec4 tes_gs[];\n"
9990                                                                          "out vec4 gs_fs;\n"
9991                                                                          "\n"
9992                                                                          "void main()\n"
9993                                                                          "{\n"
9994                                                                          "    if (TYPE(0) == block.man)\n"
9995                                                                          "    {\n"
9996                                                                          "        gs_fs = block.boy;\n"
9997                                                                          "    }\n"
9998                                                                          "\n"
9999                                                                          "    gs_fs += tes_gs[0];\n"
10000                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10001                                                                          "    EmitVertex();\n"
10002                                                                          "    gs_fs += tes_gs[0];\n"
10003                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10004                                                                          "    EmitVertex();\n"
10005                                                                          "    gs_fs += tes_gs[0];\n"
10006                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10007                                                                          "    EmitVertex();\n"
10008                                                                          "    gs_fs += tes_gs[0];\n"
10009                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10010                                                                          "    EmitVertex();\n"
10011                                                                          "}\n"
10012                                                                          "\n";
10013         static const GLchar* tcs = "#version 430 core\n"
10014                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10015                                                            "\n"
10016                                                            "layout(vertices = 1) out;\n"
10017                                                            "\n"
10018                                                            "in  vec4 vs_tcs[];\n"
10019                                                            "out vec4 tcs_tes[];\n"
10020                                                            "\n"
10021                                                            "void main()\n"
10022                                                            "{\n"
10023                                                            "\n"
10024                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10025                                                            "\n"
10026                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10027                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10028                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10029                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10030                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10031                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10032                                                            "}\n"
10033                                                            "\n";
10034         static const GLchar* tcs_tested = "#version 430 core\n"
10035                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10036                                                                           "\n"
10037                                                                           "layout(vertices = 1) out;\n"
10038                                                                           "\n"
10039                                                                           "layout (std140) uniform Block {\n"
10040                                                                           "    vec4 boy;\n"
10041                                                                           "    layout (align = ALIGN) TYPE man;\n"
10042                                                                           "} block;\n"
10043                                                                           "\n"
10044                                                                           "in  vec4 vs_tcs[];\n"
10045                                                                           "out vec4 tcs_tes[];\n"
10046                                                                           "\n"
10047                                                                           "void main()\n"
10048                                                                           "{\n"
10049                                                                           "    if (TYPE(0) == block.man)\n"
10050                                                                           "    {\n"
10051                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10052                                                                           "    }\n"
10053                                                                           "\n"
10054                                                                           "\n"
10055                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10056                                                                           "\n"
10057                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10058                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10059                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10060                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10061                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10062                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10063                                                                           "}\n"
10064                                                                           "\n";
10065         static const GLchar* tes = "#version 430 core\n"
10066                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10067                                                            "\n"
10068                                                            "layout(isolines, point_mode) in;\n"
10069                                                            "\n"
10070                                                            "in  vec4 tcs_tes[];\n"
10071                                                            "out vec4 tes_gs;\n"
10072                                                            "\n"
10073                                                            "void main()\n"
10074                                                            "{\n"
10075                                                            "    tes_gs = tcs_tes[0];\n"
10076                                                            "}\n"
10077                                                            "\n";
10078         static const GLchar* tes_tested = "#version 430 core\n"
10079                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10080                                                                           "\n"
10081                                                                           "layout(isolines, point_mode) in;\n"
10082                                                                           "\n"
10083                                                                           "layout (std140) uniform Block {\n"
10084                                                                           "    vec4 boy;\n"
10085                                                                           "    layout (align = ALIGN) TYPE man;\n"
10086                                                                           "} block;\n"
10087                                                                           "\n"
10088                                                                           "in  vec4 tcs_tes[];\n"
10089                                                                           "out vec4 tes_gs;\n"
10090                                                                           "\n"
10091                                                                           "void main()\n"
10092                                                                           "{\n"
10093                                                                           "    if (TYPE(0) == block.man)\n"
10094                                                                           "    {\n"
10095                                                                           "        tes_gs = block.boy;\n"
10096                                                                           "    }\n"
10097                                                                           "\n"
10098                                                                           "    tes_gs += tcs_tes[0];\n"
10099                                                                           "}\n"
10100                                                                           "\n";
10101         static const GLchar* vs = "#version 430 core\n"
10102                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10103                                                           "\n"
10104                                                           "in  vec4 in_vs;\n"
10105                                                           "out vec4 vs_tcs;\n"
10106                                                           "\n"
10107                                                           "void main()\n"
10108                                                           "{\n"
10109                                                           "    vs_tcs = in_vs;\n"
10110                                                           "}\n"
10111                                                           "\n";
10112         static const GLchar* vs_tested = "#version 430 core\n"
10113                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10114                                                                          "\n"
10115                                                                          "layout (std140) uniform Block {\n"
10116                                                                          "    vec4 boy;\n"
10117                                                                          "    layout (align = ALIGN) TYPE man;\n"
10118                                                                          "} block;\n"
10119                                                                          "\n"
10120                                                                          "in  vec4 in_vs;\n"
10121                                                                          "out vec4 vs_tcs;\n"
10122                                                                          "\n"
10123                                                                          "void main()\n"
10124                                                                          "{\n"
10125                                                                          "    if (TYPE(0) == block.man)\n"
10126                                                                          "    {\n"
10127                                                                          "        vs_tcs = block.boy;\n"
10128                                                                          "    }\n"
10129                                                                          "\n"
10130                                                                          "    vs_tcs += in_vs;\n"
10131                                                                          "}\n"
10132                                                                          "\n";
10133
10134         std::string source;
10135         testCase&   test_case = m_test_cases[test_case_index];
10136
10137         if (test_case.m_stage == stage)
10138         {
10139                 GLchar                     buffer[16];
10140                 const GLuint       alignment = test_case.m_alignment;
10141                 const Utils::Type& type          = test_case.m_type;
10142                 const GLchar*     type_name = type.GetGLSLTypeName();
10143                 size_t                     position  = 0;
10144
10145                 switch (stage)
10146                 {
10147                 case Utils::Shader::COMPUTE:
10148                         source = cs;
10149                         break;
10150                 case Utils::Shader::FRAGMENT:
10151                         source = fs_tested;
10152                         break;
10153                 case Utils::Shader::GEOMETRY:
10154                         source = gs_tested;
10155                         break;
10156                 case Utils::Shader::TESS_CTRL:
10157                         source = tcs_tested;
10158                         break;
10159                 case Utils::Shader::TESS_EVAL:
10160                         source = tes_tested;
10161                         break;
10162                 case Utils::Shader::VERTEX:
10163                         source = vs_tested;
10164                         break;
10165                 default:
10166                         TCU_FAIL("Invalid enum");
10167                 }
10168
10169                 sprintf(buffer, "%d", alignment);
10170                 Utils::replaceToken("ALIGN", position, buffer, source);
10171                 Utils::replaceToken("TYPE", position, type_name, source);
10172                 Utils::replaceToken("TYPE", position, type_name, source);
10173         }
10174         else
10175         {
10176                 switch (stage)
10177                 {
10178                 case Utils::Shader::FRAGMENT:
10179                         source = fs;
10180                         break;
10181                 case Utils::Shader::GEOMETRY:
10182                         source = gs;
10183                         break;
10184                 case Utils::Shader::TESS_CTRL:
10185                         source = tcs;
10186                         break;
10187                 case Utils::Shader::TESS_EVAL:
10188                         source = tes;
10189                         break;
10190                 case Utils::Shader::VERTEX:
10191                         source = vs;
10192                         break;
10193                 default:
10194                         TCU_FAIL("Invalid enum");
10195                 }
10196         }
10197
10198         return source;
10199 }
10200
10201 /** Get description of test case
10202  *
10203  * @param test_case_index Index of test case
10204  *
10205  * @return Type name and offset
10206  **/
10207 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10208 {
10209         std::stringstream stream;
10210         testCase&                 test_case = m_test_cases[test_case_index];
10211
10212         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10213
10214         return stream.str();
10215 }
10216
10217 /** Get number of test cases
10218  *
10219  * @return Number of test cases
10220  **/
10221 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10222 {
10223         return static_cast<GLuint>(m_test_cases.size());
10224 }
10225
10226 /** Selects if "compute" stage is relevant for test
10227  *
10228  * @param test_case_index Index of test case
10229  *
10230  * @return true when tested stage is compute
10231  **/
10232 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10233 {
10234         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10235 }
10236
10237 /** Checks if stage is supported
10238  *
10239  * @param ignored
10240  *
10241  * @return true
10242  **/
10243 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10244 {
10245         return true;
10246 }
10247
10248 /** Selects if compilation failure is expected result
10249  *
10250  * @param test_case_index Index of test case
10251  *
10252  * @return should_fail field from testCase
10253  **/
10254 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10255 {
10256         return m_test_cases[test_case_index].m_should_fail;
10257 }
10258
10259 /** Prepare all test cases
10260  *
10261  **/
10262 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10263 {
10264         static const GLuint dmat4_size = 128;
10265         const GLuint            n_types = getTypesNumber();
10266         bool                            stage_support[Utils::Shader::STAGE_MAX];
10267
10268         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10269         {
10270                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10271         }
10272
10273         for (GLuint j = 0; j < n_types; ++j)
10274         {
10275                 const Utils::Type& type = getType(j);
10276
10277                 for (GLuint align = 0; align <= dmat4_size; ++align)
10278                 {
10279
10280 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10281
10282                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10283
10284 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10285
10286                         const bool should_fail = !isPowerOf2(align);
10287
10288 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10289
10290                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10291                         {
10292                                 if (false == stage_support[stage])
10293                                 {
10294                                         continue;
10295                                 }
10296
10297                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10298
10299                                 m_test_cases.push_back(test_case);
10300                         }
10301                 }
10302         }
10303 }
10304
10305 /** Check if value is power of 2
10306  *
10307  * @param val Tested value
10308  *
10309  * @return true if val is power of 2, false otherwise
10310  **/
10311 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10312 {
10313         if (0 == val)
10314         {
10315                 return false;
10316         }
10317
10318         return (0 == (val & (val - 1)));
10319 }
10320
10321 /** Constructor
10322  *
10323  * @param context Test framework context
10324  **/
10325 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10326         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10327 {
10328 }
10329
10330 /** Get interface of program
10331  *
10332  * @param ignored
10333  * @param program_interface Interface of program
10334  * @param varying_passthrough Collection of connections between in and out variables
10335  **/
10336 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10337                                                                                                         Utils::ProgramInterface&   program_interface,
10338                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10339 {
10340         static const Utils::Type vec4 = Utils::Type::vec4;
10341
10342 #if WRKARD_UNIFORMBLOCKALIGNMENT
10343
10344         static const GLuint block_align = 16;
10345
10346 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10347
10348         static const GLuint block_align = 64;
10349
10350 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10351
10352         static const GLuint vec4_stride = 16;
10353         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10354
10355         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10356          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10357          */
10358         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10359         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10360         const GLuint third_offset =
10361                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10362         const GLuint fourth_offset =
10363                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10364         const GLuint fifth_offset =
10365                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10366         const GLuint sixth_offset =
10367                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10368
10369         Utils::Interface* structure = program_interface.Structure("Data");
10370
10371         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10372                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10373
10374         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10375                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10376                                           Utils::Type::vec4.GetSize() /* offset */);
10377
10378         /* Prepare Block */
10379         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10380
10381         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10382                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10383
10384         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10385                                                  0 /* n_array_elements */, data_stride, second_offset);
10386
10387         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10388                                                  2 /* n_array_elements */, data_stride, third_offset);
10389
10390         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10391                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10392
10393         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10394                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10395
10396         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10397                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10398
10399         const GLuint stride = calculateStride(*vs_uni_block);
10400         m_data.resize(stride);
10401         generateData(*vs_uni_block, 0, m_data);
10402
10403         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10404
10405 /* Add uniform BLOCK */
10406 #if WRKARD_UNIFORMBLOCKALIGNMENT
10407         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10408                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10409 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10410         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10411                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10412 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10413
10414         program_interface.CloneVertexInterface(varying_passthrough);
10415 }
10416
10417 /** Constructor
10418  *
10419  * @param context Test framework context
10420  **/
10421 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10422         : TextureTestBase(context, "ssb_member_offset_and_align",
10423                                           "Test verifies offsets and alignment of storage buffer members")
10424 {
10425 }
10426
10427 /** Get interface of program
10428  *
10429  * @param test_case_index     Test case index
10430  * @param program_interface   Interface of program
10431  * @param varying_passthrough Collection of connections between in and out variables
10432  **/
10433 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10434                                                                                                           Utils::ProgramInterface&   program_interface,
10435                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10436 {
10437         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10438                                                   "const int type_align = TYPE_ALIGN;\n"
10439                                                   "const int type_size  = TYPE_SIZE;\n";
10440
10441         Utils::Type  type                = getType(test_case_index);
10442         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10443         const GLuint base_align  = type.GetBaseAlignment(false);
10444         const GLuint array_align = type.GetBaseAlignment(true);
10445         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10446         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10447
10448         /* Calculate offsets */
10449         const GLuint first_offset  = 0;
10450         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10451
10452 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10453
10454         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10455         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10456         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10457         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10458         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10459         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10460
10461 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10462
10463         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10464         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
10465         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10466         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10467         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10468         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
10469
10470 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10471
10472         /* Prepare data */
10473         const std::vector<GLubyte>& first  = type.GenerateData();
10474         const std::vector<GLubyte>& second = type.GenerateData();
10475         const std::vector<GLubyte>& third  = type.GenerateData();
10476         const std::vector<GLubyte>& fourth = type.GenerateData();
10477
10478         m_data.resize(eigth_offset + base_stride);
10479         GLubyte* ptr = &m_data[0];
10480         memcpy(ptr + first_offset, &first[0], first.size());
10481         memcpy(ptr + second_offset, &second[0], second.size());
10482         memcpy(ptr + third_offset, &third[0], third.size());
10483         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10484         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10485         memcpy(ptr + sixth_offset, &third[0], third.size());
10486         memcpy(ptr + seventh_offset, &second[0], second.size());
10487         memcpy(ptr + eigth_offset, &first[0], first.size());
10488
10489         /* Prepare globals */
10490         size_t position = 0;
10491         GLchar buffer[16];
10492
10493         sprintf(buffer, "%d", basic_size);
10494         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10495
10496         sprintf(buffer, "%d", type_align);
10497         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10498
10499         sprintf(buffer, "%d", base_stride);
10500         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10501
10502         /* Prepare Block */
10503         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10504
10505         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10506                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10507                                                  first_offset);
10508
10509         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10510                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10511                                                  0 /* n_array_elements */, base_stride, second_offset);
10512
10513         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10514                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10515                                                  third_offset);
10516
10517         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10518                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10519                                                  fourth_offset);
10520
10521         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10522                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10523
10524         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10525                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10526
10527         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10528                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10529                                                  eigth_offset);
10530
10531         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10532
10533         /* Add globals */
10534         vs_si.m_globals = globals;
10535
10536         /* Add uniform BLOCK */
10537         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10538                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10539
10540         /* */
10541         program_interface.CloneVertexInterface(varying_passthrough);
10542 }
10543
10544 /** Get type name
10545  *
10546  * @param test_case_index Index of test case
10547  *
10548  * @return Name of type test in test_case_index
10549  **/
10550 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10551 {
10552         return getTypeName(test_case_index);
10553 }
10554
10555 /** Returns number of types to test
10556  *
10557  * @return Number of types, 34
10558  **/
10559 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10560 {
10561         return getTypesNumber();
10562 }
10563
10564 /** Prepare code snippet that will verify in and uniform variables
10565  *
10566  * @param ignored
10567  * @param ignored
10568  * @param stage   Shader stage
10569  *
10570  * @return Code that verify variables
10571  **/
10572 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10573                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10574                                                                                                                                 Utils::Shader::STAGES stage)
10575 {
10576         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10577                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10578                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10579                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10580                                                            "    {\n"
10581                                                            "        result = 0;\n"
10582                                                            "    }";
10583
10584         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10585
10586         Utils::replaceAllTokens("PREFIX", prefix, verification);
10587
10588         return verification;
10589 }
10590
10591 /** Selects if "draw" stages are relevant for test
10592  *
10593  * @param ignored
10594  *
10595  * @return true if all stages support shader storage buffers, false otherwise
10596  **/
10597 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10598 {
10599         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10600         GLint                    gs_supported_buffers  = 0;
10601         GLint                    tcs_supported_buffers = 0;
10602         GLint                    tes_supported_buffers = 0;
10603         GLint                    vs_supported_buffers  = 0;
10604
10605         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10606         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10607         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10608         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10609
10610         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10611
10612         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10613                         (1 <= vs_supported_buffers));
10614 }
10615
10616 /** Constructor
10617  *
10618  * @param context Test framework context
10619  **/
10620 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10621         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10622                                                                                                                                  "offset and/or align qualifiers are used with storage "
10623                                                                                                                                  "block")
10624 {
10625         /* Nothing to be done here */
10626 }
10627
10628 /** Source for given test case and stage
10629  *
10630  * @param test_case_index Index of test case
10631  * @param stage           Shader stage
10632  *
10633  * @return Shader source
10634  **/
10635 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10636 {
10637         static const GLchar* cs = "#version 430 core\n"
10638                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10639                                                           "\n"
10640                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10641                                                           "\n"
10642                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10643                                                           "    layout(offset = 16) vec4 boy;\n"
10644                                                           "    layout(align  = 64) vec4 man;\n"
10645                                                           "} uni_block;\n"
10646                                                           "\n"
10647                                                           "writeonly uniform image2D uni_image;\n"
10648                                                           "\n"
10649                                                           "void main()\n"
10650                                                           "{\n"
10651                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10652                                                           "\n"
10653                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10654                                                           "}\n"
10655                                                           "\n";
10656         static const GLchar* fs = "#version 430 core\n"
10657                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10658                                                           "\n"
10659                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10660                                                           "    layout(offset = 16) vec4 boy;\n"
10661                                                           "    layout(align  = 64) vec4 man;\n"
10662                                                           "} uni_block;\n"
10663                                                           "\n"
10664                                                           "in  vec4 gs_fs;\n"
10665                                                           "out vec4 fs_out;\n"
10666                                                           "\n"
10667                                                           "void main()\n"
10668                                                           "{\n"
10669                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10670                                                           "}\n"
10671                                                           "\n";
10672         static const GLchar* gs = "#version 430 core\n"
10673                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10674                                                           "\n"
10675                                                           "layout(points)                           in;\n"
10676                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10677                                                           "\n"
10678                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10679                                                           "    layout(offset = 16) vec4 boy;\n"
10680                                                           "    layout(align  = 64) vec4 man;\n"
10681                                                           "} uni_block;\n"
10682                                                           "\n"
10683                                                           "in  vec4 tes_gs[];\n"
10684                                                           "out vec4 gs_fs;\n"
10685                                                           "\n"
10686                                                           "void main()\n"
10687                                                           "{\n"
10688                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10689                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10690                                                           "    EmitVertex();\n"
10691                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10692                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10693                                                           "    EmitVertex();\n"
10694                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10695                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10696                                                           "    EmitVertex();\n"
10697                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10698                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10699                                                           "    EmitVertex();\n"
10700                                                           "}\n"
10701                                                           "\n";
10702         static const GLchar* tcs =
10703                 "#version 430 core\n"
10704                 "#extension GL_ARB_enhanced_layouts : require\n"
10705                 "\n"
10706                 "layout(vertices = 1) out;\n"
10707                 "\n"
10708                 "layout (QUALIFIERbinding = BINDING) buffer tcs_Block {\n"
10709                 "    layout(offset = 16) vec4 boy;\n"
10710                 "    layout(align  = 64) vec4 man;\n"
10711                 "} uni_block;\n"
10712                 "\n"
10713                 "in  vec4 vs_tcs[];\n"
10714                 "out vec4 tcs_tes[];\n"
10715                 "\n"
10716                 "void main()\n"
10717                 "{\n"
10718                 "\n"
10719                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10720                 "\n"
10721                 "    gl_TessLevelOuter[0] = 1.0;\n"
10722                 "    gl_TessLevelOuter[1] = 1.0;\n"
10723                 "    gl_TessLevelOuter[2] = 1.0;\n"
10724                 "    gl_TessLevelOuter[3] = 1.0;\n"
10725                 "    gl_TessLevelInner[0] = 1.0;\n"
10726                 "    gl_TessLevelInner[1] = 1.0;\n"
10727                 "}\n"
10728                 "\n";
10729         static const GLchar* tes = "#version 430 core\n"
10730                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10731                                                            "\n"
10732                                                            "layout(isolines, point_mode) in;\n"
10733                                                            "\n"
10734                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10735                                                            "    layout(offset = 16) vec4 boy;\n"
10736                                                            "    layout(align  = 64) vec4 man;\n"
10737                                                            "} uni_block;\n"
10738                                                            "\n"
10739                                                            "in  vec4 tcs_tes[];\n"
10740                                                            "out vec4 tes_gs;\n"
10741                                                            "\n"
10742                                                            "void main()\n"
10743                                                            "{\n"
10744                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10745                                                            "}\n"
10746                                                            "\n";
10747         static const GLchar* vs = "#version 430 core\n"
10748                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10749                                                           "\n"
10750                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_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 in_vs;\n"
10756                                                           "out vec4 vs_tcs;\n"
10757                                                           "\n"
10758                                                           "void main()\n"
10759                                                           "{\n"
10760                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10761                                                           "}\n"
10762                                                           "\n";
10763
10764         GLchar          buffer[16];
10765         size_t          position = 0;
10766         std::string source;
10767         testCase&   test_case = m_test_cases[test_case_index];
10768         std::string qualifier = getQualifierName(test_case.m_qualifier);
10769
10770         if (false == qualifier.empty())
10771         {
10772                 qualifier.append(", ");
10773         }
10774
10775         sprintf(buffer, "%d", stage);
10776
10777         switch (stage)
10778         {
10779         case Utils::Shader::COMPUTE:
10780                 source = cs;
10781                 break;
10782         case Utils::Shader::FRAGMENT:
10783                 source = fs;
10784                 break;
10785         case Utils::Shader::GEOMETRY:
10786                 source = gs;
10787                 break;
10788         case Utils::Shader::TESS_CTRL:
10789                 source = tcs;
10790                 break;
10791         case Utils::Shader::TESS_EVAL:
10792                 source = tes;
10793                 break;
10794         case Utils::Shader::VERTEX:
10795                 source = vs;
10796                 break;
10797         default:
10798                 TCU_FAIL("Invalid enum");
10799         }
10800
10801         if (test_case.m_stage == stage)
10802         {
10803                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10804         }
10805         else
10806         {
10807                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10808         }
10809
10810         Utils::replaceToken("BINDING", position, buffer, source);
10811
10812         return source;
10813 }
10814
10815 /** Get description of test case
10816  *
10817  * @param test_case_index Index of test case
10818  *
10819  * @return Qualifier name
10820  **/
10821 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10822 {
10823         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10824
10825         return result;
10826 }
10827
10828 /** Get number of test cases
10829  *
10830  * @return Number of test cases
10831  **/
10832 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10833 {
10834         return static_cast<GLuint>(m_test_cases.size());
10835 }
10836
10837 /** Selects if "compute" stage is relevant for test
10838  *
10839  * @param test_case_index Index of test case
10840  *
10841  * @return true when tested stage is compute
10842  **/
10843 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10844 {
10845         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10846 }
10847
10848 /** Selects if compilation failure is expected result
10849  *
10850  * @param test_case_index Index of test case
10851  *
10852  * @return false for STD140 and STD430 cases, true otherwise
10853  **/
10854 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10855 {
10856         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10857
10858         return !((STD140 == qualifier) || (STD430 == qualifier));
10859 }
10860
10861 /** Checks if stage is supported
10862  *
10863  * @param stage Shader stage
10864  *
10865  * @return true if supported, false otherwise
10866  **/
10867 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10868 {
10869         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10870         GLint                    max_supported_buffers = 0;
10871         GLenum                   pname                             = 0;
10872
10873         switch (stage)
10874         {
10875         case Utils::Shader::COMPUTE:
10876                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10877                 break;
10878         case Utils::Shader::FRAGMENT:
10879                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10880                 break;
10881         case Utils::Shader::GEOMETRY:
10882                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10883                 break;
10884         case Utils::Shader::TESS_CTRL:
10885                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10886                 break;
10887         case Utils::Shader::TESS_EVAL:
10888                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
10889                 break;
10890         case Utils::Shader::VERTEX:
10891                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
10892                 break;
10893         default:
10894                 TCU_FAIL("Invalid enum");
10895         }
10896
10897         gl.getIntegerv(pname, &max_supported_buffers);
10898         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10899
10900         return 1 <= max_supported_buffers;
10901 }
10902
10903 /** Prepare all test cases
10904  *
10905  **/
10906 void SSBLayoutQualifierConflictTest::testInit()
10907 {
10908         bool stage_support[Utils::Shader::STAGE_MAX];
10909
10910         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10911         {
10912                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10913         }
10914
10915         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
10916         {
10917                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10918                 {
10919                         if (false == stage_support[stage])
10920                         {
10921                                 continue;
10922                         }
10923
10924                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
10925
10926                         m_test_cases.push_back(test_case);
10927                 }
10928         }
10929 }
10930
10931 /** Get name of glsl constant
10932  *
10933  * @param Constant id
10934  *
10935  * @return Name of constant used in GLSL
10936  **/
10937 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
10938 {
10939         const GLchar* name = "";
10940
10941         switch (qualifier)
10942         {
10943         case DEFAULT:
10944                 name = "";
10945                 break;
10946         case STD140:
10947                 name = "std140";
10948                 break;
10949         case STD430:
10950                 name = "std430";
10951                 break;
10952         case SHARED:
10953                 name = "shared";
10954                 break;
10955         case PACKED:
10956                 name = "packed";
10957                 break;
10958         default:
10959                 TCU_FAIL("Invalid enum");
10960         }
10961
10962         return name;
10963 }
10964
10965 /** Constructor
10966  *
10967  * @param context Test framework context
10968  **/
10969 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
10970         : UniformBlockMemberInvalidOffsetAlignmentTest(
10971                   context, "ssb_member_invalid_offset_alignment",
10972                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
10973 {
10974         /* Nothing to be done here */
10975 }
10976
10977 /** Source for given test case and stage
10978  *
10979  * @param test_case_index Index of test case
10980  * @param stage           Shader stage
10981  *
10982  * @return Shader source
10983  **/
10984 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10985 {
10986         static const GLchar* cs = "#version 430 core\n"
10987                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10988                                                           "\n"
10989                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10990                                                           "\n"
10991                                                           "layout (std140) buffer Block {\n"
10992                                                           "    layout (offset = OFFSET) TYPE member;\n"
10993                                                           "} block;\n"
10994                                                           "\n"
10995                                                           "writeonly uniform image2D uni_image;\n"
10996                                                           "\n"
10997                                                           "void main()\n"
10998                                                           "{\n"
10999                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11000                                                           "\n"
11001                                                           "    if (TYPE(1) == block.member)\n"
11002                                                           "    {\n"
11003                                                           "        result = vec4(1, 1, 1, 1);\n"
11004                                                           "    }\n"
11005                                                           "\n"
11006                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11007                                                           "}\n"
11008                                                           "\n";
11009         static const GLchar* fs = "#version 430 core\n"
11010                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11011                                                           "\n"
11012                                                           "in  vec4 gs_fs;\n"
11013                                                           "out vec4 fs_out;\n"
11014                                                           "\n"
11015                                                           "void main()\n"
11016                                                           "{\n"
11017                                                           "    fs_out = gs_fs;\n"
11018                                                           "}\n"
11019                                                           "\n";
11020         static const GLchar* fs_tested = "#version 430 core\n"
11021                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11022                                                                          "\n"
11023                                                                          "layout (std140) buffer Block {\n"
11024                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11025                                                                          "} block;\n"
11026                                                                          "\n"
11027                                                                          "in  vec4 gs_fs;\n"
11028                                                                          "out vec4 fs_out;\n"
11029                                                                          "\n"
11030                                                                          "void main()\n"
11031                                                                          "{\n"
11032                                                                          "    if (TYPE(1) == block.member)\n"
11033                                                                          "    {\n"
11034                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11035                                                                          "    }\n"
11036                                                                          "\n"
11037                                                                          "    fs_out += gs_fs;\n"
11038                                                                          "}\n"
11039                                                                          "\n";
11040         static const GLchar* gs = "#version 430 core\n"
11041                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11042                                                           "\n"
11043                                                           "layout(points)                           in;\n"
11044                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11045                                                           "\n"
11046                                                           "in  vec4 tes_gs[];\n"
11047                                                           "out vec4 gs_fs;\n"
11048                                                           "\n"
11049                                                           "void main()\n"
11050                                                           "{\n"
11051                                                           "    gs_fs = tes_gs[0];\n"
11052                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11053                                                           "    EmitVertex();\n"
11054                                                           "    gs_fs = tes_gs[0];\n"
11055                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11056                                                           "    EmitVertex();\n"
11057                                                           "    gs_fs = tes_gs[0];\n"
11058                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11059                                                           "    EmitVertex();\n"
11060                                                           "    gs_fs = tes_gs[0];\n"
11061                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11062                                                           "    EmitVertex();\n"
11063                                                           "}\n"
11064                                                           "\n";
11065         static const GLchar* gs_tested = "#version 430 core\n"
11066                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11067                                                                          "\n"
11068                                                                          "layout(points)                           in;\n"
11069                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11070                                                                          "\n"
11071                                                                          "layout (std140) buffer Block {\n"
11072                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11073                                                                          "} block;\n"
11074                                                                          "\n"
11075                                                                          "in  vec4 tes_gs[];\n"
11076                                                                          "out vec4 gs_fs;\n"
11077                                                                          "\n"
11078                                                                          "void main()\n"
11079                                                                          "{\n"
11080                                                                          "    if (TYPE(1) == block.member)\n"
11081                                                                          "    {\n"
11082                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11083                                                                          "    }\n"
11084                                                                          "\n"
11085                                                                          "    gs_fs += tes_gs[0];\n"
11086                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11087                                                                          "    EmitVertex();\n"
11088                                                                          "    gs_fs += tes_gs[0];\n"
11089                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11090                                                                          "    EmitVertex();\n"
11091                                                                          "    gs_fs += tes_gs[0];\n"
11092                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11093                                                                          "    EmitVertex();\n"
11094                                                                          "    gs_fs += tes_gs[0];\n"
11095                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11096                                                                          "    EmitVertex();\n"
11097                                                                          "}\n"
11098                                                                          "\n";
11099         static const GLchar* tcs = "#version 430 core\n"
11100                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11101                                                            "\n"
11102                                                            "layout(vertices = 1) out;\n"
11103                                                            "\n"
11104                                                            "in  vec4 vs_tcs[];\n"
11105                                                            "out vec4 tcs_tes[];\n"
11106                                                            "\n"
11107                                                            "void main()\n"
11108                                                            "{\n"
11109                                                            "\n"
11110                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11111                                                            "\n"
11112                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11113                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11114                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11115                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11116                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11117                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11118                                                            "}\n"
11119                                                            "\n";
11120         static const GLchar* tcs_tested = "#version 430 core\n"
11121                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11122                                                                           "\n"
11123                                                                           "layout(vertices = 1) out;\n"
11124                                                                           "\n"
11125                                                                           "layout (std140) buffer Block {\n"
11126                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11127                                                                           "} block;\n"
11128                                                                           "\n"
11129                                                                           "in  vec4 vs_tcs[];\n"
11130                                                                           "out vec4 tcs_tes[];\n"
11131                                                                           "\n"
11132                                                                           "void main()\n"
11133                                                                           "{\n"
11134                                                                           "    if (TYPE(1) == block.member)\n"
11135                                                                           "    {\n"
11136                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11137                                                                           "    }\n"
11138                                                                           "\n"
11139                                                                           "\n"
11140                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11141                                                                           "\n"
11142                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11143                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11144                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11145                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11146                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11147                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11148                                                                           "}\n"
11149                                                                           "\n";
11150         static const GLchar* tes = "#version 430 core\n"
11151                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11152                                                            "\n"
11153                                                            "layout(isolines, point_mode) in;\n"
11154                                                            "\n"
11155                                                            "in  vec4 tcs_tes[];\n"
11156                                                            "out vec4 tes_gs;\n"
11157                                                            "\n"
11158                                                            "void main()\n"
11159                                                            "{\n"
11160                                                            "    tes_gs = tcs_tes[0];\n"
11161                                                            "}\n"
11162                                                            "\n";
11163         static const GLchar* tes_tested = "#version 430 core\n"
11164                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11165                                                                           "\n"
11166                                                                           "layout(isolines, point_mode) in;\n"
11167                                                                           "\n"
11168                                                                           "layout (std140) buffer Block {\n"
11169                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11170                                                                           "} block;\n"
11171                                                                           "\n"
11172                                                                           "in  vec4 tcs_tes[];\n"
11173                                                                           "out vec4 tes_gs;\n"
11174                                                                           "\n"
11175                                                                           "void main()\n"
11176                                                                           "{\n"
11177                                                                           "    if (TYPE(1) == block.member)\n"
11178                                                                           "    {\n"
11179                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11180                                                                           "    }\n"
11181                                                                           "\n"
11182                                                                           "    tes_gs += tcs_tes[0];\n"
11183                                                                           "}\n"
11184                                                                           "\n";
11185         static const GLchar* vs = "#version 430 core\n"
11186                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11187                                                           "\n"
11188                                                           "in  vec4 in_vs;\n"
11189                                                           "out vec4 vs_tcs;\n"
11190                                                           "\n"
11191                                                           "void main()\n"
11192                                                           "{\n"
11193                                                           "    vs_tcs = in_vs;\n"
11194                                                           "}\n"
11195                                                           "\n";
11196         static const GLchar* vs_tested = "#version 430 core\n"
11197                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11198                                                                          "\n"
11199                                                                          "layout (std140) buffer Block {\n"
11200                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11201                                                                          "} block;\n"
11202                                                                          "\n"
11203                                                                          "in  vec4 in_vs;\n"
11204                                                                          "out vec4 vs_tcs;\n"
11205                                                                          "\n"
11206                                                                          "void main()\n"
11207                                                                          "{\n"
11208                                                                          "    if (TYPE(1) == block.member)\n"
11209                                                                          "    {\n"
11210                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11211                                                                          "    }\n"
11212                                                                          "\n"
11213                                                                          "    vs_tcs += in_vs;\n"
11214                                                                          "}\n"
11215                                                                          "\n";
11216
11217         std::string source;
11218         testCase&   test_case = m_test_cases[test_case_index];
11219
11220         if (test_case.m_stage == stage)
11221         {
11222                 GLchar                     buffer[16];
11223                 const GLuint       offset       = test_case.m_offset;
11224                 size_t                     position  = 0;
11225                 const Utils::Type& type          = test_case.m_type;
11226                 const GLchar*     type_name = type.GetGLSLTypeName();
11227
11228                 sprintf(buffer, "%d", offset);
11229
11230                 switch (stage)
11231                 {
11232                 case Utils::Shader::COMPUTE:
11233                         source = cs;
11234                         break;
11235                 case Utils::Shader::FRAGMENT:
11236                         source = fs_tested;
11237                         break;
11238                 case Utils::Shader::GEOMETRY:
11239                         source = gs_tested;
11240                         break;
11241                 case Utils::Shader::TESS_CTRL:
11242                         source = tcs_tested;
11243                         break;
11244                 case Utils::Shader::TESS_EVAL:
11245                         source = tes_tested;
11246                         break;
11247                 case Utils::Shader::VERTEX:
11248                         source = vs_tested;
11249                         break;
11250                 default:
11251                         TCU_FAIL("Invalid enum");
11252                 }
11253
11254                 Utils::replaceToken("OFFSET", position, buffer, source);
11255                 Utils::replaceToken("TYPE", position, type_name, source);
11256                 Utils::replaceToken("TYPE", position, type_name, source);
11257         }
11258         else
11259         {
11260                 switch (stage)
11261                 {
11262                 case Utils::Shader::FRAGMENT:
11263                         source = fs;
11264                         break;
11265                 case Utils::Shader::GEOMETRY:
11266                         source = gs;
11267                         break;
11268                 case Utils::Shader::TESS_CTRL:
11269                         source = tcs;
11270                         break;
11271                 case Utils::Shader::TESS_EVAL:
11272                         source = tes;
11273                         break;
11274                 case Utils::Shader::VERTEX:
11275                         source = vs;
11276                         break;
11277                 default:
11278                         TCU_FAIL("Invalid enum");
11279                 }
11280         }
11281
11282         return source;
11283 }
11284
11285 /** Checks if stage is supported
11286  *
11287  * @param stage Shader stage
11288  *
11289  * @return true if supported, false otherwise
11290  **/
11291 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11292 {
11293         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11294         GLint                    max_supported_buffers = 0;
11295         GLenum                   pname                             = 0;
11296
11297         switch (stage)
11298         {
11299         case Utils::Shader::COMPUTE:
11300                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11301                 break;
11302         case Utils::Shader::FRAGMENT:
11303                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11304                 break;
11305         case Utils::Shader::GEOMETRY:
11306                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11307                 break;
11308         case Utils::Shader::TESS_CTRL:
11309                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11310                 break;
11311         case Utils::Shader::TESS_EVAL:
11312                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11313                 break;
11314         case Utils::Shader::VERTEX:
11315                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11316                 break;
11317         default:
11318                 TCU_FAIL("Invalid enum");
11319         }
11320
11321         gl.getIntegerv(pname, &max_supported_buffers);
11322         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11323
11324         return 1 <= max_supported_buffers;
11325 }
11326
11327 /** Constructor
11328  *
11329  * @param context Test framework context
11330  **/
11331 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11332         : UniformBlockMemberOverlappingOffsetsTest(
11333                   context, "ssb_member_overlapping_offsets",
11334                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11335 {
11336         /* Nothing to be done here */
11337 }
11338
11339 /** Source for given test case and stage
11340  *
11341  * @param test_case_index Index of test case
11342  * @param stage           Shader stage
11343  *
11344  * @return Shader source
11345  **/
11346 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11347 {
11348         static const GLchar* cs = "#version 430 core\n"
11349                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11350                                                           "\n"
11351                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11352                                                           "\n"
11353                                                           "layout (std140) buffer Block {\n"
11354                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11355                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11356                                                           "} block;\n"
11357                                                           "\n"
11358                                                           "writeonly uniform image2D uni_image;\n"
11359                                                           "\n"
11360                                                           "void main()\n"
11361                                                           "{\n"
11362                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11363                                                           "\n"
11364                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11365                                                           "        (MAN_TYPE(0) == block.man) )\n"
11366                                                           "    {\n"
11367                                                           "        result = vec4(1, 1, 1, 1);\n"
11368                                                           "    }\n"
11369                                                           "\n"
11370                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11371                                                           "}\n"
11372                                                           "\n";
11373         static const GLchar* fs = "#version 430 core\n"
11374                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11375                                                           "\n"
11376                                                           "in  vec4 gs_fs;\n"
11377                                                           "out vec4 fs_out;\n"
11378                                                           "\n"
11379                                                           "void main()\n"
11380                                                           "{\n"
11381                                                           "    fs_out = gs_fs;\n"
11382                                                           "}\n"
11383                                                           "\n";
11384         static const GLchar* fs_tested = "#version 430 core\n"
11385                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11386                                                                          "\n"
11387                                                                          "layout (std140) buffer Block {\n"
11388                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11389                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11390                                                                          "} block;\n"
11391                                                                          "\n"
11392                                                                          "in  vec4 gs_fs;\n"
11393                                                                          "out vec4 fs_out;\n"
11394                                                                          "\n"
11395                                                                          "void main()\n"
11396                                                                          "{\n"
11397                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11398                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11399                                                                          "    {\n"
11400                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11401                                                                          "    }\n"
11402                                                                          "\n"
11403                                                                          "    fs_out += gs_fs;\n"
11404                                                                          "}\n"
11405                                                                          "\n";
11406         static const GLchar* gs = "#version 430 core\n"
11407                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11408                                                           "\n"
11409                                                           "layout(points)                           in;\n"
11410                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11411                                                           "\n"
11412                                                           "in  vec4 tes_gs[];\n"
11413                                                           "out vec4 gs_fs;\n"
11414                                                           "\n"
11415                                                           "void main()\n"
11416                                                           "{\n"
11417                                                           "    gs_fs = tes_gs[0];\n"
11418                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11419                                                           "    EmitVertex();\n"
11420                                                           "    gs_fs = tes_gs[0];\n"
11421                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11422                                                           "    EmitVertex();\n"
11423                                                           "    gs_fs = tes_gs[0];\n"
11424                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11425                                                           "    EmitVertex();\n"
11426                                                           "    gs_fs = tes_gs[0];\n"
11427                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11428                                                           "    EmitVertex();\n"
11429                                                           "}\n"
11430                                                           "\n";
11431         static const GLchar* gs_tested = "#version 430 core\n"
11432                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11433                                                                          "\n"
11434                                                                          "layout(points)                           in;\n"
11435                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11436                                                                          "\n"
11437                                                                          "layout (std140) buffer Block {\n"
11438                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11439                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11440                                                                          "} block;\n"
11441                                                                          "\n"
11442                                                                          "in  vec4 tes_gs[];\n"
11443                                                                          "out vec4 gs_fs;\n"
11444                                                                          "\n"
11445                                                                          "void main()\n"
11446                                                                          "{\n"
11447                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11448                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11449                                                                          "    {\n"
11450                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11451                                                                          "    }\n"
11452                                                                          "\n"
11453                                                                          "    gs_fs += tes_gs[0];\n"
11454                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11455                                                                          "    EmitVertex();\n"
11456                                                                          "    gs_fs += tes_gs[0];\n"
11457                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11458                                                                          "    EmitVertex();\n"
11459                                                                          "    gs_fs += tes_gs[0];\n"
11460                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11461                                                                          "    EmitVertex();\n"
11462                                                                          "    gs_fs += tes_gs[0];\n"
11463                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11464                                                                          "    EmitVertex();\n"
11465                                                                          "}\n"
11466                                                                          "\n";
11467         static const GLchar* tcs = "#version 430 core\n"
11468                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11469                                                            "\n"
11470                                                            "layout(vertices = 1) out;\n"
11471                                                            "\n"
11472                                                            "in  vec4 vs_tcs[];\n"
11473                                                            "out vec4 tcs_tes[];\n"
11474                                                            "\n"
11475                                                            "void main()\n"
11476                                                            "{\n"
11477                                                            "\n"
11478                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11479                                                            "\n"
11480                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11481                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11482                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11483                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11484                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11485                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11486                                                            "}\n"
11487                                                            "\n";
11488         static const GLchar* tcs_tested = "#version 430 core\n"
11489                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11490                                                                           "\n"
11491                                                                           "layout(vertices = 1) out;\n"
11492                                                                           "\n"
11493                                                                           "layout (std140) buffer Block {\n"
11494                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11495                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11496                                                                           "} block;\n"
11497                                                                           "\n"
11498                                                                           "in  vec4 vs_tcs[];\n"
11499                                                                           "out vec4 tcs_tes[];\n"
11500                                                                           "\n"
11501                                                                           "void main()\n"
11502                                                                           "{\n"
11503                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11504                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11505                                                                           "    {\n"
11506                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11507                                                                           "    }\n"
11508                                                                           "\n"
11509                                                                           "\n"
11510                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11511                                                                           "\n"
11512                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11513                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11514                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11515                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11516                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11517                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11518                                                                           "}\n"
11519                                                                           "\n";
11520         static const GLchar* tes = "#version 430 core\n"
11521                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11522                                                            "\n"
11523                                                            "layout(isolines, point_mode) in;\n"
11524                                                            "\n"
11525                                                            "in  vec4 tcs_tes[];\n"
11526                                                            "out vec4 tes_gs;\n"
11527                                                            "\n"
11528                                                            "void main()\n"
11529                                                            "{\n"
11530                                                            "    tes_gs = tcs_tes[0];\n"
11531                                                            "}\n"
11532                                                            "\n";
11533         static const GLchar* tes_tested = "#version 430 core\n"
11534                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11535                                                                           "\n"
11536                                                                           "layout(isolines, point_mode) in;\n"
11537                                                                           "\n"
11538                                                                           "layout (std140) buffer Block {\n"
11539                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11540                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11541                                                                           "} block;\n"
11542                                                                           "\n"
11543                                                                           "in  vec4 tcs_tes[];\n"
11544                                                                           "out vec4 tes_gs;\n"
11545                                                                           "\n"
11546                                                                           "void main()\n"
11547                                                                           "{\n"
11548                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11549                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11550                                                                           "    {\n"
11551                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11552                                                                           "    }\n"
11553                                                                           "\n"
11554                                                                           "    tes_gs += tcs_tes[0];\n"
11555                                                                           "}\n"
11556                                                                           "\n";
11557         static const GLchar* vs = "#version 430 core\n"
11558                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11559                                                           "\n"
11560                                                           "in  vec4 in_vs;\n"
11561                                                           "out vec4 vs_tcs;\n"
11562                                                           "\n"
11563                                                           "void main()\n"
11564                                                           "{\n"
11565                                                           "    vs_tcs = in_vs;\n"
11566                                                           "}\n"
11567                                                           "\n";
11568         static const GLchar* vs_tested = "#version 430 core\n"
11569                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11570                                                                          "\n"
11571                                                                          "layout (std140) buffer Block {\n"
11572                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11573                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11574                                                                          "} block;\n"
11575                                                                          "\n"
11576                                                                          "in  vec4 in_vs;\n"
11577                                                                          "out vec4 vs_tcs;\n"
11578                                                                          "\n"
11579                                                                          "void main()\n"
11580                                                                          "{\n"
11581                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11582                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11583                                                                          "    {\n"
11584                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11585                                                                          "    }\n"
11586                                                                          "\n"
11587                                                                          "    vs_tcs += in_vs;\n"
11588                                                                          "}\n"
11589                                                                          "\n";
11590
11591         std::string source;
11592         testCase&   test_case = m_test_cases[test_case_index];
11593
11594         if (test_case.m_stage == stage)
11595         {
11596                 GLchar                     buffer[16];
11597                 const GLuint       boy_offset   = test_case.m_boy_offset;
11598                 const Utils::Type& boy_type              = test_case.m_boy_type;
11599                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11600                 const GLuint       man_offset   = test_case.m_man_offset;
11601                 const Utils::Type& man_type              = test_case.m_man_type;
11602                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11603                 size_t                     position              = 0;
11604
11605                 switch (stage)
11606                 {
11607                 case Utils::Shader::COMPUTE:
11608                         source = cs;
11609                         break;
11610                 case Utils::Shader::FRAGMENT:
11611                         source = fs_tested;
11612                         break;
11613                 case Utils::Shader::GEOMETRY:
11614                         source = gs_tested;
11615                         break;
11616                 case Utils::Shader::TESS_CTRL:
11617                         source = tcs_tested;
11618                         break;
11619                 case Utils::Shader::TESS_EVAL:
11620                         source = tes_tested;
11621                         break;
11622                 case Utils::Shader::VERTEX:
11623                         source = vs_tested;
11624                         break;
11625                 default:
11626                         TCU_FAIL("Invalid enum");
11627                 }
11628
11629                 sprintf(buffer, "%d", boy_offset);
11630                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11631                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11632                 sprintf(buffer, "%d", man_offset);
11633                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11634                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11635                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11636                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11637         }
11638         else
11639         {
11640                 switch (stage)
11641                 {
11642                 case Utils::Shader::FRAGMENT:
11643                         source = fs;
11644                         break;
11645                 case Utils::Shader::GEOMETRY:
11646                         source = gs;
11647                         break;
11648                 case Utils::Shader::TESS_CTRL:
11649                         source = tcs;
11650                         break;
11651                 case Utils::Shader::TESS_EVAL:
11652                         source = tes;
11653                         break;
11654                 case Utils::Shader::VERTEX:
11655                         source = vs;
11656                         break;
11657                 default:
11658                         TCU_FAIL("Invalid enum");
11659                 }
11660         }
11661
11662         return source;
11663 }
11664
11665 /** Checks if stage is supported
11666  *
11667  * @param stage Shader stage
11668  *
11669  * @return true if supported, false otherwise
11670  **/
11671 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11672 {
11673         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11674         GLint                    max_supported_buffers = 0;
11675         GLenum                   pname                             = 0;
11676
11677         switch (stage)
11678         {
11679         case Utils::Shader::COMPUTE:
11680                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11681                 break;
11682         case Utils::Shader::FRAGMENT:
11683                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11684                 break;
11685         case Utils::Shader::GEOMETRY:
11686                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11687                 break;
11688         case Utils::Shader::TESS_CTRL:
11689                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11690                 break;
11691         case Utils::Shader::TESS_EVAL:
11692                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11693                 break;
11694         case Utils::Shader::VERTEX:
11695                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11696                 break;
11697         default:
11698                 TCU_FAIL("Invalid enum");
11699         }
11700
11701         gl.getIntegerv(pname, &max_supported_buffers);
11702         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11703
11704         return 1 <= max_supported_buffers;
11705 }
11706
11707 /** Constructor
11708  *
11709  * @param context Test framework context
11710  **/
11711 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11712         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11713                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11714 {
11715         /* Nothing to be done here */
11716 }
11717
11718 /** Source for given test case and stage
11719  *
11720  * @param test_case_index Index of test case
11721  * @param stage           Shader stage
11722  *
11723  * @return Shader source
11724  **/
11725 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11726 {
11727         static const GLchar* cs = "#version 430 core\n"
11728                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11729                                                           "\n"
11730                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11731                                                           "\n"
11732                                                           "layout (std140) buffer Block {\n"
11733                                                           "    vec4 boy;\n"
11734                                                           "    layout (align = ALIGN) TYPE man;\n"
11735                                                           "} block;\n"
11736                                                           "\n"
11737                                                           "writeonly uniform image2D uni_image;\n"
11738                                                           "\n"
11739                                                           "void main()\n"
11740                                                           "{\n"
11741                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11742                                                           "\n"
11743                                                           "    if (TYPE(0) == block.man)\n"
11744                                                           "    {\n"
11745                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11746                                                           "    }\n"
11747                                                           "\n"
11748                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11749                                                           "}\n"
11750                                                           "\n";
11751         static const GLchar* fs = "#version 430 core\n"
11752                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11753                                                           "\n"
11754                                                           "in  vec4 gs_fs;\n"
11755                                                           "out vec4 fs_out;\n"
11756                                                           "\n"
11757                                                           "void main()\n"
11758                                                           "{\n"
11759                                                           "    fs_out = gs_fs;\n"
11760                                                           "}\n"
11761                                                           "\n";
11762         static const GLchar* fs_tested = "#version 430 core\n"
11763                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11764                                                                          "\n"
11765                                                                          "layout (std140) buffer Block {\n"
11766                                                                          "    vec4 boy;\n"
11767                                                                          "    layout (align = ALIGN) TYPE man;\n"
11768                                                                          "} block;\n"
11769                                                                          "\n"
11770                                                                          "in  vec4 gs_fs;\n"
11771                                                                          "out vec4 fs_out;\n"
11772                                                                          "\n"
11773                                                                          "void main()\n"
11774                                                                          "{\n"
11775                                                                          "    if (TYPE(0) == block.man)\n"
11776                                                                          "    {\n"
11777                                                                          "        fs_out = block.boy;\n"
11778                                                                          "    }\n"
11779                                                                          "\n"
11780                                                                          "    fs_out += gs_fs;\n"
11781                                                                          "}\n"
11782                                                                          "\n";
11783         static const GLchar* gs = "#version 430 core\n"
11784                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11785                                                           "\n"
11786                                                           "layout(points)                           in;\n"
11787                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11788                                                           "\n"
11789                                                           "in  vec4 tes_gs[];\n"
11790                                                           "out vec4 gs_fs;\n"
11791                                                           "\n"
11792                                                           "void main()\n"
11793                                                           "{\n"
11794                                                           "    gs_fs = tes_gs[0];\n"
11795                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11796                                                           "    EmitVertex();\n"
11797                                                           "    gs_fs = tes_gs[0];\n"
11798                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11799                                                           "    EmitVertex();\n"
11800                                                           "    gs_fs = tes_gs[0];\n"
11801                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11802                                                           "    EmitVertex();\n"
11803                                                           "    gs_fs = tes_gs[0];\n"
11804                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11805                                                           "    EmitVertex();\n"
11806                                                           "}\n"
11807                                                           "\n";
11808         static const GLchar* gs_tested = "#version 430 core\n"
11809                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11810                                                                          "\n"
11811                                                                          "layout(points)                           in;\n"
11812                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11813                                                                          "\n"
11814                                                                          "layout (std140) buffer Block {\n"
11815                                                                          "    vec4 boy;\n"
11816                                                                          "    layout (align = ALIGN) TYPE man;\n"
11817                                                                          "} block;\n"
11818                                                                          "\n"
11819                                                                          "in  vec4 tes_gs[];\n"
11820                                                                          "out vec4 gs_fs;\n"
11821                                                                          "\n"
11822                                                                          "void main()\n"
11823                                                                          "{\n"
11824                                                                          "    if (TYPE(0) == block.man)\n"
11825                                                                          "    {\n"
11826                                                                          "        gs_fs = block.boy;\n"
11827                                                                          "    }\n"
11828                                                                          "\n"
11829                                                                          "    gs_fs += tes_gs[0];\n"
11830                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11831                                                                          "    EmitVertex();\n"
11832                                                                          "    gs_fs += tes_gs[0];\n"
11833                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11834                                                                          "    EmitVertex();\n"
11835                                                                          "    gs_fs += tes_gs[0];\n"
11836                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11837                                                                          "    EmitVertex();\n"
11838                                                                          "    gs_fs += tes_gs[0];\n"
11839                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11840                                                                          "    EmitVertex();\n"
11841                                                                          "}\n"
11842                                                                          "\n";
11843         static const GLchar* tcs = "#version 430 core\n"
11844                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11845                                                            "\n"
11846                                                            "layout(vertices = 1) out;\n"
11847                                                            "\n"
11848                                                            "in  vec4 vs_tcs[];\n"
11849                                                            "out vec4 tcs_tes[];\n"
11850                                                            "\n"
11851                                                            "void main()\n"
11852                                                            "{\n"
11853                                                            "\n"
11854                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11855                                                            "\n"
11856                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11857                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11858                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11859                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11860                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11861                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11862                                                            "}\n"
11863                                                            "\n";
11864         static const GLchar* tcs_tested = "#version 430 core\n"
11865                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11866                                                                           "\n"
11867                                                                           "layout(vertices = 1) out;\n"
11868                                                                           "\n"
11869                                                                           "layout (std140) buffer Block {\n"
11870                                                                           "    vec4 boy;\n"
11871                                                                           "    layout (align = ALIGN) TYPE man;\n"
11872                                                                           "} block;\n"
11873                                                                           "\n"
11874                                                                           "in  vec4 vs_tcs[];\n"
11875                                                                           "out vec4 tcs_tes[];\n"
11876                                                                           "\n"
11877                                                                           "void main()\n"
11878                                                                           "{\n"
11879                                                                           "    if (TYPE(0) == block.man)\n"
11880                                                                           "    {\n"
11881                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
11882                                                                           "    }\n"
11883                                                                           "\n"
11884                                                                           "\n"
11885                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11886                                                                           "\n"
11887                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11888                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11889                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11890                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11891                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11892                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11893                                                                           "}\n"
11894                                                                           "\n";
11895         static const GLchar* tes = "#version 430 core\n"
11896                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11897                                                            "\n"
11898                                                            "layout(isolines, point_mode) in;\n"
11899                                                            "\n"
11900                                                            "in  vec4 tcs_tes[];\n"
11901                                                            "out vec4 tes_gs;\n"
11902                                                            "\n"
11903                                                            "void main()\n"
11904                                                            "{\n"
11905                                                            "    tes_gs = tcs_tes[0];\n"
11906                                                            "}\n"
11907                                                            "\n";
11908         static const GLchar* tes_tested = "#version 430 core\n"
11909                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11910                                                                           "\n"
11911                                                                           "layout(isolines, point_mode) in;\n"
11912                                                                           "\n"
11913                                                                           "layout (std140) buffer Block {\n"
11914                                                                           "    vec4 boy;\n"
11915                                                                           "    layout (align = ALIGN) TYPE man;\n"
11916                                                                           "} block;\n"
11917                                                                           "\n"
11918                                                                           "in  vec4 tcs_tes[];\n"
11919                                                                           "out vec4 tes_gs;\n"
11920                                                                           "\n"
11921                                                                           "void main()\n"
11922                                                                           "{\n"
11923                                                                           "    if (TYPE(0) == block.man)\n"
11924                                                                           "    {\n"
11925                                                                           "        tes_gs = block.boy;\n"
11926                                                                           "    }\n"
11927                                                                           "\n"
11928                                                                           "    tes_gs += tcs_tes[0];\n"
11929                                                                           "}\n"
11930                                                                           "\n";
11931         static const GLchar* vs = "#version 430 core\n"
11932                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11933                                                           "\n"
11934                                                           "in  vec4 in_vs;\n"
11935                                                           "out vec4 vs_tcs;\n"
11936                                                           "\n"
11937                                                           "void main()\n"
11938                                                           "{\n"
11939                                                           "    vs_tcs = in_vs;\n"
11940                                                           "}\n"
11941                                                           "\n";
11942         static const GLchar* vs_tested = "#version 430 core\n"
11943                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11944                                                                          "\n"
11945                                                                          "layout (std140) buffer Block {\n"
11946                                                                          "    vec4 boy;\n"
11947                                                                          "    layout (align = ALIGN) TYPE man;\n"
11948                                                                          "} block;\n"
11949                                                                          "\n"
11950                                                                          "in  vec4 in_vs;\n"
11951                                                                          "out vec4 vs_tcs;\n"
11952                                                                          "\n"
11953                                                                          "void main()\n"
11954                                                                          "{\n"
11955                                                                          "    if (TYPE(0) == block.man)\n"
11956                                                                          "    {\n"
11957                                                                          "        vs_tcs = block.boy;\n"
11958                                                                          "    }\n"
11959                                                                          "\n"
11960                                                                          "    vs_tcs += in_vs;\n"
11961                                                                          "}\n"
11962                                                                          "\n";
11963
11964         std::string source;
11965         testCase&   test_case = m_test_cases[test_case_index];
11966
11967         if (test_case.m_stage == stage)
11968         {
11969                 GLchar                     buffer[16];
11970                 const GLuint       alignment = test_case.m_alignment;
11971                 const Utils::Type& type          = test_case.m_type;
11972                 const GLchar*     type_name = type.GetGLSLTypeName();
11973                 size_t                     position  = 0;
11974
11975                 switch (stage)
11976                 {
11977                 case Utils::Shader::COMPUTE:
11978                         source = cs;
11979                         break;
11980                 case Utils::Shader::FRAGMENT:
11981                         source = fs_tested;
11982                         break;
11983                 case Utils::Shader::GEOMETRY:
11984                         source = gs_tested;
11985                         break;
11986                 case Utils::Shader::TESS_CTRL:
11987                         source = tcs_tested;
11988                         break;
11989                 case Utils::Shader::TESS_EVAL:
11990                         source = tes_tested;
11991                         break;
11992                 case Utils::Shader::VERTEX:
11993                         source = vs_tested;
11994                         break;
11995                 default:
11996                         TCU_FAIL("Invalid enum");
11997                 }
11998
11999                 sprintf(buffer, "%d", alignment);
12000                 Utils::replaceToken("ALIGN", position, buffer, source);
12001                 Utils::replaceToken("TYPE", position, type_name, source);
12002                 Utils::replaceToken("TYPE", position, type_name, source);
12003         }
12004         else
12005         {
12006                 switch (stage)
12007                 {
12008                 case Utils::Shader::FRAGMENT:
12009                         source = fs;
12010                         break;
12011                 case Utils::Shader::GEOMETRY:
12012                         source = gs;
12013                         break;
12014                 case Utils::Shader::TESS_CTRL:
12015                         source = tcs;
12016                         break;
12017                 case Utils::Shader::TESS_EVAL:
12018                         source = tes;
12019                         break;
12020                 case Utils::Shader::VERTEX:
12021                         source = vs;
12022                         break;
12023                 default:
12024                         TCU_FAIL("Invalid enum");
12025                 }
12026         }
12027
12028         return source;
12029 }
12030
12031 /** Checks if stage is supported
12032  *
12033  * @param stage Shader stage
12034  *
12035  * @return true if supported, false otherwise
12036  **/
12037 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12038 {
12039         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12040         GLint                    max_supported_buffers = 0;
12041         GLenum                   pname                             = 0;
12042
12043         switch (stage)
12044         {
12045         case Utils::Shader::COMPUTE:
12046                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12047                 break;
12048         case Utils::Shader::FRAGMENT:
12049                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12050                 break;
12051         case Utils::Shader::GEOMETRY:
12052                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12053                 break;
12054         case Utils::Shader::TESS_CTRL:
12055                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12056                 break;
12057         case Utils::Shader::TESS_EVAL:
12058                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12059                 break;
12060         case Utils::Shader::VERTEX:
12061                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12062                 break;
12063         default:
12064                 TCU_FAIL("Invalid enum");
12065         }
12066
12067         gl.getIntegerv(pname, &max_supported_buffers);
12068         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12069
12070         return 1 <= max_supported_buffers;
12071 }
12072
12073 /** Constructor
12074  *
12075  * @param context Test framework context
12076  **/
12077 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12078         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12079 {
12080 }
12081
12082 /** Get interface of program
12083  *
12084  * @param ignored
12085  * @param program_interface Interface of program
12086  * @param varying_passthrough Collection of connections between in and out variables
12087  **/
12088 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12089                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12090 {
12091         static const Utils::Type vec4 = Utils::Type::vec4;
12092
12093 #if WRKARD_UNIFORMBLOCKALIGNMENT
12094
12095         static const GLuint block_align = 16;
12096
12097 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12098
12099         static const GLuint block_align = 64;
12100
12101 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12102
12103         static const GLuint fifth_align = 16;
12104         static const GLuint vec4_stride = 16;
12105         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12106
12107         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12108         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12109         const GLuint third_offset =
12110                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12111         const GLuint fourth_offset =
12112                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12113         const GLuint fifth_offset =
12114                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12115         const GLuint sixth_offset =
12116                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12117
12118         Utils::Interface* structure = program_interface.Structure("Data");
12119
12120         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12121                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12122
12123         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12124                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12125                                           Utils::Type::vec4.GetSize() /* offset */);
12126
12127         /* Prepare Block */
12128         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12129
12130         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12131                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12132
12133         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12134                                                  0 /* n_array_elements */, data_stride, second_offset);
12135
12136         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12137                                                  2 /* n_array_elements */, data_stride, third_offset);
12138
12139         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12140                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12141
12142         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12143                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12144
12145         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12146                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12147
12148         const GLuint stride = calculateStride(*vs_buf_Block);
12149         m_data.resize(stride);
12150         generateData(*vs_buf_Block, 0, m_data);
12151
12152         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12153
12154 /* Add uniform BLOCK */
12155 #if WRKARD_UNIFORMBLOCKALIGNMENT
12156         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12157                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12158 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12159         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12160                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12161 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12162
12163         program_interface.CloneVertexInterface(varying_passthrough);
12164 }
12165
12166 /** Selects if "draw" stages are relevant for test
12167  *
12168  * @param ignored
12169  *
12170  * @return true if all stages support shader storage buffers, false otherwise
12171  **/
12172 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12173 {
12174         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12175         GLint                    gs_supported_buffers  = 0;
12176         GLint                    tcs_supported_buffers = 0;
12177         GLint                    tes_supported_buffers = 0;
12178         GLint                    vs_supported_buffers  = 0;
12179
12180         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12181         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12182         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12183         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12184
12185         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12186
12187         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12188                         (1 <= vs_supported_buffers));
12189 }
12190
12191 /** Constructor
12192  *
12193  * @param context Test framework context
12194  **/
12195 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12196         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12197 {
12198 }
12199
12200 /** Constructor
12201  *
12202  * @param context          Test context
12203  * @param test_name        Name of test
12204  * @param test_description Description of test
12205  **/
12206 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12207                                                                                    const glw::GLchar* test_description)
12208         : TextureTestBase(context, test_name, test_description)
12209 {
12210 }
12211
12212 /** Get interface of program
12213  *
12214  * @param test_case_index     Test case
12215  * @param program_interface   Interface of program
12216  * @param varying_passthrough Collection of connections between in and out variables
12217  **/
12218 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12219                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12220 {
12221         const Utils::Type type = getType(test_case_index);
12222
12223         m_first_data = type.GenerateDataPacked();
12224         m_last_data  = type.GenerateDataPacked();
12225
12226         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12227         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12228         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12229         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12230         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12231 }
12232
12233 /** Get type name
12234  *
12235  * @param test_case_index Index of test case
12236  *
12237  * @return Name of type test in test_case_index
12238  **/
12239 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12240 {
12241         return getTypeName(test_case_index);
12242 }
12243
12244 /** Returns number of types to test
12245  *
12246  * @return Number of types, 34
12247  **/
12248 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12249 {
12250         return getTypesNumber();
12251 }
12252
12253 /** Selects if "compute" stage is relevant for test
12254  *
12255  * @param ignored
12256  *
12257  * @return false
12258  **/
12259 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12260 {
12261         return false;
12262 }
12263
12264 /**
12265  *
12266  *
12267  **/
12268 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12269 {
12270         GLchar          buffer[16];
12271         std::string globals = "const uint first_input_location  = 0u;\n"
12272                                                   "const uint first_output_location = 0u;\n"
12273                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12274                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12275         size_t position = 100; /* Skip first part */
12276
12277         sprintf(buffer, "%d", last_in_loc);
12278         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12279
12280         sprintf(buffer, "%d", last_out_loc);
12281         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12282
12283         return globals;
12284 }
12285
12286 /**
12287  *
12288  **/
12289 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12290                                                                                           Utils::ProgramInterface&   program_interface,
12291                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12292 {
12293         const GLuint array_length  = 1;
12294         const GLuint first_in_loc  = 0;
12295         const GLuint first_out_loc = 0;
12296         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12297         size_t           position         = 0;
12298
12299         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12300
12301         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12302
12303         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12304         const GLchar* qual_first_out = "layout (location = first_output_location)";
12305         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12306         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12307
12308         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12309         const GLuint                    type_size = type.GetSize();
12310
12311         std::string first_in_name  = "PREFIXfirst";
12312         std::string first_out_name = "PREFIXfirst";
12313         std::string last_in_name   = "PREFIXlast";
12314         std::string last_out_name  = "PREFIXlast";
12315
12316         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12317         position = 0;
12318         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12319         position = 0;
12320         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12321         position = 0;
12322         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12323
12324         if (Utils::Shader::FRAGMENT == stage)
12325         {
12326                 qual_first_in = "layout (location = first_input_location) flat";
12327                 qual_last_in  = "layout (location = last_input_location)  flat";
12328         }
12329         if (Utils::Shader::GEOMETRY == stage)
12330         {
12331                 qual_first_out = "layout (location = first_output_location) flat";
12332                 qual_last_out  = "layout (location = last_output_location)  flat";
12333         }
12334
12335         Utils::Variable* first_in = si.Input(
12336                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12337                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12338                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12339
12340         Utils::Variable* last_in =
12341                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12342                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12343                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12344                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12345
12346         if (Utils::Shader::FRAGMENT != stage)
12347         {
12348                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12349
12350                 Utils::Variable* first_out =
12351                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12352                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12353                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12354                                           m_first_data.size() /* data_size */);
12355
12356                 Utils::Variable* last_out = si.Output(
12357                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12358                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12359                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12360
12361                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12362
12363                 varying_passthrough.Add(stage, first_in, first_out);
12364                 varying_passthrough.Add(stage, last_in, last_out);
12365         }
12366         else
12367         {
12368                 /* No outputs for fragment shader, so last_output_location can be 0 */
12369                 si.m_globals = prepareGlobals(last_in_loc, 0);
12370         }
12371 }
12372
12373 /** This test should be run with separable programs
12374  *
12375  * @param ignored
12376  *
12377  * @return true
12378  **/
12379 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12380 {
12381         return false;
12382 }
12383
12384 /* Constants used by VertexAttribLocationsTest */
12385 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12386 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12387 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12388 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12389 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12390
12391 /** Constructor
12392  *
12393  * @param context Test framework context
12394  **/
12395 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12396         : TextureTestBase(context, "vertex_attrib_locations",
12397                                           "Test verifies that attribute locations are respected by drawing operations")
12398 {
12399 }
12400
12401 /** Execute proper draw command for test case
12402  *
12403  * @param test_case_index Index of test case
12404  **/
12405 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12406 {
12407         const Functions& gl = m_context.getRenderContext().getFunctions();
12408
12409         switch (test_case_index)
12410         {
12411         case DRAWARRAYS:
12412                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12413                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12414                 break;
12415         case DRAWARRAYSINSTANCED:
12416                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12417                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12418                 break;
12419         case DRAWELEMENTS:
12420                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL);
12421                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12422                 break;
12423         case DRAWELEMENTSBASEVERTEX:
12424                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_base_vertex);
12425                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12426                 break;
12427         case DRAWELEMENTSINSTANCED:
12428                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances);
12429                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12430                 break;
12431         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12432                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12433                                                                                          m_base_instance);
12434                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12435                 break;
12436         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12437                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12438                                                                                    m_base_vertex);
12439                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12440                 break;
12441         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12442                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL,
12443                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12444                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12445                 break;
12446         default:
12447                 TCU_FAIL("Invalid enum");
12448         }
12449 }
12450
12451 /** Get interface of program
12452  *
12453  * @param ignored
12454  * @param program_interface   Interface of program
12455  * @param ignored
12456  **/
12457 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12458                                                                                                         Utils::ProgramInterface& program_interface,
12459                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12460 {
12461         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12462
12463         /* Globals */
12464         si.m_globals = "const uint vertex_index_location   = 2;\n"
12465                                    "const uint instance_index_location = 5;\n";
12466
12467         /* Attributes */
12468         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12469                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12470                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12471                          (GLvoid*)0 /* data */, 0 /* data_size */);
12472         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12473                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12474                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12475                          (GLvoid*)0 /* data */, 0 /* data_size */);
12476 }
12477
12478 /** Get name of test case
12479  *
12480  * @param test_case_index Index of test case
12481  *
12482  * @return Name of test case
12483  **/
12484 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12485 {
12486         std::string result;
12487
12488         switch (test_case_index)
12489         {
12490         case DRAWARRAYS:
12491                 result = "DrawArrays";
12492                 break;
12493         case DRAWARRAYSINSTANCED:
12494                 result = "DrawArraysInstanced";
12495                 break;
12496         case DRAWELEMENTS:
12497                 result = "DrawElements";
12498                 break;
12499         case DRAWELEMENTSBASEVERTEX:
12500                 result = "DrawElementsBaseVertex";
12501                 break;
12502         case DRAWELEMENTSINSTANCED:
12503                 result = "DrawElementsInstanced";
12504                 break;
12505         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12506                 result = "DrawElementsInstancedBaseInstance";
12507                 break;
12508         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12509                 result = "DrawElementsInstancedBaseVertex";
12510                 break;
12511         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12512                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12513                 break;
12514         default:
12515                 TCU_FAIL("Invalid enum");
12516         }
12517
12518         return result;
12519 }
12520
12521 /** Get number of test cases
12522  *
12523  * @return Number of test cases
12524  **/
12525 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12526 {
12527         return TESTCASES_MAX;
12528 }
12529
12530 /** Prepare code snippet that will verify in and uniform variables
12531  *
12532  * @param ignored
12533  * @param ignored
12534  * @param stage   Shader stage
12535  *
12536  * @return Code that verify variables
12537  **/
12538 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12539                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12540                                                                                                                           Utils::Shader::STAGES stage)
12541 {
12542         std::string verification;
12543
12544         if (Utils::Shader::VERTEX == stage)
12545         {
12546
12547 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12548
12549                 verification = "if (gl_InstanceID != instance_index)\n"
12550                                            "    {\n"
12551                                            "        result = 12u;\n"
12552                                            "    }\n"
12553                                            "    else if (gl_VertexID != vertex_index)\n"
12554                                            "    {\n"
12555                                            "        result = 11u;\n"
12556                                            "    }\n";
12557
12558 #else
12559
12560                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12561                                            "        (gl_InstanceID != instance_index) )\n"
12562                                            "    {\n"
12563                                            "        result = 0u;\n"
12564                                            "    }\n";
12565
12566 #endif
12567         }
12568         else
12569         {
12570                 verification = "";
12571         }
12572
12573         return verification;
12574 }
12575
12576 /** Selects if "compute" stage is relevant for test
12577  *
12578  * @param ignored
12579  *
12580  * @return false
12581  **/
12582 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12583 {
12584         return false;
12585 }
12586
12587 /** Prepare attributes, vertex array object and array buffer
12588  *
12589  * @param ignored
12590  * @param ignored Interface of program
12591  * @param buffer  Array buffer
12592  * @param vao     Vertex array object
12593  **/
12594 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12595                                                                                                   Utils::ProgramInterface& /* program_interface */,
12596                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12597 {
12598         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12599         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12600
12601         std::vector<GLuint> buffer_data;
12602         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12603
12604         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12605
12606         /*
12607          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12608          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12609          */
12610         if (test_case_index >= 2)
12611         {
12612                 buffer.m_buffer = Utils::Buffer::Element;
12613         }
12614         vao.Bind();
12615         buffer.Bind();
12616
12617         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12618                                   0 /* stride */, 0 /* offset */);
12619
12620         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12621                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12622         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12623         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12624         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12625                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12626         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12627                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12628
12629         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12630         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12631
12632         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12633 }
12634
12635 /** This test should be run with separable programs
12636  *
12637  * @param ignored
12638  *
12639  * @return true
12640  **/
12641 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12642 {
12643         return false;
12644 }
12645
12646 /** Constructor
12647  *
12648  * @param context Test framework context
12649  **/
12650 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12651         : VaryingLocationsTest(context, "varying_array_locations",
12652                                                    "Test verifies that input and output locations are respected for arrays")
12653 {
12654 }
12655
12656 /**
12657  *
12658  **/
12659 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12660                                                                                                    Utils::ProgramInterface&   program_interface,
12661                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12662 {
12663         const GLuint array_length  = 1u;
12664         const GLuint first_in_loc  = 0;
12665         const GLuint first_out_loc = 0;
12666         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12667         size_t           position         = 0;
12668
12669         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12670
12671         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12672
12673         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12674         const GLchar* qual_first_out = "layout (location = first_output_location)";
12675         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12676         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12677
12678         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12679         const GLuint                    type_size = type.GetSize();
12680
12681         std::string first_in_name  = "PREFIXfirst";
12682         std::string first_out_name = "PREFIXfirst";
12683         std::string last_in_name   = "PREFIXlast";
12684         std::string last_out_name  = "PREFIXlast";
12685
12686         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12687         position = 0;
12688         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12689         position = 0;
12690         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12691         position = 0;
12692         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12693
12694         if (Utils::Shader::FRAGMENT == stage)
12695         {
12696                 qual_first_in = "layout (location = first_input_location) flat";
12697                 qual_last_in  = "layout (location = last_input_location)  flat";
12698         }
12699         if (Utils::Shader::GEOMETRY == stage)
12700         {
12701                 qual_first_out = "layout (location = first_output_location) flat";
12702                 qual_last_out  = "layout (location = last_output_location)  flat";
12703         }
12704
12705         Utils::Variable* first_in =
12706                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12707                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12708                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12709                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12710
12711         Utils::Variable* last_in =
12712                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12713                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12714                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12715                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12716
12717         if (Utils::Shader::FRAGMENT != stage)
12718         {
12719                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12720
12721                 Utils::Variable* first_out =
12722                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12723                                           first_out_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_out =
12728                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12729                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12730                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12731                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12732
12733                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12734
12735                 varying_passthrough.Add(stage, first_in, first_out);
12736                 varying_passthrough.Add(stage, last_in, last_out);
12737         }
12738         else
12739         {
12740                 /* No outputs for fragment shader, so last_output_location can be 0 */
12741                 si.m_globals = prepareGlobals(last_in_loc, 0);
12742         }
12743 }
12744
12745 /** Constructor
12746  *
12747  * @param context Test framework context
12748  **/
12749 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12750         : TextureTestBase(context, "varying_structure_locations",
12751                                           "Test verifies that locations are respected when structures are used as in and out ")
12752 {
12753 }
12754
12755 /** Prepare code snippet that will pass in variables to out variables
12756  *
12757  * @param ignored
12758  * @param varying_passthrough Collection of connections between in and out variables
12759  * @param stage               Shader stage
12760  *
12761  * @return Code that pass in variables to next stage
12762  **/
12763 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12764                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12765                                                                                                                   Utils::Shader::STAGES          stage)
12766 {
12767         std::string result;
12768
12769         if (Utils::Shader::VERTEX != stage)
12770         {
12771                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12772         }
12773         else
12774         {
12775                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12776                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12777         }
12778
12779         return result;
12780 }
12781
12782 /** Get interface of program
12783  *
12784  * @param test_case_index     Test case
12785  * @param program_interface   Interface of program
12786  * @param varying_passthrough Collection of connections between in and out variables
12787  **/
12788 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12789                                                                                                                 Utils::ProgramInterface&   program_interface,
12790                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12791 {
12792         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12793         const Utils::Type               type = getType(test_case_index);
12794
12795         /* Prepare data */
12796         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12797         m_single_data = type.GenerateDataPacked();
12798         m_array_data  = type.GenerateDataPacked();
12799
12800         m_data.resize(m_single_data.size() + m_array_data.size());
12801         GLubyte* ptr = (GLubyte*)&m_data[0];
12802         memcpy(ptr, &m_single_data[0], m_single_data.size());
12803         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12804
12805         Utils::Interface* structure = program_interface.Structure("Data");
12806
12807         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12808                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12809
12810         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12811         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12812                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12813
12814         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12815                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12816                          m_single_data.size() /* data_size */);
12817
12818         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12819                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12820                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12821
12822         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12823                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12824                           m_data.size() /* data_size */);
12825
12826         program_interface.CloneVertexInterface(varying_passthrough);
12827 }
12828
12829 /** Get type name
12830  *
12831  * @param test_case_index Index of test case
12832  *
12833  * @return Name of type test in test_case_index
12834  **/
12835 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12836 {
12837         return getTypeName(test_case_index);
12838 }
12839
12840 /** Returns number of types to test
12841  *
12842  * @return Number of types, 34
12843  **/
12844 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12845 {
12846         return getTypesNumber();
12847 }
12848
12849 /** Selects if "compute" stage is relevant for test
12850  *
12851  * @param ignored
12852  *
12853  * @return false
12854  **/
12855 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12856 {
12857         return false;
12858 }
12859
12860 /** This test should be run with separable programs
12861  *
12862  * @param ignored
12863  *
12864  * @return true
12865  **/
12866 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12867 {
12868         return false;
12869 }
12870
12871 /** Constructor
12872  *
12873  * @param context          Test context
12874  * @param test_name        Name of test
12875  * @param test_description Description of test
12876  **/
12877 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
12878         : NegativeTestBase(context, "varying_structure_member_location",
12879                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
12880 {
12881 }
12882
12883 /** Source for given test case and stage
12884  *
12885  * @param test_case_index Index of test case
12886  * @param stage           Shader stage
12887  *
12888  * @return Shader source
12889  **/
12890 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
12891 {
12892         static const GLchar* struct_definition = "struct Data {\n"
12893                                                                                          "    vec4 gohan;\n"
12894                                                                                          "    layout (location = 4) vec4 goten;\n"
12895                                                                                          "};\n";
12896         static const GLchar* input_var  = "in Data data;\n";
12897         static const GLchar* output_var = "out Data data;\n";
12898         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
12899         static const GLchar* output_use = "    data.gohan = result / 2;\n"
12900                                                                           "    data.goten = result / 4 - data.gohan;\n";
12901         static const GLchar* fs = "#version 430 core\n"
12902                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12903                                                           "\n"
12904                                                           "in  vec4 gs_fs;\n"
12905                                                           "out vec4 fs_out;\n"
12906                                                           "\n"
12907                                                           "void main()\n"
12908                                                           "{\n"
12909                                                           "    fs_out = gs_fs;\n"
12910                                                           "}\n"
12911                                                           "\n";
12912         static const GLchar* fs_tested = "#version 430 core\n"
12913                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12914                                                                          "\n"
12915                                                                          "STRUCT_DEFINITION"
12916                                                                          "\n"
12917                                                                          "VARIABLE_DEFINITION"
12918                                                                          "\n"
12919                                                                          "in  vec4 gs_fs;\n"
12920                                                                          "out vec4 fs_out;\n"
12921                                                                          "\n"
12922                                                                          "void main()\n"
12923                                                                          "{\n"
12924                                                                          "    vec4 result = gs_fs;\n"
12925                                                                          "\n"
12926                                                                          "VARIABLE_USE"
12927                                                                          "\n"
12928                                                                          "    fs_out += result;\n"
12929                                                                          "}\n"
12930                                                                          "\n";
12931         static const GLchar* gs = "#version 430 core\n"
12932                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12933                                                           "\n"
12934                                                           "layout(points)                           in;\n"
12935                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
12936                                                           "\n"
12937                                                           "in  vec4 tes_gs[];\n"
12938                                                           "out vec4 gs_fs;\n"
12939                                                           "\n"
12940                                                           "void main()\n"
12941                                                           "{\n"
12942                                                           "    gs_fs = tes_gs[0];\n"
12943                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12944                                                           "    EmitVertex();\n"
12945                                                           "    gs_fs = tes_gs[0];\n"
12946                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12947                                                           "    EmitVertex();\n"
12948                                                           "    gs_fs = tes_gs[0];\n"
12949                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
12950                                                           "    EmitVertex();\n"
12951                                                           "    gs_fs = tes_gs[0];\n"
12952                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
12953                                                           "    EmitVertex();\n"
12954                                                           "}\n"
12955                                                           "\n";
12956         static const GLchar* gs_tested = "#version 430 core\n"
12957                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12958                                                                          "\n"
12959                                                                          "layout(points)                           in;\n"
12960                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
12961                                                                          "\n"
12962                                                                          "STRUCT_DEFINITION"
12963                                                                          "\n"
12964                                                                          "VARIABLE_DEFINITION"
12965                                                                          "\n"
12966                                                                          "in  vec4 tes_gs[];\n"
12967                                                                          "out vec4 gs_fs;\n"
12968                                                                          "\n"
12969                                                                          "void main()\n"
12970                                                                          "{\n"
12971                                                                          "    vec4 result = tes_gs[0];\n"
12972                                                                          "\n"
12973                                                                          "VARIABLE_USE"
12974                                                                          "\n"
12975                                                                          "    gs_fs = result;\n"
12976                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12977                                                                          "    EmitVertex();\n"
12978                                                                          "    gs_fs = result;\n"
12979                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12980                                                                          "    EmitVertex();\n"
12981                                                                          "    gs_fs = result;\n"
12982                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
12983                                                                          "    EmitVertex();\n"
12984                                                                          "    gs_fs = result;\n"
12985                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
12986                                                                          "    EmitVertex();\n"
12987                                                                          "}\n"
12988                                                                          "\n";
12989         static const GLchar* tcs = "#version 430 core\n"
12990                                                            "#extension GL_ARB_enhanced_layouts : require\n"
12991                                                            "\n"
12992                                                            "layout(vertices = 1) out;\n"
12993                                                            "\n"
12994                                                            "in  vec4 vs_tcs[];\n"
12995                                                            "out vec4 tcs_tes[];\n"
12996                                                            "\n"
12997                                                            "void main()\n"
12998                                                            "{\n"
12999                                                            "\n"
13000                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13001                                                            "\n"
13002                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13003                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13004                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13005                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13006                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13007                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13008                                                            "}\n"
13009                                                            "\n";
13010         static const GLchar* tcs_tested = "#version 430 core\n"
13011                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13012                                                                           "\n"
13013                                                                           "layout(vertices = 1) out;\n"
13014                                                                           "\n"
13015                                                                           "STRUCT_DEFINITION"
13016                                                                           "\n"
13017                                                                           "VARIABLE_DEFINITION"
13018                                                                           "\n"
13019                                                                           "in  vec4 vs_tcs[];\n"
13020                                                                           "out vec4 tcs_tes[];\n"
13021                                                                           "\n"
13022                                                                           "void main()\n"
13023                                                                           "{\n"
13024                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13025                                                                           "\n"
13026                                                                           "VARIABLE_USE"
13027                                                                           "\n"
13028                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13029                                                                           "\n"
13030                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13031                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13032                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13033                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13034                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13035                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13036                                                                           "}\n"
13037                                                                           "\n";
13038         static const GLchar* tes = "#version 430 core\n"
13039                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13040                                                            "\n"
13041                                                            "layout(isolines, point_mode) in;\n"
13042                                                            "\n"
13043                                                            "in  vec4 tcs_tes[];\n"
13044                                                            "out vec4 tes_gs;\n"
13045                                                            "\n"
13046                                                            "void main()\n"
13047                                                            "{\n"
13048                                                            "    tes_gs = tcs_tes[0];\n"
13049                                                            "}\n"
13050                                                            "\n";
13051         static const GLchar* tes_tested = "#version 430 core\n"
13052                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13053                                                                           "\n"
13054                                                                           "layout(isolines, point_mode) in;\n"
13055                                                                           "\n"
13056                                                                           "STRUCT_DEFINITION"
13057                                                                           "\n"
13058                                                                           "VARIABLE_DEFINITION"
13059                                                                           "\n"
13060                                                                           "in  vec4 tcs_tes[];\n"
13061                                                                           "out vec4 tes_gs;\n"
13062                                                                           "\n"
13063                                                                           "void main()\n"
13064                                                                           "{\n"
13065                                                                           "    vec4 result = tcs_tes[0];\n"
13066                                                                           "\n"
13067                                                                           "VARIABLE_USE"
13068                                                                           "\n"
13069                                                                           "    tes_gs += result;\n"
13070                                                                           "}\n"
13071                                                                           "\n";
13072         static const GLchar* vs = "#version 430 core\n"
13073                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13074                                                           "\n"
13075                                                           "in  vec4 in_vs;\n"
13076                                                           "out vec4 vs_tcs;\n"
13077                                                           "\n"
13078                                                           "void main()\n"
13079                                                           "{\n"
13080                                                           "    vs_tcs = in_vs;\n"
13081                                                           "}\n"
13082                                                           "\n";
13083         static const GLchar* vs_tested = "#version 430 core\n"
13084                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13085                                                                          "\n"
13086                                                                          "STRUCT_DEFINITION"
13087                                                                          "\n"
13088                                                                          "VARIABLE_DEFINITION"
13089                                                                          "\n"
13090                                                                          "in  vec4 in_vs;\n"
13091                                                                          "out vec4 vs_tcs;\n"
13092                                                                          "\n"
13093                                                                          "void main()\n"
13094                                                                          "{\n"
13095                                                                          "    vec4 result = in_vs;\n"
13096                                                                          "\n"
13097                                                                          "VARIABLE_USE"
13098                                                                          "\n"
13099                                                                          "    vs_tcs += result;\n"
13100                                                                          "}\n"
13101                                                                          "\n";
13102
13103         std::string   source;
13104         testCase&        test_case               = m_test_cases[test_case_index];
13105         const GLchar* var_definition = 0;
13106         const GLchar* var_use            = 0;
13107
13108         if (true == test_case.m_is_input)
13109         {
13110                 var_definition = input_var;
13111                 var_use            = input_use;
13112         }
13113         else
13114         {
13115                 var_definition = output_var;
13116                 var_use            = output_use;
13117         }
13118
13119         if (test_case.m_stage == stage)
13120         {
13121                 size_t position = 0;
13122
13123                 switch (stage)
13124                 {
13125                 case Utils::Shader::FRAGMENT:
13126                         source = fs_tested;
13127                         break;
13128                 case Utils::Shader::GEOMETRY:
13129                         source = gs_tested;
13130                         break;
13131                 case Utils::Shader::TESS_CTRL:
13132                         source = tcs_tested;
13133                         break;
13134                 case Utils::Shader::TESS_EVAL:
13135                         source = tes_tested;
13136                         break;
13137                 case Utils::Shader::VERTEX:
13138                         source = vs_tested;
13139                         break;
13140                 default:
13141                         TCU_FAIL("Invalid enum");
13142                 }
13143
13144                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13145                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13146                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13147         }
13148         else
13149         {
13150                 switch (stage)
13151                 {
13152                 case Utils::Shader::FRAGMENT:
13153                         source = fs;
13154                         break;
13155                 case Utils::Shader::GEOMETRY:
13156                         source = gs;
13157                         break;
13158                 case Utils::Shader::TESS_CTRL:
13159                         source = tcs;
13160                         break;
13161                 case Utils::Shader::TESS_EVAL:
13162                         source = tes;
13163                         break;
13164                 case Utils::Shader::VERTEX:
13165                         source = vs;
13166                         break;
13167                 default:
13168                         TCU_FAIL("Invalid enum");
13169                 }
13170         }
13171
13172         return source;
13173 }
13174
13175 /** Get description of test case
13176  *
13177  * @param test_case_index Index of test case
13178  *
13179  * @return Test case description
13180  **/
13181 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13182 {
13183         std::stringstream stream;
13184         testCase&                 test_case = m_test_cases[test_case_index];
13185
13186         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13187
13188         if (true == test_case.m_is_input)
13189         {
13190                 stream << "input";
13191         }
13192         else
13193         {
13194                 stream << "output";
13195         }
13196
13197         return stream.str();
13198 }
13199
13200 /** Get number of test cases
13201  *
13202  * @return Number of test cases
13203  **/
13204 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13205 {
13206         return static_cast<GLuint>(m_test_cases.size());
13207 }
13208
13209 /** Selects if "compute" stage is relevant for test
13210  *
13211  * @param ignored
13212  *
13213  * @return false
13214  **/
13215 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13216 {
13217         return false;
13218 }
13219
13220 /** Prepare all test cases
13221  *
13222  **/
13223 void VaryingStructureMemberLocationTest::testInit()
13224 {
13225         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13226         {
13227                 if (Utils::Shader::COMPUTE == stage)
13228                 {
13229                         continue;
13230                 }
13231
13232                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13233                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13234
13235                 m_test_cases.push_back(test_case_in);
13236
13237                 if (Utils::Shader::FRAGMENT != stage)
13238                 {
13239                         m_test_cases.push_back(test_case_out);
13240                 }
13241         }
13242 }
13243
13244 /** Constructor
13245  *
13246  * @param context Test framework context
13247  **/
13248 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13249         : TextureTestBase(context, "varying_block_locations",
13250                                           "Test verifies that locations are respected when blocks are used as in and out ")
13251 {
13252 }
13253
13254 /** Prepare code snippet that will pass in variables to out variables
13255  *
13256  * @param ignored
13257  * @param varying_passthrough Collection of connections between in and out variables
13258  * @param stage               Shader stage
13259  *
13260  * @return Code that pass in variables to next stage
13261  **/
13262 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13263                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13264                                                                                                           Utils::Shader::STAGES          stage)
13265 {
13266         std::string result;
13267
13268         if (Utils::Shader::VERTEX != stage)
13269         {
13270                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13271         }
13272         else
13273         {
13274                 result = "vs_tcs_block.third  = vs_in_third;\n"
13275                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13276                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13277         }
13278
13279         return result;
13280 }
13281
13282 /** Get interface of program
13283  *
13284  * @param ignored
13285  * @param program_interface   Interface of program
13286  * @param varying_passthrough Collection of connections between in and out variables
13287  **/
13288 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13289                                                                                                         Utils::ProgramInterface&   program_interface,
13290                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13291 {
13292         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13293         const Utils::Type               vec4 = Utils::Type::vec4;
13294
13295         /* Prepare data */
13296         m_third_data  = vec4.GenerateData();
13297         m_fourth_data = vec4.GenerateData();
13298         m_fifth_data  = vec4.GenerateData();
13299
13300         /* Memory layout is different from location layout */
13301         const GLuint fifth_offset  = 0u;
13302         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13303         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13304
13305         m_data.resize(fourth_offset + m_fourth_data.size());
13306         GLubyte* ptr = (GLubyte*)&m_data[0];
13307         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13308         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13309         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13310
13311         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13312
13313         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13314                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13315
13316         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13317                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13318
13319         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13320                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13321
13322         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13323                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13324                           m_data.size() /* data_size */);
13325
13326         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13327                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13328                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13329
13330         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13331                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13332                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13333
13334         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13335                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13336                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13337
13338         program_interface.CloneVertexInterface(varying_passthrough);
13339 }
13340
13341 /** Selects if "compute" stage is relevant for test
13342  *
13343  * @param ignored
13344  *
13345  * @return false
13346  **/
13347 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13348 {
13349         return false;
13350 }
13351
13352 /** This test should be run with separable programs
13353  *
13354  * @param ignored
13355  *
13356  * @return true
13357  **/
13358 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13359 {
13360         return false;
13361 }
13362
13363 /** Constructor
13364  *
13365  * @param context Test framework context
13366  **/
13367 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13368         : NegativeTestBase(
13369                   context, "varying_block_member_locations",
13370                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13371 {
13372 }
13373
13374 /** Source for given test case and stage
13375  *
13376  * @param test_case_index Index of test case
13377  * @param stage           Shader stage
13378  *
13379  * @return Shader source
13380  **/
13381 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13382 {
13383         static const GLchar* block_definition_all = "Goku {\n"
13384                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13385                                                                                                 "    layout (location = 4) vec4 goten;\n"
13386                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13387                                                                                                 "} gokuARRAY;\n";
13388         static const GLchar* block_definition_default = "Goku {\n"
13389                                                                                                         "    vec4 gohan;\n"
13390                                                                                                         "    vec4 goten;\n"
13391                                                                                                         "    vec4 chichi;\n"
13392                                                                                                         "} gokuARRAY;\n";
13393         static const GLchar* block_definition_one = "Goku {\n"
13394                                                                                                 "    vec4 gohan;\n"
13395                                                                                                 "    layout (location = 4) vec4 goten;\n"
13396                                                                                                 "    vec4 chichi;\n"
13397                                                                                                 "} gokuARRAY;\n";
13398         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13399         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13400                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13401                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13402         static const GLchar* fs = "#version 430 core\n"
13403                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13404                                                           "\n"
13405                                                           "in  vec4 gs_fs;\n"
13406                                                           "out vec4 fs_out;\n"
13407                                                           "\n"
13408                                                           "void main()\n"
13409                                                           "{\n"
13410                                                           "    fs_out = gs_fs;\n"
13411                                                           "}\n"
13412                                                           "\n";
13413         static const GLchar* fs_tested = "#version 430 core\n"
13414                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13415                                                                          "\n"
13416                                                                          "DIRECTION BLOCK_DEFINITION"
13417                                                                          "\n"
13418                                                                          "in  vec4 gs_fs;\n"
13419                                                                          "out vec4 fs_out;\n"
13420                                                                          "\n"
13421                                                                          "void main()\n"
13422                                                                          "{\n"
13423                                                                          "    vec4 result = gs_fs;\n"
13424                                                                          "\n"
13425                                                                          "VARIABLE_USE"
13426                                                                          "\n"
13427                                                                          "    fs_out = result;\n"
13428                                                                          "}\n"
13429                                                                          "\n";
13430         static const GLchar* gs = "#version 430 core\n"
13431                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13432                                                           "\n"
13433                                                           "layout(points)                           in;\n"
13434                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13435                                                           "\n"
13436                                                           "in  vec4 tes_gs[];\n"
13437                                                           "out vec4 gs_fs;\n"
13438                                                           "\n"
13439                                                           "void main()\n"
13440                                                           "{\n"
13441                                                           "    gs_fs = tes_gs[0];\n"
13442                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13443                                                           "    EmitVertex();\n"
13444                                                           "    gs_fs = tes_gs[0];\n"
13445                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13446                                                           "    EmitVertex();\n"
13447                                                           "    gs_fs = tes_gs[0];\n"
13448                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13449                                                           "    EmitVertex();\n"
13450                                                           "    gs_fs = tes_gs[0];\n"
13451                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13452                                                           "    EmitVertex();\n"
13453                                                           "}\n"
13454                                                           "\n";
13455         static const GLchar* gs_tested = "#version 430 core\n"
13456                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13457                                                                          "\n"
13458                                                                          "layout(points)                           in;\n"
13459                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13460                                                                          "\n"
13461                                                                          "DIRECTION BLOCK_DEFINITION"
13462                                                                          "\n"
13463                                                                          "in  vec4 tes_gs[];\n"
13464                                                                          "out vec4 gs_fs;\n"
13465                                                                          "\n"
13466                                                                          "void main()\n"
13467                                                                          "{\n"
13468                                                                          "    vec4 result = tes_gs[0];\n"
13469                                                                          "\n"
13470                                                                          "VARIABLE_USE"
13471                                                                          "\n"
13472                                                                          "    gs_fs = result;\n"
13473                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13474                                                                          "    EmitVertex();\n"
13475                                                                          "    gs_fs = result;\n"
13476                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13477                                                                          "    EmitVertex();\n"
13478                                                                          "    gs_fs = result;\n"
13479                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13480                                                                          "    EmitVertex();\n"
13481                                                                          "    gs_fs = result;\n"
13482                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13483                                                                          "    EmitVertex();\n"
13484                                                                          "}\n"
13485                                                                          "\n";
13486         static const GLchar* tcs = "#version 430 core\n"
13487                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13488                                                            "\n"
13489                                                            "layout(vertices = 1) out;\n"
13490                                                            "\n"
13491                                                            "in  vec4 vs_tcs[];\n"
13492                                                            "out vec4 tcs_tes[];\n"
13493                                                            "\n"
13494                                                            "void main()\n"
13495                                                            "{\n"
13496                                                            "\n"
13497                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13498                                                            "\n"
13499                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13500                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13501                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13502                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13503                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13504                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13505                                                            "}\n"
13506                                                            "\n";
13507         static const GLchar* tcs_tested = "#version 430 core\n"
13508                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13509                                                                           "\n"
13510                                                                           "layout(vertices = 1) out;\n"
13511                                                                           "\n"
13512                                                                           "DIRECTION BLOCK_DEFINITION"
13513                                                                           "\n"
13514                                                                           "in  vec4 vs_tcs[];\n"
13515                                                                           "out vec4 tcs_tes[];\n"
13516                                                                           "\n"
13517                                                                           "void main()\n"
13518                                                                           "{\n"
13519                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13520                                                                           "\n"
13521                                                                           "VARIABLE_USE"
13522                                                                           "\n"
13523                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13524                                                                           "\n"
13525                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13526                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13527                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13528                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13529                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13530                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13531                                                                           "}\n"
13532                                                                           "\n";
13533         static const GLchar* tes = "#version 430 core\n"
13534                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13535                                                            "\n"
13536                                                            "layout(isolines, point_mode) in;\n"
13537                                                            "\n"
13538                                                            "in  vec4 tcs_tes[];\n"
13539                                                            "out vec4 tes_gs;\n"
13540                                                            "\n"
13541                                                            "void main()\n"
13542                                                            "{\n"
13543                                                            "    tes_gs = tcs_tes[0];\n"
13544                                                            "}\n"
13545                                                            "\n";
13546         static const GLchar* tes_tested = "#version 430 core\n"
13547                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13548                                                                           "\n"
13549                                                                           "layout(isolines, point_mode) in;\n"
13550                                                                           "\n"
13551                                                                           "DIRECTION BLOCK_DEFINITION"
13552                                                                           "\n"
13553                                                                           "in  vec4 tcs_tes[];\n"
13554                                                                           "out vec4 tes_gs;\n"
13555                                                                           "\n"
13556                                                                           "void main()\n"
13557                                                                           "{\n"
13558                                                                           "    vec4 result = tcs_tes[0];\n"
13559                                                                           "\n"
13560                                                                           "VARIABLE_USE"
13561                                                                           "\n"
13562                                                                           "    tes_gs = result;\n"
13563                                                                           "}\n"
13564                                                                           "\n";
13565         static const GLchar* vs = "#version 430 core\n"
13566                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13567                                                           "\n"
13568                                                           "in  vec4 in_vs;\n"
13569                                                           "out vec4 vs_tcs;\n"
13570                                                           "\n"
13571                                                           "void main()\n"
13572                                                           "{\n"
13573                                                           "    vs_tcs = in_vs;\n"
13574                                                           "}\n"
13575                                                           "\n";
13576         static const GLchar* vs_tested = "#version 430 core\n"
13577                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13578                                                                          "\n"
13579                                                                          "DIRECTION BLOCK_DEFINITION"
13580                                                                          "\n"
13581                                                                          "in  vec4 in_vs;\n"
13582                                                                          "out vec4 vs_tcs;\n"
13583                                                                          "\n"
13584                                                                          "void main()\n"
13585                                                                          "{\n"
13586                                                                          "    vec4 result = in_vs;\n"
13587                                                                          "\n"
13588                                                                          "VARIABLE_USE"
13589                                                                          "\n"
13590                                                                          "    vs_tcs = result;\n"
13591                                                                          "}\n"
13592                                                                          "\n";
13593
13594         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13595                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13596                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13597                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13598                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13599                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13600
13601         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13602                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13603                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13604                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13605                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13606                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13607
13608         static const bool require_modifications_in[6][6] = {
13609                 /* cs  */ { false, false, false, false, false, false },
13610                 /* vs  */ { false, true, false, false, false, false },
13611                 /* tcs */ { false, true, true, false, false, false },
13612                 /* tes */ { false, false, true, true, false, false },
13613                 /* gs  */ { false, false, false, true, true, false },
13614                 /* fs  */ { false, false, false, false, true, true }
13615         };
13616
13617         static const bool require_modifications_out[6][6] = {
13618                 /* cs  */ { false, false, false, false, false, false },
13619                 /* vs  */ { false, true, true, false, false, false },
13620                 /* tcs */ { false, false, true, true, false, false },
13621                 /* tes */ { false, false, false, true, true, false },
13622                 /* gs  */ { false, false, false, false, true, true },
13623                 /* fs  */ { false, false, false, false, false, false }
13624         };
13625
13626         const GLchar* array                                     = "";
13627         const GLchar* definition                        = block_definition_default;
13628         const GLchar* direction                         = "out";
13629         const GLchar* index                                     = "";
13630         bool              require_modifications = false;
13631         std::string   source;
13632         testCase&        test_case = m_test_cases[test_case_index];
13633         const GLchar* var_use   = output_use;
13634
13635         if (true == test_case.m_is_input)
13636         {
13637                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13638                 source                            = shaders_in[test_case.m_stage][stage];
13639
13640                 if (test_case.m_stage == stage)
13641                 {
13642                         direction = "in";
13643                         var_use   = input_use;
13644                 }
13645         }
13646         else
13647         {
13648                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13649                 source                            = shaders_out[test_case.m_stage][stage];
13650
13651                 if (test_case.m_stage != stage)
13652                 {
13653                         direction = "in";
13654                         var_use   = input_use;
13655                 }
13656         }
13657
13658         if (test_case.m_stage == stage)
13659         {
13660                 if (true == test_case.m_qualify_all)
13661                 {
13662                         definition = block_definition_all;
13663                 }
13664                 else
13665                 {
13666                         definition = block_definition_one;
13667                 }
13668         }
13669
13670         switch (stage)
13671         {
13672         case Utils::Shader::FRAGMENT:
13673                 break;
13674         case Utils::Shader::GEOMETRY:
13675                 array = "[]";
13676                 index = "[0]";
13677                 break;
13678         case Utils::Shader::TESS_CTRL:
13679                 array = "[]";
13680                 index = "[gl_InvocationID]";
13681                 break;
13682         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13683         // the GS input block is an array, so the DS output can't be declared as an array
13684         case Utils::Shader::TESS_EVAL:
13685         {
13686                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13687                 {
13688                         array = "[]";
13689                         index = "[0]";
13690                 }
13691                 else // match DS output and GS input
13692                 {
13693                         array = "";
13694                         index = "";
13695                 }
13696         }
13697         break;
13698         case Utils::Shader::VERTEX:
13699                 break;
13700         default:
13701                 TCU_FAIL("Invalid enum");
13702         }
13703
13704         if (true == require_modifications)
13705         {
13706                 size_t position = 0;
13707                 size_t temp;
13708
13709                 Utils::replaceToken("DIRECTION", position, direction, source);
13710                 temp = position;
13711                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13712                 position = temp;
13713                 Utils::replaceToken("ARRAY", position, array, source);
13714                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13715
13716                 Utils::replaceAllTokens("INDEX", index, source);
13717         }
13718         else
13719         {
13720                 switch (stage)
13721                 {
13722                 case Utils::Shader::FRAGMENT:
13723                         source = fs;
13724                         break;
13725                 case Utils::Shader::GEOMETRY:
13726                         source = gs;
13727                         break;
13728                 case Utils::Shader::TESS_CTRL:
13729                         source = tcs;
13730                         break;
13731                 case Utils::Shader::TESS_EVAL:
13732                         source = tes;
13733                         break;
13734                 case Utils::Shader::VERTEX:
13735                         source = vs;
13736                         break;
13737                 default:
13738                         TCU_FAIL("Invalid enum");
13739                 }
13740         }
13741
13742         return source;
13743 }
13744
13745 /** Get description of test case
13746  *
13747  * @param test_case_index Index of test case
13748  *
13749  * @return Test case description
13750  **/
13751 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13752 {
13753         std::stringstream stream;
13754         testCase&                 test_case = m_test_cases[test_case_index];
13755
13756         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13757
13758         if (true == test_case.m_is_input)
13759         {
13760                 stream << "input";
13761         }
13762         else
13763         {
13764                 stream << "output";
13765         }
13766
13767         if (true == test_case.m_qualify_all)
13768         {
13769                 stream << ", all members qualified";
13770         }
13771         else
13772         {
13773                 stream << ", not all members qualified";
13774         }
13775
13776         return stream.str();
13777 }
13778
13779 /** Get number of test cases
13780  *
13781  * @return Number of test cases
13782  **/
13783 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13784 {
13785         return static_cast<GLuint>(m_test_cases.size());
13786 }
13787
13788 /** Selects if "compute" stage is relevant for test
13789  *
13790  * @param ignored
13791  *
13792  * @return false
13793  **/
13794 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13795 {
13796         return false;
13797 }
13798
13799 /** Selects if compilation failure is expected result
13800  *
13801  * @param test_case_index Index of test case
13802  *
13803  * @return false when all members are qualified, true otherwise
13804  **/
13805 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13806 {
13807         return (true != m_test_cases[test_case_index].m_qualify_all);
13808 }
13809
13810 /** Prepare all test cases
13811  *
13812  **/
13813 void VaryingBlockMemberLocationsTest::testInit()
13814 {
13815         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13816         {
13817                 if (Utils::Shader::COMPUTE == stage)
13818                 {
13819                         continue;
13820                 }
13821
13822                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13823                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13824                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13825                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13826
13827                 if (Utils::Shader::VERTEX != stage)
13828                 {
13829                         m_test_cases.push_back(test_case_in_all);
13830                         m_test_cases.push_back(test_case_in_one);
13831                 }
13832
13833                 if (Utils::Shader::FRAGMENT != stage)
13834                 {
13835                         m_test_cases.push_back(test_case_out_all);
13836                         m_test_cases.push_back(test_case_out_one);
13837                 }
13838         }
13839 }
13840
13841 /** Constructor
13842  *
13843  * @param context Test framework context
13844  **/
13845 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13846         : NegativeTestBase(
13847                   context, "varying_block_automatic_member_locations",
13848                   "Test verifies that compiler assigns subsequent locations to block members, even if this casue error")
13849 {
13850 }
13851
13852 /** Source for given test case and stage
13853  *
13854  * @param test_case_index Index of test case
13855  * @param stage           Shader stage
13856  *
13857  * @return Shader source
13858  **/
13859 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13860                                                                                                                                           Utils::Shader::STAGES stage)
13861 {
13862         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13863                                                                                         "    vec4 goku;\n"
13864                                                                                         "    vec4 gohan[4];\n"
13865                                                                                         "    vec4 goten;\n"
13866                                                                                         "    layout (location = 1) vec4 chichi;\n"
13867                                                                                         "    vec4 pan;\n"
13868                                                                                         "} dbzARRAY;\n";
13869         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13870                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13871                                                                          "dbzINDEX.pan;\n";
13872         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
13873                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
13874                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
13875                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
13876                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
13877                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
13878                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
13879                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
13880                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
13881         static const GLchar* fs = "#version 430 core\n"
13882                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13883                                                           "\n"
13884                                                           "in  vec4 gs_fs;\n"
13885                                                           "out vec4 fs_out;\n"
13886                                                           "\n"
13887                                                           "void main()\n"
13888                                                           "{\n"
13889                                                           "    fs_out = gs_fs;\n"
13890                                                           "}\n"
13891                                                           "\n";
13892         static const GLchar* fs_tested = "#version 430 core\n"
13893                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13894                                                                          "\n"
13895                                                                          "BLOCK_DEFINITION"
13896                                                                          "\n"
13897                                                                          "in  vec4 gs_fs;\n"
13898                                                                          "out vec4 fs_out;\n"
13899                                                                          "\n"
13900                                                                          "void main()\n"
13901                                                                          "{\n"
13902                                                                          "    vec4 result = gs_fs;\n"
13903                                                                          "\n"
13904                                                                          "VARIABLE_USE"
13905                                                                          "\n"
13906                                                                          "    fs_out += result;\n"
13907                                                                          "}\n"
13908                                                                          "\n";
13909         static const GLchar* gs = "#version 430 core\n"
13910                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13911                                                           "\n"
13912                                                           "layout(points)                           in;\n"
13913                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13914                                                           "\n"
13915                                                           "in  vec4 tes_gs[];\n"
13916                                                           "out vec4 gs_fs;\n"
13917                                                           "\n"
13918                                                           "void main()\n"
13919                                                           "{\n"
13920                                                           "    gs_fs = tes_gs[0];\n"
13921                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13922                                                           "    EmitVertex();\n"
13923                                                           "    gs_fs = tes_gs[0];\n"
13924                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13925                                                           "    EmitVertex();\n"
13926                                                           "    gs_fs = tes_gs[0];\n"
13927                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13928                                                           "    EmitVertex();\n"
13929                                                           "    gs_fs = tes_gs[0];\n"
13930                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13931                                                           "    EmitVertex();\n"
13932                                                           "}\n"
13933                                                           "\n";
13934         static const GLchar* gs_tested = "#version 430 core\n"
13935                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13936                                                                          "\n"
13937                                                                          "layout(points)                           in;\n"
13938                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13939                                                                          "\n"
13940                                                                          "BLOCK_DEFINITION"
13941                                                                          "\n"
13942                                                                          "in  vec4 tes_gs[];\n"
13943                                                                          "out vec4 gs_fs;\n"
13944                                                                          "\n"
13945                                                                          "void main()\n"
13946                                                                          "{\n"
13947                                                                          "    vec4 result = tes_gs[0];\n"
13948                                                                          "\n"
13949                                                                          "VARIABLE_USE"
13950                                                                          "\n"
13951                                                                          "    gs_fs = result;\n"
13952                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13953                                                                          "    EmitVertex();\n"
13954                                                                          "    gs_fs = result;\n"
13955                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13956                                                                          "    EmitVertex();\n"
13957                                                                          "    gs_fs = result;\n"
13958                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13959                                                                          "    EmitVertex();\n"
13960                                                                          "    gs_fs = result;\n"
13961                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13962                                                                          "    EmitVertex();\n"
13963                                                                          "}\n"
13964                                                                          "\n";
13965         static const GLchar* tcs = "#version 430 core\n"
13966                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13967                                                            "\n"
13968                                                            "layout(vertices = 1) out;\n"
13969                                                            "\n"
13970                                                            "in  vec4 vs_tcs[];\n"
13971                                                            "out vec4 tcs_tes[];\n"
13972                                                            "\n"
13973                                                            "void main()\n"
13974                                                            "{\n"
13975                                                            "\n"
13976                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13977                                                            "\n"
13978                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13979                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13980                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13981                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13982                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13983                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13984                                                            "}\n"
13985                                                            "\n";
13986         static const GLchar* tcs_tested = "#version 430 core\n"
13987                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13988                                                                           "\n"
13989                                                                           "layout(vertices = 1) out;\n"
13990                                                                           "\n"
13991                                                                           "BLOCK_DEFINITION"
13992                                                                           "\n"
13993                                                                           "in  vec4 vs_tcs[];\n"
13994                                                                           "out vec4 tcs_tes[];\n"
13995                                                                           "\n"
13996                                                                           "void main()\n"
13997                                                                           "{\n"
13998                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13999                                                                           "\n"
14000                                                                           "VARIABLE_USE"
14001                                                                           "\n"
14002                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14003                                                                           "\n"
14004                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14005                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14006                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14007                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14008                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14009                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14010                                                                           "}\n"
14011                                                                           "\n";
14012         static const GLchar* tes = "#version 430 core\n"
14013                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14014                                                            "\n"
14015                                                            "layout(isolines, point_mode) in;\n"
14016                                                            "\n"
14017                                                            "in  vec4 tcs_tes[];\n"
14018                                                            "out vec4 tes_gs;\n"
14019                                                            "\n"
14020                                                            "void main()\n"
14021                                                            "{\n"
14022                                                            "    tes_gs = tcs_tes[0];\n"
14023                                                            "}\n"
14024                                                            "\n";
14025         static const GLchar* tes_tested = "#version 430 core\n"
14026                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14027                                                                           "\n"
14028                                                                           "layout(isolines, point_mode) in;\n"
14029                                                                           "\n"
14030                                                                           "BLOCK_DEFINITION"
14031                                                                           "\n"
14032                                                                           "in  vec4 tcs_tes[];\n"
14033                                                                           "out vec4 tes_gs;\n"
14034                                                                           "\n"
14035                                                                           "void main()\n"
14036                                                                           "{\n"
14037                                                                           "    vec4 result = tcs_tes[0];\n"
14038                                                                           "\n"
14039                                                                           "VARIABLE_USE"
14040                                                                           "\n"
14041                                                                           "    tes_gs += result;\n"
14042                                                                           "}\n"
14043                                                                           "\n";
14044         static const GLchar* vs = "#version 430 core\n"
14045                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14046                                                           "\n"
14047                                                           "in  vec4 in_vs;\n"
14048                                                           "out vec4 vs_tcs;\n"
14049                                                           "\n"
14050                                                           "void main()\n"
14051                                                           "{\n"
14052                                                           "    vs_tcs = in_vs;\n"
14053                                                           "}\n"
14054                                                           "\n";
14055         static const GLchar* vs_tested = "#version 430 core\n"
14056                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14057                                                                          "\n"
14058                                                                          "BLOCK_DEFINITION"
14059                                                                          "\n"
14060                                                                          "in  vec4 in_vs;\n"
14061                                                                          "out vec4 vs_tcs;\n"
14062                                                                          "\n"
14063                                                                          "void main()\n"
14064                                                                          "{\n"
14065                                                                          "    vec4 result = in_vs;\n"
14066                                                                          "\n"
14067                                                                          "VARIABLE_USE"
14068                                                                          "\n"
14069                                                                          "    vs_tcs += result;\n"
14070                                                                          "}\n"
14071                                                                          "\n";
14072
14073         const GLchar* array             = "";
14074         const GLchar* direction = "out";
14075         const GLchar* index             = "";
14076         std::string   source;
14077         testCase&        test_case = m_test_cases[test_case_index];
14078         const GLchar* var_use   = output_use;
14079
14080         if (true == test_case.m_is_input)
14081         {
14082                 direction = "in ";
14083                 var_use   = input_use;
14084         }
14085
14086         if (test_case.m_stage == stage)
14087         {
14088                 size_t position = 0;
14089                 size_t temp;
14090
14091                 switch (stage)
14092                 {
14093                 case Utils::Shader::FRAGMENT:
14094                         source = fs_tested;
14095                         break;
14096                 case Utils::Shader::GEOMETRY:
14097                         source = gs_tested;
14098                         array  = "[]";
14099                         index  = "[0]";
14100                         break;
14101                 case Utils::Shader::TESS_CTRL:
14102                         source = tcs_tested;
14103                         array  = "[]";
14104                         index  = "[gl_InvocationID]";
14105                         break;
14106                 case Utils::Shader::TESS_EVAL:
14107                         source = tes_tested;
14108                         array  = "[]";
14109                         index  = "[0]";
14110                         break;
14111                 case Utils::Shader::VERTEX:
14112                         source = vs_tested;
14113                         break;
14114                 default:
14115                         TCU_FAIL("Invalid enum");
14116                 }
14117
14118                 temp = position;
14119                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14120                 position = temp;
14121                 Utils::replaceToken("DIRECTION", position, direction, source);
14122                 Utils::replaceToken("ARRAY", position, array, source);
14123                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14124
14125                 Utils::replaceAllTokens("INDEX", index, source);
14126         }
14127         else
14128         {
14129                 switch (stage)
14130                 {
14131                 case Utils::Shader::FRAGMENT:
14132                         source = fs;
14133                         break;
14134                 case Utils::Shader::GEOMETRY:
14135                         source = gs;
14136                         break;
14137                 case Utils::Shader::TESS_CTRL:
14138                         source = tcs;
14139                         break;
14140                 case Utils::Shader::TESS_EVAL:
14141                         source = tes;
14142                         break;
14143                 case Utils::Shader::VERTEX:
14144                         source = vs;
14145                         break;
14146                 default:
14147                         TCU_FAIL("Invalid enum");
14148                 }
14149         }
14150
14151         return source;
14152 }
14153
14154 /** Get description of test case
14155  *
14156  * @param test_case_index Index of test case
14157  *
14158  * @return Test case description
14159  **/
14160 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14161 {
14162         std::stringstream stream;
14163         testCase&                 test_case = m_test_cases[test_case_index];
14164
14165         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14166
14167         if (true == test_case.m_is_input)
14168         {
14169                 stream << "input";
14170         }
14171         else
14172         {
14173                 stream << "output";
14174         }
14175
14176         return stream.str();
14177 }
14178
14179 /** Get number of test cases
14180  *
14181  * @return Number of test cases
14182  **/
14183 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14184 {
14185         return static_cast<GLuint>(m_test_cases.size());
14186 }
14187
14188 /** Selects if "compute" stage is relevant for test
14189  *
14190  * @param ignored
14191  *
14192  * @return false
14193  **/
14194 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14195 {
14196         return false;
14197 }
14198
14199 /** Prepare all test cases
14200  *
14201  **/
14202 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14203 {
14204         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14205         {
14206                 if (Utils::Shader::COMPUTE == stage)
14207                 {
14208                         continue;
14209                 }
14210
14211                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14212                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14213
14214                 if (Utils::Shader::VERTEX != stage)
14215                 {
14216                         m_test_cases.push_back(test_case_in);
14217                 }
14218
14219                 if (Utils::Shader::FRAGMENT != stage)
14220                 {
14221                         m_test_cases.push_back(test_case_out);
14222                 }
14223         }
14224 }
14225
14226 /** Constructor
14227  *
14228  * @param context Test framework context
14229  **/
14230 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14231         : NegativeTestBase(context, "varying_location_limit",
14232                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14233 {
14234 }
14235
14236 /** Source for given test case and stage
14237  *
14238  * @param test_case_index Index of test case
14239  * @param stage           Shader stage
14240  *
14241  * @return Shader source
14242  **/
14243 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14244 {
14245         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14246         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14247                                                                          "    {\n"
14248                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14249                                                                          "    }\n";
14250         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14251                                                                           "    if (vec4(0) == result)\n"
14252                                                                           "    {\n"
14253                                                                           "        gokuINDEX = TYPE(1);\n"
14254                                                                           "    }\n";
14255         static const GLchar* fs = "#version 430 core\n"
14256                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14257                                                           "\n"
14258                                                           "in  vec4 gs_fs;\n"
14259                                                           "out vec4 fs_out;\n"
14260                                                           "\n"
14261                                                           "void main()\n"
14262                                                           "{\n"
14263                                                           "    fs_out = gs_fs;\n"
14264                                                           "}\n"
14265                                                           "\n";
14266         static const GLchar* fs_tested = "#version 430 core\n"
14267                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14268                                                                          "\n"
14269                                                                          "VAR_DEFINITION"
14270                                                                          "\n"
14271                                                                          "in  vec4 gs_fs;\n"
14272                                                                          "out vec4 fs_out;\n"
14273                                                                          "\n"
14274                                                                          "void main()\n"
14275                                                                          "{\n"
14276                                                                          "    vec4 result = gs_fs;\n"
14277                                                                          "\n"
14278                                                                          "VARIABLE_USE"
14279                                                                          "\n"
14280                                                                          "    fs_out += result;\n"
14281                                                                          "}\n"
14282                                                                          "\n";
14283         static const GLchar* gs = "#version 430 core\n"
14284                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14285                                                           "\n"
14286                                                           "layout(points)                           in;\n"
14287                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14288                                                           "\n"
14289                                                           "in  vec4 tes_gs[];\n"
14290                                                           "out vec4 gs_fs;\n"
14291                                                           "\n"
14292                                                           "void main()\n"
14293                                                           "{\n"
14294                                                           "    gs_fs = tes_gs[0];\n"
14295                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14296                                                           "    EmitVertex();\n"
14297                                                           "    gs_fs = tes_gs[0];\n"
14298                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14299                                                           "    EmitVertex();\n"
14300                                                           "    gs_fs = tes_gs[0];\n"
14301                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14302                                                           "    EmitVertex();\n"
14303                                                           "    gs_fs = tes_gs[0];\n"
14304                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14305                                                           "    EmitVertex();\n"
14306                                                           "}\n"
14307                                                           "\n";
14308         static const GLchar* gs_tested = "#version 430 core\n"
14309                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14310                                                                          "\n"
14311                                                                          "layout(points)                           in;\n"
14312                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14313                                                                          "\n"
14314                                                                          "VAR_DEFINITION"
14315                                                                          "\n"
14316                                                                          "in  vec4 tes_gs[];\n"
14317                                                                          "out vec4 gs_fs;\n"
14318                                                                          "\n"
14319                                                                          "void main()\n"
14320                                                                          "{\n"
14321                                                                          "    vec4 result = tes_gs[0];\n"
14322                                                                          "\n"
14323                                                                          "VARIABLE_USE"
14324                                                                          "\n"
14325                                                                          "    gs_fs = result;\n"
14326                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14327                                                                          "    EmitVertex();\n"
14328                                                                          "    gs_fs = result;\n"
14329                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14330                                                                          "    EmitVertex();\n"
14331                                                                          "    gs_fs = result;\n"
14332                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14333                                                                          "    EmitVertex();\n"
14334                                                                          "    gs_fs = result;\n"
14335                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14336                                                                          "    EmitVertex();\n"
14337                                                                          "}\n"
14338                                                                          "\n";
14339         static const GLchar* tcs = "#version 430 core\n"
14340                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14341                                                            "\n"
14342                                                            "layout(vertices = 1) out;\n"
14343                                                            "\n"
14344                                                            "in  vec4 vs_tcs[];\n"
14345                                                            "out vec4 tcs_tes[];\n"
14346                                                            "\n"
14347                                                            "void main()\n"
14348                                                            "{\n"
14349                                                            "\n"
14350                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14351                                                            "\n"
14352                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14353                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14354                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14355                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14356                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14357                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14358                                                            "}\n"
14359                                                            "\n";
14360         static const GLchar* tcs_tested = "#version 430 core\n"
14361                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14362                                                                           "\n"
14363                                                                           "layout(vertices = 1) out;\n"
14364                                                                           "\n"
14365                                                                           "VAR_DEFINITION"
14366                                                                           "\n"
14367                                                                           "in  vec4 vs_tcs[];\n"
14368                                                                           "out vec4 tcs_tes[];\n"
14369                                                                           "\n"
14370                                                                           "void main()\n"
14371                                                                           "{\n"
14372                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14373                                                                           "\n"
14374                                                                           "VARIABLE_USE"
14375                                                                           "\n"
14376                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14377                                                                           "\n"
14378                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14379                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14380                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14381                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14382                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14383                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14384                                                                           "}\n"
14385                                                                           "\n";
14386         static const GLchar* tes = "#version 430 core\n"
14387                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14388                                                            "\n"
14389                                                            "layout(isolines, point_mode) in;\n"
14390                                                            "\n"
14391                                                            "in  vec4 tcs_tes[];\n"
14392                                                            "out vec4 tes_gs;\n"
14393                                                            "\n"
14394                                                            "void main()\n"
14395                                                            "{\n"
14396                                                            "    tes_gs = tcs_tes[0];\n"
14397                                                            "}\n"
14398                                                            "\n";
14399         static const GLchar* tes_tested = "#version 430 core\n"
14400                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14401                                                                           "\n"
14402                                                                           "layout(isolines, point_mode) in;\n"
14403                                                                           "\n"
14404                                                                           "VAR_DEFINITION"
14405                                                                           "\n"
14406                                                                           "in  vec4 tcs_tes[];\n"
14407                                                                           "out vec4 tes_gs;\n"
14408                                                                           "\n"
14409                                                                           "void main()\n"
14410                                                                           "{\n"
14411                                                                           "    vec4 result = tcs_tes[0];\n"
14412                                                                           "\n"
14413                                                                           "VARIABLE_USE"
14414                                                                           "\n"
14415                                                                           "    tes_gs += result;\n"
14416                                                                           "}\n"
14417                                                                           "\n";
14418         static const GLchar* vs = "#version 430 core\n"
14419                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14420                                                           "\n"
14421                                                           "in  vec4 in_vs;\n"
14422                                                           "out vec4 vs_tcs;\n"
14423                                                           "\n"
14424                                                           "void main()\n"
14425                                                           "{\n"
14426                                                           "    vs_tcs = in_vs;\n"
14427                                                           "}\n"
14428                                                           "\n";
14429         static const GLchar* vs_tested = "#version 430 core\n"
14430                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14431                                                                          "\n"
14432                                                                          "VAR_DEFINITION"
14433                                                                          "\n"
14434                                                                          "in  vec4 in_vs;\n"
14435                                                                          "out vec4 vs_tcs;\n"
14436                                                                          "\n"
14437                                                                          "void main()\n"
14438                                                                          "{\n"
14439                                                                          "    vec4 result = in_vs;\n"
14440                                                                          "\n"
14441                                                                          "VARIABLE_USE"
14442                                                                          "\n"
14443                                                                          "    vs_tcs += result;\n"
14444                                                                          "}\n"
14445                                                                          "\n";
14446
14447         std::string source;
14448         testCase&   test_case = m_test_cases[test_case_index];
14449
14450         if (test_case.m_stage == stage)
14451         {
14452                 const GLchar*                    array = "";
14453                 GLchar                                   buffer[16];
14454                 const GLchar*                    direction = "in ";
14455                 const GLchar*                    flat     = "";
14456                 const GLchar*                    index   = "";
14457                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14458                 size_t                                   position  = 0;
14459                 size_t                                   temp;
14460                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14461                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14462                 const GLchar*                    var_use   = input_use;
14463
14464                 if (false == test_case.m_is_input)
14465                 {
14466                         direction = "out";
14467                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14468                         storage   = Utils::Variable::VARYING_OUTPUT;
14469                         var_use   = output_use;
14470                 }
14471
14472                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14473                 {
14474                         flat = "flat";
14475                 }
14476
14477                 sprintf(buffer, "%d", last);
14478
14479                 switch (stage)
14480                 {
14481                 case Utils::Shader::FRAGMENT:
14482                         source = fs_tested;
14483                         break;
14484                 case Utils::Shader::GEOMETRY:
14485                         source = gs_tested;
14486                         array  = "[]";
14487                         index  = "[0]";
14488                         break;
14489                 case Utils::Shader::TESS_CTRL:
14490                         source = tcs_tested;
14491                         array  = "[]";
14492                         index  = "[gl_InvocationID]";
14493                         break;
14494                 case Utils::Shader::TESS_EVAL:
14495                         source = tes_tested;
14496                         array  = "[]";
14497                         index  = "[0]";
14498                         break;
14499                 case Utils::Shader::VERTEX:
14500                         source = vs_tested;
14501                         break;
14502                 default:
14503                         TCU_FAIL("Invalid enum");
14504                 }
14505
14506                 temp = position;
14507                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14508                 position = temp;
14509                 Utils::replaceToken("LAST", position, buffer, source);
14510                 Utils::replaceToken("FLAT", position, flat, source);
14511                 Utils::replaceToken("DIRECTION", position, direction, source);
14512                 Utils::replaceToken("ARRAY", position, array, source);
14513                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14514
14515                 Utils::replaceAllTokens("TYPE", type_name, source);
14516                 Utils::replaceAllTokens("INDEX", index, source);
14517         }
14518         else
14519         {
14520                 switch (stage)
14521                 {
14522                 case Utils::Shader::FRAGMENT:
14523                         source = fs;
14524                         break;
14525                 case Utils::Shader::GEOMETRY:
14526                         source = gs;
14527                         break;
14528                 case Utils::Shader::TESS_CTRL:
14529                         source = tcs;
14530                         break;
14531                 case Utils::Shader::TESS_EVAL:
14532                         source = tes;
14533                         break;
14534                 case Utils::Shader::VERTEX:
14535                         source = vs;
14536                         break;
14537                 default:
14538                         TCU_FAIL("Invalid enum");
14539                 }
14540         }
14541
14542         return source;
14543 }
14544
14545 /** Get description of test case
14546  *
14547  * @param test_case_index Index of test case
14548  *
14549  * @return Test case description
14550  **/
14551 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14552 {
14553         std::stringstream stream;
14554         testCase&                 test_case = m_test_cases[test_case_index];
14555
14556         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14557                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14558
14559         if (true == test_case.m_is_input)
14560         {
14561                 stream << "input";
14562         }
14563         else
14564         {
14565                 stream << "output";
14566         }
14567
14568         return stream.str();
14569 }
14570
14571 /** Get number of test cases
14572  *
14573  * @return Number of test cases
14574  **/
14575 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14576 {
14577         return static_cast<GLuint>(m_test_cases.size());
14578 }
14579
14580 /** Selects if "compute" stage is relevant for test
14581  *
14582  * @param ignored
14583  *
14584  * @return false
14585  **/
14586 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14587 {
14588         return false;
14589 }
14590
14591 /** Prepare all test cases
14592  *
14593  **/
14594 void VaryingLocationLimitTest::testInit()
14595 {
14596         const GLuint n_types = getTypesNumber();
14597
14598         for (GLuint i = 0; i < n_types; ++i)
14599         {
14600                 const Utils::Type& type = getType(i);
14601
14602                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14603                 {
14604                         if (Utils::Shader::COMPUTE == stage)
14605                         {
14606                                 continue;
14607                         }
14608
14609                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14610                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14611
14612                         m_test_cases.push_back(test_case_in);
14613
14614                         if (Utils::Shader::FRAGMENT != stage)
14615                         {
14616                                 m_test_cases.push_back(test_case_out);
14617                         }
14618                 }
14619         }
14620 }
14621
14622 /** Constructor
14623  *
14624  * @param context Test framework context
14625  **/
14626 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14627         : VaryingLocationsTest(context, "varying_components",
14628                                                    "Test verifies that input and output components are respected")
14629 {
14630 }
14631
14632 /** Constructor
14633  *
14634  * @param context          Test framework context
14635  * @param test_name        Name of test
14636  * @param test_description Description of test
14637  **/
14638 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14639                                                                                          const glw::GLchar* test_description)
14640         : VaryingLocationsTest(context, test_name, test_description)
14641 {
14642 }
14643
14644 /** Get interface of program
14645  *
14646  * @param test_case_index     Test case
14647  * @param program_interface   Interface of program
14648  * @param varying_passthrough Collection of connections between in and out variables
14649  **/
14650 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14651                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14652 {
14653         GLuint                             array_length = getArrayLength();
14654         const testCase&            test_case    = m_test_cases[test_case_index];
14655         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14656         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14657
14658         /* Zero means no array, however we still need at least 1 slot of data */
14659         if (0 == array_length)
14660         {
14661                 array_length += 1;
14662         }
14663
14664         /* Generate data */
14665         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14666         const size_t                            data_size = data.size();
14667
14668         /* Prepare data for variables */
14669         m_data.resize(array_length * data_size);
14670
14671         GLubyte*           dst = &m_data[0];
14672         const GLubyte* src = &data[0];
14673
14674         for (GLuint i = 0; i < array_length; ++i)
14675         {
14676                 memcpy(dst + data_size * i, src, data_size);
14677         }
14678
14679         /* Prepare interface for each stage */
14680         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14681         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14682         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14683         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14684         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14685 }
14686
14687 /** Get type name
14688  *
14689  * @param test_case_index Index of test case
14690  *
14691  * @return Name of type test in test_case_index
14692  **/
14693 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14694 {
14695         std::string name;
14696
14697         const testCase& test_case = m_test_cases[test_case_index];
14698
14699         name = "Type: ";
14700
14701         switch (test_case.m_type)
14702         {
14703         case Utils::Type::Double:
14704                 name.append(Utils::Type::_double.GetGLSLTypeName());
14705                 break;
14706         case Utils::Type::Float:
14707                 name.append(Utils::Type::_float.GetGLSLTypeName());
14708                 break;
14709         case Utils::Type::Int:
14710                 name.append(Utils::Type::_int.GetGLSLTypeName());
14711                 break;
14712         case Utils::Type::Uint:
14713                 name.append(Utils::Type::uint.GetGLSLTypeName());
14714                 break;
14715         }
14716
14717         name.append(", layout: ");
14718
14719         switch (test_case.m_layout)
14720         {
14721         case GVEC4:
14722                 name.append("GVEC4");
14723                 break;
14724         case SCALAR_GVEC3:
14725                 name.append("SCALAR_GVEC3");
14726                 break;
14727         case GVEC3_SCALAR:
14728                 name.append("GVEC3_SCALAR");
14729                 break;
14730         case GVEC2_GVEC2:
14731                 name.append("GVEC2_GVEC2");
14732                 break;
14733         case GVEC2_SCALAR_SCALAR:
14734                 name.append("GVEC2_SCALAR_SCALAR");
14735                 break;
14736         case SCALAR_GVEC2_SCALAR:
14737                 name.append("SCALAR_GVEC2_SCALAR");
14738                 break;
14739         case SCALAR_SCALAR_GVEC2:
14740                 name.append("SCALAR_SCALAR_GVEC2");
14741                 break;
14742         case SCALAR_SCALAR_SCALAR_SCALAR:
14743                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14744                 break;
14745         }
14746
14747         return name;
14748 }
14749
14750 /** Returns number of types to test
14751  *
14752  * @return Number of types, 34
14753  **/
14754 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14755 {
14756         return static_cast<GLuint>(m_test_cases.size());
14757 }
14758
14759 /* Prepare test cases */
14760 void VaryingComponentsTest::testInit()
14761 {
14762         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Double));
14763         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Double));
14764         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Double));
14765         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Double));
14766         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Double));
14767         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Double));
14768         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Double));
14769         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Double));
14770
14771         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14772         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14773         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14774         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14775         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14776         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14777         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14778         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14779
14780         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14781         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14782         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14783         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14784         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14785         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14786         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14787         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14788
14789         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14790         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14791         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14792         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14793         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14794         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14795         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14796         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14797 }
14798
14799 /** Inform that test use components
14800  *
14801  * @param ignored
14802  *
14803  * @return true
14804  **/
14805 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14806 {
14807         return true;
14808 }
14809
14810 /** Get length of arrays that should be used during test
14811  *
14812  * @return 0u - no array at all
14813  **/
14814 GLuint VaryingComponentsTest::getArrayLength()
14815 {
14816         return 0;
14817 }
14818
14819 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14820 {
14821         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14822
14823         globals.append("const uint comp_x = 0u;\n"
14824                                    "const uint comp_y = 1u;\n"
14825                                    "const uint comp_z = 2u;\n"
14826                                    "const uint comp_w = 3u;\n");
14827
14828         return globals;
14829 }
14830
14831 /**
14832  *
14833  **/
14834 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14835                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14836 {
14837         GLchar            buffer[16];
14838         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14839         size_t            position = 0;
14840         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14841
14842         Utils::replaceToken("PREFIX", position, prefix, result);
14843         Utils::replaceToken("NAME", position, name, result);
14844
14845         sprintf(buffer, "%d", location);
14846         Utils::replaceToken("LOCATION", position, buffer, result);
14847
14848         sprintf(buffer, "%d", component);
14849         Utils::replaceToken("COMPONENT", position, buffer, result);
14850
14851         return result;
14852 }
14853
14854 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14855                                                                                                          const glw::GLchar* interpolation)
14856 {
14857         size_t          position   = 0;
14858         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14859
14860         Utils::replaceToken("LOCATION", position, location, qualifiers);
14861         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14862         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14863
14864         return qualifiers;
14865 }
14866
14867 /**
14868  *
14869  **/
14870 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14871                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14872                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14873 {
14874         const GLuint                    array_length = getArrayLength();
14875         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14876         descriptor                              desc_in[8];
14877         descriptor                              desc_out[8];
14878         const GLuint                    first_in_loc  = 0;
14879         const GLuint                    first_out_loc = 0;
14880         const GLchar*                   interpolation = "";
14881         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
14882         GLuint                                  last_out_loc  = 0;
14883         GLuint                                  n_desc            = 0;
14884         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
14885
14886         /* Select interpolation */
14887         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
14888         {
14889                 interpolation = " flat";
14890         }
14891
14892         if (Utils::Shader::FRAGMENT != stage)
14893         {
14894                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
14895         }
14896
14897         switch (test_case.m_layout)
14898         {
14899         case GVEC4:
14900                 n_desc = 2;
14901                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
14902                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
14903
14904                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
14905                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
14906                 break;
14907         case SCALAR_GVEC3:
14908                 n_desc = 4;
14909                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14910                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14911                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
14912                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
14913
14914                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14915                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14916                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
14917                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
14918                 break;
14919         case GVEC3_SCALAR:
14920                 n_desc = 4;
14921                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
14922                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
14923                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14924                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14925
14926                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
14927                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
14928                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14929                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14930                 break;
14931         case GVEC2_GVEC2:
14932                 n_desc = 4;
14933                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14934                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14935                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14936                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14937
14938                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14939                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14940                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14941                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14942                 break;
14943         case GVEC2_SCALAR_SCALAR:
14944                 n_desc = 6;
14945                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14946                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14947                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
14948                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
14949                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14950                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14951
14952                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14953                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14954                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
14955                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
14956                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14957                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14958                 break;
14959         case SCALAR_GVEC2_SCALAR:
14960                 n_desc = 6;
14961                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14962                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14963                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
14964                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
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", 1, "scalar");
14969                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14970                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
14971                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
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_SCALAR_GVEC2:
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", 1, "scalar");
14980                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
14981                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14982                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
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", 1, "scalar");
14987                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
14988                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14989                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14990                 break;
14991         case SCALAR_SCALAR_SCALAR_SCALAR:
14992                 n_desc = 8;
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", 1, "scalar");
14998                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
14999                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15000                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15001
15002                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15003                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15004                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15005                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15006                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15007                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15008                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15009                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15010                 break;
15011         }
15012
15013         for (GLuint i = 0; i < n_desc; ++i)
15014         {
15015                 const descriptor& in_desc = desc_in[i];
15016
15017                 Utils::Variable* in =
15018                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15019
15020                 if (Utils::Shader::FRAGMENT != stage)
15021                 {
15022                         const descriptor& out_desc = desc_out[i];
15023
15024                         Utils::Variable* out =
15025                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15026
15027                         varying_passthrough.Add(stage, in, out);
15028                 }
15029         }
15030
15031         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15032 }
15033
15034 /**
15035  *
15036  **/
15037 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15038                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15039                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15040 {
15041         const GLuint       array_length   = getArrayLength();
15042         const GLuint       component_size = basic_type.GetSize();
15043         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15044         const GLuint       offset                 = desc.m_component * component_size;
15045         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15046         const GLuint       size                   = desc.m_n_rows * component_size;
15047         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15048         Utils::Variable*   var                    = 0;
15049
15050         if (Utils::Variable::VARYING_INPUT == storage)
15051         {
15052                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15053                                            desc.m_location /* expected_location */, type, /* built_in_type */
15054                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15055                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15056         }
15057         else
15058         {
15059                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15060                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15061                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15062                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15063         }
15064
15065         return var;
15066 }
15067
15068 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15069                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15070                                                                                            const glw::GLchar* name)
15071 {
15072         m_component             = component;
15073         m_component_str = component_str;
15074         m_location              = location;
15075         m_location_str  = location_str;
15076         m_n_rows                = n_rows;
15077         m_name                  = name;
15078 }
15079
15080 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15081         : m_layout(layout), m_type(type)
15082 {
15083 }
15084
15085 /** Constructor
15086  *
15087  * @param context Test framework context
15088  **/
15089 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15090         : VaryingComponentsTest(context, "varying_array_components",
15091                                                         "Test verifies that input and output components are respected for arrays")
15092 {
15093 }
15094
15095 /** Get length of arrays that should be used during test
15096  *
15097  * @return 4u
15098  **/
15099 GLuint VaryingArrayComponentsTest::getArrayLength()
15100 {
15101         return 4u;
15102 }
15103
15104 /** Constructor
15105  *
15106  * @param context Test framework context
15107  **/
15108 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15109         : NegativeTestBase(context, "varying_exceeding_components",
15110                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15111 {
15112 }
15113
15114 /** Source for given test case and stage
15115  *
15116  * @param test_case_index Index of test case
15117  * @param stage           Shader stage
15118  *
15119  * @return Shader source
15120  **/
15121 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15122 {
15123         static const GLchar* var_definition_arr =
15124                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15125         static const GLchar* var_definition_one =
15126                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15127         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15128                                                                                  "    {\n"
15129                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15130                                                                                  "    }\n";
15131         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15132                                                                                  "    {\n"
15133                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15134                                                                                  "    }\n";
15135         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15136                                                                                   "    if (vec4(0) == result)\n"
15137                                                                                   "    {\n"
15138                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15139                                                                                   "    }\n";
15140         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15141                                                                                   "    if (vec4(0) == result)\n"
15142                                                                                   "    {\n"
15143                                                                                   "        gokuINDEX = TYPE(1);\n"
15144                                                                                   "    }\n";
15145         static const GLchar* fs = "#version 430 core\n"
15146                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15147                                                           "\n"
15148                                                           "in  vec4 gs_fs;\n"
15149                                                           "out vec4 fs_out;\n"
15150                                                           "\n"
15151                                                           "void main()\n"
15152                                                           "{\n"
15153                                                           "    fs_out = gs_fs;\n"
15154                                                           "}\n"
15155                                                           "\n";
15156         static const GLchar* fs_tested = "#version 430 core\n"
15157                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15158                                                                          "\n"
15159                                                                          "VAR_DEFINITION"
15160                                                                          "\n"
15161                                                                          "in  vec4 gs_fs;\n"
15162                                                                          "out vec4 fs_out;\n"
15163                                                                          "\n"
15164                                                                          "void main()\n"
15165                                                                          "{\n"
15166                                                                          "    vec4 result = gs_fs;\n"
15167                                                                          "\n"
15168                                                                          "VARIABLE_USE"
15169                                                                          "\n"
15170                                                                          "    fs_out += result;\n"
15171                                                                          "}\n"
15172                                                                          "\n";
15173         static const GLchar* gs = "#version 430 core\n"
15174                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15175                                                           "\n"
15176                                                           "layout(points)                           in;\n"
15177                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15178                                                           "\n"
15179                                                           "in  vec4 tes_gs[];\n"
15180                                                           "out vec4 gs_fs;\n"
15181                                                           "\n"
15182                                                           "void main()\n"
15183                                                           "{\n"
15184                                                           "    gs_fs = tes_gs[0];\n"
15185                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15186                                                           "    EmitVertex();\n"
15187                                                           "    gs_fs = tes_gs[0];\n"
15188                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15189                                                           "    EmitVertex();\n"
15190                                                           "    gs_fs = tes_gs[0];\n"
15191                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15192                                                           "    EmitVertex();\n"
15193                                                           "    gs_fs = tes_gs[0];\n"
15194                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15195                                                           "    EmitVertex();\n"
15196                                                           "}\n"
15197                                                           "\n";
15198         static const GLchar* gs_tested = "#version 430 core\n"
15199                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15200                                                                          "\n"
15201                                                                          "layout(points)                           in;\n"
15202                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15203                                                                          "\n"
15204                                                                          "VAR_DEFINITION"
15205                                                                          "\n"
15206                                                                          "in  vec4 tes_gs[];\n"
15207                                                                          "out vec4 gs_fs;\n"
15208                                                                          "\n"
15209                                                                          "void main()\n"
15210                                                                          "{\n"
15211                                                                          "    vec4 result = tes_gs[0];\n"
15212                                                                          "\n"
15213                                                                          "VARIABLE_USE"
15214                                                                          "\n"
15215                                                                          "    gs_fs = result;\n"
15216                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15217                                                                          "    EmitVertex();\n"
15218                                                                          "    gs_fs = result;\n"
15219                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15220                                                                          "    EmitVertex();\n"
15221                                                                          "    gs_fs = result;\n"
15222                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15223                                                                          "    EmitVertex();\n"
15224                                                                          "    gs_fs = result;\n"
15225                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15226                                                                          "    EmitVertex();\n"
15227                                                                          "}\n"
15228                                                                          "\n";
15229         static const GLchar* tcs = "#version 430 core\n"
15230                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15231                                                            "\n"
15232                                                            "layout(vertices = 1) out;\n"
15233                                                            "\n"
15234                                                            "in  vec4 vs_tcs[];\n"
15235                                                            "out vec4 tcs_tes[];\n"
15236                                                            "\n"
15237                                                            "void main()\n"
15238                                                            "{\n"
15239                                                            "\n"
15240                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15241                                                            "\n"
15242                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15243                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15244                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15245                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15246                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15247                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15248                                                            "}\n"
15249                                                            "\n";
15250         static const GLchar* tcs_tested = "#version 430 core\n"
15251                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15252                                                                           "\n"
15253                                                                           "layout(vertices = 1) out;\n"
15254                                                                           "\n"
15255                                                                           "VAR_DEFINITION"
15256                                                                           "\n"
15257                                                                           "in  vec4 vs_tcs[];\n"
15258                                                                           "out vec4 tcs_tes[];\n"
15259                                                                           "\n"
15260                                                                           "void main()\n"
15261                                                                           "{\n"
15262                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15263                                                                           "\n"
15264                                                                           "VARIABLE_USE"
15265                                                                           "\n"
15266                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15267                                                                           "\n"
15268                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15269                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15270                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15271                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15272                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15273                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15274                                                                           "}\n"
15275                                                                           "\n";
15276         static const GLchar* tes = "#version 430 core\n"
15277                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15278                                                            "\n"
15279                                                            "layout(isolines, point_mode) in;\n"
15280                                                            "\n"
15281                                                            "in  vec4 tcs_tes[];\n"
15282                                                            "out vec4 tes_gs;\n"
15283                                                            "\n"
15284                                                            "void main()\n"
15285                                                            "{\n"
15286                                                            "    tes_gs = tcs_tes[0];\n"
15287                                                            "}\n"
15288                                                            "\n";
15289         static const GLchar* tes_tested = "#version 430 core\n"
15290                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15291                                                                           "\n"
15292                                                                           "layout(isolines, point_mode) in;\n"
15293                                                                           "\n"
15294                                                                           "VAR_DEFINITION"
15295                                                                           "\n"
15296                                                                           "in  vec4 tcs_tes[];\n"
15297                                                                           "out vec4 tes_gs;\n"
15298                                                                           "\n"
15299                                                                           "void main()\n"
15300                                                                           "{\n"
15301                                                                           "    vec4 result = tcs_tes[0];\n"
15302                                                                           "\n"
15303                                                                           "VARIABLE_USE"
15304                                                                           "\n"
15305                                                                           "    tes_gs += result;\n"
15306                                                                           "}\n"
15307                                                                           "\n";
15308         static const GLchar* vs = "#version 430 core\n"
15309                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15310                                                           "\n"
15311                                                           "in  vec4 in_vs;\n"
15312                                                           "out vec4 vs_tcs;\n"
15313                                                           "\n"
15314                                                           "void main()\n"
15315                                                           "{\n"
15316                                                           "    vs_tcs = in_vs;\n"
15317                                                           "}\n"
15318                                                           "\n";
15319         static const GLchar* vs_tested = "#version 430 core\n"
15320                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15321                                                                          "\n"
15322                                                                          "VAR_DEFINITION"
15323                                                                          "\n"
15324                                                                          "in  vec4 in_vs;\n"
15325                                                                          "out vec4 vs_tcs;\n"
15326                                                                          "\n"
15327                                                                          "void main()\n"
15328                                                                          "{\n"
15329                                                                          "    vec4 result = in_vs;\n"
15330                                                                          "\n"
15331                                                                          "VARIABLE_USE"
15332                                                                          "\n"
15333                                                                          "    vs_tcs += result;\n"
15334                                                                          "}\n"
15335                                                                          "\n";
15336
15337         std::string source;
15338         testCase&   test_case = m_test_cases[test_case_index];
15339
15340         if (test_case.m_stage == stage)
15341         {
15342                 const GLchar* array = "";
15343                 GLchar            buffer[16];
15344                 const GLchar* var_definition = 0;
15345                 const GLchar* direction          = "in ";
15346                 const GLchar* index                      = "";
15347                 size_t            position               = 0;
15348                 size_t            temp;
15349                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15350                 const GLchar* var_use   = 0;
15351
15352                 if (false == test_case.m_is_input)
15353                 {
15354                         direction = "out";
15355
15356                         if (false == test_case.m_is_array)
15357                         {
15358                                 var_definition = var_definition_one;
15359                                 var_use            = output_use_one;
15360                         }
15361                         else
15362                         {
15363                                 var_definition = var_definition_arr;
15364                                 var_use            = output_use_arr;
15365                         }
15366                 }
15367                 else
15368                 {
15369                         if (false == test_case.m_is_array)
15370                         {
15371                                 var_definition = var_definition_one;
15372                                 var_use            = input_use_one;
15373                         }
15374                         else
15375                         {
15376                                 var_definition = var_definition_arr;
15377                                 var_use            = input_use_arr;
15378                         }
15379                 }
15380
15381                 sprintf(buffer, "%d", test_case.m_component);
15382
15383                 switch (stage)
15384                 {
15385                 case Utils::Shader::FRAGMENT:
15386                         source = fs_tested;
15387                         break;
15388                 case Utils::Shader::GEOMETRY:
15389                         source = gs_tested;
15390                         array  = "[]";
15391                         index  = "[0]";
15392                         break;
15393                 case Utils::Shader::TESS_CTRL:
15394                         source = tcs_tested;
15395                         array  = "[]";
15396                         index  = "[gl_InvocationID]";
15397                         break;
15398                 case Utils::Shader::TESS_EVAL:
15399                         source = tes_tested;
15400                         array  = "[]";
15401                         index  = "[0]";
15402                         break;
15403                 case Utils::Shader::VERTEX:
15404                         source = vs_tested;
15405                         break;
15406                 default:
15407                         TCU_FAIL("Invalid enum");
15408                 }
15409
15410                 temp = position;
15411                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15412                 position = temp;
15413                 Utils::replaceToken("COMPONENT", position, buffer, source);
15414                 Utils::replaceToken("DIRECTION", position, direction, source);
15415                 Utils::replaceToken("ARRAY", position, array, source);
15416                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15417
15418                 Utils::replaceAllTokens("TYPE", type_name, source);
15419                 Utils::replaceAllTokens("INDEX", index, source);
15420         }
15421         else
15422         {
15423                 switch (stage)
15424                 {
15425                 case Utils::Shader::FRAGMENT:
15426                         source = fs;
15427                         break;
15428                 case Utils::Shader::GEOMETRY:
15429                         source = gs;
15430                         break;
15431                 case Utils::Shader::TESS_CTRL:
15432                         source = tcs;
15433                         break;
15434                 case Utils::Shader::TESS_EVAL:
15435                         source = tes;
15436                         break;
15437                 case Utils::Shader::VERTEX:
15438                         source = vs;
15439                         break;
15440                 default:
15441                         TCU_FAIL("Invalid enum");
15442                 }
15443         }
15444
15445         return source;
15446 }
15447
15448 /** Get description of test case
15449  *
15450  * @param test_case_index Index of test case
15451  *
15452  * @return Test case description
15453  **/
15454 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15455 {
15456         std::stringstream stream;
15457         testCase&                 test_case = m_test_cases[test_case_index];
15458
15459         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15460                    << " type: " << test_case.m_type.GetGLSLTypeName();
15461
15462         if (true == test_case.m_is_array)
15463         {
15464                 stream << "[1]";
15465         }
15466
15467         stream << ", direction: ";
15468
15469         if (true == test_case.m_is_input)
15470         {
15471                 stream << "input";
15472         }
15473         else
15474         {
15475                 stream << "output";
15476         }
15477
15478         stream << ", component: " << test_case.m_component;
15479
15480         return stream.str();
15481 }
15482
15483 /** Get number of test cases
15484  *
15485  * @return Number of test cases
15486  **/
15487 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15488 {
15489         return static_cast<GLuint>(m_test_cases.size());
15490 }
15491
15492 /** Selects if "compute" stage is relevant for test
15493  *
15494  * @param ignored
15495  *
15496  * @return false
15497  **/
15498 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15499 {
15500         return false;
15501 }
15502
15503 /** Prepare all test cases
15504  *
15505  **/
15506 void VaryingExceedingComponentsTest::testInit()
15507 {
15508         static const GLuint n_components_per_location = 4;
15509         const GLuint            n_types                                   = getTypesNumber();
15510
15511         for (GLuint i = 0; i < n_types; ++i)
15512         {
15513                 const Utils::Type& type                          = getType(i);
15514                 const GLuint       n_req_components  = type.m_n_rows;
15515                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15516                 const GLuint       invalid_component = valid_component + 1;
15517
15518                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15519                 {
15520                         if (Utils::Shader::COMPUTE == stage)
15521                         {
15522                                 continue;
15523                         }
15524
15525                         /* Component cannot be used for matrices */
15526                         if (1 != type.m_n_columns)
15527                         {
15528                                 continue;
15529                         }
15530
15531                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15532                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15533                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15534                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15535
15536                         m_test_cases.push_back(test_case_in_arr);
15537                         m_test_cases.push_back(test_case_in_one);
15538
15539                         if (Utils::Shader::FRAGMENT != stage)
15540                         {
15541                                 m_test_cases.push_back(test_case_out_arr);
15542                                 m_test_cases.push_back(test_case_out_one);
15543                         }
15544                 }
15545         }
15546 }
15547
15548 /** Constructor
15549  *
15550  * @param context Test framework context
15551  **/
15552 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15553         : NegativeTestBase(context, "varying_component_without_location",
15554                                            "Test verifies that compiler reports error when component qualifier is used without location")
15555 {
15556 }
15557
15558 /** Source for given test case and stage
15559  *
15560  * @param test_case_index Index of test case
15561  * @param stage           Shader stage
15562  *
15563  * @return Shader source
15564  **/
15565 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15566 {
15567         static const GLchar* var_definition = "layout (component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15568         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15569                                                                          "    {\n"
15570                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15571                                                                          "    }\n";
15572         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15573                                                                           "    if (vec4(0) == result)\n"
15574                                                                           "    {\n"
15575                                                                           "        gokuINDEX = TYPE(1);\n"
15576                                                                           "    }\n";
15577         static const GLchar* fs = "#version 430 core\n"
15578                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15579                                                           "\n"
15580                                                           "in  vec4 gs_fs;\n"
15581                                                           "out vec4 fs_out;\n"
15582                                                           "\n"
15583                                                           "void main()\n"
15584                                                           "{\n"
15585                                                           "    fs_out = gs_fs;\n"
15586                                                           "}\n"
15587                                                           "\n";
15588         static const GLchar* fs_tested = "#version 430 core\n"
15589                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15590                                                                          "\n"
15591                                                                          "VAR_DEFINITION"
15592                                                                          "\n"
15593                                                                          "in  vec4 gs_fs;\n"
15594                                                                          "out vec4 fs_out;\n"
15595                                                                          "\n"
15596                                                                          "void main()\n"
15597                                                                          "{\n"
15598                                                                          "    vec4 result = gs_fs;\n"
15599                                                                          "\n"
15600                                                                          "VARIABLE_USE"
15601                                                                          "\n"
15602                                                                          "    fs_out += result;\n"
15603                                                                          "}\n"
15604                                                                          "\n";
15605         static const GLchar* gs = "#version 430 core\n"
15606                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15607                                                           "\n"
15608                                                           "layout(points)                           in;\n"
15609                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15610                                                           "\n"
15611                                                           "in  vec4 tes_gs[];\n"
15612                                                           "out vec4 gs_fs;\n"
15613                                                           "\n"
15614                                                           "void main()\n"
15615                                                           "{\n"
15616                                                           "    gs_fs = tes_gs[0];\n"
15617                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15618                                                           "    EmitVertex();\n"
15619                                                           "    gs_fs = tes_gs[0];\n"
15620                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15621                                                           "    EmitVertex();\n"
15622                                                           "    gs_fs = tes_gs[0];\n"
15623                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15624                                                           "    EmitVertex();\n"
15625                                                           "    gs_fs = tes_gs[0];\n"
15626                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15627                                                           "    EmitVertex();\n"
15628                                                           "}\n"
15629                                                           "\n";
15630         static const GLchar* gs_tested = "#version 430 core\n"
15631                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15632                                                                          "\n"
15633                                                                          "layout(points)                           in;\n"
15634                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15635                                                                          "\n"
15636                                                                          "VAR_DEFINITION"
15637                                                                          "\n"
15638                                                                          "in  vec4 tes_gs[];\n"
15639                                                                          "out vec4 gs_fs;\n"
15640                                                                          "\n"
15641                                                                          "void main()\n"
15642                                                                          "{\n"
15643                                                                          "    vec4 result = tes_gs[0];\n"
15644                                                                          "\n"
15645                                                                          "VARIABLE_USE"
15646                                                                          "\n"
15647                                                                          "    gs_fs = result;\n"
15648                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15649                                                                          "    EmitVertex();\n"
15650                                                                          "    gs_fs = result;\n"
15651                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15652                                                                          "    EmitVertex();\n"
15653                                                                          "    gs_fs = result;\n"
15654                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15655                                                                          "    EmitVertex();\n"
15656                                                                          "    gs_fs = result;\n"
15657                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15658                                                                          "    EmitVertex();\n"
15659                                                                          "}\n"
15660                                                                          "\n";
15661         static const GLchar* tcs = "#version 430 core\n"
15662                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15663                                                            "\n"
15664                                                            "layout(vertices = 1) out;\n"
15665                                                            "\n"
15666                                                            "in  vec4 vs_tcs[];\n"
15667                                                            "out vec4 tcs_tes[];\n"
15668                                                            "\n"
15669                                                            "void main()\n"
15670                                                            "{\n"
15671                                                            "\n"
15672                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15673                                                            "\n"
15674                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15675                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15676                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15677                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15678                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15679                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15680                                                            "}\n"
15681                                                            "\n";
15682         static const GLchar* tcs_tested = "#version 430 core\n"
15683                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15684                                                                           "\n"
15685                                                                           "layout(vertices = 1) out;\n"
15686                                                                           "\n"
15687                                                                           "VAR_DEFINITION"
15688                                                                           "\n"
15689                                                                           "in  vec4 vs_tcs[];\n"
15690                                                                           "out vec4 tcs_tes[];\n"
15691                                                                           "\n"
15692                                                                           "void main()\n"
15693                                                                           "{\n"
15694                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15695                                                                           "\n"
15696                                                                           "VARIABLE_USE"
15697                                                                           "\n"
15698                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15699                                                                           "\n"
15700                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15701                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15702                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15703                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15704                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15705                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15706                                                                           "}\n"
15707                                                                           "\n";
15708         static const GLchar* tes = "#version 430 core\n"
15709                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15710                                                            "\n"
15711                                                            "layout(isolines, point_mode) in;\n"
15712                                                            "\n"
15713                                                            "in  vec4 tcs_tes[];\n"
15714                                                            "out vec4 tes_gs;\n"
15715                                                            "\n"
15716                                                            "void main()\n"
15717                                                            "{\n"
15718                                                            "    tes_gs = tcs_tes[0];\n"
15719                                                            "}\n"
15720                                                            "\n";
15721         static const GLchar* tes_tested = "#version 430 core\n"
15722                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15723                                                                           "\n"
15724                                                                           "layout(isolines, point_mode) in;\n"
15725                                                                           "\n"
15726                                                                           "VAR_DEFINITION"
15727                                                                           "\n"
15728                                                                           "in  vec4 tcs_tes[];\n"
15729                                                                           "out vec4 tes_gs;\n"
15730                                                                           "\n"
15731                                                                           "void main()\n"
15732                                                                           "{\n"
15733                                                                           "    vec4 result = tcs_tes[0];\n"
15734                                                                           "\n"
15735                                                                           "VARIABLE_USE"
15736                                                                           "\n"
15737                                                                           "    tes_gs += result;\n"
15738                                                                           "}\n"
15739                                                                           "\n";
15740         static const GLchar* vs = "#version 430 core\n"
15741                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15742                                                           "\n"
15743                                                           "in  vec4 in_vs;\n"
15744                                                           "out vec4 vs_tcs;\n"
15745                                                           "\n"
15746                                                           "void main()\n"
15747                                                           "{\n"
15748                                                           "    vs_tcs = in_vs;\n"
15749                                                           "}\n"
15750                                                           "\n";
15751         static const GLchar* vs_tested = "#version 430 core\n"
15752                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15753                                                                          "\n"
15754                                                                          "VAR_DEFINITION"
15755                                                                          "\n"
15756                                                                          "in  vec4 in_vs;\n"
15757                                                                          "out vec4 vs_tcs;\n"
15758                                                                          "\n"
15759                                                                          "void main()\n"
15760                                                                          "{\n"
15761                                                                          "    vec4 result = in_vs;\n"
15762                                                                          "\n"
15763                                                                          "VARIABLE_USE"
15764                                                                          "\n"
15765                                                                          "    vs_tcs += result;\n"
15766                                                                          "}\n"
15767                                                                          "\n";
15768
15769         std::string source;
15770         testCase&   test_case = m_test_cases[test_case_index];
15771
15772         if (test_case.m_stage == stage)
15773         {
15774                 const GLchar* array = "";
15775                 GLchar            buffer[16];
15776                 const GLchar* direction = "in ";
15777                 const GLchar* index             = "";
15778                 size_t            position  = 0;
15779                 size_t            temp;
15780                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15781                 const GLchar* var_use   = input_use;
15782
15783                 if (false == test_case.m_is_input)
15784                 {
15785                         direction = "out";
15786                         var_use   = output_use;
15787                 }
15788
15789                 sprintf(buffer, "%d", test_case.m_component);
15790
15791                 switch (stage)
15792                 {
15793                 case Utils::Shader::FRAGMENT:
15794                         source = fs_tested;
15795                         break;
15796                 case Utils::Shader::GEOMETRY:
15797                         source = gs_tested;
15798                         array  = "[]";
15799                         index  = "[0]";
15800                         break;
15801                 case Utils::Shader::TESS_CTRL:
15802                         source = tcs_tested;
15803                         array  = "[]";
15804                         index  = "[gl_InvocationID]";
15805                         break;
15806                 case Utils::Shader::TESS_EVAL:
15807                         source = tes_tested;
15808                         array  = "[]";
15809                         index  = "[0]";
15810                         break;
15811                 case Utils::Shader::VERTEX:
15812                         source = vs_tested;
15813                         break;
15814                 default:
15815                         TCU_FAIL("Invalid enum");
15816                 }
15817
15818                 temp = position;
15819                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15820                 position = temp;
15821                 Utils::replaceToken("COMPONENT", position, buffer, source);
15822                 Utils::replaceToken("DIRECTION", position, direction, source);
15823                 Utils::replaceToken("ARRAY", position, array, source);
15824                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15825
15826                 Utils::replaceAllTokens("TYPE", type_name, source);
15827                 Utils::replaceAllTokens("INDEX", index, source);
15828         }
15829         else
15830         {
15831                 switch (stage)
15832                 {
15833                 case Utils::Shader::FRAGMENT:
15834                         source = fs;
15835                         break;
15836                 case Utils::Shader::GEOMETRY:
15837                         source = gs;
15838                         break;
15839                 case Utils::Shader::TESS_CTRL:
15840                         source = tcs;
15841                         break;
15842                 case Utils::Shader::TESS_EVAL:
15843                         source = tes;
15844                         break;
15845                 case Utils::Shader::VERTEX:
15846                         source = vs;
15847                         break;
15848                 default:
15849                         TCU_FAIL("Invalid enum");
15850                 }
15851         }
15852
15853         return source;
15854 }
15855
15856 /** Get description of test case
15857  *
15858  * @param test_case_index Index of test case
15859  *
15860  * @return Test case description
15861  **/
15862 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15863 {
15864         std::stringstream stream;
15865         testCase&                 test_case = m_test_cases[test_case_index];
15866
15867         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15868                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15869
15870         if (true == test_case.m_is_input)
15871         {
15872                 stream << "input";
15873         }
15874         else
15875         {
15876                 stream << "output";
15877         }
15878
15879         stream << ", component: " << test_case.m_component;
15880
15881         return stream.str();
15882 }
15883
15884 /** Get number of test cases
15885  *
15886  * @return Number of test cases
15887  **/
15888 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
15889 {
15890         return static_cast<GLuint>(m_test_cases.size());
15891 }
15892
15893 /** Selects if "compute" stage is relevant for test
15894  *
15895  * @param ignored
15896  *
15897  * @return false
15898  **/
15899 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
15900 {
15901         return false;
15902 }
15903
15904 /** Prepare all test cases
15905  *
15906  **/
15907 void VaryingComponentWithoutLocationTest::testInit()
15908 {
15909         static const GLuint n_components_per_location = 4;
15910         const GLuint            n_types                                   = getTypesNumber();
15911
15912         for (GLuint i = 0; i < n_types; ++i)
15913         {
15914                 const Utils::Type& type                         = getType(i);
15915                 const GLuint       n_req_components = type.m_n_rows;
15916                 const GLuint       valid_component  = n_components_per_location - n_req_components;
15917
15918                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15919                 {
15920                         if (Utils::Shader::COMPUTE == stage)
15921                         {
15922                                 continue;
15923                         }
15924
15925                         /* Component cannot be used for matrices */
15926                         if (1 != type.m_n_columns)
15927                         {
15928                                 continue;
15929                         }
15930
15931                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
15932                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
15933
15934                         m_test_cases.push_back(test_case_in);
15935
15936                         if (Utils::Shader::FRAGMENT != stage)
15937                         {
15938                                 m_test_cases.push_back(test_case_out);
15939                         }
15940                 }
15941         }
15942 }
15943
15944 /** Constructor
15945  *
15946  * @param context Test framework context
15947  **/
15948 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
15949         : NegativeTestBase(context, "varying_component_of_invalid_type",
15950                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
15951 {
15952 }
15953
15954 /** Source for given test case and stage
15955  *
15956  * @param test_case_index Index of test case
15957  * @param stage           Shader stage
15958  *
15959  * @return Shader source
15960  **/
15961 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15962 {
15963         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15964                                                                                                 "    TYPE member;\n"
15965                                                                                                 "} gokuARRAY[1];\n";
15966         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15967                                                                                                 "    TYPE member;\n"
15968                                                                                                 "} gokuARRAY;\n";
15969         static const GLchar* matrix_definition_arr =
15970                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15971         static const GLchar* matrix_definition_one =
15972                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15973         static const GLchar* struct_definition_arr =
15974                 "struct Goku {\n"
15975                 "    TYPE member;\n"
15976                 "};\n"
15977                 "\n"
15978                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
15979         static const GLchar* struct_definition_one =
15980                 "struct Goku {\n"
15981                 "    TYPE member;\n"
15982                 "};\n"
15983                 "\n"
15984                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
15985         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15986                                                                                                 "    {\n"
15987                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15988                                                                                                 "    }\n";
15989         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15990                                                                                                 "    {\n"
15991                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15992                                                                                                 "    }\n";
15993         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15994                                                                                                  "    if (vec4(0) == result)\n"
15995                                                                                                  "    {\n"
15996                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
15997                                                                                                  "    }\n";
15998         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
15999                                                                                                  "    if (vec4(0) == result)\n"
16000                                                                                                  "    {\n"
16001                                                                                                  "        gokuINDEX = TYPE(1);\n"
16002                                                                                                  "    }\n";
16003         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16004                                                                                                 "    {\n"
16005                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16006                                                                                                 "    }\n";
16007         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16008                                                                                                 "    {\n"
16009                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16010                                                                                                 "    }\n";
16011         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16012                                                                                                  "    if (vec4(0) == result)\n"
16013                                                                                                  "    {\n"
16014                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16015                                                                                                  "    }\n";
16016         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16017                                                                                                  "    if (vec4(0) == result)\n"
16018                                                                                                  "    {\n"
16019                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16020                                                                                                  "    }\n";
16021         static const GLchar* fs = "#version 430 core\n"
16022                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16023                                                           "\n"
16024                                                           "in  vec4 gs_fs;\n"
16025                                                           "out vec4 fs_out;\n"
16026                                                           "\n"
16027                                                           "void main()\n"
16028                                                           "{\n"
16029                                                           "    fs_out = gs_fs;\n"
16030                                                           "}\n"
16031                                                           "\n";
16032         static const GLchar* fs_tested = "#version 430 core\n"
16033                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16034                                                                          "\n"
16035                                                                          "VAR_DEFINITION"
16036                                                                          "\n"
16037                                                                          "in  vec4 gs_fs;\n"
16038                                                                          "out vec4 fs_out;\n"
16039                                                                          "\n"
16040                                                                          "void main()\n"
16041                                                                          "{\n"
16042                                                                          "    vec4 result = gs_fs;\n"
16043                                                                          "\n"
16044                                                                          "VARIABLE_USE"
16045                                                                          "\n"
16046                                                                          "    fs_out += result;\n"
16047                                                                          "}\n"
16048                                                                          "\n";
16049         static const GLchar* gs = "#version 430 core\n"
16050                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16051                                                           "\n"
16052                                                           "layout(points)                           in;\n"
16053                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16054                                                           "\n"
16055                                                           "in  vec4 tes_gs[];\n"
16056                                                           "out vec4 gs_fs;\n"
16057                                                           "\n"
16058                                                           "void main()\n"
16059                                                           "{\n"
16060                                                           "    gs_fs = tes_gs[0];\n"
16061                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16062                                                           "    EmitVertex();\n"
16063                                                           "    gs_fs = tes_gs[0];\n"
16064                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16065                                                           "    EmitVertex();\n"
16066                                                           "    gs_fs = tes_gs[0];\n"
16067                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16068                                                           "    EmitVertex();\n"
16069                                                           "    gs_fs = tes_gs[0];\n"
16070                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16071                                                           "    EmitVertex();\n"
16072                                                           "}\n"
16073                                                           "\n";
16074         static const GLchar* gs_tested = "#version 430 core\n"
16075                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16076                                                                          "\n"
16077                                                                          "layout(points)                           in;\n"
16078                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16079                                                                          "\n"
16080                                                                          "VAR_DEFINITION"
16081                                                                          "\n"
16082                                                                          "in  vec4 tes_gs[];\n"
16083                                                                          "out vec4 gs_fs;\n"
16084                                                                          "\n"
16085                                                                          "void main()\n"
16086                                                                          "{\n"
16087                                                                          "    vec4 result = tes_gs[0];\n"
16088                                                                          "\n"
16089                                                                          "VARIABLE_USE"
16090                                                                          "\n"
16091                                                                          "    gs_fs = result;\n"
16092                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16093                                                                          "    EmitVertex();\n"
16094                                                                          "    gs_fs = result;\n"
16095                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16096                                                                          "    EmitVertex();\n"
16097                                                                          "    gs_fs = result;\n"
16098                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16099                                                                          "    EmitVertex();\n"
16100                                                                          "    gs_fs = result;\n"
16101                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16102                                                                          "    EmitVertex();\n"
16103                                                                          "}\n"
16104                                                                          "\n";
16105         static const GLchar* tcs = "#version 430 core\n"
16106                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16107                                                            "\n"
16108                                                            "layout(vertices = 1) out;\n"
16109                                                            "\n"
16110                                                            "in  vec4 vs_tcs[];\n"
16111                                                            "out vec4 tcs_tes[];\n"
16112                                                            "\n"
16113                                                            "void main()\n"
16114                                                            "{\n"
16115                                                            "\n"
16116                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16117                                                            "\n"
16118                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16119                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16120                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16121                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16122                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16123                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16124                                                            "}\n"
16125                                                            "\n";
16126         static const GLchar* tcs_tested = "#version 430 core\n"
16127                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16128                                                                           "\n"
16129                                                                           "layout(vertices = 1) out;\n"
16130                                                                           "\n"
16131                                                                           "VAR_DEFINITION"
16132                                                                           "\n"
16133                                                                           "in  vec4 vs_tcs[];\n"
16134                                                                           "out vec4 tcs_tes[];\n"
16135                                                                           "\n"
16136                                                                           "void main()\n"
16137                                                                           "{\n"
16138                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16139                                                                           "\n"
16140                                                                           "VARIABLE_USE"
16141                                                                           "\n"
16142                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16143                                                                           "\n"
16144                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16145                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16146                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16147                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16148                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16149                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16150                                                                           "}\n"
16151                                                                           "\n";
16152         static const GLchar* tes = "#version 430 core\n"
16153                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16154                                                            "\n"
16155                                                            "layout(isolines, point_mode) in;\n"
16156                                                            "\n"
16157                                                            "in  vec4 tcs_tes[];\n"
16158                                                            "out vec4 tes_gs;\n"
16159                                                            "\n"
16160                                                            "void main()\n"
16161                                                            "{\n"
16162                                                            "    tes_gs = tcs_tes[0];\n"
16163                                                            "}\n"
16164                                                            "\n";
16165         static const GLchar* tes_tested = "#version 430 core\n"
16166                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16167                                                                           "\n"
16168                                                                           "layout(isolines, point_mode) in;\n"
16169                                                                           "\n"
16170                                                                           "VAR_DEFINITION"
16171                                                                           "\n"
16172                                                                           "in  vec4 tcs_tes[];\n"
16173                                                                           "out vec4 tes_gs;\n"
16174                                                                           "\n"
16175                                                                           "void main()\n"
16176                                                                           "{\n"
16177                                                                           "    vec4 result = tcs_tes[0];\n"
16178                                                                           "\n"
16179                                                                           "VARIABLE_USE"
16180                                                                           "\n"
16181                                                                           "    tes_gs += result;\n"
16182                                                                           "}\n"
16183                                                                           "\n";
16184         static const GLchar* vs = "#version 430 core\n"
16185                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16186                                                           "\n"
16187                                                           "in  vec4 in_vs;\n"
16188                                                           "out vec4 vs_tcs;\n"
16189                                                           "\n"
16190                                                           "void main()\n"
16191                                                           "{\n"
16192                                                           "    vs_tcs = in_vs;\n"
16193                                                           "}\n"
16194                                                           "\n";
16195         static const GLchar* vs_tested = "#version 430 core\n"
16196                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16197                                                                          "\n"
16198                                                                          "VAR_DEFINITION"
16199                                                                          "\n"
16200                                                                          "in  vec4 in_vs;\n"
16201                                                                          "out vec4 vs_tcs;\n"
16202                                                                          "\n"
16203                                                                          "void main()\n"
16204                                                                          "{\n"
16205                                                                          "    vec4 result = in_vs;\n"
16206                                                                          "\n"
16207                                                                          "VARIABLE_USE"
16208                                                                          "\n"
16209                                                                          "    vs_tcs += result;\n"
16210                                                                          "}\n"
16211                                                                          "\n";
16212
16213         std::string source;
16214         testCase&   test_case = m_test_cases[test_case_index];
16215
16216         if (test_case.m_stage == stage)
16217         {
16218                 const GLchar* array = "";
16219                 GLchar            buffer[16];
16220                 const GLchar* var_definition = 0;
16221                 const GLchar* direction          = "in ";
16222                 const GLchar* index                      = "";
16223                 size_t            position               = 0;
16224                 size_t            temp;
16225                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16226                 const GLchar* var_use   = 0;
16227
16228                 if (false == test_case.m_is_input)
16229                 {
16230                         direction = "out";
16231
16232                         if (false == test_case.m_is_array)
16233                         {
16234                                 switch (test_case.m_case)
16235                                 {
16236                                 case BLOCK:
16237                                         var_definition = block_definition_one;
16238                                         var_use            = member_output_use_one;
16239                                         break;
16240                                 case MATRIX:
16241                                         var_definition = matrix_definition_one;
16242                                         var_use            = matrix_output_use_one;
16243                                         break;
16244                                 case STRUCT:
16245                                         var_definition = struct_definition_one;
16246                                         var_use            = member_output_use_one;
16247                                         break;
16248                                 default:
16249                                         TCU_FAIL("Invalid enum");
16250                                 }
16251                         }
16252                         else
16253                         {
16254                                 switch (test_case.m_case)
16255                                 {
16256                                 case BLOCK:
16257                                         var_definition = block_definition_arr;
16258                                         var_use            = member_output_use_arr;
16259                                         break;
16260                                 case MATRIX:
16261                                         var_definition = matrix_definition_arr;
16262                                         var_use            = matrix_output_use_arr;
16263                                         break;
16264                                 case STRUCT:
16265                                         var_definition = struct_definition_arr;
16266                                         var_use            = member_output_use_arr;
16267                                         break;
16268                                 default:
16269                                         TCU_FAIL("Invalid enum");
16270                                 }
16271                         }
16272                 }
16273                 else
16274                 {
16275                         if (false == test_case.m_is_array)
16276                         {
16277                                 switch (test_case.m_case)
16278                                 {
16279                                 case BLOCK:
16280                                         var_definition = block_definition_one;
16281                                         var_use            = member_input_use_one;
16282                                         break;
16283                                 case MATRIX:
16284                                         var_definition = matrix_definition_one;
16285                                         var_use            = matrix_input_use_one;
16286                                         break;
16287                                 case STRUCT:
16288                                         var_definition = struct_definition_one;
16289                                         var_use            = member_input_use_one;
16290                                         break;
16291                                 default:
16292                                         TCU_FAIL("Invalid enum");
16293                                 }
16294                         }
16295                         else
16296                         {
16297                                 switch (test_case.m_case)
16298                                 {
16299                                 case BLOCK:
16300                                         var_definition = block_definition_arr;
16301                                         var_use            = member_input_use_arr;
16302                                         break;
16303                                 case MATRIX:
16304                                         var_definition = matrix_definition_arr;
16305                                         var_use            = matrix_input_use_arr;
16306                                         break;
16307                                 case STRUCT:
16308                                         var_definition = struct_definition_arr;
16309                                         var_use            = member_input_use_arr;
16310                                         break;
16311                                 default:
16312                                         TCU_FAIL("Invalid enum");
16313                                 }
16314                         }
16315                 }
16316
16317                 sprintf(buffer, "%d", test_case.m_component);
16318
16319                 switch (stage)
16320                 {
16321                 case Utils::Shader::FRAGMENT:
16322                         source = fs_tested;
16323                         break;
16324                 case Utils::Shader::GEOMETRY:
16325                         source = gs_tested;
16326                         array  = "[]";
16327                         index  = "[0]";
16328                         break;
16329                 case Utils::Shader::TESS_CTRL:
16330                         source = tcs_tested;
16331                         array  = "[]";
16332                         index  = "[gl_InvocationID]";
16333                         break;
16334                 case Utils::Shader::TESS_EVAL:
16335                         source = tes_tested;
16336                         array  = "[]";
16337                         index  = "[0]";
16338                         break;
16339                 case Utils::Shader::VERTEX:
16340                         source = vs_tested;
16341                         break;
16342                 default:
16343                         TCU_FAIL("Invalid enum");
16344                 }
16345
16346                 temp = position;
16347                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16348                 position = temp;
16349                 Utils::replaceToken("COMPONENT", position, buffer, source);
16350                 Utils::replaceToken("DIRECTION", position, direction, source);
16351                 Utils::replaceToken("ARRAY", position, array, source);
16352                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16353
16354                 Utils::replaceAllTokens("TYPE", type_name, source);
16355                 Utils::replaceAllTokens("INDEX", index, source);
16356         }
16357         else
16358         {
16359                 switch (stage)
16360                 {
16361                 case Utils::Shader::FRAGMENT:
16362                         source = fs;
16363                         break;
16364                 case Utils::Shader::GEOMETRY:
16365                         source = gs;
16366                         break;
16367                 case Utils::Shader::TESS_CTRL:
16368                         source = tcs;
16369                         break;
16370                 case Utils::Shader::TESS_EVAL:
16371                         source = tes;
16372                         break;
16373                 case Utils::Shader::VERTEX:
16374                         source = vs;
16375                         break;
16376                 default:
16377                         TCU_FAIL("Invalid enum");
16378                 }
16379         }
16380
16381         return source;
16382 }
16383
16384 /** Get description of test case
16385  *
16386  * @param test_case_index Index of test case
16387  *
16388  * @return Test case description
16389  **/
16390 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16391 {
16392         std::stringstream stream;
16393         testCase&                 test_case = m_test_cases[test_case_index];
16394
16395         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16396                    << " type: " << test_case.m_type.GetGLSLTypeName();
16397
16398         if (true == test_case.m_is_array)
16399         {
16400                 stream << "[1]";
16401         }
16402
16403         stream << ", direction: ";
16404
16405         if (true == test_case.m_is_input)
16406         {
16407                 stream << "input";
16408         }
16409         else
16410         {
16411                 stream << "output";
16412         }
16413
16414         stream << ", component: " << test_case.m_component;
16415
16416         return stream.str();
16417 }
16418
16419 /** Get number of test cases
16420  *
16421  * @return Number of test cases
16422  **/
16423 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16424 {
16425         return static_cast<GLuint>(m_test_cases.size());
16426 }
16427
16428 /** Selects if "compute" stage is relevant for test
16429  *
16430  * @param ignored
16431  *
16432  * @return false
16433  **/
16434 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16435 {
16436         return false;
16437 }
16438
16439 /** Prepare all test cases
16440  *
16441  **/
16442 void VaryingComponentOfInvalidTypeTest::testInit()
16443 {
16444         static const GLuint n_components_per_location = 4;
16445         const GLuint            n_types                                   = getTypesNumber();
16446
16447         for (GLuint i = 0; i < n_types; ++i)
16448         {
16449                 const Utils::Type& type                         = getType(i);
16450                 const GLuint       n_req_components = type.m_n_rows;
16451                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16452
16453                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16454                 {
16455                         if (Utils::Shader::COMPUTE == stage)
16456                         {
16457                                 continue;
16458                         }
16459
16460                         /* Use different CASE for matrices */
16461                         if (1 != type.m_n_columns)
16462                         {
16463                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16464                                 testCase test_case_in_one = {
16465                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16466                                 };
16467                                 testCase test_case_out_arr = {
16468                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16469                                 };
16470                                 testCase test_case_out_one = {
16471                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16472                                 };
16473
16474                                 m_test_cases.push_back(test_case_in_arr);
16475                                 m_test_cases.push_back(test_case_in_one);
16476
16477                                 if (Utils::Shader::FRAGMENT != stage)
16478                                 {
16479                                         m_test_cases.push_back(test_case_out_arr);
16480                                         m_test_cases.push_back(test_case_out_one);
16481                                 }
16482                         }
16483                         else
16484                         {
16485                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16486                                 {
16487                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16488                                                                                                   type };
16489                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16490                                                                                                   type };
16491                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16492                                                                                                    type };
16493                                         testCase test_case_out_one = {
16494                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16495                                         };
16496
16497                                         if (Utils::Shader::VERTEX != stage)
16498                                         {
16499                                                 m_test_cases.push_back(test_case_in_arr);
16500                                                 m_test_cases.push_back(test_case_in_one);
16501                                         }
16502
16503                                         if (Utils::Shader::FRAGMENT != stage)
16504                                         {
16505                                                 m_test_cases.push_back(test_case_out_arr);
16506                                                 m_test_cases.push_back(test_case_out_one);
16507                                         }
16508                                 }
16509                         }
16510                 }
16511         }
16512 }
16513
16514 /** Constructor
16515  *
16516  * @param context Test framework context
16517  **/
16518 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16519         : NegativeTestBase(context, "input_component_aliasing",
16520                                            "Test verifies that compiler reports component aliasing as error")
16521 {
16522 }
16523
16524 /** Source for given test case and stage
16525  *
16526  * @param test_case_index Index of test case
16527  * @param stage           Shader stage
16528  *
16529  * @return Shader source
16530  **/
16531 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16532 {
16533         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16534                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16535         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16536                                                                         "    {\n"
16537                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16538                                                                         "    }\n";
16539         static const GLchar* test_both = "    if (TYPE(0) == gohanINDEX)\n"
16540                                                                          "    {\n"
16541                                                                          "        result = vec4(goten.xxxx);\n"
16542                                                                          "    }\n";
16543         static const GLchar* fs = "#version 430 core\n"
16544                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16545                                                           "\n"
16546                                                           "in  vec4 gs_fs;\n"
16547                                                           "out vec4 fs_out;\n"
16548                                                           "\n"
16549                                                           "void main()\n"
16550                                                           "{\n"
16551                                                           "    fs_out = gs_fs;\n"
16552                                                           "}\n"
16553                                                           "\n";
16554         static const GLchar* fs_tested = "#version 430 core\n"
16555                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16556                                                                          "\n"
16557                                                                          "VAR_DEFINITION"
16558                                                                          "\n"
16559                                                                          "in  vec4 gs_fs;\n"
16560                                                                          "out vec4 fs_out;\n"
16561                                                                          "\n"
16562                                                                          "void main()\n"
16563                                                                          "{\n"
16564                                                                          "    vec4 result = gs_fs;\n"
16565                                                                          "\n"
16566                                                                          "VARIABLE_USE"
16567                                                                          "\n"
16568                                                                          "    fs_out += result;\n"
16569                                                                          "}\n"
16570                                                                          "\n";
16571         static const GLchar* gs = "#version 430 core\n"
16572                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16573                                                           "\n"
16574                                                           "layout(points)                           in;\n"
16575                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16576                                                           "\n"
16577                                                           "in  vec4 tes_gs[];\n"
16578                                                           "out vec4 gs_fs;\n"
16579                                                           "\n"
16580                                                           "void main()\n"
16581                                                           "{\n"
16582                                                           "    gs_fs = tes_gs[0];\n"
16583                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16584                                                           "    EmitVertex();\n"
16585                                                           "    gs_fs = tes_gs[0];\n"
16586                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16587                                                           "    EmitVertex();\n"
16588                                                           "    gs_fs = tes_gs[0];\n"
16589                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16590                                                           "    EmitVertex();\n"
16591                                                           "    gs_fs = tes_gs[0];\n"
16592                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16593                                                           "    EmitVertex();\n"
16594                                                           "}\n"
16595                                                           "\n";
16596         static const GLchar* gs_tested = "#version 430 core\n"
16597                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16598                                                                          "\n"
16599                                                                          "layout(points)                           in;\n"
16600                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16601                                                                          "\n"
16602                                                                          "VAR_DEFINITION"
16603                                                                          "\n"
16604                                                                          "in  vec4 tes_gs[];\n"
16605                                                                          "out vec4 gs_fs;\n"
16606                                                                          "\n"
16607                                                                          "void main()\n"
16608                                                                          "{\n"
16609                                                                          "    vec4 result = tes_gs[0];\n"
16610                                                                          "\n"
16611                                                                          "VARIABLE_USE"
16612                                                                          "\n"
16613                                                                          "    gs_fs = result;\n"
16614                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16615                                                                          "    EmitVertex();\n"
16616                                                                          "    gs_fs = result;\n"
16617                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16618                                                                          "    EmitVertex();\n"
16619                                                                          "    gs_fs = result;\n"
16620                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16621                                                                          "    EmitVertex();\n"
16622                                                                          "    gs_fs = result;\n"
16623                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16624                                                                          "    EmitVertex();\n"
16625                                                                          "}\n"
16626                                                                          "\n";
16627         static const GLchar* tcs = "#version 430 core\n"
16628                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16629                                                            "\n"
16630                                                            "layout(vertices = 1) out;\n"
16631                                                            "\n"
16632                                                            "in  vec4 vs_tcs[];\n"
16633                                                            "out vec4 tcs_tes[];\n"
16634                                                            "\n"
16635                                                            "void main()\n"
16636                                                            "{\n"
16637                                                            "\n"
16638                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16639                                                            "\n"
16640                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16641                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16642                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16643                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16644                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16645                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16646                                                            "}\n"
16647                                                            "\n";
16648         static const GLchar* tcs_tested = "#version 430 core\n"
16649                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16650                                                                           "\n"
16651                                                                           "layout(vertices = 1) out;\n"
16652                                                                           "\n"
16653                                                                           "VAR_DEFINITION"
16654                                                                           "\n"
16655                                                                           "in  vec4 vs_tcs[];\n"
16656                                                                           "out vec4 tcs_tes[];\n"
16657                                                                           "\n"
16658                                                                           "void main()\n"
16659                                                                           "{\n"
16660                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16661                                                                           "\n"
16662                                                                           "VARIABLE_USE"
16663                                                                           "\n"
16664                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16665                                                                           "\n"
16666                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16667                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16668                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16669                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16670                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16671                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16672                                                                           "}\n"
16673                                                                           "\n";
16674         static const GLchar* tes = "#version 430 core\n"
16675                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16676                                                            "\n"
16677                                                            "layout(isolines, point_mode) in;\n"
16678                                                            "\n"
16679                                                            "in  vec4 tcs_tes[];\n"
16680                                                            "out vec4 tes_gs;\n"
16681                                                            "\n"
16682                                                            "void main()\n"
16683                                                            "{\n"
16684                                                            "    tes_gs = tcs_tes[0];\n"
16685                                                            "}\n"
16686                                                            "\n";
16687         static const GLchar* tes_tested = "#version 430 core\n"
16688                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16689                                                                           "\n"
16690                                                                           "layout(isolines, point_mode) in;\n"
16691                                                                           "\n"
16692                                                                           "VAR_DEFINITION"
16693                                                                           "\n"
16694                                                                           "in  vec4 tcs_tes[];\n"
16695                                                                           "out vec4 tes_gs;\n"
16696                                                                           "\n"
16697                                                                           "void main()\n"
16698                                                                           "{\n"
16699                                                                           "    vec4 result = tcs_tes[0];\n"
16700                                                                           "\n"
16701                                                                           "VARIABLE_USE"
16702                                                                           "\n"
16703                                                                           "    tes_gs += result;\n"
16704                                                                           "}\n"
16705                                                                           "\n";
16706         static const GLchar* vs = "#version 430 core\n"
16707                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16708                                                           "\n"
16709                                                           "in  vec4 in_vs;\n"
16710                                                           "out vec4 vs_tcs;\n"
16711                                                           "\n"
16712                                                           "void main()\n"
16713                                                           "{\n"
16714                                                           "    vs_tcs = in_vs;\n"
16715                                                           "}\n"
16716                                                           "\n";
16717         static const GLchar* vs_tested = "#version 430 core\n"
16718                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16719                                                                          "\n"
16720                                                                          "VAR_DEFINITION"
16721                                                                          "\n"
16722                                                                          "in  vec4 in_vs;\n"
16723                                                                          "out vec4 vs_tcs;\n"
16724                                                                          "\n"
16725                                                                          "void main()\n"
16726                                                                          "{\n"
16727                                                                          "    vec4 result = in_vs;\n"
16728                                                                          "\n"
16729                                                                          "VARIABLE_USE"
16730                                                                          "\n"
16731                                                                          "    vs_tcs += result;\n"
16732                                                                          "}\n"
16733                                                                          "\n";
16734
16735         std::string source;
16736         testCase&   test_case = m_test_cases[test_case_index];
16737
16738         if (test_case.m_stage == stage)
16739         {
16740                 const GLchar* array = "";
16741                 GLchar            buffer_gohan[16];
16742                 GLchar            buffer_goten[16];
16743                 const GLchar* flat                = "";
16744                 const GLchar* index               = "";
16745                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16746                 size_t            position      = 0;
16747                 size_t            temp;
16748                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16749                 const GLchar* var_use   = test_one;
16750
16751                 if (true == test_case.m_use_both)
16752                 {
16753                         var_use = test_both;
16754                 }
16755
16756                 if (true == is_flat_req)
16757                 {
16758                         flat = "flat";
16759                 }
16760
16761                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16762                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16763
16764                 switch (stage)
16765                 {
16766                 case Utils::Shader::FRAGMENT:
16767                         source = fs_tested;
16768                         break;
16769                 case Utils::Shader::GEOMETRY:
16770                         source = gs_tested;
16771                         array  = "[]";
16772                         index  = "[0]";
16773                         break;
16774                 case Utils::Shader::TESS_CTRL:
16775                         source = tcs_tested;
16776                         array  = "[]";
16777                         index  = "[gl_InvocationID]";
16778                         break;
16779                 case Utils::Shader::TESS_EVAL:
16780                         source = tes_tested;
16781                         array  = "[]";
16782                         index  = "[0]";
16783                         break;
16784                 case Utils::Shader::VERTEX:
16785                         source = vs_tested;
16786                         break;
16787                 default:
16788                         TCU_FAIL("Invalid enum");
16789                 }
16790
16791                 temp = position;
16792                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16793                 position = temp;
16794                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16795                 Utils::replaceToken("ARRAY", position, array, source);
16796                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16797                 Utils::replaceToken("ARRAY", position, array, source);
16798                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16799
16800                 Utils::replaceAllTokens("FLAT", flat, source);
16801                 Utils::replaceAllTokens("TYPE", type_name, source);
16802                 Utils::replaceAllTokens("INDEX", index, source);
16803         }
16804         else
16805         {
16806                 switch (stage)
16807                 {
16808                 case Utils::Shader::FRAGMENT:
16809                         source = fs;
16810                         break;
16811                 case Utils::Shader::GEOMETRY:
16812                         source = gs;
16813                         break;
16814                 case Utils::Shader::TESS_CTRL:
16815                         source = tcs;
16816                         break;
16817                 case Utils::Shader::TESS_EVAL:
16818                         source = tes;
16819                         break;
16820                 case Utils::Shader::VERTEX:
16821                         source = vs;
16822                         break;
16823                 default:
16824                         TCU_FAIL("Invalid enum");
16825                 }
16826         }
16827
16828         return source;
16829 }
16830
16831 /** Get description of test case
16832  *
16833  * @param test_case_index Index of test case
16834  *
16835  * @return Test case description
16836  **/
16837 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16838 {
16839         std::stringstream stream;
16840         testCase&                 test_case = m_test_cases[test_case_index];
16841
16842         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16843                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16844                    << " & " << test_case.m_component_goten;
16845
16846         return stream.str();
16847 }
16848
16849 /** Get number of test cases
16850  *
16851  * @return Number of test cases
16852  **/
16853 GLuint InputComponentAliasingTest::getTestCaseNumber()
16854 {
16855         return static_cast<GLuint>(m_test_cases.size());
16856 }
16857
16858 /** Selects if "compute" stage is relevant for test
16859  *
16860  * @param ignored
16861  *
16862  * @return false
16863  **/
16864 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16865 {
16866         return false;
16867 }
16868
16869 /** Selects if compilation failure is expected result
16870  *
16871  * @param test_case_index Index of test case
16872  *
16873  * @return false for VS that use only single variable, true otherwise
16874  **/
16875 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16876 {
16877         testCase& test_case = m_test_cases[test_case_index];
16878
16879         return !((Utils::Shader::VERTEX == test_case.m_stage) && (false == test_case.m_use_both));
16880 }
16881
16882 /** Prepare all test cases
16883  *
16884  **/
16885 void InputComponentAliasingTest::testInit()
16886 {
16887         static const GLuint n_components_per_location = 4;
16888         const GLuint            n_types                                   = getTypesNumber();
16889
16890         for (GLuint i = 0; i < n_types; ++i)
16891         {
16892                 const Utils::Type& type                         = getType(i);
16893                 const GLuint       n_req_components = type.m_n_rows;
16894                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16895
16896                 /* Skip matrices */
16897                 if (1 != type.m_n_columns)
16898                 {
16899                         continue;
16900                 }
16901
16902                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16903                 {
16904                         if (Utils::Shader::COMPUTE == stage)
16905                         {
16906                                 continue;
16907                         }
16908
16909                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
16910                         {
16911                                 const GLint first_aliasing = gohan - n_req_components + 1;
16912                                 const GLint last_aliasing  = gohan + n_req_components - 1;
16913
16914                                 const GLuint goten_start = std::max(0, first_aliasing);
16915                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
16916
16917                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
16918                                 {
16919                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type, false };
16920
16921                                         m_test_cases.push_back(test_case);
16922
16923                                         if (Utils::Shader::VERTEX == test_case.m_stage)
16924                                         {
16925                                                 test_case.m_use_both = true;
16926
16927                                                 m_test_cases.push_back(test_case);
16928                                         }
16929                                 }
16930                         }
16931                 }
16932         }
16933 }
16934
16935 /** Constructor
16936  *
16937  * @param context Test framework context
16938  **/
16939 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
16940         : NegativeTestBase(context, "output_component_aliasing",
16941                                            "Test verifies that compiler reports component aliasing as error")
16942 {
16943 }
16944
16945 /** Source for given test case and stage
16946  *
16947  * @param test_case_index Index of test case
16948  * @param stage           Shader stage
16949  *
16950  * @return Shader source
16951  **/
16952 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16953 {
16954         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
16955                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
16956         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
16957                                                                   "    gotenINDEX = TYPE(0);\n";
16958         static const GLchar* fs = "#version 430 core\n"
16959                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16960                                                           "\n"
16961                                                           "in  vec4 gs_fs;\n"
16962                                                           "out vec4 fs_out;\n"
16963                                                           "\n"
16964                                                           "void main()\n"
16965                                                           "{\n"
16966                                                           "    fs_out = gs_fs;\n"
16967                                                           "}\n"
16968                                                           "\n";
16969         static const GLchar* fs_tested = "#version 430 core\n"
16970                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16971                                                                          "\n"
16972                                                                          "VAR_DEFINITION"
16973                                                                          "\n"
16974                                                                          "in  vec4 gs_fs;\n"
16975                                                                          "out vec4 fs_out;\n"
16976                                                                          "\n"
16977                                                                          "void main()\n"
16978                                                                          "{\n"
16979                                                                          "    vec4 result = gs_fs;\n"
16980                                                                          "\n"
16981                                                                          "VARIABLE_USE"
16982                                                                          "\n"
16983                                                                          "    fs_out += result;\n"
16984                                                                          "}\n"
16985                                                                          "\n";
16986         static const GLchar* gs = "#version 430 core\n"
16987                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16988                                                           "\n"
16989                                                           "layout(points)                           in;\n"
16990                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16991                                                           "\n"
16992                                                           "in  vec4 tes_gs[];\n"
16993                                                           "out vec4 gs_fs;\n"
16994                                                           "\n"
16995                                                           "void main()\n"
16996                                                           "{\n"
16997                                                           "    gs_fs = tes_gs[0];\n"
16998                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16999                                                           "    EmitVertex();\n"
17000                                                           "    gs_fs = tes_gs[0];\n"
17001                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17002                                                           "    EmitVertex();\n"
17003                                                           "    gs_fs = tes_gs[0];\n"
17004                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17005                                                           "    EmitVertex();\n"
17006                                                           "    gs_fs = tes_gs[0];\n"
17007                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17008                                                           "    EmitVertex();\n"
17009                                                           "}\n"
17010                                                           "\n";
17011         static const GLchar* gs_tested = "#version 430 core\n"
17012                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17013                                                                          "\n"
17014                                                                          "layout(points)                           in;\n"
17015                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17016                                                                          "\n"
17017                                                                          "VAR_DEFINITION"
17018                                                                          "\n"
17019                                                                          "in  vec4 tes_gs[];\n"
17020                                                                          "out vec4 gs_fs;\n"
17021                                                                          "\n"
17022                                                                          "void main()\n"
17023                                                                          "{\n"
17024                                                                          "    vec4 result = tes_gs[0];\n"
17025                                                                          "\n"
17026                                                                          "VARIABLE_USE"
17027                                                                          "\n"
17028                                                                          "    gs_fs = result;\n"
17029                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17030                                                                          "    EmitVertex();\n"
17031                                                                          "    gs_fs = result;\n"
17032                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17033                                                                          "    EmitVertex();\n"
17034                                                                          "    gs_fs = result;\n"
17035                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17036                                                                          "    EmitVertex();\n"
17037                                                                          "    gs_fs = result;\n"
17038                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17039                                                                          "    EmitVertex();\n"
17040                                                                          "}\n"
17041                                                                          "\n";
17042         static const GLchar* tcs = "#version 430 core\n"
17043                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17044                                                            "\n"
17045                                                            "layout(vertices = 1) out;\n"
17046                                                            "\n"
17047                                                            "in  vec4 vs_tcs[];\n"
17048                                                            "out vec4 tcs_tes[];\n"
17049                                                            "\n"
17050                                                            "void main()\n"
17051                                                            "{\n"
17052                                                            "\n"
17053                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17054                                                            "\n"
17055                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17056                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17057                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17058                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17059                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17060                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17061                                                            "}\n"
17062                                                            "\n";
17063         static const GLchar* tcs_tested = "#version 430 core\n"
17064                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17065                                                                           "\n"
17066                                                                           "layout(vertices = 1) out;\n"
17067                                                                           "\n"
17068                                                                           "VAR_DEFINITION"
17069                                                                           "\n"
17070                                                                           "in  vec4 vs_tcs[];\n"
17071                                                                           "out vec4 tcs_tes[];\n"
17072                                                                           "\n"
17073                                                                           "void main()\n"
17074                                                                           "{\n"
17075                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17076                                                                           "\n"
17077                                                                           "VARIABLE_USE"
17078                                                                           "\n"
17079                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17080                                                                           "\n"
17081                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17082                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17083                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17084                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17085                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17086                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17087                                                                           "}\n"
17088                                                                           "\n";
17089         static const GLchar* tes = "#version 430 core\n"
17090                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17091                                                            "\n"
17092                                                            "layout(isolines, point_mode) in;\n"
17093                                                            "\n"
17094                                                            "in  vec4 tcs_tes[];\n"
17095                                                            "out vec4 tes_gs;\n"
17096                                                            "\n"
17097                                                            "void main()\n"
17098                                                            "{\n"
17099                                                            "    tes_gs = tcs_tes[0];\n"
17100                                                            "}\n"
17101                                                            "\n";
17102         static const GLchar* tes_tested = "#version 430 core\n"
17103                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17104                                                                           "\n"
17105                                                                           "layout(isolines, point_mode) in;\n"
17106                                                                           "\n"
17107                                                                           "VAR_DEFINITION"
17108                                                                           "\n"
17109                                                                           "in  vec4 tcs_tes[];\n"
17110                                                                           "out vec4 tes_gs;\n"
17111                                                                           "\n"
17112                                                                           "void main()\n"
17113                                                                           "{\n"
17114                                                                           "    vec4 result = tcs_tes[0];\n"
17115                                                                           "\n"
17116                                                                           "VARIABLE_USE"
17117                                                                           "\n"
17118                                                                           "    tes_gs += result;\n"
17119                                                                           "}\n"
17120                                                                           "\n";
17121         static const GLchar* vs = "#version 430 core\n"
17122                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17123                                                           "\n"
17124                                                           "in  vec4 in_vs;\n"
17125                                                           "out vec4 vs_tcs;\n"
17126                                                           "\n"
17127                                                           "void main()\n"
17128                                                           "{\n"
17129                                                           "    vs_tcs = in_vs;\n"
17130                                                           "}\n"
17131                                                           "\n";
17132         static const GLchar* vs_tested = "#version 430 core\n"
17133                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17134                                                                          "\n"
17135                                                                          "VAR_DEFINITION"
17136                                                                          "\n"
17137                                                                          "in  vec4 in_vs;\n"
17138                                                                          "out vec4 vs_tcs;\n"
17139                                                                          "\n"
17140                                                                          "void main()\n"
17141                                                                          "{\n"
17142                                                                          "    vec4 result = in_vs;\n"
17143                                                                          "\n"
17144                                                                          "VARIABLE_USE"
17145                                                                          "\n"
17146                                                                          "    vs_tcs += result;\n"
17147                                                                          "}\n"
17148                                                                          "\n";
17149
17150         std::string source;
17151         testCase&   test_case = m_test_cases[test_case_index];
17152
17153         if (test_case.m_stage == stage)
17154         {
17155                 const GLchar* array = "";
17156                 GLchar            buffer_gohan[16];
17157                 GLchar            buffer_goten[16];
17158                 const GLchar* index     = "";
17159                 size_t            position = 0;
17160                 size_t            temp;
17161                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17162
17163                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17164                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17165
17166                 switch (stage)
17167                 {
17168                 case Utils::Shader::FRAGMENT:
17169                         source = fs_tested;
17170                         break;
17171                 case Utils::Shader::GEOMETRY:
17172                         source = gs_tested;
17173                         array  = "[]";
17174                         index  = "[0]";
17175                         break;
17176                 case Utils::Shader::TESS_CTRL:
17177                         source = tcs_tested;
17178                         array  = "[]";
17179                         index  = "[gl_InvocationID]";
17180                         break;
17181                 case Utils::Shader::TESS_EVAL:
17182                         source = tes_tested;
17183                         array  = "[]";
17184                         index  = "[0]";
17185                         break;
17186                 case Utils::Shader::VERTEX:
17187                         source = vs_tested;
17188                         break;
17189                 default:
17190                         TCU_FAIL("Invalid enum");
17191                 }
17192
17193                 temp = position;
17194                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17195                 position = temp;
17196                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17197                 Utils::replaceToken("ARRAY", position, array, source);
17198                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17199                 Utils::replaceToken("ARRAY", position, array, source);
17200                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17201
17202                 Utils::replaceAllTokens("TYPE", type_name, source);
17203                 Utils::replaceAllTokens("INDEX", index, source);
17204         }
17205         else
17206         {
17207                 switch (stage)
17208                 {
17209                 case Utils::Shader::FRAGMENT:
17210                         source = fs;
17211                         break;
17212                 case Utils::Shader::GEOMETRY:
17213                         source = gs;
17214                         break;
17215                 case Utils::Shader::TESS_CTRL:
17216                         source = tcs;
17217                         break;
17218                 case Utils::Shader::TESS_EVAL:
17219                         source = tes;
17220                         break;
17221                 case Utils::Shader::VERTEX:
17222                         source = vs;
17223                         break;
17224                 default:
17225                         TCU_FAIL("Invalid enum");
17226                 }
17227         }
17228
17229         return source;
17230 }
17231
17232 /** Get description of test case
17233  *
17234  * @param test_case_index Index of test case
17235  *
17236  * @return Test case description
17237  **/
17238 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17239 {
17240         std::stringstream stream;
17241         testCase&                 test_case = m_test_cases[test_case_index];
17242
17243         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17244                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17245                    << " & " << test_case.m_component_goten;
17246
17247         return stream.str();
17248 }
17249
17250 /** Get number of test cases
17251  *
17252  * @return Number of test cases
17253  **/
17254 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17255 {
17256         return static_cast<GLuint>(m_test_cases.size());
17257 }
17258
17259 /** Selects if "compute" stage is relevant for test
17260  *
17261  * @param ignored
17262  *
17263  * @return false
17264  **/
17265 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17266 {
17267         return false;
17268 }
17269
17270 /** Prepare all test cases
17271  *
17272  **/
17273 void OutputComponentAliasingTest::testInit()
17274 {
17275         static const GLuint n_components_per_location = 4;
17276         const GLuint            n_types                                   = getTypesNumber();
17277
17278         for (GLuint i = 0; i < n_types; ++i)
17279         {
17280                 const Utils::Type& type                         = getType(i);
17281                 const GLuint       n_req_components = type.m_n_rows;
17282                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17283
17284                 /* Skip matrices */
17285                 if (1 != type.m_n_columns)
17286                 {
17287                         continue;
17288                 }
17289
17290                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17291                 {
17292                         if (Utils::Shader::COMPUTE == stage)
17293                         {
17294                                 continue;
17295                         }
17296
17297                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17298                         {
17299                                 continue;
17300                         }
17301
17302                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17303                         {
17304                                 const GLint first_aliasing = gohan - n_req_components + 1;
17305                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17306
17307                                 const GLuint goten_start = std::max(0, first_aliasing);
17308                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17309
17310                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17311                                 {
17312                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17313
17314                                         m_test_cases.push_back(test_case);
17315                                 }
17316                         }
17317                 }
17318         }
17319 }
17320
17321 /** Constructor
17322  *
17323  * @param context Test framework context
17324  **/
17325 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17326         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17327                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17328 {
17329 }
17330
17331 /** Source for given test case and stage
17332  *
17333  * @param test_case_index Index of test case
17334  * @param stage           Shader stage
17335  *
17336  * @return Shader source
17337  **/
17338 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17339                                                                                                                                            Utils::Shader::STAGES stage)
17340 {
17341         static const GLchar* var_definition =
17342                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17343                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17344         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17345                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17346                                                                          "    {\n"
17347                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17348                                                                          "    }\n";
17349         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17350                                                                           "    gotenINDEX = TYPE(1);\n"
17351                                                                           "    if (vec4(0) == result)\n"
17352                                                                           "    {\n"
17353                                                                           "        gohanINDEX = TYPE(1);\n"
17354                                                                           "        gotenINDEX = TYPE(0);\n"
17355                                                                           "    }\n";
17356         static const GLchar* fs = "#version 430 core\n"
17357                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17358                                                           "\n"
17359                                                           "in  vec4 gs_fs;\n"
17360                                                           "out vec4 fs_out;\n"
17361                                                           "\n"
17362                                                           "void main()\n"
17363                                                           "{\n"
17364                                                           "    fs_out = gs_fs;\n"
17365                                                           "}\n"
17366                                                           "\n";
17367         static const GLchar* fs_tested = "#version 430 core\n"
17368                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17369                                                                          "\n"
17370                                                                          "VAR_DEFINITION"
17371                                                                          "\n"
17372                                                                          "in  vec4 gs_fs;\n"
17373                                                                          "out vec4 fs_out;\n"
17374                                                                          "\n"
17375                                                                          "void main()\n"
17376                                                                          "{\n"
17377                                                                          "    vec4 result = gs_fs;\n"
17378                                                                          "\n"
17379                                                                          "VARIABLE_USE"
17380                                                                          "\n"
17381                                                                          "    fs_out += result;\n"
17382                                                                          "}\n"
17383                                                                          "\n";
17384         static const GLchar* gs = "#version 430 core\n"
17385                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17386                                                           "\n"
17387                                                           "layout(points)                           in;\n"
17388                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17389                                                           "\n"
17390                                                           "in  vec4 tes_gs[];\n"
17391                                                           "out vec4 gs_fs;\n"
17392                                                           "\n"
17393                                                           "void main()\n"
17394                                                           "{\n"
17395                                                           "    gs_fs = tes_gs[0];\n"
17396                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17397                                                           "    EmitVertex();\n"
17398                                                           "    gs_fs = tes_gs[0];\n"
17399                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17400                                                           "    EmitVertex();\n"
17401                                                           "    gs_fs = tes_gs[0];\n"
17402                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17403                                                           "    EmitVertex();\n"
17404                                                           "    gs_fs = tes_gs[0];\n"
17405                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17406                                                           "    EmitVertex();\n"
17407                                                           "}\n"
17408                                                           "\n";
17409         static const GLchar* gs_tested = "#version 430 core\n"
17410                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17411                                                                          "\n"
17412                                                                          "layout(points)                           in;\n"
17413                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17414                                                                          "\n"
17415                                                                          "VAR_DEFINITION"
17416                                                                          "\n"
17417                                                                          "in  vec4 tes_gs[];\n"
17418                                                                          "out vec4 gs_fs;\n"
17419                                                                          "\n"
17420                                                                          "void main()\n"
17421                                                                          "{\n"
17422                                                                          "    vec4 result = tes_gs[0];\n"
17423                                                                          "\n"
17424                                                                          "VARIABLE_USE"
17425                                                                          "\n"
17426                                                                          "    gs_fs = result;\n"
17427                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17428                                                                          "    EmitVertex();\n"
17429                                                                          "    gs_fs = result;\n"
17430                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17431                                                                          "    EmitVertex();\n"
17432                                                                          "    gs_fs = result;\n"
17433                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17434                                                                          "    EmitVertex();\n"
17435                                                                          "    gs_fs = result;\n"
17436                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17437                                                                          "    EmitVertex();\n"
17438                                                                          "}\n"
17439                                                                          "\n";
17440         static const GLchar* tcs = "#version 430 core\n"
17441                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17442                                                            "\n"
17443                                                            "layout(vertices = 1) out;\n"
17444                                                            "\n"
17445                                                            "in  vec4 vs_tcs[];\n"
17446                                                            "out vec4 tcs_tes[];\n"
17447                                                            "\n"
17448                                                            "void main()\n"
17449                                                            "{\n"
17450                                                            "\n"
17451                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17452                                                            "\n"
17453                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17454                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17455                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17456                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17457                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17458                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17459                                                            "}\n"
17460                                                            "\n";
17461         static const GLchar* tcs_tested = "#version 430 core\n"
17462                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17463                                                                           "\n"
17464                                                                           "layout(vertices = 1) out;\n"
17465                                                                           "\n"
17466                                                                           "VAR_DEFINITION"
17467                                                                           "\n"
17468                                                                           "in  vec4 vs_tcs[];\n"
17469                                                                           "out vec4 tcs_tes[];\n"
17470                                                                           "\n"
17471                                                                           "void main()\n"
17472                                                                           "{\n"
17473                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17474                                                                           "\n"
17475                                                                           "VARIABLE_USE"
17476                                                                           "\n"
17477                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17478                                                                           "\n"
17479                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17480                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17481                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17482                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17483                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17484                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17485                                                                           "}\n"
17486                                                                           "\n";
17487         static const GLchar* tes = "#version 430 core\n"
17488                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17489                                                            "\n"
17490                                                            "layout(isolines, point_mode) in;\n"
17491                                                            "\n"
17492                                                            "in  vec4 tcs_tes[];\n"
17493                                                            "out vec4 tes_gs;\n"
17494                                                            "\n"
17495                                                            "void main()\n"
17496                                                            "{\n"
17497                                                            "    tes_gs = tcs_tes[0];\n"
17498                                                            "}\n"
17499                                                            "\n";
17500         static const GLchar* tes_tested = "#version 430 core\n"
17501                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17502                                                                           "\n"
17503                                                                           "layout(isolines, point_mode) in;\n"
17504                                                                           "\n"
17505                                                                           "VAR_DEFINITION"
17506                                                                           "\n"
17507                                                                           "in  vec4 tcs_tes[];\n"
17508                                                                           "out vec4 tes_gs;\n"
17509                                                                           "\n"
17510                                                                           "void main()\n"
17511                                                                           "{\n"
17512                                                                           "    vec4 result = tcs_tes[0];\n"
17513                                                                           "\n"
17514                                                                           "VARIABLE_USE"
17515                                                                           "\n"
17516                                                                           "    tes_gs += result;\n"
17517                                                                           "}\n"
17518                                                                           "\n";
17519         static const GLchar* vs = "#version 430 core\n"
17520                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17521                                                           "\n"
17522                                                           "in  vec4 in_vs;\n"
17523                                                           "out vec4 vs_tcs;\n"
17524                                                           "\n"
17525                                                           "void main()\n"
17526                                                           "{\n"
17527                                                           "    vs_tcs = in_vs;\n"
17528                                                           "}\n"
17529                                                           "\n";
17530         static const GLchar* vs_tested = "#version 430 core\n"
17531                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17532                                                                          "\n"
17533                                                                          "VAR_DEFINITION"
17534                                                                          "\n"
17535                                                                          "in  vec4 in_vs;\n"
17536                                                                          "out vec4 vs_tcs;\n"
17537                                                                          "\n"
17538                                                                          "void main()\n"
17539                                                                          "{\n"
17540                                                                          "    vec4 result = in_vs;\n"
17541                                                                          "\n"
17542                                                                          "VARIABLE_USE"
17543                                                                          "\n"
17544                                                                          "    vs_tcs += result;\n"
17545                                                                          "}\n"
17546                                                                          "\n";
17547
17548         std::string source;
17549         testCase&   test_case = m_test_cases[test_case_index];
17550
17551         if (test_case.m_stage == stage)
17552         {
17553                 const GLchar*                    array = "";
17554                 GLchar                                   buffer_gohan[16];
17555                 GLchar                                   buffer_goten[16];
17556                 const GLchar*                    direction  = "in ";
17557                 const GLchar*                    flat_gohan = "";
17558                 const GLchar*                    flat_goten = "";
17559                 const GLchar*                    index          = "";
17560                 size_t                                   position   = 0;
17561                 size_t                                   temp;
17562                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17563                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17564                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17565                 const GLchar*                    var_use                 = input_use;
17566
17567                 if (false == test_case.m_is_input)
17568                 {
17569                         direction = "out";
17570                         storage   = Utils::Variable::VARYING_OUTPUT;
17571                         var_use   = output_use;
17572                 }
17573
17574                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17575                 {
17576                         flat_gohan = "flat";
17577                 }
17578
17579                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17580                 {
17581                         flat_goten = "flat";
17582                 }
17583
17584                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17585                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17586
17587                 switch (stage)
17588                 {
17589                 case Utils::Shader::FRAGMENT:
17590                         source = fs_tested;
17591                         break;
17592                 case Utils::Shader::GEOMETRY:
17593                         source = gs_tested;
17594                         array  = "[]";
17595                         index  = "[0]";
17596                         break;
17597                 case Utils::Shader::TESS_CTRL:
17598                         source = tcs_tested;
17599                         array  = "[]";
17600                         index  = "[gl_InvocationID]";
17601                         break;
17602                 case Utils::Shader::TESS_EVAL:
17603                         source = tes_tested;
17604                         array  = "[]";
17605                         index  = "[0]";
17606                         break;
17607                 case Utils::Shader::VERTEX:
17608                         source = vs_tested;
17609                         break;
17610                 default:
17611                         TCU_FAIL("Invalid enum");
17612                 }
17613
17614                 temp = position;
17615                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17616                 position = temp;
17617                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17618                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17619                 Utils::replaceToken("DIRECTION", position, direction, source);
17620                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17621                 Utils::replaceToken("ARRAY", position, array, source);
17622                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17623                 Utils::replaceToken("FLAT", position, flat_goten, source);
17624                 Utils::replaceToken("DIRECTION", position, direction, source);
17625                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17626                 Utils::replaceToken("ARRAY", position, array, source);
17627
17628                 temp = position;
17629                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17630                 position = temp;
17631                 if (true == test_case.m_is_input)
17632                 {
17633                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17634                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17635                 }
17636                 else
17637                 {
17638                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17639                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17640                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17641                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17642                 }
17643
17644                 Utils::replaceAllTokens("INDEX", index, source);
17645         }
17646         else
17647         {
17648                 switch (stage)
17649                 {
17650                 case Utils::Shader::FRAGMENT:
17651                         source = fs;
17652                         break;
17653                 case Utils::Shader::GEOMETRY:
17654                         source = gs;
17655                         break;
17656                 case Utils::Shader::TESS_CTRL:
17657                         source = tcs;
17658                         break;
17659                 case Utils::Shader::TESS_EVAL:
17660                         source = tes;
17661                         break;
17662                 case Utils::Shader::VERTEX:
17663                         source = vs;
17664                         break;
17665                 default:
17666                         TCU_FAIL("Invalid enum");
17667                 }
17668         }
17669
17670         return source;
17671 }
17672
17673 /** Get description of test case
17674  *
17675  * @param test_case_index Index of test case
17676  *
17677  * @return Test case description
17678  **/
17679 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17680 {
17681         std::stringstream stream;
17682         testCase&                 test_case = m_test_cases[test_case_index];
17683
17684         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17685                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17686                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17687
17688         if (true == test_case.m_is_input)
17689         {
17690                 stream << "input";
17691         }
17692         else
17693         {
17694                 stream << "output";
17695         }
17696
17697         return stream.str();
17698 }
17699
17700 /** Get number of test cases
17701  *
17702  * @return Number of test cases
17703  **/
17704 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17705 {
17706         return static_cast<GLuint>(m_test_cases.size());
17707 }
17708
17709 /** Selects if "compute" stage is relevant for test
17710  *
17711  * @param ignored
17712  *
17713  * @return false
17714  **/
17715 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17716 {
17717         return false;
17718 }
17719
17720 /** Prepare all test cases
17721  *
17722  **/
17723 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17724 {
17725         static const GLuint n_components_per_location = 4;
17726         const GLuint            n_types                                   = getTypesNumber();
17727
17728         for (GLuint i = 0; i < n_types; ++i)
17729         {
17730                 const Utils::Type& type_gohan              = getType(i);
17731                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17732
17733                 /* Skip matrices */
17734                 if (1 != type_gohan.m_n_columns)
17735                 {
17736                         continue;
17737                 }
17738
17739                 for (GLuint j = 0; j < n_types; ++j)
17740                 {
17741                         const Utils::Type& type_goten              = getType(j);
17742                         const bool                 is_float_type_goten = isFloatType(type_goten);
17743
17744                         /* Skip matrices */
17745                         if (1 != type_goten.m_n_columns)
17746                         {
17747                                 continue;
17748                         }
17749
17750                         /* Skip valid combinations */
17751                         if (is_float_type_gohan == is_float_type_goten)
17752                         {
17753                                 continue;
17754                         }
17755
17756                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17757                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17758                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17759                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17760
17761                         /* Skip pairs that cannot fit into one location */
17762                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17763                         {
17764                                 continue;
17765                         }
17766
17767                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17768                         {
17769                                 /* Skip compute shader */
17770                                 if (Utils::Shader::COMPUTE == stage)
17771                                 {
17772                                         continue;
17773                                 }
17774
17775                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17776                                 {
17777                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17778                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17779
17780                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17781                                         const GLuint goten_upper_limit = last_aliasing + 1;
17782
17783                                         /* Compoennets before gohan */
17784                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17785                                         {
17786                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17787                                                                                                   type_gohan, type_goten };
17788                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17789                                                                                                    type_gohan, type_goten };
17790
17791                                                 m_test_cases.push_back(test_case_in);
17792
17793                                                 /* Skip double outputs in fragment shader */
17794                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17795                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17796                                                 {
17797                                                         m_test_cases.push_back(test_case_out);
17798                                                 }
17799                                         }
17800
17801                                         /* Components after gohan */
17802                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17803                                         {
17804                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17805                                                                                                   type_gohan, type_goten };
17806                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17807                                                                                                    type_gohan, type_goten };
17808
17809                                                 m_test_cases.push_back(test_case_in);
17810
17811                                                 /* Skip double outputs in fragment shader */
17812                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17813                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17814                                                 {
17815                                                         m_test_cases.push_back(test_case_out);
17816                                                 }
17817                                         }
17818                                 }
17819                         }
17820                 }
17821         }
17822 }
17823
17824 /** Check if given type is float
17825  *
17826  * @param type Type in question
17827  *
17828  * @return true if tpye is float, false otherwise
17829  **/
17830 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17831 {
17832         bool is_float = false;
17833
17834         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17835         {
17836                 is_float = true;
17837         }
17838
17839         return is_float;
17840 }
17841
17842 /** Constructor
17843  *
17844  * @param context Test framework context
17845  **/
17846 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17847         deqp::Context& context)
17848         : NegativeTestBase(
17849                   context, "varying_location_aliasing_with_mixed_interpolation",
17850                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17851 {
17852 }
17853
17854 /** Source for given test case and stage
17855  *
17856  * @param test_case_index Index of test case
17857  * @param stage           Shader stage
17858  *
17859  * @return Shader source
17860  **/
17861 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17862                                                                                                                                                            Utils::Shader::STAGES stage)
17863 {
17864         static const GLchar* var_definition =
17865                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17866                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17867         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17868                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17869                                                                          "    {\n"
17870                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17871                                                                          "    }\n";
17872         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17873                                                                           "    gotenINDEX = TYPE(1);\n"
17874                                                                           "    if (vec4(0) == result)\n"
17875                                                                           "    {\n"
17876                                                                           "        gohanINDEX = TYPE(1);\n"
17877                                                                           "        gotenINDEX = TYPE(0);\n"
17878                                                                           "    }\n";
17879         static const GLchar* fs = "#version 430 core\n"
17880                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17881                                                           "\n"
17882                                                           "in  vec4 gs_fs;\n"
17883                                                           "out vec4 fs_out;\n"
17884                                                           "\n"
17885                                                           "void main()\n"
17886                                                           "{\n"
17887                                                           "    fs_out = gs_fs;\n"
17888                                                           "}\n"
17889                                                           "\n";
17890         static const GLchar* fs_tested = "#version 430 core\n"
17891                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17892                                                                          "\n"
17893                                                                          "VAR_DEFINITION"
17894                                                                          "\n"
17895                                                                          "in  vec4 gs_fs;\n"
17896                                                                          "out vec4 fs_out;\n"
17897                                                                          "\n"
17898                                                                          "void main()\n"
17899                                                                          "{\n"
17900                                                                          "    vec4 result = gs_fs;\n"
17901                                                                          "\n"
17902                                                                          "VARIABLE_USE"
17903                                                                          "\n"
17904                                                                          "    fs_out = result;\n"
17905                                                                          "}\n"
17906                                                                          "\n";
17907         static const GLchar* gs = "#version 430 core\n"
17908                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17909                                                           "\n"
17910                                                           "layout(points)                           in;\n"
17911                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17912                                                           "\n"
17913                                                           "in  vec4 tes_gs[];\n"
17914                                                           "out vec4 gs_fs;\n"
17915                                                           "\n"
17916                                                           "void main()\n"
17917                                                           "{\n"
17918                                                           "    gs_fs = tes_gs[0];\n"
17919                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17920                                                           "    EmitVertex();\n"
17921                                                           "    gs_fs = tes_gs[0];\n"
17922                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17923                                                           "    EmitVertex();\n"
17924                                                           "    gs_fs = tes_gs[0];\n"
17925                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17926                                                           "    EmitVertex();\n"
17927                                                           "    gs_fs = tes_gs[0];\n"
17928                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17929                                                           "    EmitVertex();\n"
17930                                                           "}\n"
17931                                                           "\n";
17932         static const GLchar* gs_tested = "#version 430 core\n"
17933                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17934                                                                          "\n"
17935                                                                          "layout(points)                           in;\n"
17936                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17937                                                                          "\n"
17938                                                                          "VAR_DEFINITION"
17939                                                                          "\n"
17940                                                                          "in  vec4 tes_gs[];\n"
17941                                                                          "out vec4 gs_fs;\n"
17942                                                                          "\n"
17943                                                                          "void main()\n"
17944                                                                          "{\n"
17945                                                                          "    vec4 result = tes_gs[0];\n"
17946                                                                          "\n"
17947                                                                          "VARIABLE_USE"
17948                                                                          "\n"
17949                                                                          "    gs_fs = result;\n"
17950                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17951                                                                          "    EmitVertex();\n"
17952                                                                          "    gs_fs = result;\n"
17953                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17954                                                                          "    EmitVertex();\n"
17955                                                                          "    gs_fs = result;\n"
17956                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17957                                                                          "    EmitVertex();\n"
17958                                                                          "    gs_fs = result;\n"
17959                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17960                                                                          "    EmitVertex();\n"
17961                                                                          "}\n"
17962                                                                          "\n";
17963         static const GLchar* tcs = "#version 430 core\n"
17964                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17965                                                            "\n"
17966                                                            "layout(vertices = 1) out;\n"
17967                                                            "\n"
17968                                                            "in  vec4 vs_tcs[];\n"
17969                                                            "out vec4 tcs_tes[];\n"
17970                                                            "\n"
17971                                                            "void main()\n"
17972                                                            "{\n"
17973                                                            "\n"
17974                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17975                                                            "\n"
17976                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17977                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17978                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17979                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17980                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17981                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17982                                                            "}\n"
17983                                                            "\n";
17984         static const GLchar* tcs_tested = "#version 430 core\n"
17985                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17986                                                                           "\n"
17987                                                                           "layout(vertices = 1) out;\n"
17988                                                                           "\n"
17989                                                                           "VAR_DEFINITION"
17990                                                                           "\n"
17991                                                                           "in  vec4 vs_tcs[];\n"
17992                                                                           "out vec4 tcs_tes[];\n"
17993                                                                           "\n"
17994                                                                           "void main()\n"
17995                                                                           "{\n"
17996                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17997                                                                           "\n"
17998                                                                           "VARIABLE_USE"
17999                                                                           "\n"
18000                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18001                                                                           "\n"
18002                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18003                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18004                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18005                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18006                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18007                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18008                                                                           "}\n"
18009                                                                           "\n";
18010         static const GLchar* tes = "#version 430 core\n"
18011                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18012                                                            "\n"
18013                                                            "layout(isolines, point_mode) in;\n"
18014                                                            "\n"
18015                                                            "in  vec4 tcs_tes[];\n"
18016                                                            "out vec4 tes_gs;\n"
18017                                                            "\n"
18018                                                            "void main()\n"
18019                                                            "{\n"
18020                                                            "    tes_gs = tcs_tes[0];\n"
18021                                                            "}\n"
18022                                                            "\n";
18023         static const GLchar* tes_tested = "#version 430 core\n"
18024                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18025                                                                           "\n"
18026                                                                           "layout(isolines, point_mode) in;\n"
18027                                                                           "\n"
18028                                                                           "VAR_DEFINITION"
18029                                                                           "\n"
18030                                                                           "in  vec4 tcs_tes[];\n"
18031                                                                           "out vec4 tes_gs;\n"
18032                                                                           "\n"
18033                                                                           "void main()\n"
18034                                                                           "{\n"
18035                                                                           "    vec4 result = tcs_tes[0];\n"
18036                                                                           "\n"
18037                                                                           "VARIABLE_USE"
18038                                                                           "\n"
18039                                                                           "    tes_gs += result;\n"
18040                                                                           "}\n"
18041                                                                           "\n";
18042         static const GLchar* vs = "#version 430 core\n"
18043                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18044                                                           "\n"
18045                                                           "in  vec4 in_vs;\n"
18046                                                           "out vec4 vs_tcs;\n"
18047                                                           "\n"
18048                                                           "void main()\n"
18049                                                           "{\n"
18050                                                           "    vs_tcs = in_vs;\n"
18051                                                           "}\n"
18052                                                           "\n";
18053         static const GLchar* vs_tested = "#version 430 core\n"
18054                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18055                                                                          "\n"
18056                                                                          "VAR_DEFINITION"
18057                                                                          "\n"
18058                                                                          "in  vec4 in_vs;\n"
18059                                                                          "out vec4 vs_tcs;\n"
18060                                                                          "\n"
18061                                                                          "void main()\n"
18062                                                                          "{\n"
18063                                                                          "    vec4 result = in_vs;\n"
18064                                                                          "\n"
18065                                                                          "VARIABLE_USE"
18066                                                                          "\n"
18067                                                                          "    vs_tcs += result;\n"
18068                                                                          "}\n"
18069                                                                          "\n";
18070
18071         std::string source;
18072         testCase&   test_case = m_test_cases[test_case_index];
18073
18074         if (test_case.m_stage == stage)
18075         {
18076                 const GLchar* array = "";
18077                 GLchar            buffer_gohan[16];
18078                 GLchar            buffer_goten[16];
18079                 const GLchar* direction = "in ";
18080                 const GLchar* index             = "";
18081                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18082                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18083                 size_t            position  = 0;
18084                 size_t            temp;
18085                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18086                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18087                 const GLchar* var_use             = input_use;
18088
18089                 if (false == test_case.m_is_input)
18090                 {
18091                         direction = "out";
18092
18093                         var_use = output_use;
18094                 }
18095
18096                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18097                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18098
18099                 switch (stage)
18100                 {
18101                 case Utils::Shader::FRAGMENT:
18102                         source = fs_tested;
18103                         break;
18104                 case Utils::Shader::GEOMETRY:
18105                         source = gs_tested;
18106                         array  = "[]";
18107                         index  = "[0]";
18108                         break;
18109                 case Utils::Shader::TESS_CTRL:
18110                         source = tcs_tested;
18111                         array  = "[]";
18112                         index  = "[gl_InvocationID]";
18113                         break;
18114                 case Utils::Shader::TESS_EVAL:
18115                         source = tes_tested;
18116                         array  = "[]";
18117                         index  = "[0]";
18118                         break;
18119                 case Utils::Shader::VERTEX:
18120                         source = vs_tested;
18121                         break;
18122                 default:
18123                         TCU_FAIL("Invalid enum");
18124                 }
18125
18126                 temp = position;
18127                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18128                 position = temp;
18129                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18130                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18131                 Utils::replaceToken("DIRECTION", position, direction, source);
18132                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18133                 Utils::replaceToken("ARRAY", position, array, source);
18134                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18135                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18136                 Utils::replaceToken("DIRECTION", position, direction, source);
18137                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18138                 Utils::replaceToken("ARRAY", position, array, source);
18139
18140                 temp = position;
18141                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18142                 position = temp;
18143                 if (true == test_case.m_is_input)
18144                 {
18145                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18146                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18147                 }
18148                 else
18149                 {
18150                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18151                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18152                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18153                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18154                 }
18155
18156                 Utils::replaceAllTokens("INDEX", index, source);
18157         }
18158         else
18159         {
18160                 switch (stage)
18161                 {
18162                 case Utils::Shader::FRAGMENT:
18163                         source = fs;
18164                         break;
18165                 case Utils::Shader::GEOMETRY:
18166                         source = gs;
18167                         break;
18168                 case Utils::Shader::TESS_CTRL:
18169                         source = tcs;
18170                         break;
18171                 case Utils::Shader::TESS_EVAL:
18172                         source = tes;
18173                         break;
18174                 case Utils::Shader::VERTEX:
18175                         source = vs;
18176                         break;
18177                 default:
18178                         TCU_FAIL("Invalid enum");
18179                 }
18180         }
18181
18182         return source;
18183 }
18184
18185 /** Get description of test case
18186  *
18187  * @param test_case_index Index of test case
18188  *
18189  * @return Test case description
18190  **/
18191 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18192 {
18193         std::stringstream stream;
18194         testCase&                 test_case = m_test_cases[test_case_index];
18195
18196         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18197                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18198                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18199                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18200                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18201
18202         if (true == test_case.m_is_input)
18203         {
18204                 stream << "input";
18205         }
18206         else
18207         {
18208                 stream << "output";
18209         }
18210
18211         return stream.str();
18212 }
18213
18214 /** Get number of test cases
18215  *
18216  * @return Number of test cases
18217  **/
18218 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18219 {
18220         return static_cast<GLuint>(m_test_cases.size());
18221 }
18222
18223 /** Selects if "compute" stage is relevant for test
18224  *
18225  * @param ignored
18226  *
18227  * @return false
18228  **/
18229 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18230 {
18231         return false;
18232 }
18233
18234 /** Prepare all test cases
18235  *
18236  **/
18237 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18238 {
18239         static const GLuint n_components_per_location = 4;
18240         const GLuint            n_types                                   = getTypesNumber();
18241
18242         for (GLuint i = 0; i < n_types; ++i)
18243         {
18244                 const Utils::Type& type_gohan              = getType(i);
18245                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18246
18247                 /* Skip matrices */
18248                 if (1 != type_gohan.m_n_columns)
18249                 {
18250                         continue;
18251                 }
18252
18253                 for (GLuint j = 0; j < n_types; ++j)
18254                 {
18255                         const Utils::Type& type_goten              = getType(j);
18256                         const bool                 is_float_type_goten = isFloatType(type_goten);
18257
18258                         /* Skip matrices */
18259                         if (1 != type_goten.m_n_columns)
18260                         {
18261                                 continue;
18262                         }
18263
18264                         /* Skip invalid combinations */
18265                         if (is_float_type_gohan != is_float_type_goten)
18266                         {
18267                                 continue;
18268                         }
18269
18270                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18271                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18272
18273                         /* Skip pairs that cannot fit into one location */
18274                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18275                         {
18276                                 continue;
18277                         }
18278
18279                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18280                         {
18281                                 /* Skip compute shader */
18282                                 if (Utils::Shader::COMPUTE == stage)
18283                                 {
18284                                         continue;
18285                                 }
18286
18287                                 const GLuint gohan = 0;
18288                                 const GLuint goten = gohan + n_req_components_gohan;
18289
18290                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18291                                 {
18292                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18293                                         {
18294                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18295                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18296                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18297                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18298                                                 const bool is_gohan_accepted_as_fs_in =
18299                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18300                                                 const bool is_goten_accepted_as_fs_in =
18301                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18302                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18303
18304                                                 /* Skip when both are the same */
18305                                                 if (int_gohan == int_goten)
18306                                                 {
18307                                                         continue;
18308                                                 }
18309
18310                                                 testCase test_case_in = { gohan,
18311                                                                                                   goten,
18312                                                                                                   (INTERPOLATIONS)int_gohan,
18313                                                                                                   (INTERPOLATIONS)int_goten,
18314                                                                                                   true,
18315                                                                                                   (Utils::Shader::STAGES)stage,
18316                                                                                                   type_gohan,
18317                                                                                                   type_goten };
18318
18319                                                 testCase test_case_out = { gohan,
18320                                                                                                    goten,
18321                                                                                                    (INTERPOLATIONS)int_gohan,
18322                                                                                                    (INTERPOLATIONS)int_goten,
18323                                                                                                    false,
18324                                                                                                    (Utils::Shader::STAGES)stage,
18325                                                                                                    type_gohan,
18326                                                                                                    type_goten };
18327
18328                                                 /* Skip inputs in:
18329                                                  * vertex shader,
18330                                                  * fragment shader when not flat double is used
18331                                                  */
18332                                                 if ((Utils::Shader::VERTEX != stage) &&
18333                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18334                                                 {
18335                                                         m_test_cases.push_back(test_case_in);
18336                                                 }
18337
18338                                                 /* Skip outputs in fragment shader */
18339                                                 if (Utils::Shader::FRAGMENT != stage)
18340                                                 {
18341                                                         m_test_cases.push_back(test_case_out);
18342                                                 }
18343                                         }
18344                                 }
18345                         }
18346                 }
18347         }
18348 }
18349
18350 /** Get interpolation qualifier
18351  *
18352  * @param interpolation Enumeration
18353  *
18354  * @return GLSL qualifier
18355  **/
18356 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18357 {
18358         const GLchar* result = 0;
18359
18360         switch (interpolation)
18361         {
18362         case SMOOTH:
18363                 result = "smooth";
18364                 break;
18365         case FLAT:
18366                 result = "flat";
18367                 break;
18368         case NO_PERSPECTIVE:
18369                 result = "noperspective";
18370                 break;
18371         default:
18372                 TCU_FAIL("Invalid enum");
18373         }
18374
18375         return result;
18376 }
18377
18378 /** Check if given type is float
18379  *
18380  * @param type Type in question
18381  *
18382  * @return true if tpye is float, false otherwise
18383  **/
18384 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18385 {
18386         bool is_float = false;
18387
18388         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18389         {
18390                 is_float = true;
18391         }
18392
18393         return is_float;
18394 }
18395
18396 /** Constructor
18397  *
18398  * @param context Test framework context
18399  **/
18400 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18401         deqp::Context& context)
18402         : NegativeTestBase(
18403                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18404                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18405 {
18406 }
18407
18408 /** Source for given test case and stage
18409  *
18410  * @param test_case_index Index of test case
18411  * @param stage           Shader stage
18412  *
18413  * @return Shader source
18414  **/
18415 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18416                                                                                                                                                                   Utils::Shader::STAGES stage)
18417 {
18418         static const GLchar* var_definition =
18419                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18420                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18421         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18422                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18423                                                                          "    {\n"
18424                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18425                                                                          "    }\n";
18426         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18427                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18428                                                                           "    if (vec4(0) == result)\n"
18429                                                                           "    {\n"
18430                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18431                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18432                                                                           "    }\n";
18433         static const GLchar* fs = "#version 430 core\n"
18434                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18435                                                           "\n"
18436                                                           "in  vec4 gs_fs;\n"
18437                                                           "out vec4 fs_out;\n"
18438                                                           "\n"
18439                                                           "void main()\n"
18440                                                           "{\n"
18441                                                           "    fs_out = gs_fs;\n"
18442                                                           "}\n"
18443                                                           "\n";
18444         static const GLchar* fs_tested = "#version 430 core\n"
18445                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18446                                                                          "\n"
18447                                                                          "VAR_DEFINITION"
18448                                                                          "\n"
18449                                                                          "in  vec4 gs_fs;\n"
18450                                                                          "out vec4 fs_out;\n"
18451                                                                          "\n"
18452                                                                          "void main()\n"
18453                                                                          "{\n"
18454                                                                          "    vec4 result = gs_fs;\n"
18455                                                                          "\n"
18456                                                                          "VARIABLE_USE"
18457                                                                          "\n"
18458                                                                          "    fs_out = result;\n"
18459                                                                          "}\n"
18460                                                                          "\n";
18461         static const GLchar* gs = "#version 430 core\n"
18462                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18463                                                           "\n"
18464                                                           "layout(points)                           in;\n"
18465                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18466                                                           "\n"
18467                                                           "in  vec4 tes_gs[];\n"
18468                                                           "out vec4 gs_fs;\n"
18469                                                           "\n"
18470                                                           "void main()\n"
18471                                                           "{\n"
18472                                                           "    gs_fs = tes_gs[0];\n"
18473                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18474                                                           "    EmitVertex();\n"
18475                                                           "    gs_fs = tes_gs[0];\n"
18476                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18477                                                           "    EmitVertex();\n"
18478                                                           "    gs_fs = tes_gs[0];\n"
18479                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18480                                                           "    EmitVertex();\n"
18481                                                           "    gs_fs = tes_gs[0];\n"
18482                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18483                                                           "    EmitVertex();\n"
18484                                                           "}\n"
18485                                                           "\n";
18486         static const GLchar* gs_tested = "#version 430 core\n"
18487                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18488                                                                          "\n"
18489                                                                          "layout(points)                           in;\n"
18490                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18491                                                                          "\n"
18492                                                                          "VAR_DEFINITION"
18493                                                                          "\n"
18494                                                                          "in  vec4 tes_gs[];\n"
18495                                                                          "out vec4 gs_fs;\n"
18496                                                                          "\n"
18497                                                                          "void main()\n"
18498                                                                          "{\n"
18499                                                                          "    vec4 result = tes_gs[0];\n"
18500                                                                          "\n"
18501                                                                          "VARIABLE_USE"
18502                                                                          "\n"
18503                                                                          "    gs_fs = result;\n"
18504                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18505                                                                          "    EmitVertex();\n"
18506                                                                          "    gs_fs = result;\n"
18507                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18508                                                                          "    EmitVertex();\n"
18509                                                                          "    gs_fs = result;\n"
18510                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18511                                                                          "    EmitVertex();\n"
18512                                                                          "    gs_fs = result;\n"
18513                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18514                                                                          "    EmitVertex();\n"
18515                                                                          "}\n"
18516                                                                          "\n";
18517         static const GLchar* tcs = "#version 430 core\n"
18518                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18519                                                            "\n"
18520                                                            "layout(vertices = 1) out;\n"
18521                                                            "\n"
18522                                                            "in  vec4 vs_tcs[];\n"
18523                                                            "out vec4 tcs_tes[];\n"
18524                                                            "\n"
18525                                                            "void main()\n"
18526                                                            "{\n"
18527                                                            "\n"
18528                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18529                                                            "\n"
18530                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18531                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18532                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18533                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18534                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18535                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18536                                                            "}\n"
18537                                                            "\n";
18538         static const GLchar* tcs_tested = "#version 430 core\n"
18539                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18540                                                                           "\n"
18541                                                                           "layout(vertices = 1) out;\n"
18542                                                                           "\n"
18543                                                                           "VAR_DEFINITION"
18544                                                                           "\n"
18545                                                                           "in  vec4 vs_tcs[];\n"
18546                                                                           "out vec4 tcs_tes[];\n"
18547                                                                           "\n"
18548                                                                           "void main()\n"
18549                                                                           "{\n"
18550                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18551                                                                           "\n"
18552                                                                           "VARIABLE_USE"
18553                                                                           "\n"
18554                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18555                                                                           "\n"
18556                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18557                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18558                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18559                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18560                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18561                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18562                                                                           "}\n"
18563                                                                           "\n";
18564         static const GLchar* tes = "#version 430 core\n"
18565                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18566                                                            "\n"
18567                                                            "layout(isolines, point_mode) in;\n"
18568                                                            "\n"
18569                                                            "in  vec4 tcs_tes[];\n"
18570                                                            "out vec4 tes_gs;\n"
18571                                                            "\n"
18572                                                            "void main()\n"
18573                                                            "{\n"
18574                                                            "    tes_gs = tcs_tes[0];\n"
18575                                                            "}\n"
18576                                                            "\n";
18577         static const GLchar* tes_tested = "#version 430 core\n"
18578                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18579                                                                           "\n"
18580                                                                           "layout(isolines, point_mode) in;\n"
18581                                                                           "\n"
18582                                                                           "VAR_DEFINITION"
18583                                                                           "\n"
18584                                                                           "in  vec4 tcs_tes[];\n"
18585                                                                           "out vec4 tes_gs;\n"
18586                                                                           "\n"
18587                                                                           "void main()\n"
18588                                                                           "{\n"
18589                                                                           "    vec4 result = tcs_tes[0];\n"
18590                                                                           "\n"
18591                                                                           "VARIABLE_USE"
18592                                                                           "\n"
18593                                                                           "    tes_gs += result;\n"
18594                                                                           "}\n"
18595                                                                           "\n";
18596         static const GLchar* vs = "#version 430 core\n"
18597                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18598                                                           "\n"
18599                                                           "in  vec4 in_vs;\n"
18600                                                           "out vec4 vs_tcs;\n"
18601                                                           "\n"
18602                                                           "void main()\n"
18603                                                           "{\n"
18604                                                           "    vs_tcs = in_vs;\n"
18605                                                           "}\n"
18606                                                           "\n";
18607         static const GLchar* vs_tested = "#version 430 core\n"
18608                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18609                                                                          "\n"
18610                                                                          "VAR_DEFINITION"
18611                                                                          "\n"
18612                                                                          "in  vec4 in_vs;\n"
18613                                                                          "out vec4 vs_tcs;\n"
18614                                                                          "\n"
18615                                                                          "void main()\n"
18616                                                                          "{\n"
18617                                                                          "    vec4 result = in_vs;\n"
18618                                                                          "\n"
18619                                                                          "VARIABLE_USE"
18620                                                                          "\n"
18621                                                                          "    vs_tcs += result;\n"
18622                                                                          "}\n"
18623                                                                          "\n";
18624
18625         std::string source;
18626         testCase&   test_case = m_test_cases[test_case_index];
18627
18628         if (test_case.m_stage == stage)
18629         {
18630                 const GLchar* array_gohan = "";
18631                 const GLchar* array_goten = "";
18632                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18633                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18634                 GLchar            buffer_gohan[16];
18635                 GLchar            buffer_goten[16];
18636                 const GLchar* direction   = "in ";
18637                 const GLchar* index_gohan = "";
18638                 const GLchar* index_goten = "";
18639                 const GLchar* int_gohan   = test_case.m_int_gohan;
18640                 const GLchar* int_goten   = test_case.m_int_goten;
18641                 size_t            position      = 0;
18642                 size_t            temp;
18643                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18644                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18645                 const GLchar* var_use             = input_use;
18646
18647                 if (false == test_case.m_is_input)
18648                 {
18649                         direction = "out";
18650
18651                         var_use = output_use;
18652                 }
18653
18654                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18655                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18656
18657                 switch (stage)
18658                 {
18659                 case Utils::Shader::FRAGMENT:
18660                         source = fs_tested;
18661                         break;
18662                 case Utils::Shader::GEOMETRY:
18663                         source          = gs_tested;
18664                         array_gohan = "[]";
18665                         index_gohan = "[0]";
18666                         array_goten = "[]";
18667                         index_goten = "[0]";
18668                         break;
18669                 case Utils::Shader::TESS_CTRL:
18670                         source = tcs_tested;
18671                         if (PATCH != test_case.m_aux_gohan)
18672                         {
18673                                 array_gohan = "[]";
18674                                 index_gohan = "[gl_InvocationID]";
18675                         }
18676                         if (PATCH != test_case.m_aux_goten)
18677                         {
18678                                 array_goten = "[]";
18679                                 index_goten = "[gl_InvocationID]";
18680                         }
18681                         break;
18682                 case Utils::Shader::TESS_EVAL:
18683                         source          = tes_tested;
18684                         array_gohan = "[]";
18685                         index_gohan = "[0]";
18686                         array_goten = "[]";
18687                         index_goten = "[0]";
18688                         break;
18689                 case Utils::Shader::VERTEX:
18690                         source = vs_tested;
18691                         break;
18692                 default:
18693                         TCU_FAIL("Invalid enum");
18694                 }
18695
18696                 temp = position;
18697                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18698                 position = temp;
18699                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18700                 Utils::replaceToken("AUX", position, aux_gohan, source);
18701                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18702                 Utils::replaceToken("DIRECTION", position, direction, source);
18703                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18704                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18705                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18706                 Utils::replaceToken("AUX", position, aux_goten, source);
18707                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18708                 Utils::replaceToken("DIRECTION", position, direction, source);
18709                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18710                 Utils::replaceToken("ARRAY", position, array_goten, source);
18711
18712                 temp = position;
18713                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18714                 position = temp;
18715                 if (true == test_case.m_is_input)
18716                 {
18717                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18718                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18719                 }
18720                 else
18721                 {
18722                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18723                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18724                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18725                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18726                 }
18727
18728                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18729                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18730         }
18731         else
18732         {
18733                 switch (stage)
18734                 {
18735                 case Utils::Shader::FRAGMENT:
18736                         source = fs;
18737                         break;
18738                 case Utils::Shader::GEOMETRY:
18739                         source = gs;
18740                         break;
18741                 case Utils::Shader::TESS_CTRL:
18742                         source = tcs;
18743                         break;
18744                 case Utils::Shader::TESS_EVAL:
18745                         source = tes;
18746                         break;
18747                 case Utils::Shader::VERTEX:
18748                         source = vs;
18749                         break;
18750                 default:
18751                         TCU_FAIL("Invalid enum");
18752                 }
18753         }
18754
18755         return source;
18756 }
18757
18758 /** Get description of test case
18759  *
18760  * @param test_case_index Index of test case
18761  *
18762  * @return Test case description
18763  **/
18764 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18765 {
18766         std::stringstream stream;
18767         testCase&                 test_case = m_test_cases[test_case_index];
18768
18769         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18770                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18771                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18772                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18773
18774         if (true == test_case.m_is_input)
18775         {
18776                 stream << "input";
18777         }
18778         else
18779         {
18780                 stream << "output";
18781         }
18782
18783         return stream.str();
18784 }
18785
18786 /** Get number of test cases
18787  *
18788  * @return Number of test cases
18789  **/
18790 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18791 {
18792         return static_cast<GLuint>(m_test_cases.size());
18793 }
18794
18795 /** Selects if "compute" stage is relevant for test
18796  *
18797  * @param ignored
18798  *
18799  * @return false
18800  **/
18801 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18802 {
18803         return false;
18804 }
18805
18806 /** Prepare all test cases
18807  *
18808  **/
18809 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18810 {
18811         static const GLuint n_components_per_location = 4;
18812         const GLuint            n_types                                   = getTypesNumber();
18813
18814         for (GLuint i = 0; i < n_types; ++i)
18815         {
18816                 const Utils::Type& type_gohan              = getType(i);
18817                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18818
18819                 /* Skip matrices */
18820                 if (1 != type_gohan.m_n_columns)
18821                 {
18822                         continue;
18823                 }
18824
18825                 for (GLuint j = 0; j < n_types; ++j)
18826                 {
18827                         const Utils::Type& type_goten              = getType(j);
18828                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18829                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18830                         const bool                 is_float_type_goten = isFloatType(type_goten);
18831
18832                         /* Skip matrices */
18833                         if (1 != type_goten.m_n_columns)
18834                         {
18835                                 continue;
18836                         }
18837
18838                         /* Skip invalid combinations */
18839                         if (is_float_type_gohan != is_float_type_goten)
18840                         {
18841                                 continue;
18842                         }
18843
18844                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18845                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18846
18847                         /* Skip pairs that cannot fit into one location */
18848                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18849                         {
18850                                 continue;
18851                         }
18852
18853                         const GLuint gohan = 0;
18854                         const GLuint goten = gohan + n_req_components_gohan;
18855
18856                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18857                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18858
18859                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18860                                                                                   type_gohan, type_goten };
18861
18862                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18863                                                                                   type_gohan, type_goten };
18864
18865                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18866                                                                                   type_gohan, type_goten };
18867
18868                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18869                                                                                   type_gohan, type_goten };
18870
18871                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18872                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18873                                                                                  type_gohan,   type_goten };
18874
18875                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18876                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18877                                                                                  type_gohan,   type_goten };
18878
18879                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18880                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18881                                                                                  type_gohan,   type_goten };
18882
18883                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
18884                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18885                                                                                  type_gohan,   type_goten };
18886
18887                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
18888                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18889                                                                                  type_gohan,   type_goten };
18890
18891                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
18892                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18893                                                                                  type_gohan,   type_goten };
18894
18895                         m_test_cases.push_back(test_case_tcs_np);
18896                         m_test_cases.push_back(test_case_tcs_pn);
18897                         m_test_cases.push_back(test_case_tes_np);
18898                         m_test_cases.push_back(test_case_tes_pn);
18899                         m_test_cases.push_back(test_case_fs_nc);
18900                         m_test_cases.push_back(test_case_fs_cn);
18901                         m_test_cases.push_back(test_case_fs_ns);
18902                         m_test_cases.push_back(test_case_fs_sn);
18903                         m_test_cases.push_back(test_case_fs_cs);
18904                         m_test_cases.push_back(test_case_fs_sc);
18905                 }
18906         }
18907 }
18908
18909 /** Get auxiliary storage qualifier
18910  *
18911  * @param aux Enumeration
18912  *
18913  * @return GLSL qualifier
18914  **/
18915 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
18916 {
18917         const GLchar* result = 0;
18918
18919         switch (aux)
18920         {
18921         case NONE:
18922                 result = "";
18923                 break;
18924         case PATCH:
18925                 result = "patch";
18926                 break;
18927         case CENTROID:
18928                 result = "centroid";
18929                 break;
18930         case SAMPLE:
18931                 result = "sample";
18932                 break;
18933         default:
18934                 TCU_FAIL("Invalid enum");
18935         }
18936
18937         return result;
18938 }
18939
18940 /** Check if given type is float
18941  *
18942  * @param type Type in question
18943  *
18944  * @return true if tpye is float, false otherwise
18945  **/
18946 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
18947 {
18948         bool is_float = false;
18949
18950         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18951         {
18952                 is_float = true;
18953         }
18954
18955         return is_float;
18956 }
18957
18958 /* Constants used by VertexAttribLocationAPITest */
18959 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
18960
18961 /** Constructor
18962  *
18963  * @param context Test framework context
18964  **/
18965 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
18966         : TextureTestBase(context, "vertex_attrib_location_api",
18967                                           "Test verifies that attribute locations API works as expected")
18968 {
18969 }
18970
18971 /** Does BindAttribLocation for "goten" and relink program
18972  *
18973  * @param program           Program object
18974  * @param program_interface Interface of program
18975  **/
18976 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
18977                                                                                                                 Utils::ProgramInterface& program_interface)
18978 {
18979         const Functions& gl = m_context.getRenderContext().getFunctions();
18980
18981         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
18982         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
18983
18984         program.Link(gl, program.m_id);
18985
18986         /* We still need to get locations for gohan and chichi */
18987         TextureTestBase::prepareAttribLocation(program, program_interface);
18988 }
18989
18990 /** Get interface of program
18991  *
18992  * @param ignored
18993  * @param program_interface   Interface of program
18994  * @param ignored
18995  **/
18996 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
18997                                                                                                           Utils::ProgramInterface& program_interface,
18998                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
18999 {
19000         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19001         const Utils::Type&              type      = Utils::Type::vec4;
19002         const GLuint                    type_size = type.GetSize();
19003
19004         /* Offsets */
19005         const GLuint chichi_offset = 0;
19006         const GLuint goten_offset  = chichi_offset + type_size;
19007         const GLuint gohan_offset  = goten_offset + type_size;
19008         const GLuint goku_offset   = gohan_offset + type_size;
19009
19010         /* Locations */
19011         const GLuint goku_location  = 2;
19012         const GLuint goten_location = m_goten_location;
19013
19014         /* Generate data */
19015         m_goku_data   = type.GenerateDataPacked();
19016         m_gohan_data  = type.GenerateDataPacked();
19017         m_goten_data  = type.GenerateDataPacked();
19018         m_chichi_data = type.GenerateDataPacked();
19019
19020         /* Globals */
19021         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19022
19023         /* Attributes */
19024         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19025                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19026                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19027                          m_goku_data.size() /* data_size */);
19028
19029         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19030                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19031                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19032                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19033
19034         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19035                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19036                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19037                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19038
19039         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19040                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19041                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19042                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19043 }
19044
19045 /** Selects if "compute" stage is relevant for test
19046  *
19047  * @param ignored
19048  *
19049  * @return false
19050  **/
19051 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19052 {
19053         return false;
19054 }
19055
19056 /* Constants used by FragmentDataLocationAPITest */
19057 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19058
19059 /** Constructor
19060  *
19061  * @param context Test framework context
19062  **/
19063 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19064         : TextureTestBase(context, "fragment_data_location_api",
19065                                           "Test verifies that fragment data locations API works as expected")
19066         , m_goku(context)
19067         , m_gohan(context)
19068         , m_goten(context)
19069         , m_chichi(context)
19070 {
19071 }
19072
19073 /** Verifies contents of drawn images
19074  *
19075  * @param ignored
19076  * @param ignored
19077  *
19078  * @return true if images are filled with expected values, false otherwise
19079  **/
19080 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19081 {
19082         static const GLuint size                        = m_width * m_height;
19083         static const GLuint expected_goku   = 0xff000000;
19084         static const GLuint expected_gohan  = 0xff0000ff;
19085         static const GLuint expected_goten  = 0xff00ff00;
19086         static const GLuint expected_chichi = 0xffff0000;
19087
19088         std::vector<GLuint> data;
19089         data.resize(size);
19090
19091         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19092
19093         for (GLuint i = 0; i < size; ++i)
19094         {
19095                 const GLuint color = data[i];
19096
19097                 if (expected_goku != color)
19098                 {
19099                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19100                                                                                                 << tcu::TestLog::EndMessage;
19101                         return false;
19102                 }
19103         }
19104
19105         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19106
19107         for (GLuint i = 0; i < size; ++i)
19108         {
19109                 const GLuint color = data[i];
19110
19111                 if (expected_gohan != color)
19112                 {
19113                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19114                                                                                                 << tcu::TestLog::EndMessage;
19115                         return false;
19116                 }
19117         }
19118
19119         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19120
19121         for (GLuint i = 0; i < size; ++i)
19122         {
19123                 const GLuint color = data[i];
19124
19125                 if (expected_goten != color)
19126                 {
19127                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19128                                                                                                 << tcu::TestLog::EndMessage;
19129                         return false;
19130                 }
19131         }
19132
19133         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19134
19135         for (GLuint i = 0; i < size; ++i)
19136         {
19137                 const GLuint color = data[i];
19138
19139                 if (expected_chichi != color)
19140                 {
19141                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19142                                                                                                 << tcu::TestLog::EndMessage;
19143                         return false;
19144                 }
19145         }
19146
19147         return true;
19148 }
19149
19150 /** Prepare code snippet that will set out variables
19151  *
19152  * @param ignored
19153  * @param ignored
19154  * @param stage               Shader stage
19155  *
19156  * @return Code that pass in variables to next stage
19157  **/
19158 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19159                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19160                                                                                                                 Utils::Shader::STAGES stage)
19161 {
19162         std::string result;
19163
19164         /* Skip for compute shader */
19165         if (Utils::Shader::FRAGMENT != stage)
19166         {
19167                 result = "";
19168         }
19169         else
19170         {
19171                 result = "chichi = vec4(0, 0, 1, 1);\n"
19172                                  "    goku   = vec4(0, 0, 0, 1);\n"
19173                                  "    goten  = vec4(0, 1, 0, 1);\n"
19174                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19175         }
19176
19177         return result;
19178 }
19179
19180 /** Get interface of program
19181  *
19182  * @param ignored
19183  * @param program_interface Interface of program
19184  * @param ignored
19185  **/
19186 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19187                                                                                                           Utils::ProgramInterface& program_interface,
19188                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19189 {
19190         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19191         const Utils::Type&              type = Utils::Type::vec4;
19192
19193         /* Locations */
19194         m_goku_location = 2;
19195
19196         /* Globals */
19197         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19198
19199         /* Attributes */
19200         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19201                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19202                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19203
19204         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19205                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19206                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19207
19208         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19209                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19210                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19211
19212         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19213                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19214                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19215 }
19216
19217 /** Selects if "compute" stage is relevant for test
19218  *
19219  * @param ignored
19220  *
19221  * @return false
19222  **/
19223 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19224 {
19225         return false;
19226 }
19227
19228 /** Get locations for all outputs with automatic_location
19229  *
19230  * @param program           Program object
19231  * @param program_interface Interface of program
19232  **/
19233 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19234                                                                                                                  Utils::ProgramInterface& program_interface)
19235 {
19236         /* Bind location of goten */
19237         const Functions& gl = m_context.getRenderContext().getFunctions();
19238
19239         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19240         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19241
19242         program.Link(gl, program.m_id);
19243
19244         /* Prepare locations for gohan and chichi */
19245         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19246
19247         /* Get all locations */
19248         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19249
19250         Utils::Variable::PtrVector& outputs = si.m_outputs;
19251
19252         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19253         {
19254                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19255
19256                 if (0 == desc.m_name.compare("gohan"))
19257                 {
19258                         m_gohan_location = desc.m_expected_location;
19259                 }
19260                 else if (0 == desc.m_name.compare("chichi"))
19261                 {
19262                         m_chichi_location = desc.m_expected_location;
19263                 }
19264
19265                 /* Locations of goku and goten are fixed */
19266         }
19267 }
19268
19269 /** Prepare framebuffer with single texture as color attachment
19270  *
19271  * @param framebuffer     Framebuffer
19272  * @param color_0_texture Texture that will used as color attachment
19273  **/
19274 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19275 {
19276         /* Let parent prepare its stuff */
19277         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19278
19279         /* Prepare data */
19280         std::vector<GLuint> texture_data;
19281         texture_data.resize(m_width * m_height);
19282
19283         for (GLuint i = 0; i < texture_data.size(); ++i)
19284         {
19285                 texture_data[i] = 0x20406080;
19286         }
19287
19288         /* Prepare textures */
19289         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19290
19291         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19292
19293         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19294
19295         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19296
19297         /* Attach textures to framebuffer */
19298         framebuffer.Bind();
19299         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19300         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19301         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19302         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19303
19304         /* Set up drawbuffers */
19305         const Functions& gl = m_context.getRenderContext().getFunctions();
19306         //  1. There are only 4 outputs in fragment shader, so only need to do buffer mapping for 4 attachments,
19307         //  2. another issue is each output variable has a location, it is the fragment color index, so the index of
19308         //  GL_COLOR_ATTACHMENT in glDrawBuffers() should keep the same with the location, to make test correct,
19309         //  we needt to change the above code of glDrawBuffers() as :
19310         GLint  buffers_size = 4;
19311         GLenum buffers[]        = { GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location),
19312                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location),
19313                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location),
19314                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location) };
19315         gl.drawBuffers(buffers_size, buffers);
19316         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19317 }
19318
19319 /** Constructor
19320  *
19321  * @param context Test framework context
19322  **/
19323 XFBInputTest::XFBInputTest(deqp::Context& context)
19324         : NegativeTestBase(context, "xfb_input",
19325                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19326 {
19327 }
19328
19329 /** Source for given test case and stage
19330  *
19331  * @param test_case_index Index of test case
19332  * @param stage           Shader stage
19333  *
19334  * @return Shader source
19335  **/
19336 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19337 {
19338         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19339         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19340         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19341         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19342         static const GLchar* fs                                    = "#version 430 core\n"
19343                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19344                                                           "\n"
19345                                                           "in  vec4 gs_fs;\n"
19346                                                           "out vec4 fs_out;\n"
19347                                                           "\n"
19348                                                           "void main()\n"
19349                                                           "{\n"
19350                                                           "    fs_out = gs_fs;\n"
19351                                                           "}\n"
19352                                                           "\n";
19353         static const GLchar* fs_tested = "#version 430 core\n"
19354                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19355                                                                          "\n"
19356                                                                          "VAR_DEFINITION"
19357                                                                          "\n"
19358                                                                          "in  vec4 gs_fs;\n"
19359                                                                          "out vec4 fs_out;\n"
19360                                                                          "\n"
19361                                                                          "void main()\n"
19362                                                                          "{\n"
19363                                                                          "    vec4 result = gs_fs;\n"
19364                                                                          "\n"
19365                                                                          "VARIABLE_USE"
19366                                                                          "\n"
19367                                                                          "    fs_out = result;\n"
19368                                                                          "}\n"
19369                                                                          "\n";
19370         static const GLchar* gs = "#version 430 core\n"
19371                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19372                                                           "\n"
19373                                                           "layout(points)                           in;\n"
19374                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19375                                                           "\n"
19376                                                           "in  vec4 tes_gs[];\n"
19377                                                           "out vec4 gs_fs;\n"
19378                                                           "\n"
19379                                                           "void main()\n"
19380                                                           "{\n"
19381                                                           "    gs_fs = tes_gs[0];\n"
19382                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19383                                                           "    EmitVertex();\n"
19384                                                           "    gs_fs = tes_gs[0];\n"
19385                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19386                                                           "    EmitVertex();\n"
19387                                                           "    gs_fs = tes_gs[0];\n"
19388                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19389                                                           "    EmitVertex();\n"
19390                                                           "    gs_fs = tes_gs[0];\n"
19391                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19392                                                           "    EmitVertex();\n"
19393                                                           "}\n"
19394                                                           "\n";
19395         static const GLchar* gs_tested = "#version 430 core\n"
19396                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19397                                                                          "\n"
19398                                                                          "layout(points)                           in;\n"
19399                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19400                                                                          "\n"
19401                                                                          "VAR_DEFINITION"
19402                                                                          "\n"
19403                                                                          "in  vec4 tes_gs[];\n"
19404                                                                          "out vec4 gs_fs;\n"
19405                                                                          "\n"
19406                                                                          "void main()\n"
19407                                                                          "{\n"
19408                                                                          "    vec4 result = tes_gs[0];\n"
19409                                                                          "\n"
19410                                                                          "VARIABLE_USE"
19411                                                                          "\n"
19412                                                                          "    gs_fs = result;\n"
19413                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19414                                                                          "    EmitVertex();\n"
19415                                                                          "    gs_fs = result;\n"
19416                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19417                                                                          "    EmitVertex();\n"
19418                                                                          "    gs_fs = result;\n"
19419                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19420                                                                          "    EmitVertex();\n"
19421                                                                          "    gs_fs = result;\n"
19422                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19423                                                                          "    EmitVertex();\n"
19424                                                                          "}\n"
19425                                                                          "\n";
19426         static const GLchar* tcs = "#version 430 core\n"
19427                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19428                                                            "\n"
19429                                                            "layout(vertices = 1) out;\n"
19430                                                            "\n"
19431                                                            "in  vec4 vs_tcs[];\n"
19432                                                            "out vec4 tcs_tes[];\n"
19433                                                            "\n"
19434                                                            "void main()\n"
19435                                                            "{\n"
19436                                                            "\n"
19437                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19438                                                            "\n"
19439                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19440                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19441                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19442                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19443                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19444                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19445                                                            "}\n"
19446                                                            "\n";
19447         static const GLchar* tcs_tested = "#version 430 core\n"
19448                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19449                                                                           "\n"
19450                                                                           "layout(vertices = 1) out;\n"
19451                                                                           "\n"
19452                                                                           "VAR_DEFINITION"
19453                                                                           "\n"
19454                                                                           "in  vec4 vs_tcs[];\n"
19455                                                                           "out vec4 tcs_tes[];\n"
19456                                                                           "\n"
19457                                                                           "void main()\n"
19458                                                                           "{\n"
19459                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19460                                                                           "\n"
19461                                                                           "VARIABLE_USE"
19462                                                                           "\n"
19463                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19464                                                                           "\n"
19465                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19466                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19467                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19468                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19469                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19470                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19471                                                                           "}\n"
19472                                                                           "\n";
19473         static const GLchar* tes = "#version 430 core\n"
19474                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19475                                                            "\n"
19476                                                            "layout(isolines, point_mode) in;\n"
19477                                                            "\n"
19478                                                            "in  vec4 tcs_tes[];\n"
19479                                                            "out vec4 tes_gs;\n"
19480                                                            "\n"
19481                                                            "void main()\n"
19482                                                            "{\n"
19483                                                            "    tes_gs = tcs_tes[0];\n"
19484                                                            "}\n"
19485                                                            "\n";
19486         static const GLchar* tes_tested = "#version 430 core\n"
19487                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19488                                                                           "\n"
19489                                                                           "layout(isolines, point_mode) in;\n"
19490                                                                           "\n"
19491                                                                           "VAR_DEFINITION"
19492                                                                           "\n"
19493                                                                           "in  vec4 tcs_tes[];\n"
19494                                                                           "out vec4 tes_gs;\n"
19495                                                                           "\n"
19496                                                                           "void main()\n"
19497                                                                           "{\n"
19498                                                                           "    vec4 result = tcs_tes[0];\n"
19499                                                                           "\n"
19500                                                                           "VARIABLE_USE"
19501                                                                           "\n"
19502                                                                           "    tes_gs += result;\n"
19503                                                                           "}\n"
19504                                                                           "\n";
19505         static const GLchar* vs = "#version 430 core\n"
19506                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19507                                                           "\n"
19508                                                           "in  vec4 in_vs;\n"
19509                                                           "out vec4 vs_tcs;\n"
19510                                                           "\n"
19511                                                           "void main()\n"
19512                                                           "{\n"
19513                                                           "    vs_tcs = in_vs;\n"
19514                                                           "}\n"
19515                                                           "\n";
19516         static const GLchar* vs_tested = "#version 430 core\n"
19517                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19518                                                                          "\n"
19519                                                                          "VAR_DEFINITION"
19520                                                                          "\n"
19521                                                                          "in  vec4 in_vs;\n"
19522                                                                          "out vec4 vs_tcs;\n"
19523                                                                          "\n"
19524                                                                          "void main()\n"
19525                                                                          "{\n"
19526                                                                          "    vec4 result = in_vs;\n"
19527                                                                          "\n"
19528                                                                          "VARIABLE_USE"
19529                                                                          "\n"
19530                                                                          "    vs_tcs += result;\n"
19531                                                                          "}\n"
19532                                                                          "\n";
19533
19534         std::string source;
19535         testCase&   test_case = m_test_cases[test_case_index];
19536
19537         if (test_case.m_stage == stage)
19538         {
19539                 const GLchar* array     = "";
19540                 const GLchar* index     = "";
19541                 size_t            position = 0;
19542                 size_t            temp;
19543                 const GLchar* var_definition = 0;
19544                 const GLchar* var_use            = input_use;
19545
19546                 switch (test_case.m_qualifier)
19547                 {
19548                 case BUFFER:
19549                         var_definition = buffer_var_definition;
19550                         break;
19551                 case OFFSET:
19552                         var_definition = offset_var_definition;
19553                         break;
19554                 case STRIDE:
19555                         var_definition = stride_var_definition;
19556                         break;
19557                 default:
19558                         TCU_FAIL("Invalid enum");
19559                 }
19560
19561                 switch (stage)
19562                 {
19563                 case Utils::Shader::FRAGMENT:
19564                         source = fs_tested;
19565                         break;
19566                 case Utils::Shader::GEOMETRY:
19567                         source = gs_tested;
19568                         array  = "[]";
19569                         index  = "[0]";
19570                         break;
19571                 case Utils::Shader::TESS_CTRL:
19572                         source = tcs_tested;
19573                         array  = "[]";
19574                         index  = "[gl_InvocationID]";
19575                         break;
19576                 case Utils::Shader::TESS_EVAL:
19577                         source = tes_tested;
19578                         array  = "[]";
19579                         index  = "[0]";
19580                         break;
19581                 case Utils::Shader::VERTEX:
19582                         source = vs_tested;
19583                         break;
19584                 default:
19585                         TCU_FAIL("Invalid enum");
19586                 }
19587
19588                 temp = position;
19589                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19590                 position = temp;
19591                 Utils::replaceToken("ARRAY", position, array, source);
19592                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19593
19594                 Utils::replaceAllTokens("INDEX", index, source);
19595         }
19596         else
19597         {
19598                 switch (stage)
19599                 {
19600                 case Utils::Shader::FRAGMENT:
19601                         source = fs;
19602                         break;
19603                 case Utils::Shader::GEOMETRY:
19604                         source = gs;
19605                         break;
19606                 case Utils::Shader::TESS_CTRL:
19607                         source = tcs;
19608                         break;
19609                 case Utils::Shader::TESS_EVAL:
19610                         source = tes;
19611                         break;
19612                 case Utils::Shader::VERTEX:
19613                         source = vs;
19614                         break;
19615                 default:
19616                         TCU_FAIL("Invalid enum");
19617                 }
19618         }
19619
19620         return source;
19621 }
19622
19623 /** Get description of test case
19624  *
19625  * @param test_case_index Index of test case
19626  *
19627  * @return Test case description
19628  **/
19629 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19630 {
19631         std::stringstream stream;
19632         testCase&                 test_case = m_test_cases[test_case_index];
19633
19634         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19635
19636         switch (test_case.m_qualifier)
19637         {
19638         case BUFFER:
19639                 stream << "xfb_buffer";
19640                 break;
19641         case OFFSET:
19642                 stream << "xfb_offset";
19643                 break;
19644         case STRIDE:
19645                 stream << "xfb_stride";
19646                 break;
19647         default:
19648                 TCU_FAIL("Invalid enum");
19649         }
19650
19651         return stream.str();
19652 }
19653
19654 /** Get number of test cases
19655  *
19656  * @return Number of test cases
19657  **/
19658 GLuint XFBInputTest::getTestCaseNumber()
19659 {
19660         return static_cast<GLuint>(m_test_cases.size());
19661 }
19662
19663 /** Selects if "compute" stage is relevant for test
19664  *
19665  * @param ignored
19666  *
19667  * @return false
19668  **/
19669 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19670 {
19671         return false;
19672 }
19673
19674 /** Prepare all test cases
19675  *
19676  **/
19677 void XFBInputTest::testInit()
19678 {
19679         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19680         {
19681                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19682                 {
19683                         if (Utils::Shader::COMPUTE == stage)
19684                         {
19685                                 continue;
19686                         }
19687
19688                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19689
19690                         m_test_cases.push_back(test_case);
19691                 }
19692         }
19693 }
19694
19695 /* Constants used by XFBAllStagesTest */
19696 const GLuint XFBAllStagesTest::m_gs_index = 3;
19697
19698 /** Constructor
19699  *
19700  * @param context Test context
19701  **/
19702 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19703         : BufferTestBase(context, "xfb_all_stages",
19704                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19705 {
19706         /* Nothing to be done here */
19707 }
19708
19709 /** Get descriptors of buffers necessary for test
19710  *
19711  * @param ignored
19712  * @param out_descriptors Descriptors of buffers used by test
19713  **/
19714 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19715                                                                                         bufferDescriptor::Vector& out_descriptors)
19716 {
19717         static const GLuint n_stages = 4;
19718         const Utils::Type&  vec4         = Utils::Type::vec4;
19719
19720         /* Data */
19721         tcu::Vec4 sum;
19722
19723         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19724         out_descriptors.resize(n_stages * 2 + 1);
19725
19726         /* */
19727         for (GLuint i = 0; i < n_stages; ++i)
19728         {
19729                 /* Get references */
19730                 bufferDescriptor& uniform = out_descriptors[i + 0];
19731                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19732
19733                 /* Index */
19734                 uniform.m_index = i;
19735                 xfb.m_index             = i;
19736
19737                 /* Target */
19738                 uniform.m_target = Utils::Buffer::Uniform;
19739                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19740
19741                 /* Data */
19742                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19743
19744                 sum += var;
19745
19746                 uniform.m_initial_data.resize(vec4.GetSize());
19747                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19748
19749                 xfb.m_initial_data = vec4.GenerateDataPacked();
19750
19751                 if (m_gs_index != i)
19752                 {
19753                         xfb.m_expected_data = xfb.m_initial_data;
19754                 }
19755                 else
19756                 {
19757                         xfb.m_expected_data.resize(vec4.GetSize());
19758                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19759                 }
19760         }
19761
19762         /* FS */
19763         {
19764                 /* Get reference */
19765                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19766
19767                 /* Index */
19768                 uniform.m_index = n_stages;
19769
19770                 /* Target */
19771                 uniform.m_target = Utils::Buffer::Uniform;
19772
19773                 /* Data */
19774                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19775
19776                 uniform.m_initial_data.resize(vec4.GetSize());
19777                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19778         }
19779 }
19780
19781 /** Get body of main function for given shader stage
19782  *
19783  * @param ignored
19784  * @param stage            Shader stage
19785  * @param out_assignments  Set to empty
19786  * @param out_calculations Set to empty
19787  **/
19788 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19789                                                                          std::string& out_assignments, std::string& out_calculations)
19790 {
19791         out_calculations = "";
19792
19793         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19794         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19795         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19796         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19797         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19798
19799         const GLchar* assignments = 0;
19800         switch (stage)
19801         {
19802         case Utils::Shader::FRAGMENT:
19803                 assignments = fs;
19804                 break;
19805         case Utils::Shader::GEOMETRY:
19806                 assignments = gs;
19807                 break;
19808         case Utils::Shader::TESS_CTRL:
19809                 assignments = tcs;
19810                 break;
19811         case Utils::Shader::TESS_EVAL:
19812                 assignments = tes;
19813                 break;
19814         case Utils::Shader::VERTEX:
19815                 assignments = vs;
19816                 break;
19817         default:
19818                 TCU_FAIL("Invalid enum");
19819         }
19820
19821         out_assignments = assignments;
19822 }
19823
19824 /** Get interface of shader
19825  *
19826  * @param ignored
19827  * @param stage         Shader stage
19828  * @param out_interface Set to ""
19829  **/
19830 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19831                                                                                   std::string& out_interface)
19832 {
19833         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19834                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19835                                                           "    vec4 uni_vs;\n"
19836                                                           "};\n";
19837         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19838                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19839                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19840                                                            "    vec4 uni_tcs;\n"
19841                                                            "};\n";
19842         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19843                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19844                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19845                                                            "    vec4 uni_tes;\n"
19846                                                            "};\n";
19847         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19848                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19849                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19850                                                           "    vec4 uni_gs;\n"
19851                                                           "};\n";
19852         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19853                                                           "                       out     vec4 fs_out;\n"
19854                                                           "layout(binding    = 4) uniform fs_block {\n"
19855                                                           "    vec4 uni_fs;\n"
19856                                                           "};\n";
19857
19858         const GLchar* interface = 0;
19859         switch (stage)
19860         {
19861         case Utils::Shader::FRAGMENT:
19862                 interface = fs;
19863                 break;
19864         case Utils::Shader::GEOMETRY:
19865                 interface = gs;
19866                 break;
19867         case Utils::Shader::TESS_CTRL:
19868                 interface = tcs;
19869                 break;
19870         case Utils::Shader::TESS_EVAL:
19871                 interface = tes;
19872                 break;
19873         case Utils::Shader::VERTEX:
19874                 interface = vs;
19875                 break;
19876         default:
19877                 TCU_FAIL("Invalid enum");
19878         }
19879
19880         out_interface = interface;
19881 }
19882
19883 /* Constants used by XFBStrideOfEmptyListTest */
19884 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
19885
19886 /** Constructor
19887  *
19888  * @param context Test context
19889  **/
19890 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
19891         : BufferTestBase(context, "xfb_stride_of_empty_list",
19892                                          "Test verifies that xfb_stride qualifier is respected when no xfb_offset is specified")
19893 {
19894         /* Nothing to be done here */
19895 }
19896
19897 /** Execute drawArrays for single vertex
19898  *
19899  * @param test_case_index Index of test case
19900  *
19901  * @return true if proper error is reported
19902  **/
19903 bool XFBStrideOfEmptyListTest::executeDrawCall(GLuint test_case_index)
19904 {
19905         const Functions& gl             = m_context.getRenderContext().getFunctions();
19906         bool                     result = true;
19907
19908         /* Draw */
19909         gl.disable(GL_RASTERIZER_DISCARD);
19910         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
19911
19912         gl.beginTransformFeedback(GL_POINTS);
19913         GLenum error = gl.getError();
19914         switch (test_case_index)
19915         {
19916         case VALID:
19917                 if (GL_NO_ERROR != error)
19918                 {
19919                         gl.endTransformFeedback();
19920                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
19921                 }
19922
19923                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
19924                 error = gl.getError();
19925
19926                 gl.endTransformFeedback();
19927                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
19928                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
19929
19930                 break;
19931
19932         case FIRST_MISSING:
19933                 if (GL_NO_ERROR == error)
19934                 {
19935                         gl.endTransformFeedback();
19936                 }
19937
19938                 if (GL_INVALID_OPERATION != error)
19939                 {
19940                         m_context.getTestContext().getLog()
19941                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
19942                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19943                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19944
19945                         result = false;
19946                 }
19947
19948                 break;
19949
19950         case SECOND_MISSING:
19951                 if (GL_NO_ERROR == error)
19952                 {
19953                         gl.endTransformFeedback();
19954                 }
19955
19956                 if (GL_INVALID_OPERATION != error)
19957                 {
19958                         m_context.getTestContext().getLog()
19959                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
19960                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19961                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19962
19963                         result = false;
19964                 }
19965
19966                 break;
19967         }
19968
19969         /* Done */
19970         return result;
19971 }
19972
19973 /** Get descriptors of buffers necessary for test
19974  *
19975  * @param test_case_index Index of test case
19976  * @param out_descriptors Descriptors of buffers used by test
19977  **/
19978 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
19979                                                                                                         bufferDescriptor::Vector& out_descriptors)
19980 {
19981         switch (test_case_index)
19982         {
19983         case VALID:
19984         {
19985                 /* Test needs single uniform and two xfbs */
19986                 out_descriptors.resize(3);
19987
19988                 /* Get references */
19989                 bufferDescriptor& uniform = out_descriptors[0];
19990                 bufferDescriptor& xfb_0   = out_descriptors[1];
19991                 bufferDescriptor& xfb_1   = out_descriptors[2];
19992
19993                 /* Index */
19994                 uniform.m_index = 0;
19995                 xfb_0.m_index   = 0;
19996                 xfb_1.m_index   = 1;
19997
19998                 /* Target */
19999                 uniform.m_target = Utils::Buffer::Uniform;
20000                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20001                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20002
20003                 /* Data */
20004                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20005
20006                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20007                 xfb_0.m_expected_data = uniform.m_initial_data;
20008
20009                 /* Data, contents are the same as no modification is expected */
20010                 xfb_1.m_initial_data.resize(m_stride);
20011                 xfb_1.m_expected_data.resize(m_stride);
20012
20013                 for (GLuint i = 0; i < m_stride; ++i)
20014                 {
20015                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20016                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20017                 }
20018         }
20019
20020         break;
20021
20022         case FIRST_MISSING:
20023         {
20024                 /* Test needs single uniform and two xfbs */
20025                 out_descriptors.resize(2);
20026
20027                 /* Get references */
20028                 bufferDescriptor& uniform = out_descriptors[0];
20029                 bufferDescriptor& xfb_1   = out_descriptors[1];
20030
20031                 /* Index */
20032                 uniform.m_index = 0;
20033                 xfb_1.m_index   = 1;
20034
20035                 /* Target */
20036                 uniform.m_target = Utils::Buffer::Uniform;
20037                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20038
20039                 /* Data */
20040                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20041
20042                 /* Draw call will not be executed, contents does not matter */
20043                 xfb_1.m_initial_data.resize(m_stride);
20044         }
20045
20046         break;
20047
20048         case SECOND_MISSING:
20049         {
20050                 /* Test needs single uniform and two xfbs */
20051                 out_descriptors.resize(2);
20052
20053                 /* Get references */
20054                 bufferDescriptor& uniform = out_descriptors[0];
20055                 bufferDescriptor& xfb_0   = out_descriptors[1];
20056
20057                 /* Index */
20058                 uniform.m_index = 0;
20059                 xfb_0.m_index   = 0;
20060
20061                 /* Target */
20062                 uniform.m_target = Utils::Buffer::Uniform;
20063                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20064
20065                 /* Data */
20066                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20067
20068                 /* Draw call will not be executed, contents does not matter */
20069                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20070         }
20071
20072         break;
20073         }
20074 }
20075
20076 /** Get body of main function for given shader stage
20077  *
20078  * @param ignored
20079  * @param stage            Shader stage
20080  * @param out_assignments  Set to empty
20081  * @param out_calculations Set to empty
20082  **/
20083 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20084                                                                                          std::string& out_assignments, std::string& out_calculations)
20085 {
20086         out_calculations = "";
20087
20088         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20089         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20090
20091         const GLchar* assignments = "";
20092         switch (stage)
20093         {
20094         case Utils::Shader::FRAGMENT:
20095                 assignments = fs;
20096                 break;
20097         case Utils::Shader::GEOMETRY:
20098                 assignments = gs;
20099                 break;
20100         default:
20101                 break;
20102         }
20103
20104         out_assignments = assignments;
20105 }
20106
20107 /** Get interface of shader
20108  *
20109  * @param ignored
20110  * @param stage            Shader stage
20111  * @param out_interface    Set to ""
20112  **/
20113 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20114                                                                                                   std::string& out_interface)
20115 {
20116         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20117                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20118                                                           "\n"
20119                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20120                                                           "    vec4 uni_gs;\n"
20121                                                           "};\n";
20122         static const GLchar* fs = "in  vec4 gs_fs;\n"
20123                                                           "out vec4 fs_out;\n";
20124
20125         switch (stage)
20126         {
20127         case Utils::Shader::FRAGMENT:
20128                 out_interface = fs;
20129                 break;
20130         case Utils::Shader::GEOMETRY:
20131                 out_interface = gs;
20132                 break;
20133         default:
20134                 out_interface = "";
20135                 return;
20136         }
20137 }
20138
20139 /** Returns buffer details in human readable form.
20140  *
20141  * @param test_case_index Index of test case
20142  *
20143  * @return Case description
20144  **/
20145 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20146 {
20147         std::string result;
20148
20149         switch (test_case_index)
20150         {
20151         case VALID:
20152                 result = "Valid case";
20153                 break;
20154         case FIRST_MISSING:
20155                 result = "Missing xfb at index 0";
20156                 break;
20157         case SECOND_MISSING:
20158                 result = "Missing xfb at index 1";
20159                 break;
20160         default:
20161                 TCU_FAIL("Invalid enum");
20162         }
20163
20164         return result;
20165 }
20166
20167 /** Get number of test cases
20168  *
20169  * @return 3
20170  **/
20171 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20172 {
20173         return 3;
20174 }
20175
20176 /* Constants used by XFBStrideOfEmptyListTest */
20177 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20178
20179 /** Constructor
20180  *
20181  * @param context Test context
20182  **/
20183 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20184         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20185                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20186 {
20187         /* Nothing to be done here */
20188 }
20189
20190 /** Execute drawArrays for single vertex
20191  *
20192  * @param test_case_index Index of test case
20193  *
20194  * @return true if proper error is reported
20195  **/
20196 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(GLuint test_case_index)
20197 {
20198         const Functions& gl             = m_context.getRenderContext().getFunctions();
20199         bool                     result = true;
20200
20201         /* Draw */
20202         gl.disable(GL_RASTERIZER_DISCARD);
20203         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20204
20205         gl.beginTransformFeedback(GL_POINTS);
20206         GLenum error = gl.getError();
20207         switch (test_case_index)
20208         {
20209         case VALID:
20210                 if (GL_NO_ERROR != error)
20211                 {
20212                         gl.endTransformFeedback();
20213                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20214                 }
20215
20216                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20217                 error = gl.getError();
20218
20219                 gl.endTransformFeedback();
20220                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20221                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20222
20223                 break;
20224
20225         case FIRST_MISSING:
20226                 if (GL_NO_ERROR == error)
20227                 {
20228                         gl.endTransformFeedback();
20229                 }
20230
20231                 if (GL_INVALID_OPERATION != error)
20232                 {
20233                         m_context.getTestContext().getLog()
20234                                 << tcu::TestLog::Message << "XFB at index 0, that is declared as empty, is missing. It was expected "
20235                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20236                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20237
20238                         result = false;
20239                 }
20240
20241                 break;
20242
20243         case SECOND_MISSING:
20244                 if (GL_NO_ERROR == error)
20245                 {
20246                         gl.endTransformFeedback();
20247                 }
20248
20249                 if (GL_INVALID_OPERATION != error)
20250                 {
20251                         m_context.getTestContext().getLog()
20252                                 << tcu::TestLog::Message << "XFB at index 1, that is written by GS, is missing. It was expected that "
20253                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20254                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20255
20256                         result = false;
20257                 }
20258
20259                 break;
20260         }
20261
20262         /* Done */
20263         return result;
20264 }
20265
20266 /** Get descriptors of buffers necessary for test
20267  *
20268  * @param test_case_index Index of test case
20269  * @param out_descriptors Descriptors of buffers used by test
20270  **/
20271 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20272                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20273 {
20274         switch (test_case_index)
20275         {
20276         case VALID:
20277         {
20278                 /* Test needs single uniform and two xfbs */
20279                 out_descriptors.resize(3);
20280
20281                 /* Get references */
20282                 bufferDescriptor& uniform = out_descriptors[0];
20283                 bufferDescriptor& xfb_0   = out_descriptors[1];
20284                 bufferDescriptor& xfb_1   = out_descriptors[2];
20285
20286                 /* Index */
20287                 uniform.m_index = 0;
20288                 xfb_0.m_index   = 0;
20289                 xfb_1.m_index   = 1;
20290
20291                 /* Target */
20292                 uniform.m_target = Utils::Buffer::Uniform;
20293                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20294                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20295
20296                 /* Data */
20297                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20298
20299                 /* Data, contents are the same as no modification is expected */
20300                 xfb_0.m_initial_data.resize(m_stride);
20301                 xfb_0.m_expected_data.resize(m_stride);
20302
20303                 for (GLuint i = 0; i < m_stride; ++i)
20304                 {
20305                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20306                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20307                 }
20308
20309                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20310                 xfb_1.m_expected_data = uniform.m_initial_data;
20311         }
20312
20313         break;
20314
20315         case FIRST_MISSING:
20316         {
20317                 /* Test needs single uniform and two xfbs */
20318                 out_descriptors.resize(2);
20319
20320                 /* Get references */
20321                 bufferDescriptor& uniform = out_descriptors[0];
20322                 bufferDescriptor& xfb_1   = out_descriptors[1];
20323
20324                 /* Index */
20325                 uniform.m_index = 0;
20326                 xfb_1.m_index   = 1;
20327
20328                 /* Target */
20329                 uniform.m_target = Utils::Buffer::Uniform;
20330                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20331
20332                 /* Data */
20333                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20334
20335                 /* Draw call will not be executed, contents does not matter */
20336                 xfb_1.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20337         }
20338
20339         break;
20340
20341         case SECOND_MISSING:
20342         {
20343                 /* Test needs single uniform and two xfbs */
20344                 out_descriptors.resize(2);
20345
20346                 /* Get references */
20347                 bufferDescriptor& uniform = out_descriptors[0];
20348                 bufferDescriptor& xfb_0   = out_descriptors[1];
20349
20350                 /* Index */
20351                 uniform.m_index = 0;
20352                 xfb_0.m_index   = 0;
20353
20354                 /* Target */
20355                 uniform.m_target = Utils::Buffer::Uniform;
20356                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20357
20358                 /* Data */
20359                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20360
20361                 /* Draw call will not be executed, contents does not matter */
20362                 xfb_0.m_initial_data.resize(m_stride);
20363         }
20364
20365         break;
20366         }
20367 }
20368
20369 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20370  *
20371  * @param ignored
20372  * @param captured_varyings Vector of varying names to be captured
20373  **/
20374 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20375                                                                                                                  Utils::Program::NameVector& captured_varyings)
20376 {
20377         captured_varyings.push_back("gs_fs");
20378 }
20379
20380 /** Get body of main function for given shader stage
20381  *
20382  * @param ignored
20383  * @param stage            Shader stage
20384  * @param out_assignments  Set to empty
20385  * @param out_calculations Set to empty
20386  **/
20387 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20388                                                                                                    std::string& out_assignments, std::string& out_calculations)
20389 {
20390         out_calculations = "";
20391
20392         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20393         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20394
20395         const GLchar* assignments = "";
20396         switch (stage)
20397         {
20398         case Utils::Shader::FRAGMENT:
20399                 assignments = fs;
20400                 break;
20401         case Utils::Shader::GEOMETRY:
20402                 assignments = gs;
20403                 break;
20404         default:
20405                 break;
20406         }
20407
20408         out_assignments = assignments;
20409 }
20410
20411 /** Get interface of shader
20412  *
20413  * @param ignored
20414  * @param stage            Shader stage
20415  * @param out_interface    Set to ""
20416  **/
20417 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20418                                                                                                                 std::string& out_interface)
20419 {
20420         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out;\n"
20421                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs;\n"
20422                                                           "\n"
20423                                                           "layout(binding    = 0) uniform gs_block {\n"
20424                                                           "    vec4 uni_gs;\n"
20425                                                           "};\n";
20426         static const GLchar* fs = "in  vec4 gs_fs;\n"
20427                                                           "out vec4 fs_out;\n";
20428
20429         switch (stage)
20430         {
20431         case Utils::Shader::FRAGMENT:
20432                 out_interface = fs;
20433                 break;
20434         case Utils::Shader::GEOMETRY:
20435                 out_interface = gs;
20436                 break;
20437         default:
20438                 out_interface = "";
20439                 return;
20440         }
20441 }
20442
20443 /** Returns buffer details in human readable form.
20444  *
20445  * @param test_case_index Index of test case
20446  *
20447  * @return Case description
20448  **/
20449 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20450 {
20451         std::string result;
20452
20453         switch (test_case_index)
20454         {
20455         case VALID:
20456                 result = "Valid case";
20457                 break;
20458         case FIRST_MISSING:
20459                 result = "Missing xfb at index 0";
20460                 break;
20461         case SECOND_MISSING:
20462                 result = "Missing xfb at index 1";
20463                 break;
20464         default:
20465                 TCU_FAIL("Invalid enum");
20466         }
20467
20468         return result;
20469 }
20470
20471 /** Get number of test cases
20472  *
20473  * @return 2
20474  **/
20475 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20476 {
20477         return 3;
20478 }
20479
20480 /** Constructor
20481  *
20482  * @param context Test framework context
20483  **/
20484 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20485         : NegativeTestBase(context, "xfb_too_small_stride",
20486                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20487 {
20488 }
20489
20490 /** Source for given test case and stage
20491  *
20492  * @param test_case_index Index of test case
20493  * @param stage           Shader stage
20494  *
20495  * @return Shader source
20496  **/
20497 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20498 {
20499         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20500                                                                                                 "\n"
20501                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20502         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20503                                                                                                 "\n"
20504                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20505                                                                                                 "    vec4 gohan;\n"
20506                                                                                                 "    vec4 goten;\n"
20507                                                                                                 "    vec4 chichi;\n"
20508                                                                                                 "} gokuARRAY;\n";
20509         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20510                                                                                                  "\n"
20511                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20512         // 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;"
20513         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20514         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20515                                                                                                  "\n"
20516                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20517         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20518                                                                          "    gohanINDEX[1] = result / 4;\n"
20519                                                                          "    gohanINDEX[2] = result / 6;\n"
20520                                                                          "    gohanINDEX[3] = result / 8;\n";
20521         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20522                                                                          "    gokuINDEX.goten  = result / 4;\n"
20523                                                                          "    gokuINDEX.chichi = result / 6;\n";
20524         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20525         static const GLchar* fs                 = "#version 430 core\n"
20526                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20527                                                           "\n"
20528                                                           "in  vec4 gs_fs;\n"
20529                                                           "out vec4 fs_out;\n"
20530                                                           "\n"
20531                                                           "void main()\n"
20532                                                           "{\n"
20533                                                           "    fs_out = gs_fs;\n"
20534                                                           "}\n"
20535                                                           "\n";
20536         static const GLchar* gs_tested = "#version 430 core\n"
20537                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20538                                                                          "\n"
20539                                                                          "layout(points)                           in;\n"
20540                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20541                                                                          "\n"
20542                                                                          "VAR_DEFINITION"
20543                                                                          "\n"
20544                                                                          "in  vec4 tes_gs[];\n"
20545                                                                          "out vec4 gs_fs;\n"
20546                                                                          "\n"
20547                                                                          "void main()\n"
20548                                                                          "{\n"
20549                                                                          "    vec4 result = tes_gs[0];\n"
20550                                                                          "\n"
20551                                                                          "VARIABLE_USE"
20552                                                                          "\n"
20553                                                                          "    gs_fs = result;\n"
20554                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20555                                                                          "    EmitVertex();\n"
20556                                                                          "    gs_fs = result;\n"
20557                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20558                                                                          "    EmitVertex();\n"
20559                                                                          "    gs_fs = result;\n"
20560                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20561                                                                          "    EmitVertex();\n"
20562                                                                          "    gs_fs = result;\n"
20563                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20564                                                                          "    EmitVertex();\n"
20565                                                                          "}\n"
20566                                                                          "\n";
20567         static const GLchar* tcs = "#version 430 core\n"
20568                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20569                                                            "\n"
20570                                                            "layout(vertices = 1) out;\n"
20571                                                            "\n"
20572                                                            "in  vec4 vs_tcs[];\n"
20573                                                            "out vec4 tcs_tes[];\n"
20574                                                            "\n"
20575                                                            "void main()\n"
20576                                                            "{\n"
20577                                                            "\n"
20578                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20579                                                            "\n"
20580                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20581                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20582                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20583                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20584                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20585                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20586                                                            "}\n"
20587                                                            "\n";
20588         static const GLchar* tcs_tested = "#version 430 core\n"
20589                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20590                                                                           "\n"
20591                                                                           "layout(vertices = 1) out;\n"
20592                                                                           "\n"
20593                                                                           "VAR_DEFINITION"
20594                                                                           "\n"
20595                                                                           "in  vec4 vs_tcs[];\n"
20596                                                                           "out vec4 tcs_tes[];\n"
20597                                                                           "\n"
20598                                                                           "void main()\n"
20599                                                                           "{\n"
20600                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20601                                                                           "\n"
20602                                                                           "VARIABLE_USE"
20603                                                                           "\n"
20604                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20605                                                                           "\n"
20606                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20607                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20608                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20609                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20610                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20611                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20612                                                                           "}\n"
20613                                                                           "\n";
20614         static const GLchar* tes_tested = "#version 430 core\n"
20615                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20616                                                                           "\n"
20617                                                                           "layout(isolines, point_mode) in;\n"
20618                                                                           "\n"
20619                                                                           "VAR_DEFINITION"
20620                                                                           "\n"
20621                                                                           "in  vec4 tcs_tes[];\n"
20622                                                                           "out vec4 tes_gs;\n"
20623                                                                           "\n"
20624                                                                           "void main()\n"
20625                                                                           "{\n"
20626                                                                           "    vec4 result = tcs_tes[0];\n"
20627                                                                           "\n"
20628                                                                           "VARIABLE_USE"
20629                                                                           "\n"
20630                                                                           "    tes_gs += result;\n"
20631                                                                           "}\n"
20632                                                                           "\n";
20633         static const GLchar* vs = "#version 430 core\n"
20634                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20635                                                           "\n"
20636                                                           "in  vec4 in_vs;\n"
20637                                                           "out vec4 vs_tcs;\n"
20638                                                           "\n"
20639                                                           "void main()\n"
20640                                                           "{\n"
20641                                                           "    vs_tcs = in_vs;\n"
20642                                                           "}\n"
20643                                                           "\n";
20644         static const GLchar* vs_tested = "#version 430 core\n"
20645                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20646                                                                          "\n"
20647                                                                          "VAR_DEFINITION"
20648                                                                          "\n"
20649                                                                          "in  vec4 in_vs;\n"
20650                                                                          "out vec4 vs_tcs;\n"
20651                                                                          "\n"
20652                                                                          "void main()\n"
20653                                                                          "{\n"
20654                                                                          "    vec4 result = in_vs;\n"
20655                                                                          "\n"
20656                                                                          "VARIABLE_USE"
20657                                                                          "\n"
20658                                                                          "    vs_tcs += result;\n"
20659                                                                          "}\n"
20660                                                                          "\n";
20661
20662         std::string source;
20663         testCase&   test_case = m_test_cases[test_case_index];
20664
20665         if (test_case.m_stage == stage)
20666         {
20667                 const GLchar* array     = "";
20668                 const GLchar* index     = "";
20669                 size_t            position = 0;
20670                 size_t            temp;
20671                 const GLchar* var_definition = 0;
20672                 const GLchar* var_use            = 0;
20673
20674                 switch (test_case.m_case)
20675                 {
20676                 case OFFSET:
20677                         var_definition = offset_var_definition;
20678                         var_use            = output_use;
20679                         break;
20680                 case STRIDE:
20681                         var_definition = stride_var_definition;
20682                         var_use            = output_use;
20683                         break;
20684                 case BLOCK:
20685                         var_definition = block_var_definition;
20686                         var_use            = block_use;
20687                         break;
20688                 case ARRAY:
20689                         var_definition = array_var_definition;
20690                         var_use            = array_use;
20691                         break;
20692                 default:
20693                         TCU_FAIL("Invalid enum");
20694                 }
20695
20696                 switch (stage)
20697                 {
20698                 case Utils::Shader::GEOMETRY:
20699                         source = gs_tested;
20700                         array  = "[]";
20701                         index  = "[0]";
20702                         break;
20703                 case Utils::Shader::TESS_CTRL:
20704                         source = tcs_tested;
20705                         array  = "[]";
20706                         index  = "[gl_InvocationID]";
20707                         break;
20708                 case Utils::Shader::TESS_EVAL:
20709                         source = tes_tested;
20710                         array  = "[]";
20711                         index  = "[0]";
20712                         break;
20713                 case Utils::Shader::VERTEX:
20714                         source = vs_tested;
20715                         break;
20716                 default:
20717                         TCU_FAIL("Invalid enum");
20718                 }
20719
20720                 temp = position;
20721                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20722                 position = temp;
20723                 Utils::replaceToken("ARRAY", position, array, source);
20724                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20725
20726                 Utils::replaceAllTokens("INDEX", index, source);
20727         }
20728         else
20729         {
20730                 switch (test_case.m_stage)
20731                 {
20732                 case Utils::Shader::GEOMETRY:
20733                         switch (stage)
20734                         {
20735                         case Utils::Shader::FRAGMENT:
20736                                 source = fs;
20737                                 break;
20738                         case Utils::Shader::VERTEX:
20739                                 source = vs;
20740                                 break;
20741                         default:
20742                                 source = "";
20743                         }
20744                         break;
20745                 case Utils::Shader::TESS_CTRL:
20746                         switch (stage)
20747                         {
20748                         case Utils::Shader::FRAGMENT:
20749                                 source = fs;
20750                                 break;
20751                         case Utils::Shader::VERTEX:
20752                                 source = vs;
20753                                 break;
20754                         default:
20755                                 source = "";
20756                         }
20757                         break;
20758                 case Utils::Shader::TESS_EVAL:
20759                         switch (stage)
20760                         {
20761                         case Utils::Shader::FRAGMENT:
20762                                 source = fs;
20763                                 break;
20764                         case Utils::Shader::TESS_CTRL:
20765                                 source = tcs;
20766                                 break;
20767                         case Utils::Shader::VERTEX:
20768                                 source = vs;
20769                                 break;
20770                         default:
20771                                 source = "";
20772                         }
20773                         break;
20774                 case Utils::Shader::VERTEX:
20775                         switch (stage)
20776                         {
20777                         case Utils::Shader::FRAGMENT:
20778                                 source = fs;
20779                                 break;
20780                         default:
20781                                 source = "";
20782                         }
20783                         break;
20784                 default:
20785                         TCU_FAIL("Invalid enum");
20786                         break;
20787                 }
20788         }
20789
20790         return source;
20791 }
20792
20793 /** Get description of test case
20794  *
20795  * @param test_case_index Index of test case
20796  *
20797  * @return Test case description
20798  **/
20799 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20800 {
20801         std::stringstream stream;
20802         testCase&                 test_case = m_test_cases[test_case_index];
20803
20804         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20805
20806         switch (test_case.m_case)
20807         {
20808         case OFFSET:
20809                 stream << "buffer stride: 40, vec4 offset: 32";
20810                 break;
20811         case STRIDE:
20812                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20813                 break;
20814         case BLOCK:
20815                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20816                 break;
20817         case ARRAY:
20818                 stream << "buffer stride: 32, vec4[4] offset 16";
20819                 break;
20820         default:
20821                 TCU_FAIL("Invalid enum");
20822         }
20823
20824         return stream.str();
20825 }
20826
20827 /** Get number of test cases
20828  *
20829  * @return Number of test cases
20830  **/
20831 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20832 {
20833         return static_cast<GLuint>(m_test_cases.size());
20834 }
20835
20836 /** Selects if "compute" stage is relevant for test
20837  *
20838  * @param ignored
20839  *
20840  * @return false
20841  **/
20842 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20843 {
20844         return false;
20845 }
20846
20847 /** Prepare all test cases
20848  *
20849  **/
20850 void XFBTooSmallStrideTest::testInit()
20851 {
20852         for (GLuint c = 0; c < CASE_MAX; ++c)
20853         {
20854                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20855                 {
20856                         /*
20857                          It is invalid to define transform feedback output in TCS, according to spec:
20858                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20859                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20860                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20861                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20862                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20863                          each primitive processed by the vertex shader.
20864                          */
20865                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20866                                 (Utils::Shader::FRAGMENT == stage))
20867                         {
20868                                 continue;
20869                         }
20870
20871                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20872
20873                         m_test_cases.push_back(test_case);
20874                 }
20875         }
20876 }
20877
20878 /** Constructor
20879  *
20880  * @param context Test framework context
20881  **/
20882 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
20883         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
20884 {
20885 }
20886
20887 /** Source for given test case and stage
20888  *
20889  * @param test_case_index Index of test case
20890  * @param stage           Shader stage
20891  *
20892  * @return Shader source
20893  **/
20894 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20895 {
20896         static const GLchar* invalid_var_definition =
20897                 "const uint type_size = SIZE;\n"
20898                 "\n"
20899                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
20900                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
20901         static const GLchar* valid_var_definition =
20902                 "const uint type_size = SIZE;\n"
20903                 "\n"
20904                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
20905         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
20906                                                                            "    vegetaINDEX = TYPE(0);\n"
20907                                                                            "    if (vec4(0) == result)\n"
20908                                                                            "    {\n"
20909                                                                            "        gokuINDEX   = TYPE(0);\n"
20910                                                                            "        vegetaINDEX = TYPE(1);\n"
20911                                                                            "    }\n";
20912         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
20913                                                                          "    if (vec4(0) == result)\n"
20914                                                                          "    {\n"
20915                                                                          "        gokuINDEX   = TYPE(0);\n"
20916                                                                          "    }\n";
20917         static const GLchar* fs = "#version 430 core\n"
20918                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20919                                                           "\n"
20920                                                           "in  vec4 any_fs;\n"
20921                                                           "out vec4 fs_out;\n"
20922                                                           "\n"
20923                                                           "void main()\n"
20924                                                           "{\n"
20925                                                           "    fs_out = any_fs;\n"
20926                                                           "}\n"
20927                                                           "\n";
20928         static const GLchar* gs_tested = "#version 430 core\n"
20929                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20930                                                                          "\n"
20931                                                                          "layout(points)                           in;\n"
20932                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20933                                                                          "\n"
20934                                                                          "VAR_DEFINITION"
20935                                                                          "\n"
20936                                                                          "in  vec4 vs_any[];\n"
20937                                                                          "out vec4 any_fs;\n"
20938                                                                          "\n"
20939                                                                          "void main()\n"
20940                                                                          "{\n"
20941                                                                          "    vec4 result = vs_any[0];\n"
20942                                                                          "\n"
20943                                                                          "VARIABLE_USE"
20944                                                                          "\n"
20945                                                                          "    any_fs = result;\n"
20946                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20947                                                                          "    EmitVertex();\n"
20948                                                                          "    any_fs = result;\n"
20949                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20950                                                                          "    EmitVertex();\n"
20951                                                                          "    any_fs = result;\n"
20952                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20953                                                                          "    EmitVertex();\n"
20954                                                                          "    any_fs = result;\n"
20955                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20956                                                                          "    EmitVertex();\n"
20957                                                                          "}\n"
20958                                                                          "\n";
20959         static const GLchar* tcs = "#version 430 core\n"
20960                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20961                                                            "\n"
20962                                                            "layout(vertices = 1) out;\n"
20963                                                            "\n"
20964                                                            "in  vec4 vs_any[];\n"
20965                                                            "out vec4 tcs_tes[];\n"
20966                                                            "\n"
20967                                                            "void main()\n"
20968                                                            "{\n"
20969                                                            "\n"
20970                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
20971                                                            "\n"
20972                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20973                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20974                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20975                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20976                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20977                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20978                                                            "}\n"
20979                                                            "\n";
20980         static const GLchar* tcs_tested = "#version 430 core\n"
20981                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20982                                                                           "\n"
20983                                                                           "layout(vertices = 1) out;\n"
20984                                                                           "\n"
20985                                                                           "VAR_DEFINITION"
20986                                                                           "\n"
20987                                                                           "in  vec4 vs_any[];\n"
20988                                                                           "out vec4 any_fs[];\n"
20989                                                                           "\n"
20990                                                                           "void main()\n"
20991                                                                           "{\n"
20992                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
20993                                                                           "\n"
20994                                                                           "VARIABLE_USE"
20995                                                                           "\n"
20996                                                                           "    any_fs[gl_InvocationID] = result;\n"
20997                                                                           "\n"
20998                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20999                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21000                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21001                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21002                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21003                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21004                                                                           "}\n"
21005                                                                           "\n";
21006         static const GLchar* tes_tested = "#version 430 core\n"
21007                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21008                                                                           "\n"
21009                                                                           "layout(isolines, point_mode) in;\n"
21010                                                                           "\n"
21011                                                                           "VAR_DEFINITION"
21012                                                                           "\n"
21013                                                                           "in  vec4 tcs_tes[];\n"
21014                                                                           "out vec4 any_fs;\n"
21015                                                                           "\n"
21016                                                                           "void main()\n"
21017                                                                           "{\n"
21018                                                                           "    vec4 result = tcs_tes[0];\n"
21019                                                                           "\n"
21020                                                                           "VARIABLE_USE"
21021                                                                           "\n"
21022                                                                           "    any_fs = result;\n"
21023                                                                           "}\n"
21024                                                                           "\n";
21025         static const GLchar* vs = "#version 430 core\n"
21026                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21027                                                           "\n"
21028                                                           "in  vec4 in_vs;\n"
21029                                                           "out vec4 vs_any;\n"
21030                                                           "\n"
21031                                                           "void main()\n"
21032                                                           "{\n"
21033                                                           "    vs_any = in_vs;\n"
21034                                                           "}\n"
21035                                                           "\n";
21036         static const GLchar* vs_tested = "#version 430 core\n"
21037                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21038                                                                          "\n"
21039                                                                          "VAR_DEFINITION"
21040                                                                          "\n"
21041                                                                          "in  vec4 in_vs;\n"
21042                                                                          "out vec4 any_fs;\n"
21043                                                                          "\n"
21044                                                                          "void main()\n"
21045                                                                          "{\n"
21046                                                                          "    vec4 result = in_vs;\n"
21047                                                                          "\n"
21048                                                                          "VARIABLE_USE"
21049                                                                          "\n"
21050                                                                          "    any_fs = result;\n"
21051                                                                          "}\n"
21052                                                                          "\n";
21053
21054         std::string source;
21055         testCase&   test_case = m_test_cases[test_case_index];
21056
21057         if (test_case.m_stage == stage)
21058         {
21059                 const GLchar* array = "";
21060                 GLchar            buffer[16];
21061                 const GLchar* index     = "";
21062                 size_t            position = 0;
21063                 size_t            temp;
21064                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21065                 const GLchar* var_definition = 0;
21066                 const GLchar* var_use            = 0;
21067
21068                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21069
21070                 switch (test_case.m_case)
21071                 {
21072                 case VALID:
21073                         var_definition = valid_var_definition;
21074                         var_use            = valid_use;
21075                         break;
21076                 case INVALID:
21077                         var_definition = invalid_var_definition;
21078                         var_use            = invalid_use;
21079                         break;
21080                 default:
21081                         TCU_FAIL("Invalid enum");
21082                 }
21083
21084                 switch (stage)
21085                 {
21086                 case Utils::Shader::GEOMETRY:
21087                         source = gs_tested;
21088                         array  = "[1]";
21089                         index  = "[0]";
21090                         break;
21091                 case Utils::Shader::TESS_CTRL:
21092                         source = tcs_tested;
21093                         array  = "[1]";
21094                         index  = "[gl_InvocationID]";
21095                         break;
21096                 case Utils::Shader::TESS_EVAL:
21097                         source = tes_tested;
21098                         array  = "[1]";
21099                         index  = "[0]";
21100                         break;
21101                 case Utils::Shader::VERTEX:
21102                         source = vs_tested;
21103                         break;
21104                 default:
21105                         TCU_FAIL("Invalid enum");
21106                 }
21107
21108                 temp = position;
21109                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21110                 position = temp;
21111                 Utils::replaceToken("SIZE", position, buffer, source);
21112                 Utils::replaceToken("ARRAY", position, array, source);
21113                 if (INVALID == test_case.m_case)
21114                 {
21115                         Utils::replaceToken("ARRAY", position, array, source);
21116                 }
21117                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21118
21119                 Utils::replaceAllTokens("TYPE", type_name, source);
21120                 Utils::replaceAllTokens("INDEX", index, source);
21121         }
21122         else
21123         {
21124                 switch (test_case.m_stage)
21125                 {
21126                 case Utils::Shader::GEOMETRY:
21127                         switch (stage)
21128                         {
21129                         case Utils::Shader::FRAGMENT:
21130                                 source = fs;
21131                                 break;
21132                         case Utils::Shader::VERTEX:
21133                                 source = vs;
21134                                 break;
21135                         default:
21136                                 source = "";
21137                         }
21138                         break;
21139                 case Utils::Shader::TESS_CTRL:
21140                         switch (stage)
21141                         {
21142                         case Utils::Shader::FRAGMENT:
21143                                 source = fs;
21144                                 break;
21145                         case Utils::Shader::VERTEX:
21146                                 source = vs;
21147                                 break;
21148                         default:
21149                                 source = "";
21150                         }
21151                         break;
21152                 case Utils::Shader::TESS_EVAL:
21153                         switch (stage)
21154                         {
21155                         case Utils::Shader::FRAGMENT:
21156                                 source = fs;
21157                                 break;
21158                         case Utils::Shader::TESS_CTRL:
21159                                 source = tcs;
21160                                 break;
21161                         case Utils::Shader::VERTEX:
21162                                 source = vs;
21163                                 break;
21164                         default:
21165                                 source = "";
21166                         }
21167                         break;
21168                 case Utils::Shader::VERTEX:
21169                         switch (stage)
21170                         {
21171                         case Utils::Shader::FRAGMENT:
21172                                 source = fs;
21173                                 break;
21174                         default:
21175                                 source = "";
21176                         }
21177                         break;
21178                 default:
21179                         TCU_FAIL("Invalid enum");
21180                         break;
21181                 }
21182         }
21183
21184         return source;
21185 }
21186
21187 /** Get description of test case
21188  *
21189  * @param test_case_index Index of test case
21190  *
21191  * @return Test case description
21192  **/
21193 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21194 {
21195         std::stringstream stream;
21196         testCase&                 test_case = m_test_cases[test_case_index];
21197
21198         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21199                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21200
21201         switch (test_case.m_case)
21202         {
21203         case VALID:
21204                 stream << "valid";
21205                 break;
21206         case INVALID:
21207                 stream << "invalid";
21208                 break;
21209         default:
21210                 TCU_FAIL("Invalid enum");
21211         }
21212
21213         return stream.str();
21214 }
21215
21216 /** Get number of test cases
21217  *
21218  * @return Number of test cases
21219  **/
21220 GLuint XFBVariableStrideTest::getTestCaseNumber()
21221 {
21222         return static_cast<GLuint>(m_test_cases.size());
21223 }
21224
21225 /** Selects if "compute" stage is relevant for test
21226  *
21227  * @param ignored
21228  *
21229  * @return false
21230  **/
21231 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21232 {
21233         return false;
21234 }
21235
21236 /** Selects if compilation failure is expected result
21237  *
21238  * @param test_case_index Index of test case
21239  *
21240  * @return true
21241  **/
21242 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21243 {
21244         testCase& test_case = m_test_cases[test_case_index];
21245
21246         return (INVALID == test_case.m_case);
21247 }
21248
21249 /** Prepare all test cases
21250  *
21251  **/
21252 void XFBVariableStrideTest::testInit()
21253 {
21254         const GLuint n_types = getTypesNumber();
21255
21256         for (GLuint i = 0; i < n_types; ++i)
21257         {
21258                 const Utils::Type& type = getType(i);
21259
21260                 /*
21261                  Some of the cases are declared as following are considered as invalid,
21262                  but accoring to spec, the following declaration is valid: shaders in the
21263                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21264                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21265                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21266                  the stride.
21267
21268                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21269                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21270                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21271                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21272
21273                  int type_size = 8;
21274                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21275                  layout (xfb_offset = type_size)                     out double vegeta;
21276                  */
21277                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21278                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21279                 {
21280                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21281                         {
21282                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21283                                         (Utils::Shader::FRAGMENT == stage))
21284                                 {
21285                                         continue;
21286                                 }
21287
21288                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21289
21290                                 m_test_cases.push_back(test_case);
21291                         }
21292                 }
21293         }
21294 }
21295
21296 /** Constructor
21297  *
21298  * @param context Test framework context
21299  **/
21300 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21301         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21302 {
21303 }
21304
21305 /** Source for given test case and stage
21306  *
21307  * @param test_case_index Index of test case
21308  * @param stage           Shader stage
21309  *
21310  * @return Shader source
21311  **/
21312 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21313 {
21314         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21315                                                                                   "    vec4 gohan;\n"
21316                                                                                   "    vec4 goten;\n"
21317                                                                                   "    vec4 chichi;\n"
21318                                                                                   "} gokuARRAY;\n";
21319         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21320                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21321                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21322                                                                    "    if (vec4(0) == result)\n"
21323                                                                    "    {\n"
21324                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21325                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21326                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21327                                                                    "    }\n";
21328         static const GLchar* gs_tested =
21329                 "#version 430 core\n"
21330                 "#extension GL_ARB_enhanced_layouts : require\n"
21331                 "\n"
21332                 "layout(points)                           in;\n"
21333                 "layout(triangle_strip, max_vertices = 4) out;\n"
21334                 "\n"
21335                 "VAR_DEFINITION"
21336                 "\n"
21337                 "out gl_PerVertex \n"
21338                 "{ \n"
21339                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21340                 "}; \n"
21341                 "in  vec4 tes_gs[];\n"
21342                 "out vec4 gs_fs;\n"
21343                 "\n"
21344                 "void main()\n"
21345                 "{\n"
21346                 "    vec4 result = tes_gs[0];\n"
21347                 "\n"
21348                 "VARIABLE_USE"
21349                 "\n"
21350                 "    gs_fs = result;\n"
21351                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21352                 "    EmitVertex();\n"
21353                 "    gs_fs = result;\n"
21354                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21355                 "    EmitVertex();\n"
21356                 "    gs_fs = result;\n"
21357                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21358                 "    EmitVertex();\n"
21359                 "    gs_fs = result;\n"
21360                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21361                 "    EmitVertex();\n"
21362                 "}\n"
21363                 "\n";
21364         static const GLchar* tcs = "#version 430 core\n"
21365                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21366                                                            "\n"
21367                                                            "layout(vertices = 1) out;\n"
21368                                                            "\n"
21369                                                            "in  vec4 vs_tcs[];\n"
21370                                                            "out vec4 tcs_tes[];\n"
21371                                                            "\n"
21372                                                            "void main()\n"
21373                                                            "{\n"
21374                                                            "\n"
21375                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21376                                                            "\n"
21377                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21378                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21379                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21380                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21381                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21382                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21383                                                            "}\n"
21384                                                            "\n";
21385 #if 0
21386         static const GLchar* tcs_tested =
21387                 "#version 430 core\n"
21388                 "#extension GL_ARB_enhanced_layouts : require\n"
21389                 "\n"
21390                 "layout(vertices = 1) out;\n"
21391                 "\n"
21392                 "VAR_DEFINITION"
21393                 "\n"
21394                 "in  vec4 vs_tcs[];\n"
21395                 "out vec4 tcs_tes[];\n"
21396                 "\n"
21397                 "void main()\n"
21398                 "{\n"
21399                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21400                 "\n"
21401                 "VARIABLE_USE"
21402                 "\n"
21403                 "    tcs_tes[gl_InvocationID] = result;\n"
21404                 "\n"
21405                 "    gl_TessLevelOuter[0] = 1.0;\n"
21406                 "    gl_TessLevelOuter[1] = 1.0;\n"
21407                 "    gl_TessLevelOuter[2] = 1.0;\n"
21408                 "    gl_TessLevelOuter[3] = 1.0;\n"
21409                 "    gl_TessLevelInner[0] = 1.0;\n"
21410                 "    gl_TessLevelInner[1] = 1.0;\n"
21411                 "}\n"
21412                 "\n";
21413 #endif
21414         static const GLchar* tes_tested = "#version 430 core\n"
21415                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21416                                                                           "\n"
21417                                                                           "layout(isolines, point_mode) in;\n"
21418                                                                           "\n"
21419                                                                           "VAR_DEFINITION"
21420                                                                           "\n"
21421                                                                           "in  vec4 tcs_tes[];\n"
21422                                                                           "out vec4 tes_gs;\n"
21423                                                                           "\n"
21424                                                                           "void main()\n"
21425                                                                           "{\n"
21426                                                                           "    vec4 result = tcs_tes[0];\n"
21427                                                                           "\n"
21428                                                                           "VARIABLE_USE"
21429                                                                           "\n"
21430                                                                           "    tes_gs += result;\n"
21431                                                                           "}\n"
21432                                                                           "\n";
21433         static const GLchar* vs = "#version 430 core\n"
21434                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21435                                                           "\n"
21436                                                           "in  vec4 in_vs;\n"
21437                                                           "out vec4 vs_tcs;\n"
21438                                                           "\n"
21439                                                           "void main()\n"
21440                                                           "{\n"
21441                                                           "    vs_tcs = in_vs;\n"
21442                                                           "}\n"
21443                                                           "\n";
21444         static const GLchar* vs_tested = "#version 430 core\n"
21445                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21446                                                                          "\n"
21447                                                                          "VAR_DEFINITION"
21448                                                                          "\n"
21449                                                                          "in  vec4 in_vs;\n"
21450                                                                          "out vec4 vs_tcs;\n"
21451                                                                          "\n"
21452                                                                          "void main()\n"
21453                                                                          "{\n"
21454                                                                          "    vec4 result = in_vs;\n"
21455                                                                          "\n"
21456                                                                          "VARIABLE_USE"
21457                                                                          "\n"
21458                                                                          "    vs_tcs += result;\n"
21459                                                                          "}\n"
21460                                                                          "\n";
21461
21462         std::string                       source;
21463         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21464
21465         if (test_case == stage)
21466         {
21467                 const GLchar* array     = "";
21468                 const GLchar* index     = "";
21469                 size_t            position = 0;
21470                 size_t            temp;
21471                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21472                 // change array = "[]" to "[1]"
21473                 switch (stage)
21474                 {
21475                 case Utils::Shader::GEOMETRY:
21476                         source = gs_tested;
21477                         array  = "[1]";
21478                         index  = "[0]";
21479                         break;
21480 /*
21481                          It is invalid to define transform feedback output in HS
21482                          */
21483 #if 0
21484                         case Utils::Shader::TESS_CTRL:
21485                         source = tcs_tested;
21486                         array = "[]";
21487                         index = "[gl_InvocationID]";
21488                         break;
21489 #endif
21490                 case Utils::Shader::TESS_EVAL:
21491                         source = tes_tested;
21492                         array  = "[1]";
21493                         index  = "[0]";
21494                         break;
21495                 case Utils::Shader::VERTEX:
21496                         source = vs_tested;
21497                         break;
21498                 default:
21499                         TCU_FAIL("Invalid enum");
21500                 }
21501
21502                 temp = position;
21503                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21504                 position = temp;
21505                 Utils::replaceToken("ARRAY", position, array, source);
21506                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21507
21508                 Utils::replaceAllTokens("INDEX", index, source);
21509         }
21510         else
21511         {
21512                 switch (test_case)
21513                 {
21514                 case Utils::Shader::GEOMETRY:
21515                         switch (stage)
21516                         {
21517                         case Utils::Shader::VERTEX:
21518                                 source = vs;
21519                                 break;
21520                         default:
21521                                 source = "";
21522                         }
21523                         break;
21524                 case Utils::Shader::TESS_CTRL:
21525                         switch (stage)
21526                         {
21527                         case Utils::Shader::VERTEX:
21528                                 source = vs;
21529                                 break;
21530                         default:
21531                                 source = "";
21532                         }
21533                         break;
21534                 case Utils::Shader::TESS_EVAL:
21535                         switch (stage)
21536                         {
21537                         case Utils::Shader::TESS_CTRL:
21538                                 source = tcs;
21539                                 break;
21540                         case Utils::Shader::VERTEX:
21541                                 source = vs;
21542                                 break;
21543                         default:
21544                                 source = "";
21545                         }
21546                         break;
21547                 case Utils::Shader::VERTEX:
21548                         source = "";
21549                         break;
21550                 default:
21551                         TCU_FAIL("Invalid enum");
21552                         break;
21553                 }
21554         }
21555
21556         return source;
21557 }
21558
21559 /** Get description of test case
21560  *
21561  * @param test_case_index Index of test case
21562  *
21563  * @return Test case description
21564  **/
21565 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21566 {
21567         std::stringstream stream;
21568
21569         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21570
21571         return stream.str();
21572 }
21573
21574 /** Get number of test cases
21575  *
21576  * @return Number of test cases
21577  **/
21578 GLuint XFBBlockStrideTest::getTestCaseNumber()
21579 {
21580         return static_cast<GLuint>(m_test_cases.size());
21581 }
21582
21583 /** Inspects program for xfb stride
21584  *
21585  * @param program Program to query
21586  *
21587  * @return true if query results match expected values, false otherwise
21588  **/
21589 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21590 {
21591         GLint stride = 0;
21592
21593         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21594                                                 1 /* buf_size */, &stride);
21595
21596         return (128 == stride);
21597 }
21598
21599 /** Runs test case
21600  *
21601  * @param test_case_index Id of test case
21602  *
21603  * @return true if test case pass, false otherwise
21604  **/
21605 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21606 {
21607         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21608         Utils::Program   program(m_context);
21609         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21610         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21611         bool                       test_case_result = true;
21612         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21613
21614         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21615
21616         test_case_result = inspectProgram(program);
21617
21618         return test_case_result;
21619 }
21620
21621 /** Prepare all test cases
21622  *
21623  **/
21624 void XFBBlockStrideTest::testInit()
21625 {
21626         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21627         {
21628                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21629                         (Utils::Shader::FRAGMENT == stage))
21630                 {
21631                         continue;
21632                 }
21633
21634                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21635         }
21636 }
21637
21638 /** Constructor
21639  *
21640  * @param context Test context
21641  **/
21642 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21643         : BufferTestBase(context, "xfb_block_member_stride",
21644                                          "Test verifies that xfb_stride qualifier is respected for block member")
21645 {
21646         /* Nothing to be done here */
21647 }
21648
21649 /** Get descriptors of buffers necessary for test
21650  *
21651  * @param ignored
21652  * @param out_descriptors Descriptors of buffers used by test
21653  **/
21654 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21655                                                                                                         bufferDescriptor::Vector& out_descriptors)
21656 {
21657         const Utils::Type& vec4 = Utils::Type::vec4;
21658
21659         /* Test needs single uniform and xfb */
21660         out_descriptors.resize(2);
21661
21662         /* Get references */
21663         bufferDescriptor& uniform = out_descriptors[0];
21664         bufferDescriptor& xfb    = out_descriptors[1];
21665
21666         /* Index */
21667         uniform.m_index = 0;
21668         xfb.m_index             = 0;
21669
21670         /* Target */
21671         uniform.m_target = Utils::Buffer::Uniform;
21672         xfb.m_target     = Utils::Buffer::Transform_feedback;
21673
21674         /* Data */
21675         static const GLuint                     vec4_size   = 16;
21676         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21677         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21678         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21679
21680         /* Uniform data */
21681         uniform.m_initial_data.resize(3 * vec4_size);
21682         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21683         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21684         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21685
21686         /* XFB data */
21687         xfb.m_initial_data.resize(4 * vec4_size);
21688         xfb.m_expected_data.resize(4 * vec4_size);
21689
21690         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21691         {
21692                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21693                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21694         }
21695
21696         // the xfb_offset of "chichi" should be 32
21697         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21698         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21699         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21700 }
21701
21702 /** Get body of main function for given shader stage
21703  *
21704  * @param ignored
21705  * @param stage            Shader stage
21706  * @param out_assignments  Set to empty
21707  * @param out_calculations Set to empty
21708  **/
21709 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21710                                                                                          std::string& out_assignments, std::string& out_calculations)
21711 {
21712         out_calculations = "";
21713
21714         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21715                                                           "    goten  = uni_goten;\n"
21716                                                           "    chichi = uni_chichi;\n";
21717         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21718
21719         const GLchar* assignments = "";
21720         switch (stage)
21721         {
21722         case Utils::Shader::FRAGMENT:
21723                 assignments = fs;
21724                 break;
21725         case Utils::Shader::GEOMETRY:
21726                 assignments = gs;
21727                 break;
21728         default:
21729                 break;
21730         }
21731
21732         out_assignments = assignments;
21733 }
21734
21735 /** Get interface of shader
21736  *
21737  * @param ignored
21738  * @param stage            Shader stage
21739  * @param out_interface    Set to ""
21740  **/
21741 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21742                                                                                                   std::string& out_interface)
21743 {
21744         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21745                                                           "                             vec4 gohan;\n"
21746                                                           "    layout (xfb_stride = 32) vec4 goten;\n"
21747                                                           "                             vec4 chichi;\n"
21748                                                           "};\n"
21749                                                           "layout(binding = 0) uniform gs_block {\n"
21750                                                           "    vec4 uni_gohan;\n"
21751                                                           "    vec4 uni_goten;\n"
21752                                                           "    vec4 uni_chichi;\n"
21753                                                           "};\n";
21754         static const GLchar* fs = "in Goku {\n"
21755                                                           "    vec4 gohan;\n"
21756                                                           "    vec4 goten;\n"
21757                                                           "    vec4 chichi;\n"
21758                                                           "};\n"
21759                                                           "out vec4 fs_out;\n";
21760
21761         switch (stage)
21762         {
21763         case Utils::Shader::FRAGMENT:
21764                 out_interface = fs;
21765                 break;
21766         case Utils::Shader::GEOMETRY:
21767                 out_interface = gs;
21768                 break;
21769         default:
21770                 out_interface = "";
21771                 return;
21772         }
21773 }
21774
21775 /** Inspects program to check if all resources are as expected
21776  *
21777  * @param ignored
21778  * @param program    Program instance
21779  * @param out_stream Error message
21780  *
21781  * @return true if everything is ok, false otherwise
21782  **/
21783 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21784                                                                                           std::stringstream& out_stream)
21785 {
21786         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21787         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21788         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21789
21790         GLint gohan_offset  = 0;
21791         GLint goten_offset  = 0;
21792         GLint chichi_offset = 0;
21793
21794         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21795         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21796         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21797
21798         // the xfb_offset of "chichi" should be 32
21799         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21800         {
21801                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21802                                    << "] expected: [0, 16, 48]";
21803                 return false;
21804         }
21805
21806         return true;
21807 }
21808
21809 /** Constructor
21810  *
21811  * @param context Test framework context
21812  **/
21813 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21814         : NegativeTestBase(context, "xfb_duplicated_stride",
21815                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21816 {
21817 }
21818
21819 /** Source for given test case and stage
21820  *
21821  * @param test_case_index Index of test case
21822  * @param stage           Shader stage
21823  *
21824  * @return Shader source
21825  **/
21826 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21827 {
21828         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21829                                                                                                   "const uint conflicting_stride = 128;\n"
21830                                                                                                   "\n"
21831                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21832                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21833         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21834                                                                                                 "\n"
21835                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21836                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21837         static const GLchar* fs = "#version 430 core\n"
21838                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21839                                                           "\n"
21840                                                           "in  vec4 any_fs;\n"
21841                                                           "out vec4 fs_out;\n"
21842                                                           "\n"
21843                                                           "void main()\n"
21844                                                           "{\n"
21845                                                           "    fs_out = any_fs;\n"
21846                                                           "}\n"
21847                                                           "\n";
21848         static const GLchar* gs_tested = "#version 430 core\n"
21849                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21850                                                                          "\n"
21851                                                                          "layout(points)                           in;\n"
21852                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21853                                                                          "\n"
21854                                                                          "VAR_DEFINITION"
21855                                                                          "\n"
21856                                                                          "in  vec4 vs_any[];\n"
21857                                                                          "out vec4 any_fs;\n"
21858                                                                          "\n"
21859                                                                          "void main()\n"
21860                                                                          "{\n"
21861                                                                          "    vec4 result = vs_any[0];\n"
21862                                                                          "\n"
21863                                                                          "VARIABLE_USE"
21864                                                                          "\n"
21865                                                                          "    any_fs = result;\n"
21866                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21867                                                                          "    EmitVertex();\n"
21868                                                                          "    any_fs = result;\n"
21869                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21870                                                                          "    EmitVertex();\n"
21871                                                                          "    any_fs = result;\n"
21872                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21873                                                                          "    EmitVertex();\n"
21874                                                                          "    any_fs = result;\n"
21875                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21876                                                                          "    EmitVertex();\n"
21877                                                                          "}\n"
21878                                                                          "\n";
21879         static const GLchar* tcs = "#version 430 core\n"
21880                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21881                                                            "\n"
21882                                                            "layout(vertices = 1) out;\n"
21883                                                            "\n"
21884                                                            "in  vec4 vs_any[];\n"
21885                                                            "out vec4 tcs_tes[];\n"
21886                                                            "\n"
21887                                                            "void main()\n"
21888                                                            "{\n"
21889                                                            "\n"
21890                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21891                                                            "\n"
21892                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21893                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21894                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21895                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21896                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21897                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21898                                                            "}\n"
21899                                                            "\n";
21900         static const GLchar* tcs_tested = "#version 430 core\n"
21901                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21902                                                                           "\n"
21903                                                                           "layout(vertices = 1) out;\n"
21904                                                                           "\n"
21905                                                                           "VAR_DEFINITION"
21906                                                                           "\n"
21907                                                                           "in  vec4 vs_any[];\n"
21908                                                                           "out vec4 any_fs[];\n"
21909                                                                           "\n"
21910                                                                           "void main()\n"
21911                                                                           "{\n"
21912                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21913                                                                           "\n"
21914                                                                           "VARIABLE_USE"
21915                                                                           "\n"
21916                                                                           "    any_fs[gl_InvocationID] = result;\n"
21917                                                                           "\n"
21918                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21919                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21920                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21921                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21922                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21923                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21924                                                                           "}\n"
21925                                                                           "\n";
21926         static const GLchar* tes_tested = "#version 430 core\n"
21927                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21928                                                                           "\n"
21929                                                                           "layout(isolines, point_mode) in;\n"
21930                                                                           "\n"
21931                                                                           "VAR_DEFINITION"
21932                                                                           "\n"
21933                                                                           "in  vec4 tcs_tes[];\n"
21934                                                                           "out vec4 any_fs;\n"
21935                                                                           "\n"
21936                                                                           "void main()\n"
21937                                                                           "{\n"
21938                                                                           "    vec4 result = tcs_tes[0];\n"
21939                                                                           "\n"
21940                                                                           "VARIABLE_USE"
21941                                                                           "\n"
21942                                                                           "    any_fs = result;\n"
21943                                                                           "}\n"
21944                                                                           "\n";
21945         static const GLchar* vs = "#version 430 core\n"
21946                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21947                                                           "\n"
21948                                                           "in  vec4 in_vs;\n"
21949                                                           "out vec4 vs_any;\n"
21950                                                           "\n"
21951                                                           "void main()\n"
21952                                                           "{\n"
21953                                                           "    vs_any = in_vs;\n"
21954                                                           "}\n"
21955                                                           "\n";
21956         static const GLchar* vs_tested = "#version 430 core\n"
21957                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21958                                                                          "\n"
21959                                                                          "VAR_DEFINITION"
21960                                                                          "\n"
21961                                                                          "in  vec4 in_vs;\n"
21962                                                                          "out vec4 any_fs;\n"
21963                                                                          "\n"
21964                                                                          "void main()\n"
21965                                                                          "{\n"
21966                                                                          "    vec4 result = in_vs;\n"
21967                                                                          "\n"
21968                                                                          "VARIABLE_USE"
21969                                                                          "\n"
21970                                                                          "    any_fs += result;\n"
21971                                                                          "}\n"
21972                                                                          "\n";
21973
21974         std::string source;
21975         testCase&   test_case = m_test_cases[test_case_index];
21976
21977         if (test_case.m_stage == stage)
21978         {
21979                 size_t            position               = 0;
21980                 const GLchar* var_definition = 0;
21981                 const GLchar* var_use            = "";
21982
21983                 switch (test_case.m_case)
21984                 {
21985                 case VALID:
21986                         var_definition = valid_var_definition;
21987                         break;
21988                 case INVALID:
21989                         var_definition = invalid_var_definition;
21990                         break;
21991                 default:
21992                         TCU_FAIL("Invalid enum");
21993                 }
21994
21995                 switch (stage)
21996                 {
21997                 case Utils::Shader::GEOMETRY:
21998                         source = gs_tested;
21999                         break;
22000                 case Utils::Shader::TESS_CTRL:
22001                         source = tcs_tested;
22002                         break;
22003                 case Utils::Shader::TESS_EVAL:
22004                         source = tes_tested;
22005                         break;
22006                 case Utils::Shader::VERTEX:
22007                         source = vs_tested;
22008                         break;
22009                 default:
22010                         TCU_FAIL("Invalid enum");
22011                 }
22012
22013                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22014                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22015         }
22016         else
22017         {
22018                 switch (test_case.m_stage)
22019                 {
22020                 case Utils::Shader::GEOMETRY:
22021                         switch (stage)
22022                         {
22023                         case Utils::Shader::FRAGMENT:
22024                                 source = fs;
22025                                 break;
22026                         case Utils::Shader::VERTEX:
22027                                 source = vs;
22028                                 break;
22029                         default:
22030                                 source = "";
22031                         }
22032                         break;
22033                 case Utils::Shader::TESS_CTRL:
22034                         switch (stage)
22035                         {
22036                         case Utils::Shader::FRAGMENT:
22037                                 source = fs;
22038                                 break;
22039                         case Utils::Shader::VERTEX:
22040                                 source = vs;
22041                                 break;
22042                         default:
22043                                 source = "";
22044                         }
22045                         break;
22046                 case Utils::Shader::TESS_EVAL:
22047                         switch (stage)
22048                         {
22049                         case Utils::Shader::FRAGMENT:
22050                                 source = fs;
22051                                 break;
22052                         case Utils::Shader::TESS_CTRL:
22053                                 source = tcs;
22054                                 break;
22055                         case Utils::Shader::VERTEX:
22056                                 source = vs;
22057                                 break;
22058                         default:
22059                                 source = "";
22060                         }
22061                         break;
22062                 case Utils::Shader::VERTEX:
22063                         switch (stage)
22064                         {
22065                         case Utils::Shader::FRAGMENT:
22066                                 source = fs;
22067                                 break;
22068                         default:
22069                                 source = "";
22070                         }
22071                         break;
22072                 default:
22073                         TCU_FAIL("Invalid enum");
22074                         break;
22075                 }
22076         }
22077
22078         return source;
22079 }
22080
22081 /** Get description of test case
22082  *
22083  * @param test_case_index Index of test case
22084  *
22085  * @return Test case description
22086  **/
22087 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22088 {
22089         std::stringstream stream;
22090         testCase&                 test_case = m_test_cases[test_case_index];
22091
22092         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22093
22094         switch (test_case.m_case)
22095         {
22096         case VALID:
22097                 stream << "valid";
22098                 break;
22099         case INVALID:
22100                 stream << "invalid";
22101                 break;
22102         default:
22103                 TCU_FAIL("Invalid enum");
22104         }
22105
22106         return stream.str();
22107 }
22108
22109 /** Get number of test cases
22110  *
22111  * @return Number of test cases
22112  **/
22113 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22114 {
22115         return static_cast<GLuint>(m_test_cases.size());
22116 }
22117
22118 /** Selects if "compute" stage is relevant for test
22119  *
22120  * @param ignored
22121  *
22122  * @return false
22123  **/
22124 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22125 {
22126         return false;
22127 }
22128
22129 /** Selects if compilation failure is expected result
22130  *
22131  * @param test_case_index Index of test case
22132  *
22133  * @return true
22134  **/
22135 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22136 {
22137         testCase& test_case = m_test_cases[test_case_index];
22138
22139         return (INVALID == test_case.m_case);
22140 }
22141
22142 /** Prepare all test cases
22143  *
22144  **/
22145 void XFBDuplicatedStrideTest::testInit()
22146 {
22147         for (GLuint c = 0; c < CASE_MAX; ++c)
22148         {
22149                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22150                 {
22151                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22152                                 (Utils::Shader::FRAGMENT == stage))
22153                         {
22154                                 continue;
22155                         }
22156
22157                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22158
22159                         m_test_cases.push_back(test_case);
22160                 }
22161         }
22162 }
22163
22164 /** Constructor
22165  *
22166  * @param context Test framework context
22167  **/
22168 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22169         : TestBase(context, "xfb_get_program_resource_api",
22170                            "Test verifies that get program resource reports correct results for XFB")
22171 {
22172 }
22173
22174 /** Source for given test case and stage
22175  *
22176  * @param test_case_index Index of test case
22177  * @param stage           Shader stage
22178  *
22179  * @return Shader source
22180  **/
22181 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22182 {
22183         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22184                                                                                           "out TYPE b1_v1ARRAY;\n"
22185                                                                                           "out TYPE b0_v3ARRAY;\n"
22186                                                                                           "out TYPE b0_v0ARRAY;\n";
22187         static const GLchar* xfb_var_definition =
22188                 "const uint type_size = SIZE;\n"
22189                 "\n"
22190                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22191                 "\n"
22192                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22193                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22194                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22195                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22196         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22197                                                                    "    b1_v1INDEX = TYPE(1);\n"
22198                                                                    "    b0_v3INDEX = TYPE(0);\n"
22199                                                                    "    b0_v0INDEX = TYPE(1);\n"
22200                                                                    "    if (vec4(0) == result)\n"
22201                                                                    "    {\n"
22202                                                                    "        b0_v1INDEX = TYPE(1);\n"
22203                                                                    "        b1_v1INDEX = TYPE(0);\n"
22204                                                                    "        b0_v3INDEX = TYPE(1);\n"
22205                                                                    "        b0_v0INDEX = TYPE(0);\n"
22206                                                                    "    }\n";
22207         static const GLchar* gs_tested =
22208                 "#version 430 core\n"
22209                 "#extension GL_ARB_enhanced_layouts : require\n"
22210                 "\n"
22211                 "layout(points)                           in;\n"
22212                 "layout(triangle_strip, max_vertices = 4) out;\n"
22213                 "\n"
22214                 "VAR_DEFINITION"
22215                 "\n"
22216                 "out gl_PerVertex \n"
22217                 "{ \n"
22218                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22219                 "}; \n"
22220                 "in  vec4 tes_gs[];\n"
22221                 "out vec4 gs_fs;\n"
22222                 "\n"
22223                 "void main()\n"
22224                 "{\n"
22225                 "    vec4 result = tes_gs[0];\n"
22226                 "\n"
22227                 "VARIABLE_USE"
22228                 "\n"
22229                 "    gs_fs = result;\n"
22230                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22231                 "    EmitVertex();\n"
22232                 "    gs_fs = result;\n"
22233                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22234                 "    EmitVertex();\n"
22235                 "    gs_fs = result;\n"
22236                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22237                 "    EmitVertex();\n"
22238                 "    gs_fs = result;\n"
22239                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22240                 "    EmitVertex();\n"
22241                 "}\n"
22242                 "\n";
22243 #if 0
22244         static const GLchar* tcs_tested =
22245                 "#version 430 core\n"
22246                 "#extension GL_ARB_enhanced_layouts : require\n"
22247                 "\n"
22248                 "layout(vertices = 1) out;\n"
22249                 "\n"
22250                 "VAR_DEFINITION"
22251                 "\n"
22252                 "in  vec4 vs_tcs[];\n"
22253                 "out vec4 tcs_tes[];\n"
22254                 "\n"
22255                 "void main()\n"
22256                 "{\n"
22257                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22258                 "\n"
22259                 "VARIABLE_USE"
22260                 "\n"
22261                 "    tcs_tes[gl_InvocationID] = result;\n"
22262                 "\n"
22263                 "    gl_TessLevelOuter[0] = 1.0;\n"
22264                 "    gl_TessLevelOuter[1] = 1.0;\n"
22265                 "    gl_TessLevelOuter[2] = 1.0;\n"
22266                 "    gl_TessLevelOuter[3] = 1.0;\n"
22267                 "    gl_TessLevelInner[0] = 1.0;\n"
22268                 "    gl_TessLevelInner[1] = 1.0;\n"
22269                 "}\n"
22270                 "\n";
22271 #endif
22272         static const GLchar* tes_tested = "#version 430 core\n"
22273                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22274                                                                           "\n"
22275                                                                           "layout(isolines, point_mode) in;\n"
22276                                                                           "\n"
22277                                                                           "VAR_DEFINITION"
22278                                                                           "\n"
22279                                                                           "in  vec4 tcs_tes[];\n"
22280                                                                           "out vec4 tes_gs;\n"
22281                                                                           "\n"
22282                                                                           "void main()\n"
22283                                                                           "{\n"
22284                                                                           "    vec4 result = tcs_tes[0];\n"
22285                                                                           "\n"
22286                                                                           "VARIABLE_USE"
22287                                                                           "\n"
22288                                                                           "    tes_gs = result;\n"
22289                                                                           "}\n"
22290                                                                           "\n";
22291         static const GLchar* vs_tested = "#version 430 core\n"
22292                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22293                                                                          "\n"
22294                                                                          "VAR_DEFINITION"
22295                                                                          "\n"
22296                                                                          "in  vec4 in_vs;\n"
22297                                                                          "out vec4 vs_tcs;\n"
22298                                                                          "\n"
22299                                                                          "void main()\n"
22300                                                                          "{\n"
22301                                                                          "    vec4 result = in_vs;\n"
22302                                                                          "\n"
22303                                                                          "VARIABLE_USE"
22304                                                                          "\n"
22305                                                                          "    vs_tcs = result;\n"
22306                                                                          "}\n"
22307                                                                          "\n";
22308
22309         std::string              source;
22310         const test_Case& test_case = m_test_cases[test_case_index];
22311
22312         if (test_case.m_stage == stage)
22313         {
22314                 const GLchar* array = "";
22315                 GLchar            buffer[16];
22316                 const GLchar* index     = "";
22317                 size_t            position = 0;
22318                 size_t            temp;
22319                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22320                 const GLchar* var_definition = 0;
22321
22322                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22323
22324                 if (XFB == test_case.m_case)
22325                 {
22326                         var_definition = xfb_var_definition;
22327                 }
22328                 else
22329                 {
22330                         var_definition = api_var_definition;
22331                 }
22332
22333                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22334                 // change array = "[]" to "[1]"
22335                 switch (stage)
22336                 {
22337                 case Utils::Shader::GEOMETRY:
22338                         source = gs_tested;
22339                         array  = "[1]";
22340                         index  = "[0]";
22341                         break;
22342 // It is invalid to output transform feedback varyings in tessellation control shader
22343 #if 0
22344                 case Utils::Shader::TESS_CTRL:
22345                         source = tcs_tested;
22346                         array = "[]";
22347                         index = "[gl_InvocationID]";
22348                         break;
22349 #endif
22350                 case Utils::Shader::TESS_EVAL:
22351                         source = tes_tested;
22352                         array  = "[1]";
22353                         index  = "[0]";
22354                         break;
22355                 case Utils::Shader::VERTEX:
22356                         source = vs_tested;
22357                         break;
22358                 default:
22359                         TCU_FAIL("Invalid enum");
22360                 }
22361
22362                 temp = position;
22363                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22364                 if (XFB == test_case.m_case)
22365                 {
22366                         position = temp;
22367                         Utils::replaceToken("SIZE", position, buffer, source);
22368                 }
22369                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22370
22371                 Utils::replaceAllTokens("ARRAY", array, source);
22372                 Utils::replaceAllTokens("INDEX", index, source);
22373                 Utils::replaceAllTokens("TYPE", type_name, source);
22374         }
22375         else
22376         {
22377                 source = "";
22378         }
22379
22380         return source;
22381 }
22382
22383 /** Get description of test case
22384  *
22385  * @param test_case_index Index of test case
22386  *
22387  * @return Test case description
22388  **/
22389 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22390 {
22391         std::stringstream stream;
22392         const test_Case&  test_case = m_test_cases[test_case_index];
22393
22394         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22395                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22396
22397         switch (test_case.m_case)
22398         {
22399         case INTERLEAVED:
22400                 stream << "interleaved";
22401                 break;
22402         case SEPARATED:
22403                 stream << "separated";
22404                 break;
22405         case XFB:
22406                 stream << "xfb";
22407                 break;
22408         default:
22409                 TCU_FAIL("Invalid enum");
22410         }
22411
22412         return stream.str();
22413 }
22414
22415 /** Get number of test cases
22416  *
22417  * @return Number of test cases
22418  **/
22419 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22420 {
22421         return static_cast<GLuint>(m_test_cases.size());
22422 }
22423
22424 /** Inspects program for offset, buffer index, buffer stride and type
22425  *
22426  * @param test_case_index Index of test case
22427  * @param program         Program to query
22428  *
22429  * @return true if query results match expected values, false otherwise
22430  **/
22431 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22432 {
22433         GLint                    b0_stride      = 0;
22434         GLint                    b1_stride      = 0;
22435         GLint                    b0_v0_buf      = 0;
22436         GLint                    b0_v0_offset = 0;
22437         GLint                    b0_v0_type   = 0;
22438         GLint                    b0_v1_buf      = 0;
22439         GLint                    b0_v1_offset = 0;
22440         GLint                    b0_v1_type   = 0;
22441         GLint                    b0_v3_buf      = 0;
22442         GLint                    b0_v3_offset = 0;
22443         GLint                    b0_v3_type   = 0;
22444         GLint                    b1_v1_buf      = 0;
22445         GLint                    b1_v1_offset = 0;
22446         GLint                    b1_v1_type   = 0;
22447         const test_Case& test_case      = m_test_cases[test_case_index];
22448         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22449         const GLint              type_size      = test_case.m_type.GetSize();
22450
22451         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22452         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22453         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22454         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22455
22456         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22457         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22458         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22459         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22460
22461         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22462         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22463         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22464         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22465
22466         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22467                                                 1 /* buf_size */, &b0_v0_buf);
22468         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22469                                                 1 /* buf_size */, &b0_v1_buf);
22470         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22471                                                 1 /* buf_size */, &b0_v3_buf);
22472         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22473                                                 1 /* buf_size */, &b1_v1_buf);
22474
22475         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22476                                                 &b0_stride);
22477         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22478                                                 &b1_stride);
22479
22480         if (SEPARATED != test_case.m_case)
22481         {
22482                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22483                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22484                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22485                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22486                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22487                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22488                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22489         }
22490         else
22491         {
22492                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22493                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22494                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22495                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22496                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22497         }
22498 }
22499
22500 /** Insert gl_SkipComponents
22501  *
22502  * @param num_components How many gl_SkipComponents1 need to be inserted
22503  * @param varyings The transform feedback varyings string vector
22504  *
22505  **/
22506 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22507 {
22508         int num_component_4 = num_components / 4;
22509         int num_component_1 = num_components % 4;
22510         for (int i = 0; i < num_component_4; i++)
22511         {
22512                 varyings.push_back("gl_SkipComponents4");
22513         }
22514         switch (num_component_1)
22515         {
22516         case 1:
22517                 varyings.push_back("gl_SkipComponents1");
22518                 break;
22519         case 2:
22520                 varyings.push_back("gl_SkipComponents2");
22521                 break;
22522         case 3:
22523                 varyings.push_back("gl_SkipComponents3");
22524                 break;
22525         default:
22526                 break;
22527         }
22528 }
22529
22530 /** Runs test case
22531  *
22532  * @param test_case_index Id of test case
22533  *
22534  * @return true if test case pass, false otherwise
22535  **/
22536 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22537 {
22538         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22539         Utils::Program   program(m_context);
22540         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22541         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22542         const test_Case&   test_case            = m_test_cases[test_case_index];
22543         bool                       test_case_result = true;
22544         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22545
22546         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22547         // 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.
22548
22549         if (INTERLEAVED == test_case.m_case)
22550         {
22551                 /*
22552                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22553                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22554                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22555                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22556
22557                  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,
22558                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22559                  */
22560                 Utils::Program::NameVector captured_varyings;
22561                 captured_varyings.push_back("b0_v0");
22562                 captured_varyings.push_back("b0_v1");
22563                 // Compute how many gl_SkipComponents to be inserted
22564                 int numComponents = test_case.m_type.GetSize() / 4;
22565                 insertSkipComponents(numComponents, captured_varyings);
22566                 captured_varyings.push_back("b0_v3");
22567                 captured_varyings.push_back("gl_NextBuffer");
22568                 insertSkipComponents(numComponents, captured_varyings);
22569                 captured_varyings.push_back("b1_v1");
22570                 insertSkipComponents(numComponents * 2, captured_varyings);
22571
22572                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22573                                          true /* separable */);
22574         }
22575         else if (SEPARATED == test_case.m_case)
22576         {
22577                 Utils::Program::NameVector captured_varyings;
22578
22579                 captured_varyings.push_back("b0_v0");
22580                 captured_varyings.push_back("b0_v1");
22581                 captured_varyings.push_back("b0_v3");
22582                 captured_varyings.push_back("b1_v1");
22583
22584                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22585                                          true /* separable */);
22586         }
22587         else
22588         {
22589
22590                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22591         }
22592
22593         test_case_result = inspectProgram(test_case_index, program);
22594
22595         return test_case_result;
22596 }
22597
22598 /** Prepare all test cases
22599  *
22600  **/
22601 void XFBGetProgramResourceAPITest::testInit()
22602 {
22603         const Functions& gl              = m_context.getRenderContext().getFunctions();
22604         const GLuint     n_types = getTypesNumber();
22605         GLint                    max_xfb_int;
22606         GLint                    max_xfb_sep;
22607
22608         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22609         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22610
22611         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22612         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22613
22614         GLint max_varyings;
22615         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22616
22617         for (GLuint i = 0; i < n_types; ++i)
22618         {
22619                 // 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,
22620                 // 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
22621                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22622                 // to guarantee the number of varying not exceeded.
22623                 /*
22624                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22625                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22626                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22627                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22628                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22629                  in  vec4 in_vs;
22630                  out vec4 vs_tcs;
22631                  */
22632                 if (i == 7 || i == 9)
22633                         continue;
22634                 const Utils::Type& type = getType(i);
22635                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22636                 {
22637                         continue;
22638                 }
22639                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22640                 {
22641                         /*
22642                          It is invalid to define transform feedback output in HS
22643                          */
22644                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22645                                 (Utils::Shader::FRAGMENT == stage))
22646                         {
22647                                 continue;
22648                         }
22649
22650                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22651                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22652                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22653
22654                         if ((int)type.GetSize() <= max_xfb_int)
22655                         {
22656                                 m_test_cases.push_back(test_case_xfb);
22657                                 m_test_cases.push_back(test_case_int);
22658                         }
22659
22660                         if ((int)type.GetSize() <= max_xfb_sep)
22661                         {
22662                                 m_test_cases.push_back(test_case_sep);
22663                         }
22664                 }
22665         }
22666 }
22667
22668 /** Constructor
22669  *
22670  * @param context Test context
22671  **/
22672 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22673         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22674                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22675 {
22676         /* Nothing to be done here */
22677 }
22678
22679 /** Get descriptors of buffers necessary for test
22680  *
22681  * @param test_case_index Index of test case
22682  * @param out_descriptors Descriptors of buffers used by test
22683  **/
22684 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22685                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22686 {
22687         const Utils::Type& type = getType(test_case_index);
22688
22689         /* Test needs single uniform and xfb */
22690         out_descriptors.resize(2);
22691
22692         /* Get references */
22693         bufferDescriptor& uniform = out_descriptors[0];
22694         bufferDescriptor& xfb    = out_descriptors[1];
22695
22696         /* Index */
22697         uniform.m_index = 0;
22698         xfb.m_index             = 0;
22699
22700         /* Target */
22701         uniform.m_target = Utils::Buffer::Uniform;
22702         xfb.m_target     = Utils::Buffer::Transform_feedback;
22703
22704         /* Data */
22705         const GLuint                            gen_start   = Utils::s_rand;
22706         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22707         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22708         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22709         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22710
22711         Utils::s_rand                                                           = gen_start;
22712         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22713         /*
22714          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)
22715          how can make them equal ? is it as designed?  Add the following statement,  which can make sure goku_data_pck equals to goku_data
22716          */
22717         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22718
22719         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22720         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22721
22722         /* Uniform data */
22723         uniform.m_initial_data.resize(4 * type_size);
22724         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22725         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22726         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22727         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &gohan_data[0], type_size);
22728
22729         /* XFB data */
22730         xfb.m_initial_data.resize(4 * type_size_pck);
22731         xfb.m_expected_data.resize(4 * type_size_pck);
22732
22733         for (GLuint i = 0; i < 4 * type_size_pck; ++i)
22734         {
22735                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22736                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22737         }
22738
22739         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22740         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22741 }
22742
22743 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22744  *
22745  * @param ignored
22746  * @param captured_varyings List of names
22747  **/
22748 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
22749                                                                                                                    Utils::Program::NameVector& captured_varyings)
22750 {
22751         captured_varyings.resize(2);
22752
22753         captured_varyings[0] = "trunks";
22754         captured_varyings[1] = "gohan";
22755 }
22756
22757 /** Get body of main function for given shader stage
22758  *
22759  * @param test_case_index  Index of test case
22760  * @param stage            Shader stage
22761  * @param out_assignments  Set to empty
22762  * @param out_calculations Set to empty
22763  **/
22764 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22765                                                                                                          std::string& out_assignments, std::string& out_calculations)
22766 {
22767         out_calculations = "";
22768
22769         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22770                                                           "    trunks = uni_trunks;\n"
22771                                                           "    goku   = uni_goku;\n"
22772                                                           "    gohan  = uni_gohan;\n";
22773         static const GLchar* fs = "    fs_out = vec4(0);\n"
22774                                                           "    if (TYPE(1) == gohan + goku + trunks + vegeta)\n"
22775                                                           "    {\n"
22776                                                           "        fs_out = vec4(1);\n"
22777                                                           "    }\n";
22778
22779         const GLchar* assignments = "";
22780         switch (stage)
22781         {
22782         case Utils::Shader::FRAGMENT:
22783                 assignments = fs;
22784                 break;
22785         case Utils::Shader::GEOMETRY:
22786                 assignments = gs;
22787                 break;
22788         default:
22789                 break;
22790         }
22791
22792         out_assignments = assignments;
22793
22794         if (Utils::Shader::FRAGMENT == stage)
22795         {
22796                 const Utils::Type& type = getType(test_case_index);
22797
22798                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22799         }
22800 }
22801
22802 /** Get interface of shader
22803  *
22804  * @param test_case_index  Index of test case
22805  * @param stage            Shader stage
22806  * @param out_interface    Set to ""
22807  **/
22808 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22809                                                                                                                   std::string& out_interface)
22810 {
22811         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22812                                                           "\n"
22813                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22814                                                           "                                      flat out TYPE trunks;\n"
22815                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22816                                                           "                                      flat out TYPE gohan;\n"
22817                                                           "\n"
22818                                                           /*
22819                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22820                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22821                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22822                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22823                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22824                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22825                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22826                  */
22827                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22828                                                           "    TYPE uni_vegeta;\n"
22829                                                           "    TYPE uni_trunks;\n"
22830                                                           "    TYPE uni_goku;\n"
22831                                                           "    TYPE uni_gohan;\n"
22832                                                           "};\n";
22833         static const GLchar* fs = "flat in TYPE vegeta;\n"
22834                                                           "flat in TYPE trunks;\n"
22835                                                           "flat in TYPE goku;\n"
22836                                                           "flat in TYPE gohan;\n"
22837                                                           "\n"
22838                                                           "out vec4 fs_out;\n";
22839
22840         const Utils::Type& type = getType(test_case_index);
22841
22842         switch (stage)
22843         {
22844         case Utils::Shader::FRAGMENT:
22845                 out_interface = fs;
22846                 break;
22847         case Utils::Shader::GEOMETRY:
22848                 out_interface = gs;
22849                 break;
22850         default:
22851                 out_interface = "";
22852                 return;
22853         }
22854
22855         if (Utils::Shader::GEOMETRY == stage)
22856         {
22857                 GLchar           buffer[16];
22858                 size_t           position  = 0;
22859                 const GLuint type_size = type.GetSize();
22860
22861                 sprintf(buffer, "%d", type_size);
22862
22863                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22864         }
22865
22866         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22867 }
22868
22869 /** Get type name
22870  *
22871  * @param test_case_index Index of test case
22872  *
22873  * @return Name of type test in test_case_index
22874  **/
22875 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22876 {
22877         return getTypeName(test_case_index);
22878 }
22879
22880 /** Returns number of types to test
22881  *
22882  * @return Number of types, 34
22883  **/
22884 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
22885 {
22886         return getTypesNumber();
22887 }
22888
22889 /** Inspects program to check if all resources are as expected
22890  *
22891  * @param test_case_index Index of test case
22892  * @param program         Program instance
22893  * @param out_stream      Error message
22894  *
22895  * @return true if everything is ok, false otherwise
22896  **/
22897 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
22898                                                                                                           std::stringstream& out_stream)
22899 {
22900         GLint                      stride       = 0;
22901         const Utils::Type& type          = getType(test_case_index);
22902         const GLuint       type_size = type.GetSize();
22903
22904         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
22905                                                 1 /* buf_size */, &stride);
22906
22907         if ((GLint)(3 * type_size) != stride)
22908         {
22909                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
22910
22911                 return false;
22912         }
22913
22914         return true;
22915 }
22916
22917 /** Constructor
22918  *
22919  * @param context Test context
22920  **/
22921 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
22922         : BufferTestBase(context, "xfb_vertex_streams",
22923                                          "Test verifies that xfb qualifier works with multiple output streams")
22924 {
22925         /* Nothing to be done here */
22926 }
22927
22928 /** Get descriptors of buffers necessary for test
22929  *
22930  * @param ignored
22931  * @param out_descriptors Descriptors of buffers used by test
22932  **/
22933 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
22934                                                                                                 bufferDescriptor::Vector& out_descriptors)
22935 {
22936         const Utils::Type& type = Utils::Type::vec4;
22937
22938         /* Test needs single uniform and three xfbs */
22939         out_descriptors.resize(4);
22940
22941         /* Get references */
22942         bufferDescriptor& uniform = out_descriptors[0];
22943         bufferDescriptor& xfb_1   = out_descriptors[1];
22944         bufferDescriptor& xfb_2   = out_descriptors[2];
22945         bufferDescriptor& xfb_3   = out_descriptors[3];
22946
22947         /* Index */
22948         uniform.m_index = 0;
22949         xfb_1.m_index   = 1;
22950         xfb_2.m_index   = 2;
22951         xfb_3.m_index   = 3;
22952
22953         /* Target */
22954         uniform.m_target = Utils::Buffer::Uniform;
22955         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
22956         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
22957         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
22958
22959         /* Data */
22960         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22961         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22962         const std::vector<GLubyte>& goten_data  = type.GenerateData();
22963         const std::vector<GLubyte>& picolo_data = type.GenerateData();
22964         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22965         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
22966
22967         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
22968
22969         /* Uniform data */
22970         uniform.m_initial_data.resize(6 * type_size);
22971         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
22972         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
22973         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
22974         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
22975         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
22976         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
22977
22978         /* XFB data */
22979         static const GLuint xfb_stride = 64;
22980         xfb_1.m_initial_data.resize(xfb_stride);
22981         xfb_1.m_expected_data.resize(xfb_stride);
22982         xfb_2.m_initial_data.resize(xfb_stride);
22983         xfb_2.m_expected_data.resize(xfb_stride);
22984         xfb_3.m_initial_data.resize(xfb_stride);
22985         xfb_3.m_expected_data.resize(xfb_stride);
22986
22987         for (GLuint i = 0; i < xfb_stride; ++i)
22988         {
22989                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
22990                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
22991                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
22992                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
22993                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
22994                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
22995         }
22996
22997         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
22998         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
22999         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23000         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23001         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23002         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23003 }
23004
23005 /** Get body of main function for given shader stage
23006  *
23007  * @param ignored
23008  * @param stage            Shader stage
23009  * @param out_assignments  Set to empty
23010  * @param out_calculations Set to empty
23011  **/
23012 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23013                                                                                  std::string& out_assignments, std::string& out_calculations)
23014 {
23015         out_calculations = "";
23016
23017         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23018         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23019         // by the GS is assigned to specific stream.
23020         static const GLchar* gs = "    goku   = uni_goku;\n"
23021                                                           "    gohan  = uni_gohan;\n"
23022                                                           "    goten  = uni_goten;\n"
23023                                                           "    EmitStreamVertex(0);\n"
23024                                                           "    EndStreamPrimitive(0);\n"
23025                                                           "    picolo = uni_picolo;\n"
23026                                                           "    vegeta = uni_vegeta;\n"
23027                                                           "    EmitStreamVertex(1);\n"
23028                                                           "    EndStreamPrimitive(1);\n"
23029                                                           "    bulma  = uni_bulma;\n"
23030                                                           "    EmitStreamVertex(2);\n"
23031                                                           "    EndStreamPrimitive(2);\n";
23032
23033         static const GLchar* fs = "    fs_out = gohan + goku + goten + picolo + vegeta + bulma;\n";
23034
23035         const GLchar* assignments = "";
23036         switch (stage)
23037         {
23038         case Utils::Shader::FRAGMENT:
23039                 assignments = fs;
23040                 break;
23041         case Utils::Shader::GEOMETRY:
23042                 assignments = gs;
23043                 break;
23044         default:
23045                 break;
23046         }
23047
23048         out_assignments = assignments;
23049 }
23050
23051 /** Get interface of shader
23052  *
23053  * @param ignored
23054  * @param stage            Shader stage
23055  * @param out_interface    Set to ""
23056  **/
23057 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23058                                                                                           std::string& out_interface)
23059 {
23060         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23061                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23062                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23063                                                           "\n"
23064                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23065                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23066                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23067                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23068                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23069                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23070                                                           "\n"
23071                                                           "layout(binding = 0) uniform gs_block {\n"
23072                                                           "    vec4 uni_goku;\n"
23073                                                           "    vec4 uni_gohan;\n"
23074                                                           "    vec4 uni_goten;\n"
23075                                                           "    vec4 uni_picolo;\n"
23076                                                           "    vec4 uni_vegeta;\n"
23077                                                           "    vec4 uni_bulma;\n"
23078                                                           "};\n";
23079         /*
23080          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23081          */
23082         static const GLchar* fs = "in vec4 goku;\n"
23083                                                           "in vec4 gohan;\n"
23084                                                           "in vec4 goten;\n"
23085                                                           "in vec4 picolo;\n"
23086                                                           "in vec4 vegeta;\n"
23087                                                           "in vec4 bulma;\n"
23088                                                           "\n"
23089                                                           "out vec4 fs_out;\n";
23090
23091         switch (stage)
23092         {
23093         case Utils::Shader::FRAGMENT:
23094                 out_interface = fs;
23095                 break;
23096         case Utils::Shader::GEOMETRY:
23097                 out_interface = gs;
23098                 break;
23099         default:
23100                 out_interface = "";
23101                 return;
23102         }
23103 }
23104
23105 /** Constructor
23106  *
23107  * @param context Test framework context
23108  **/
23109 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23110         : NegativeTestBase(
23111                   context, "xfb_multiple_vertex_streams",
23112                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23113 {
23114 }
23115
23116 /** Source for given test case and stage
23117  *
23118  * @param ignored
23119  * @param stage           Shader stage
23120  *
23121  * @return Shader source
23122  **/
23123 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23124 {
23125         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23126                                                                                   "\n"
23127                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23128                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23129                                                                                   "\n"
23130                                                                                   "\n"
23131                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23132                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23133                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23134         static const GLchar* var_use = "    goku  = result / 2;\n"
23135                                                                    "    gohan = result / 4;\n"
23136                                                                    "    goten = result / 6;\n";
23137         static const GLchar* fs = "#version 430 core\n"
23138                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23139                                                           "\n"
23140                                                           "in  vec4 gs_fs;\n"
23141                                                           "in  vec4 goku;\n"
23142                                                           "out vec4 fs_out;\n"
23143                                                           "\n"
23144                                                           "void main()\n"
23145                                                           "{\n"
23146                                                           "    fs_out = gs_fs + goku;\n"
23147                                                           "}\n"
23148                                                           "\n";
23149         static const GLchar* gs = "#version 430 core\n"
23150                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23151                                                           "\n"
23152                                                           "layout(points)                           in;\n"
23153                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23154                                                           "\n"
23155                                                           "VAR_DEFINITION"
23156                                                           "\n"
23157                                                           "in  vec4 tes_gs[];\n"
23158                                                           "out vec4 gs_fs;\n"
23159                                                           "\n"
23160                                                           "void main()\n"
23161                                                           "{\n"
23162                                                           "    vec4 result = tes_gs[0];\n"
23163                                                           "\n"
23164                                                           "VARIABLE_USE"
23165                                                           "\n"
23166                                                           "    gs_fs = result;\n"
23167                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23168                                                           "    EmitVertex();\n"
23169                                                           "    gs_fs = result;\n"
23170                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23171                                                           "    EmitVertex();\n"
23172                                                           "    gs_fs = result;\n"
23173                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23174                                                           "    EmitVertex();\n"
23175                                                           "    gs_fs = result;\n"
23176                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23177                                                           "    EmitVertex();\n"
23178                                                           "}\n"
23179                                                           "\n";
23180         static const GLchar* vs = "#version 430 core\n"
23181                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23182                                                           "\n"
23183                                                           "in  vec4 in_vs;\n"
23184                                                           "out vec4 vs_tcs;\n"
23185                                                           "\n"
23186                                                           "void main()\n"
23187                                                           "{\n"
23188                                                           "    vs_tcs = in_vs;\n"
23189                                                           "}\n"
23190                                                           "\n";
23191
23192         std::string source;
23193
23194         if (Utils::Shader::GEOMETRY == stage)
23195         {
23196                 size_t position = 0;
23197
23198                 source = gs;
23199
23200                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23201                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23202         }
23203         else
23204         {
23205                 switch (stage)
23206                 {
23207                 case Utils::Shader::FRAGMENT:
23208                         source = fs;
23209                         break;
23210                 case Utils::Shader::VERTEX:
23211                         source = vs;
23212                         break;
23213                 default:
23214                         source = "";
23215                 }
23216         }
23217
23218         return source;
23219 }
23220
23221 /** Selects if "compute" stage is relevant for test
23222  *
23223  * @param ignored
23224  *
23225  * @return false
23226  **/
23227 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23228 {
23229         return false;
23230 }
23231
23232 /** Constructor
23233  *
23234  * @param context Test framework context
23235  **/
23236 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23237         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23238                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23239 {
23240 }
23241
23242 /** Source for given test case and stage
23243  *
23244  * @param test_case_index Index of test case
23245  * @param stage           Shader stage
23246  *
23247  * @return Shader source
23248  **/
23249 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23250 {
23251         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23252                                                                                                 "\n"
23253                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23254                                                                                                 "    vec4 member;\n"
23255                                                                                                 "} gokuARRAY;\n";
23256         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23257                                                                                                  "\n"
23258                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23259         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23260                                                                                                  "\n"
23261                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23262         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23263         static const GLchar* global_use = "";
23264         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23265         static const GLchar* fs                 = "#version 430 core\n"
23266                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23267                                                           "\n"
23268                                                           "in  vec4 gs_fs;\n"
23269                                                           "out vec4 fs_out;\n"
23270                                                           "\n"
23271                                                           "void main()\n"
23272                                                           "{\n"
23273                                                           "    fs_out = gs_fs;\n"
23274                                                           "}\n"
23275                                                           "\n";
23276         static const GLchar* gs_tested = "#version 430 core\n"
23277                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23278                                                                          "\n"
23279                                                                          "layout(points)                           in;\n"
23280                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23281                                                                          "\n"
23282                                                                          "VAR_DEFINITION"
23283                                                                          "\n"
23284                                                                          "in  vec4 tes_gs[];\n"
23285                                                                          "out vec4 gs_fs;\n"
23286                                                                          "\n"
23287                                                                          "void main()\n"
23288                                                                          "{\n"
23289                                                                          "    vec4 result = tes_gs[0];\n"
23290                                                                          "\n"
23291                                                                          "VARIABLE_USE"
23292                                                                          "\n"
23293                                                                          "    gs_fs = result;\n"
23294                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23295                                                                          "    EmitVertex();\n"
23296                                                                          "    gs_fs = result;\n"
23297                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23298                                                                          "    EmitVertex();\n"
23299                                                                          "    gs_fs = result;\n"
23300                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23301                                                                          "    EmitVertex();\n"
23302                                                                          "    gs_fs = result;\n"
23303                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23304                                                                          "    EmitVertex();\n"
23305                                                                          "}\n"
23306                                                                          "\n";
23307         static const GLchar* tcs = "#version 430 core\n"
23308                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23309                                                            "\n"
23310                                                            "layout(vertices = 1) out;\n"
23311                                                            "\n"
23312                                                            "in  vec4 vs_tcs[];\n"
23313                                                            "out vec4 tcs_tes[];\n"
23314                                                            "\n"
23315                                                            "void main()\n"
23316                                                            "{\n"
23317                                                            "\n"
23318                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23319                                                            "\n"
23320                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23321                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23322                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23323                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23324                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23325                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23326                                                            "}\n"
23327                                                            "\n";
23328         static const GLchar* tcs_tested = "#version 430 core\n"
23329                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23330                                                                           "\n"
23331                                                                           "layout(vertices = 1) out;\n"
23332                                                                           "\n"
23333                                                                           "VAR_DEFINITION"
23334                                                                           "\n"
23335                                                                           "in  vec4 vs_tcs[];\n"
23336                                                                           "out vec4 tcs_tes[];\n"
23337                                                                           "\n"
23338                                                                           "void main()\n"
23339                                                                           "{\n"
23340                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23341                                                                           "\n"
23342                                                                           "VARIABLE_USE"
23343                                                                           "\n"
23344                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23345                                                                           "\n"
23346                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23347                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23348                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23349                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23350                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23351                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23352                                                                           "}\n"
23353                                                                           "\n";
23354         static const GLchar* tes_tested = "#version 430 core\n"
23355                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23356                                                                           "\n"
23357                                                                           "layout(isolines, point_mode) in;\n"
23358                                                                           "\n"
23359                                                                           "VAR_DEFINITION"
23360                                                                           "\n"
23361                                                                           "in  vec4 tcs_tes[];\n"
23362                                                                           "out vec4 tes_gs;\n"
23363                                                                           "\n"
23364                                                                           "void main()\n"
23365                                                                           "{\n"
23366                                                                           "    vec4 result = tcs_tes[0];\n"
23367                                                                           "\n"
23368                                                                           "VARIABLE_USE"
23369                                                                           "\n"
23370                                                                           "    tes_gs += result;\n"
23371                                                                           "}\n"
23372                                                                           "\n";
23373         static const GLchar* vs = "#version 430 core\n"
23374                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23375                                                           "\n"
23376                                                           "in  vec4 in_vs;\n"
23377                                                           "out vec4 vs_tcs;\n"
23378                                                           "\n"
23379                                                           "void main()\n"
23380                                                           "{\n"
23381                                                           "    vs_tcs = in_vs;\n"
23382                                                           "}\n"
23383                                                           "\n";
23384         static const GLchar* vs_tested = "#version 430 core\n"
23385                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23386                                                                          "\n"
23387                                                                          "VAR_DEFINITION"
23388                                                                          "\n"
23389                                                                          "in  vec4 in_vs;\n"
23390                                                                          "out vec4 vs_tcs;\n"
23391                                                                          "\n"
23392                                                                          "void main()\n"
23393                                                                          "{\n"
23394                                                                          "    vec4 result = in_vs;\n"
23395                                                                          "\n"
23396                                                                          "VARIABLE_USE"
23397                                                                          "\n"
23398                                                                          "    vs_tcs = result;\n"
23399                                                                          "}\n"
23400                                                                          "\n";
23401
23402         std::string source;
23403         testCase&   test_case = m_test_cases[test_case_index];
23404
23405         if (test_case.m_stage == stage)
23406         {
23407                 const GLchar*   array = "";
23408                 GLchar                   buffer[16];
23409                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23410                 const GLchar*   index    = "";
23411                 GLint                    max_n_xfb = 0;
23412                 size_t                   position  = 0;
23413                 size_t                   temp;
23414                 const GLchar*   var_definition = 0;
23415                 const GLchar*   var_use         = 0;
23416
23417                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23418                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23419
23420                 sprintf(buffer, "%d", max_n_xfb);
23421
23422                 switch (test_case.m_case)
23423                 {
23424                 case BLOCK:
23425                         var_definition = block_var_definition;
23426                         var_use            = block_use;
23427                         break;
23428                 case GLOBAL:
23429                         var_definition = global_var_definition;
23430                         var_use            = global_use;
23431                         break;
23432                 case VECTOR:
23433                         var_definition = vector_var_definition;
23434                         var_use            = vector_use;
23435                         break;
23436                 default:
23437                         TCU_FAIL("Invalid enum");
23438                 }
23439
23440                 switch (stage)
23441                 {
23442                 case Utils::Shader::GEOMETRY:
23443                         source = gs_tested;
23444                         array  = "[]";
23445                         index  = "[0]";
23446                         break;
23447                 case Utils::Shader::TESS_CTRL:
23448                         source = tcs_tested;
23449                         array  = "[]";
23450                         index  = "[gl_InvocationID]";
23451                         break;
23452                 case Utils::Shader::TESS_EVAL:
23453                         source = tes_tested;
23454                         array  = "[]";
23455                         index  = "[0]";
23456                         break;
23457                 case Utils::Shader::VERTEX:
23458                         source = vs_tested;
23459                         break;
23460                 default:
23461                         TCU_FAIL("Invalid enum");
23462                 }
23463
23464                 temp = position;
23465                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23466                 position = temp;
23467                 Utils::replaceToken("BUFFER", position, buffer, source);
23468                 if (GLOBAL != test_case.m_case)
23469                 {
23470                         Utils::replaceToken("ARRAY", position, array, source);
23471                 }
23472                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23473
23474                 Utils::replaceAllTokens("INDEX", index, source);
23475         }
23476         else
23477         {
23478                 switch (test_case.m_stage)
23479                 {
23480                 case Utils::Shader::GEOMETRY:
23481                         switch (stage)
23482                         {
23483                         case Utils::Shader::FRAGMENT:
23484                                 source = fs;
23485                                 break;
23486                         case Utils::Shader::VERTEX:
23487                                 source = vs;
23488                                 break;
23489                         default:
23490                                 source = "";
23491                         }
23492                         break;
23493                 case Utils::Shader::TESS_CTRL:
23494                         switch (stage)
23495                         {
23496                         case Utils::Shader::FRAGMENT:
23497                                 source = fs;
23498                                 break;
23499                         case Utils::Shader::VERTEX:
23500                                 source = vs;
23501                                 break;
23502                         default:
23503                                 source = "";
23504                         }
23505                         break;
23506                 case Utils::Shader::TESS_EVAL:
23507                         switch (stage)
23508                         {
23509                         case Utils::Shader::FRAGMENT:
23510                                 source = fs;
23511                                 break;
23512                         case Utils::Shader::TESS_CTRL:
23513                                 source = tcs;
23514                                 break;
23515                         case Utils::Shader::VERTEX:
23516                                 source = vs;
23517                                 break;
23518                         default:
23519                                 source = "";
23520                         }
23521                         break;
23522                 case Utils::Shader::VERTEX:
23523                         switch (stage)
23524                         {
23525                         case Utils::Shader::FRAGMENT:
23526                                 source = fs;
23527                                 break;
23528                         default:
23529                                 source = "";
23530                         }
23531                         break;
23532                 default:
23533                         TCU_FAIL("Invalid enum");
23534                         break;
23535                 }
23536         }
23537
23538         return source;
23539 }
23540
23541 /** Get description of test case
23542  *
23543  * @param test_case_index Index of test case
23544  *
23545  * @return Test case description
23546  **/
23547 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23548 {
23549         std::stringstream stream;
23550         testCase&                 test_case = m_test_cases[test_case_index];
23551
23552         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23553
23554         switch (test_case.m_case)
23555         {
23556         case BLOCK:
23557                 stream << "BLOCK";
23558                 break;
23559         case GLOBAL:
23560                 stream << "GLOBAL";
23561                 break;
23562         case VECTOR:
23563                 stream << "VECTOR";
23564                 break;
23565         default:
23566                 TCU_FAIL("Invalid enum");
23567         }
23568
23569         return stream.str();
23570 }
23571
23572 /** Get number of test cases
23573  *
23574  * @return Number of test cases
23575  **/
23576 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23577 {
23578         return static_cast<GLuint>(m_test_cases.size());
23579 }
23580
23581 /** Selects if "compute" stage is relevant for test
23582  *
23583  * @param ignored
23584  *
23585  * @return false
23586  **/
23587 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23588 {
23589         return false;
23590 }
23591
23592 /** Prepare all test cases
23593  *
23594  **/
23595 void XFBExceedBufferLimitTest::testInit()
23596 {
23597         for (GLuint c = 0; c < CASE_MAX; ++c)
23598         {
23599                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23600                 {
23601                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23602                                 (Utils::Shader::FRAGMENT == stage))
23603                         {
23604                                 continue;
23605                         }
23606
23607                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23608
23609                         m_test_cases.push_back(test_case);
23610                 }
23611         }
23612 }
23613
23614 /** Constructor
23615  *
23616  * @param context Test framework context
23617  **/
23618 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23619         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23620                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23621 {
23622 }
23623
23624 /** Source for given test case and stage
23625  *
23626  * @param test_case_index Index of test case
23627  * @param stage           Shader stage
23628  *
23629  * @return Shader source
23630  **/
23631 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23632 {
23633         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23634                                                                                                 "\n"
23635                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23636                                                                                                 "    vec4 member;\n"
23637                                                                                                 "} gokuARRAY;\n";
23638         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23639                                                                                                  "\n"
23640                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23641         static const GLchar* vector_var_definition =
23642                 "const uint max_size = SIZE;\n"
23643                 "\n"
23644                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23645         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23646         static const GLchar* global_use = "";
23647         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23648         static const GLchar* fs                 = "#version 430 core\n"
23649                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23650                                                           "\n"
23651                                                           "in  vec4 gs_fs;\n"
23652                                                           "out vec4 fs_out;\n"
23653                                                           "\n"
23654                                                           "void main()\n"
23655                                                           "{\n"
23656                                                           "    fs_out = gs_fs;\n"
23657                                                           "}\n"
23658                                                           "\n";
23659         static const GLchar* gs_tested = "#version 430 core\n"
23660                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23661                                                                          "\n"
23662                                                                          "layout(points)                           in;\n"
23663                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23664                                                                          "\n"
23665                                                                          "VAR_DEFINITION"
23666                                                                          "\n"
23667                                                                          "in  vec4 tes_gs[];\n"
23668                                                                          "out vec4 gs_fs;\n"
23669                                                                          "\n"
23670                                                                          "void main()\n"
23671                                                                          "{\n"
23672                                                                          "    vec4 result = tes_gs[0];\n"
23673                                                                          "\n"
23674                                                                          "VARIABLE_USE"
23675                                                                          "\n"
23676                                                                          "    gs_fs = result;\n"
23677                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23678                                                                          "    EmitVertex();\n"
23679                                                                          "    gs_fs = result;\n"
23680                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23681                                                                          "    EmitVertex();\n"
23682                                                                          "    gs_fs = result;\n"
23683                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23684                                                                          "    EmitVertex();\n"
23685                                                                          "    gs_fs = result;\n"
23686                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23687                                                                          "    EmitVertex();\n"
23688                                                                          "}\n"
23689                                                                          "\n";
23690         static const GLchar* tcs = "#version 430 core\n"
23691                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23692                                                            "\n"
23693                                                            "layout(vertices = 1) out;\n"
23694                                                            "\n"
23695                                                            "in  vec4 vs_tcs[];\n"
23696                                                            "out vec4 tcs_tes[];\n"
23697                                                            "\n"
23698                                                            "void main()\n"
23699                                                            "{\n"
23700                                                            "\n"
23701                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23702                                                            "\n"
23703                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23704                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23705                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23706                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23707                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23708                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23709                                                            "}\n"
23710                                                            "\n";
23711         static const GLchar* tcs_tested = "#version 430 core\n"
23712                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23713                                                                           "\n"
23714                                                                           "layout(vertices = 1) out;\n"
23715                                                                           "\n"
23716                                                                           "VAR_DEFINITION"
23717                                                                           "\n"
23718                                                                           "in  vec4 vs_tcs[];\n"
23719                                                                           "out vec4 tcs_tes[];\n"
23720                                                                           "\n"
23721                                                                           "void main()\n"
23722                                                                           "{\n"
23723                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23724                                                                           "\n"
23725                                                                           "VARIABLE_USE"
23726                                                                           "\n"
23727                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23728                                                                           "\n"
23729                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23730                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23731                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23732                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23733                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23734                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23735                                                                           "}\n"
23736                                                                           "\n";
23737         static const GLchar* tes_tested = "#version 430 core\n"
23738                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23739                                                                           "\n"
23740                                                                           "layout(isolines, point_mode) in;\n"
23741                                                                           "\n"
23742                                                                           "VAR_DEFINITION"
23743                                                                           "\n"
23744                                                                           "in  vec4 tcs_tes[];\n"
23745                                                                           "out vec4 tes_gs;\n"
23746                                                                           "\n"
23747                                                                           "void main()\n"
23748                                                                           "{\n"
23749                                                                           "    vec4 result = tcs_tes[0];\n"
23750                                                                           "\n"
23751                                                                           "VARIABLE_USE"
23752                                                                           "\n"
23753                                                                           "    tes_gs += result;\n"
23754                                                                           "}\n"
23755                                                                           "\n";
23756         static const GLchar* vs = "#version 430 core\n"
23757                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23758                                                           "\n"
23759                                                           "in  vec4 in_vs;\n"
23760                                                           "out vec4 vs_tcs;\n"
23761                                                           "\n"
23762                                                           "void main()\n"
23763                                                           "{\n"
23764                                                           "    vs_tcs = in_vs;\n"
23765                                                           "}\n"
23766                                                           "\n";
23767         static const GLchar* vs_tested = "#version 430 core\n"
23768                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23769                                                                          "\n"
23770                                                                          "VAR_DEFINITION"
23771                                                                          "\n"
23772                                                                          "in  vec4 in_vs;\n"
23773                                                                          "out vec4 vs_tcs;\n"
23774                                                                          "\n"
23775                                                                          "void main()\n"
23776                                                                          "{\n"
23777                                                                          "    vec4 result = in_vs;\n"
23778                                                                          "\n"
23779                                                                          "VARIABLE_USE"
23780                                                                          "\n"
23781                                                                          "    vs_tcs = result;\n"
23782                                                                          "}\n"
23783                                                                          "\n";
23784
23785         std::string source;
23786         testCase&   test_case = m_test_cases[test_case_index];
23787
23788         if (test_case.m_stage == stage)
23789         {
23790                 const GLchar*   array = "";
23791                 GLchar                   buffer[16];
23792                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23793                 const GLchar*   index                    = "";
23794                 GLint                    max_n_xfb_comp  = 0;
23795                 GLint                    max_n_xfb_bytes = 0;
23796                 size_t                   position                = 0;
23797                 size_t                   temp;
23798                 const GLchar*   var_definition = 0;
23799                 const GLchar*   var_use         = 0;
23800
23801                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23802                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23803
23804                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23805
23806                 sprintf(buffer, "%d", max_n_xfb_bytes);
23807
23808                 switch (test_case.m_case)
23809                 {
23810                 case BLOCK:
23811                         var_definition = block_var_definition;
23812                         var_use            = block_use;
23813                         break;
23814                 case GLOBAL:
23815                         var_definition = global_var_definition;
23816                         var_use            = global_use;
23817                         break;
23818                 case VECTOR:
23819                         var_definition = vector_var_definition;
23820                         var_use            = vector_use;
23821                         break;
23822                 default:
23823                         TCU_FAIL("Invalid enum");
23824                 }
23825                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23826                 // change array = "[]" to "[1]"
23827                 switch (stage)
23828                 {
23829                 case Utils::Shader::GEOMETRY:
23830                         source = gs_tested;
23831                         array  = "[1]";
23832                         index  = "[0]";
23833                         break;
23834                 case Utils::Shader::TESS_CTRL:
23835                         source = tcs_tested;
23836                         array  = "[1]";
23837                         index  = "[gl_InvocationID]";
23838                         break;
23839                 case Utils::Shader::TESS_EVAL:
23840                         source = tes_tested;
23841                         array  = "[1]";
23842                         index  = "[0]";
23843                         break;
23844                 case Utils::Shader::VERTEX:
23845                         source = vs_tested;
23846                         break;
23847                 default:
23848                         TCU_FAIL("Invalid enum");
23849                 }
23850
23851                 temp = position;
23852                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23853                 position = temp;
23854                 Utils::replaceToken("SIZE", position, buffer, source);
23855                 if (GLOBAL != test_case.m_case)
23856                 {
23857                         Utils::replaceToken("ARRAY", position, array, source);
23858                 }
23859                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23860
23861                 Utils::replaceAllTokens("INDEX", index, source);
23862         }
23863         else
23864         {
23865                 switch (test_case.m_stage)
23866                 {
23867                 case Utils::Shader::GEOMETRY:
23868                         switch (stage)
23869                         {
23870                         case Utils::Shader::FRAGMENT:
23871                                 source = fs;
23872                                 break;
23873                         case Utils::Shader::VERTEX:
23874                                 source = vs;
23875                                 break;
23876                         default:
23877                                 source = "";
23878                         }
23879                         break;
23880                 case Utils::Shader::TESS_CTRL:
23881                         switch (stage)
23882                         {
23883                         case Utils::Shader::FRAGMENT:
23884                                 source = fs;
23885                                 break;
23886                         case Utils::Shader::VERTEX:
23887                                 source = vs;
23888                                 break;
23889                         default:
23890                                 source = "";
23891                         }
23892                         break;
23893                 case Utils::Shader::TESS_EVAL:
23894                         switch (stage)
23895                         {
23896                         case Utils::Shader::FRAGMENT:
23897                                 source = fs;
23898                                 break;
23899                         case Utils::Shader::TESS_CTRL:
23900                                 source = tcs;
23901                                 break;
23902                         case Utils::Shader::VERTEX:
23903                                 source = vs;
23904                                 break;
23905                         default:
23906                                 source = "";
23907                         }
23908                         break;
23909                 case Utils::Shader::VERTEX:
23910                         switch (stage)
23911                         {
23912                         case Utils::Shader::FRAGMENT:
23913                                 source = fs;
23914                                 break;
23915                         default:
23916                                 source = "";
23917                         }
23918                         break;
23919                 default:
23920                         TCU_FAIL("Invalid enum");
23921                         break;
23922                 }
23923         }
23924
23925         return source;
23926 }
23927
23928 /** Get description of test case
23929  *
23930  * @param test_case_index Index of test case
23931  *
23932  * @return Test case description
23933  **/
23934 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
23935 {
23936         std::stringstream stream;
23937         testCase&                 test_case = m_test_cases[test_case_index];
23938
23939         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23940
23941         switch (test_case.m_case)
23942         {
23943         case BLOCK:
23944                 stream << "BLOCK";
23945                 break;
23946         case GLOBAL:
23947                 stream << "GLOBAL";
23948                 break;
23949         case VECTOR:
23950                 stream << "VECTOR";
23951                 break;
23952         default:
23953                 TCU_FAIL("Invalid enum");
23954         }
23955
23956         return stream.str();
23957 }
23958
23959 /** Get number of test cases
23960  *
23961  * @return Number of test cases
23962  **/
23963 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
23964 {
23965         return static_cast<GLuint>(m_test_cases.size());
23966 }
23967
23968 /** Selects if "compute" stage is relevant for test
23969  *
23970  * @param ignored
23971  *
23972  * @return false
23973  **/
23974 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23975 {
23976         return false;
23977 }
23978
23979 /** Prepare all test cases
23980  *
23981  **/
23982 void XFBExceedOffsetLimitTest::testInit()
23983 {
23984         for (GLuint c = 0; c < CASE_MAX; ++c)
23985         {
23986                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23987                 {
23988                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23989                                 (Utils::Shader::FRAGMENT == stage))
23990                         {
23991                                 continue;
23992                         }
23993
23994                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23995
23996                         m_test_cases.push_back(test_case);
23997                 }
23998         }
23999 }
24000
24001 /** Constructor
24002  *
24003  * @param context Test context
24004  **/
24005 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24006         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24007 {
24008         /* Nothing to be done here */
24009 }
24010
24011 /** Get descriptors of buffers necessary for test
24012  *
24013  * @param test_case_index Index of test case
24014  * @param out_descriptors Descriptors of buffers used by test
24015  **/
24016 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24017 {
24018         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24019         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24020
24021         /* Test needs single uniform and two xfbs */
24022         out_descriptors.resize(3);
24023
24024         /* Get references */
24025         bufferDescriptor& uniform = out_descriptors[0];
24026         bufferDescriptor& xfb_1   = out_descriptors[1];
24027         bufferDescriptor& xfb_3   = out_descriptors[2];
24028
24029         /* Index */
24030         uniform.m_index = 0;
24031         xfb_1.m_index   = 1;
24032         xfb_3.m_index   = 3;
24033
24034         /* Target */
24035         uniform.m_target = Utils::Buffer::Uniform;
24036         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24037         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24038
24039         /* Data */
24040         const GLuint                            gen_start   = Utils::s_rand;
24041         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24042         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24043         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24044         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24045         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24046         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24047
24048         Utils::s_rand                                                           = gen_start;
24049         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24050         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24051         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24052         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24053         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24054         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24055
24056         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24057         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24058
24059         /* Uniform data */
24060         uniform.m_initial_data.resize(6 * type_size);
24061         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24062         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24063         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24064         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24065         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24066         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24067
24068         /* XFB data */
24069         xfb_1.m_initial_data.resize(3 * type_size_pck);
24070         xfb_1.m_expected_data.resize(3 * type_size_pck);
24071         xfb_3.m_initial_data.resize(3 * type_size_pck);
24072         xfb_3.m_expected_data.resize(3 * type_size_pck);
24073
24074         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24075         {
24076                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24077                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24078                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24079                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24080         }
24081
24082         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24083         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24084         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24085         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24086         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24087         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24088 }
24089
24090 /** Source for given test case and stage
24091  *
24092  * @param test_case_index Index of test case
24093  * @param stage           Shader stage
24094  *
24095  * @return Shader source
24096  **/
24097 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24098 {
24099         static const GLchar* fs =
24100                 "#version 430 core\n"
24101                 "#extension GL_ARB_enhanced_layouts : require\n"
24102                 "\n"
24103                 "flat in TYPE chichi;\n"
24104                 "flat in TYPE bulma;\n"
24105                 "in Vegeta {\n"
24106                 "    TYPE trunk;\n"
24107                 "    TYPE bra;\n"
24108                 "} vegeta;\n"
24109                 "in Goku {\n"
24110                 "    TYPE gohan;\n"
24111                 "    TYPE goten;\n"
24112                 "} goku;\n"
24113                 "\n"
24114                 "out vec4 fs_out;\n"
24115                 "\n"
24116                 "void main()\n"
24117                 "{\n"
24118                 "    fs_out = vec4(1);\n"
24119                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24120                 "    {\n"
24121                 "        fs_out = vec4(0);\n"
24122                 "    }\n"
24123                 "}\n"
24124                 "\n";
24125
24126         static const GLchar* gs = "#version 430 core\n"
24127                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24128                                                           "\n"
24129                                                           "layout(points)                   in;\n"
24130                                                           "layout(points, max_vertices = 1) out;\n"
24131                                                           "\n"
24132                                                           "INTERFACE"
24133                                                           "\n"
24134                                                           "void main()\n"
24135                                                           "{\n"
24136                                                           "ASSIGNMENTS"
24137                                                           "    EmitVertex();\n"
24138                                                           "}\n"
24139                                                           "\n";
24140
24141         static const GLchar* tcs = "#version 430 core\n"
24142                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24143                                                            "\n"
24144                                                            "layout(vertices = 1) out;\n"
24145                                                            "\n"
24146                                                            "\n"
24147                                                            "void main()\n"
24148                                                            "{\n"
24149                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24150                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24151                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24152                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24153                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24154                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24155                                                            "}\n"
24156                                                            "\n";
24157
24158         static const GLchar* tes = "#version 430 core\n"
24159                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24160                                                            "\n"
24161                                                            "layout(isolines, point_mode) in;\n"
24162                                                            "\n"
24163                                                            "INTERFACE"
24164                                                            "\n"
24165                                                            "void main()\n"
24166                                                            "{\n"
24167                                                            "ASSIGNMENTS"
24168                                                            "}\n"
24169                                                            "\n";
24170
24171         static const GLchar* vs = "#version 430 core\n"
24172                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24173                                                           "\n"
24174                                                           "void main()\n"
24175                                                           "{\n"
24176                                                           "}\n"
24177                                                           "\n";
24178
24179         static const GLchar* vs_tested = "#version 430 core\n"
24180                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24181                                                                          "\n"
24182                                                                          "INTERFACE"
24183                                                                          "\n"
24184                                                                          "void main()\n"
24185                                                                          "{\n"
24186                                                                          "ASSIGNMENTS"
24187                                                                          "}\n"
24188                                                                          "\n";
24189
24190         std::string              source;
24191         const _testCase& test_case = m_test_cases[test_case_index];
24192         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24193
24194         if (test_case.m_stage == stage)
24195         {
24196                 std::string assignments = "    chichi       = uni_chichi;\n"
24197                                                                   "    bulma        = uni_bulma;\n"
24198                                                                   "    vegeta.trunk = uni_trunk;\n"
24199                                                                   "    vegeta.bra   = uni_bra;\n"
24200                                                                   "    goku.gohan   = uni_gohan;\n"
24201                                                                   "    goku.goten   = uni_goten;\n";
24202
24203                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24204                                                                 "\n"
24205                                                                 "const uint type_size = SIZE;\n"
24206                                                                 "\n"
24207                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24208                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24209                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24210                                                                 "    TYPE trunk;\n"
24211                                                                 "    TYPE bra;\n"
24212                                                                 "} vegeta;\n"
24213                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24214                                                                 "    TYPE gohan;\n"
24215                                                                 "    TYPE goten;\n"
24216                                                                 "} goku;\n"
24217                                                                 "\n"
24218                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24219                                                                 "layout(binding = 0, std140) uniform block {\n"
24220                                                                 "    TYPE uni_chichi;\n"
24221                                                                 "    TYPE uni_bulma;\n"
24222                                                                 "    TYPE uni_trunk;\n"
24223                                                                 "    TYPE uni_bra;\n"
24224                                                                 "    TYPE uni_gohan;\n"
24225                                                                 "    TYPE uni_goten;\n"
24226                                                                 "};\n";
24227
24228                 /* Prepare interface string */
24229                 {
24230                         GLchar           buffer[16];
24231                         size_t           position  = 0;
24232                         const GLuint type_size = test_case.m_type.GetSize();
24233
24234                         sprintf(buffer, "%d", type_size);
24235
24236                         Utils::replaceToken("SIZE", position, buffer, interface);
24237                         Utils::replaceAllTokens("TYPE", type_name, interface);
24238                 }
24239
24240                 switch (stage)
24241                 {
24242                 case Utils::Shader::GEOMETRY:
24243                         source = gs;
24244                         break;
24245                 case Utils::Shader::TESS_EVAL:
24246                         source = tes;
24247                         break;
24248                 case Utils::Shader::VERTEX:
24249                         source = vs_tested;
24250                         break;
24251                 default:
24252                         TCU_FAIL("Invalid enum");
24253                 }
24254
24255                 /* Replace tokens */
24256                 {
24257                         size_t position = 0;
24258
24259                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24260                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24261                 }
24262         }
24263         else
24264         {
24265                 switch (test_case.m_stage)
24266                 {
24267                 case Utils::Shader::GEOMETRY:
24268                         switch (stage)
24269                         {
24270                         case Utils::Shader::FRAGMENT:
24271                                 source = fs;
24272                                 Utils::replaceAllTokens("TYPE", type_name, source);
24273                                 break;
24274                         case Utils::Shader::VERTEX:
24275                                 source = vs;
24276                                 break;
24277                         default:
24278                                 source = "";
24279                         }
24280                         break;
24281                 case Utils::Shader::TESS_EVAL:
24282                         switch (stage)
24283                         {
24284                         case Utils::Shader::FRAGMENT:
24285                                 source = fs;
24286                                 Utils::replaceAllTokens("TYPE", type_name, source);
24287                                 break;
24288                         case Utils::Shader::TESS_CTRL:
24289                                 source = tcs;
24290                                 break;
24291                         case Utils::Shader::VERTEX:
24292                                 source = vs;
24293                                 break;
24294                         default:
24295                                 source = "";
24296                         }
24297                         break;
24298                 case Utils::Shader::VERTEX:
24299                         switch (stage)
24300                         {
24301                         case Utils::Shader::FRAGMENT:
24302                                 source = fs;
24303                                 Utils::replaceAllTokens("TYPE", type_name, source);
24304                                 break;
24305                         default:
24306                                 source = "";
24307                         }
24308                         break;
24309                 default:
24310                         TCU_FAIL("Invalid enum");
24311                         break;
24312                 }
24313         }
24314
24315         return source;
24316 }
24317
24318 /** Get name of test case
24319  *
24320  * @param test_case_index Index of test case
24321  *
24322  * @return Name of case
24323  **/
24324 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24325 {
24326         std::string              name;
24327         const _testCase& test_case = m_test_cases[test_case_index];
24328
24329         name = "Tested stage: ";
24330         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24331         name.append(". Tested type: ");
24332         name.append(test_case.m_type.GetGLSLTypeName());
24333
24334         return name;
24335 }
24336
24337 /** Get number of cases
24338  *
24339  * @return Number of test cases
24340  **/
24341 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24342 {
24343         return static_cast<GLuint>(m_test_cases.size());
24344 }
24345
24346 /** Prepare set of test cases
24347  *
24348  **/
24349 void XFBGlobalBufferTest::testInit()
24350 {
24351         GLuint n_types = getTypesNumber();
24352
24353         for (GLuint i = 0; i < n_types; ++i)
24354         {
24355                 const Utils::Type& type = getType(i);
24356                 /*
24357                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24358                  cause a link time error.
24359                  */
24360                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24361                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24362                 {
24363                         continue;
24364                 }
24365                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24366                                                                                  { Utils::Shader::GEOMETRY, type },
24367                                                                                  { Utils::Shader::TESS_EVAL, type } };
24368
24369                 m_test_cases.push_back(test_cases[0]);
24370                 m_test_cases.push_back(test_cases[1]);
24371                 m_test_cases.push_back(test_cases[2]);
24372         }
24373 }
24374
24375 /** Constructor
24376  *
24377  * @param context Test context
24378  **/
24379 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24380         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24381 {
24382         /* Nothing to be done here */
24383 }
24384
24385 /** Execute drawArrays for single vertex
24386  *
24387  * @param test_case_index
24388  *
24389  * @return true
24390  **/
24391 bool XFBStrideTest::executeDrawCall(GLuint test_case_index)
24392 {
24393         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24394         GLenum                   primitive_type = GL_PATCHES;
24395         const testCase&  test_case              = m_test_cases[test_case_index];
24396
24397         if (Utils::Shader::VERTEX == test_case.m_stage)
24398         {
24399                 primitive_type = GL_POINTS;
24400         }
24401
24402         gl.disable(GL_RASTERIZER_DISCARD);
24403         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24404
24405         gl.beginTransformFeedback(GL_POINTS);
24406         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24407
24408         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24409         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24410
24411         gl.endTransformFeedback();
24412         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24413
24414         return true;
24415 }
24416
24417 /** Get descriptors of buffers necessary for test
24418  *
24419  * @param test_case_index Index of test case
24420  * @param out_descriptors Descriptors of buffers used by test
24421  **/
24422 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24423 {
24424         const testCase& test_case = m_test_cases[test_case_index];
24425         const Utils::Type& type          = test_case.m_type;
24426
24427         /* Test needs single uniform and xfb */
24428         out_descriptors.resize(2);
24429
24430         /* Get references */
24431         bufferDescriptor& uniform = out_descriptors[0];
24432         bufferDescriptor& xfb    = out_descriptors[1];
24433
24434         /* Index */
24435         uniform.m_index = 0;
24436         xfb.m_index             = 0;
24437
24438         /* Target */
24439         uniform.m_target = Utils::Buffer::Uniform;
24440         xfb.m_target     = Utils::Buffer::Transform_feedback;
24441
24442         /* Data */
24443         const GLuint                            rand_start   = Utils::s_rand;
24444         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24445
24446         Utils::s_rand                                            = rand_start;
24447         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24448
24449         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24450         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24451         /*
24452          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24453          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24454          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24455          only one valid data should be initialized in xfb.m_expected_data
24456          */
24457         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24458         /* Uniform data */
24459         uniform.m_initial_data.resize(uni_type_size);
24460         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24461
24462         /* XFB data */
24463         xfb.m_initial_data.resize(xfb_data_size);
24464         xfb.m_expected_data.resize(xfb_data_size);
24465
24466         for (GLuint i = 0; i < xfb_data_size; ++i)
24467         {
24468                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24469                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24470         }
24471
24472         if (test_case.m_stage == Utils::Shader::VERTEX)
24473         {
24474                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24475         }
24476         else
24477         {
24478                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24479                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24480         }
24481 }
24482
24483 /** Get body of main function for given shader stage
24484  *
24485  * @param test_case_index  Index of test case
24486  * @param stage            Shader stage
24487  * @param out_assignments  Set to empty
24488  * @param out_calculations Set to empty
24489  **/
24490 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24491                                                                   std::string& out_calculations)
24492 {
24493         const testCase& test_case = m_test_cases[test_case_index];
24494
24495         out_calculations = "";
24496
24497         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24498         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24499                                                           "    if (TYPE(0) == goku)\n"
24500                                                           "    {\n"
24501                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24502                                                           "    }\n";
24503
24504         const GLchar* assignments = "";
24505
24506         if (test_case.m_stage == stage)
24507         {
24508                 switch (stage)
24509                 {
24510                 case Utils::Shader::GEOMETRY:
24511                         assignments = vs_tes_gs;
24512                         break;
24513                 case Utils::Shader::TESS_EVAL:
24514                         assignments = vs_tes_gs;
24515                         break;
24516                 case Utils::Shader::VERTEX:
24517                         assignments = vs_tes_gs;
24518                         break;
24519                 default:
24520                         TCU_FAIL("Invalid enum");
24521                 }
24522         }
24523         else
24524         {
24525                 switch (stage)
24526                 {
24527                 case Utils::Shader::FRAGMENT:
24528                         assignments = fs;
24529                         break;
24530                 case Utils::Shader::GEOMETRY:
24531                 case Utils::Shader::TESS_CTRL:
24532                 case Utils::Shader::TESS_EVAL:
24533                 case Utils::Shader::VERTEX:
24534                         break;
24535                 default:
24536                         TCU_FAIL("Invalid enum");
24537                 }
24538         }
24539
24540         out_assignments = assignments;
24541
24542         if (Utils::Shader::FRAGMENT == stage)
24543         {
24544                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24545         }
24546 }
24547
24548 /** Get interface of shader
24549  *
24550  * @param test_case_index  Index of test case
24551  * @param stage            Shader stage
24552  * @param out_interface    Set to ""
24553  **/
24554 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24555 {
24556         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24557                                                                          "\n"
24558                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24559                                                                          "    TYPE uni_goku;\n"
24560                                                                          "};\n";
24561         static const GLchar* fs = "FLAT in TYPE goku;\n"
24562                                                           "\n"
24563                                                           "out vec4 fs_out;\n";
24564
24565         const testCase& test_case = m_test_cases[test_case_index];
24566         const GLchar*   interface = "";
24567         const GLchar*   flat      = "";
24568
24569         if (test_case.m_stage == stage)
24570         {
24571                 switch (stage)
24572                 {
24573                 case Utils::Shader::GEOMETRY:
24574                         interface = vs_tes_gs;
24575                         break;
24576                 case Utils::Shader::TESS_EVAL:
24577                         interface = vs_tes_gs;
24578                         break;
24579                 case Utils::Shader::VERTEX:
24580                         interface = vs_tes_gs;
24581                         break;
24582                 default:
24583                         TCU_FAIL("Invalid enum");
24584                 }
24585         }
24586         else
24587         {
24588                 switch (stage)
24589                 {
24590                 case Utils::Shader::FRAGMENT:
24591                         interface = fs;
24592                         break;
24593                 case Utils::Shader::GEOMETRY:
24594                 case Utils::Shader::TESS_CTRL:
24595                 case Utils::Shader::TESS_EVAL:
24596                 case Utils::Shader::VERTEX:
24597                         break;
24598                 default:
24599                         TCU_FAIL("Invalid enum");
24600                 }
24601         }
24602
24603         out_interface = interface;
24604
24605         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24606         {
24607                 flat = "flat";
24608         }
24609
24610         Utils::replaceAllTokens("FLAT", flat, out_interface);
24611         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24612 }
24613
24614 /** Get source code of shader
24615  *
24616  * @param test_case_index Index of test case
24617  * @param stage           Shader stage
24618  *
24619  * @return Source
24620  **/
24621 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24622 {
24623         std::string             source;
24624         const testCase& test_case = m_test_cases[test_case_index];
24625
24626         switch (test_case.m_stage)
24627         {
24628         case Utils::Shader::VERTEX:
24629                 switch (stage)
24630                 {
24631                 case Utils::Shader::FRAGMENT:
24632                 case Utils::Shader::VERTEX:
24633                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24634                         break;
24635                 default:
24636                         break;
24637                 }
24638                 break;
24639
24640         case Utils::Shader::TESS_EVAL:
24641                 switch (stage)
24642                 {
24643                 case Utils::Shader::FRAGMENT:
24644                 case Utils::Shader::TESS_CTRL:
24645                 case Utils::Shader::TESS_EVAL:
24646                 case Utils::Shader::VERTEX:
24647                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24648                         break;
24649                 default:
24650                         break;
24651                 }
24652                 break;
24653
24654         case Utils::Shader::GEOMETRY:
24655                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24656                 break;
24657
24658         default:
24659                 TCU_FAIL("Invalid enum");
24660                 break;
24661         }
24662
24663         /* */
24664         return source;
24665 }
24666
24667 /** Get name of test case
24668  *
24669  * @param test_case_index Index of test case
24670  *
24671  * @return Name of tested stage
24672  **/
24673 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24674 {
24675         std::stringstream stream;
24676         const testCase&   test_case = m_test_cases[test_case_index];
24677
24678         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24679                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24680
24681         return stream.str();
24682 }
24683
24684 /** Returns number of test cases
24685  *
24686  * @return TEST_MAX
24687  **/
24688 glw::GLuint XFBStrideTest::getTestCaseNumber()
24689 {
24690         return static_cast<GLuint>(m_test_cases.size());
24691 }
24692
24693 /** Prepare all test cases
24694  *
24695  **/
24696 void XFBStrideTest::testInit()
24697 {
24698         const GLuint n_types = getTypesNumber();
24699
24700         for (GLuint i = 0; i < n_types; ++i)
24701         {
24702                 const Utils::Type& type = getType(i);
24703
24704                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24705                 {
24706                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24707                                 (Utils::Shader::TESS_CTRL == stage))
24708                         {
24709                                 continue;
24710                         }
24711
24712                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24713
24714                         m_test_cases.push_back(test_case);
24715                 }
24716         }
24717 }
24718
24719 /** Constructor
24720  *
24721  * @param context Test framework context
24722  **/
24723 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24724         : NegativeTestBase(
24725                   context, "xfb_block_member_buffer",
24726                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24727 {
24728 }
24729
24730 /** Source for given test case and stage
24731  *
24732  * @param test_case_index Index of test case
24733  * @param stage           Shader stage
24734  *
24735  * @return Shader source
24736  **/
24737 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24738 {
24739         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24740                                                                                   "                            vec4 gohan;\n"
24741                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24742                                                                                   "} gokuARRAY;\n";
24743         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24744                                                                    "    gokuINDEX.goten = result / 4;\n";
24745         static const GLchar* fs = "#version 430 core\n"
24746                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24747                                                           "\n"
24748                                                           "in  vec4 gs_fs;\n"
24749                                                           "out vec4 fs_out;\n"
24750                                                           "\n"
24751                                                           "void main()\n"
24752                                                           "{\n"
24753                                                           "    fs_out = gs_fs;\n"
24754                                                           "}\n"
24755                                                           "\n";
24756         static const GLchar* gs_tested = "#version 430 core\n"
24757                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24758                                                                          "\n"
24759                                                                          "layout(points)                           in;\n"
24760                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24761                                                                          "\n"
24762                                                                          "VAR_DEFINITION"
24763                                                                          "\n"
24764                                                                          "in  vec4 tes_gs[];\n"
24765                                                                          "out vec4 gs_fs;\n"
24766                                                                          "\n"
24767                                                                          "void main()\n"
24768                                                                          "{\n"
24769                                                                          "    vec4 result = tes_gs[0];\n"
24770                                                                          "\n"
24771                                                                          "VARIABLE_USE"
24772                                                                          "\n"
24773                                                                          "    gs_fs = result;\n"
24774                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24775                                                                          "    EmitVertex();\n"
24776                                                                          "    gs_fs = result;\n"
24777                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24778                                                                          "    EmitVertex();\n"
24779                                                                          "    gs_fs = result;\n"
24780                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24781                                                                          "    EmitVertex();\n"
24782                                                                          "    gs_fs = result;\n"
24783                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24784                                                                          "    EmitVertex();\n"
24785                                                                          "}\n"
24786                                                                          "\n";
24787         static const GLchar* tcs = "#version 430 core\n"
24788                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24789                                                            "\n"
24790                                                            "layout(vertices = 1) out;\n"
24791                                                            "\n"
24792                                                            "in  vec4 vs_tcs[];\n"
24793                                                            "out vec4 tcs_tes[];\n"
24794                                                            "\n"
24795                                                            "void main()\n"
24796                                                            "{\n"
24797                                                            "\n"
24798                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24799                                                            "\n"
24800                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24801                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24802                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24803                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24804                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24805                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24806                                                            "}\n"
24807                                                            "\n";
24808         static const GLchar* tcs_tested = "#version 430 core\n"
24809                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24810                                                                           "\n"
24811                                                                           "layout(vertices = 1) out;\n"
24812                                                                           "\n"
24813                                                                           "VAR_DEFINITION"
24814                                                                           "\n"
24815                                                                           "in  vec4 vs_tcs[];\n"
24816                                                                           "out vec4 tcs_tes[];\n"
24817                                                                           "\n"
24818                                                                           "void main()\n"
24819                                                                           "{\n"
24820                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24821                                                                           "\n"
24822                                                                           "VARIABLE_USE"
24823                                                                           "\n"
24824                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24825                                                                           "\n"
24826                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24827                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24828                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24829                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24830                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24831                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24832                                                                           "}\n"
24833                                                                           "\n";
24834         static const GLchar* tes_tested = "#version 430 core\n"
24835                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24836                                                                           "\n"
24837                                                                           "layout(isolines, point_mode) in;\n"
24838                                                                           "\n"
24839                                                                           "VAR_DEFINITION"
24840                                                                           "\n"
24841                                                                           "in  vec4 tcs_tes[];\n"
24842                                                                           "out vec4 tes_gs;\n"
24843                                                                           "\n"
24844                                                                           "void main()\n"
24845                                                                           "{\n"
24846                                                                           "    vec4 result = tcs_tes[0];\n"
24847                                                                           "\n"
24848                                                                           "VARIABLE_USE"
24849                                                                           "\n"
24850                                                                           "    tes_gs += result;\n"
24851                                                                           "}\n"
24852                                                                           "\n";
24853         static const GLchar* vs = "#version 430 core\n"
24854                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24855                                                           "\n"
24856                                                           "in  vec4 in_vs;\n"
24857                                                           "out vec4 vs_tcs;\n"
24858                                                           "\n"
24859                                                           "void main()\n"
24860                                                           "{\n"
24861                                                           "    vs_tcs = in_vs;\n"
24862                                                           "}\n"
24863                                                           "\n";
24864         static const GLchar* vs_tested = "#version 430 core\n"
24865                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24866                                                                          "\n"
24867                                                                          "VAR_DEFINITION"
24868                                                                          "\n"
24869                                                                          "in  vec4 in_vs;\n"
24870                                                                          "out vec4 vs_tcs;\n"
24871                                                                          "\n"
24872                                                                          "void main()\n"
24873                                                                          "{\n"
24874                                                                          "    vec4 result = in_vs;\n"
24875                                                                          "\n"
24876                                                                          "VARIABLE_USE"
24877                                                                          "\n"
24878                                                                          "    vs_tcs = result;\n"
24879                                                                          "}\n"
24880                                                                          "\n";
24881
24882         std::string source;
24883         testCase&   test_case = m_test_cases[test_case_index];
24884
24885         if (test_case.m_stage == stage)
24886         {
24887                 const GLchar* array     = "";
24888                 const GLchar* index     = "";
24889                 size_t            position = 0;
24890
24891                 switch (stage)
24892                 {
24893                 case Utils::Shader::GEOMETRY:
24894                         source = gs_tested;
24895                         array  = "[]";
24896                         index  = "[0]";
24897                         break;
24898                 case Utils::Shader::TESS_CTRL:
24899                         source = tcs_tested;
24900                         array  = "[]";
24901                         index  = "[gl_InvocationID]";
24902                         break;
24903                 case Utils::Shader::TESS_EVAL:
24904                         source = tes_tested;
24905                         array  = "[]";
24906                         index  = "[0]";
24907                         break;
24908                 case Utils::Shader::VERTEX:
24909                         source = vs_tested;
24910                         break;
24911                 default:
24912                         TCU_FAIL("Invalid enum");
24913                 }
24914
24915                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
24916                 position = 0;
24917                 Utils::replaceToken("ARRAY", position, array, source);
24918                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
24919
24920                 Utils::replaceAllTokens("INDEX", index, source);
24921         }
24922         else
24923         {
24924                 switch (test_case.m_stage)
24925                 {
24926                 case Utils::Shader::GEOMETRY:
24927                         switch (stage)
24928                         {
24929                         case Utils::Shader::FRAGMENT:
24930                                 source = fs;
24931                                 break;
24932                         case Utils::Shader::VERTEX:
24933                                 source = vs;
24934                                 break;
24935                         default:
24936                                 source = "";
24937                         }
24938                         break;
24939                 case Utils::Shader::TESS_CTRL:
24940                         switch (stage)
24941                         {
24942                         case Utils::Shader::FRAGMENT:
24943                                 source = fs;
24944                                 break;
24945                         case Utils::Shader::VERTEX:
24946                                 source = vs;
24947                                 break;
24948                         default:
24949                                 source = "";
24950                         }
24951                         break;
24952                 case Utils::Shader::TESS_EVAL:
24953                         switch (stage)
24954                         {
24955                         case Utils::Shader::FRAGMENT:
24956                                 source = fs;
24957                                 break;
24958                         case Utils::Shader::TESS_CTRL:
24959                                 source = tcs;
24960                                 break;
24961                         case Utils::Shader::VERTEX:
24962                                 source = vs;
24963                                 break;
24964                         default:
24965                                 source = "";
24966                         }
24967                         break;
24968                 case Utils::Shader::VERTEX:
24969                         switch (stage)
24970                         {
24971                         case Utils::Shader::FRAGMENT:
24972                                 source = fs;
24973                                 break;
24974                         default:
24975                                 source = "";
24976                         }
24977                         break;
24978                 default:
24979                         TCU_FAIL("Invalid enum");
24980                         break;
24981                 }
24982         }
24983
24984         return source;
24985 }
24986
24987 /** Get description of test case
24988  *
24989  * @param test_case_index Index of test case
24990  *
24991  * @return Test case description
24992  **/
24993 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
24994 {
24995         std::stringstream stream;
24996         testCase&                 test_case = m_test_cases[test_case_index];
24997
24998         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24999
25000         return stream.str();
25001 }
25002
25003 /** Get number of test cases
25004  *
25005  * @return Number of test cases
25006  **/
25007 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25008 {
25009         return static_cast<GLuint>(m_test_cases.size());
25010 }
25011
25012 /** Selects if "compute" stage is relevant for test
25013  *
25014  * @param ignored
25015  *
25016  * @return false
25017  **/
25018 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25019 {
25020         return false;
25021 }
25022
25023 /** Prepare all test cases
25024  *
25025  **/
25026 void XFBBlockMemberBufferTest::testInit()
25027 {
25028         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25029         {
25030                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25031                         (Utils::Shader::FRAGMENT == stage))
25032                 {
25033                         continue;
25034                 }
25035
25036                 testCase test_case = { (Utils::Shader::STAGES)stage };
25037
25038                 m_test_cases.push_back(test_case);
25039         }
25040 }
25041
25042 /** Constructor
25043  *
25044  * @param context Test framework context
25045  **/
25046 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25047         : NegativeTestBase(context, "xfb_output_overlapping",
25048                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25049 {
25050 }
25051
25052 /** Source for given test case and stage
25053  *
25054  * @param test_case_index Index of test case
25055  * @param stage           Shader stage
25056  *
25057  * @return Shader source
25058  **/
25059 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25060 {
25061         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25062                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25063         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25064                                                                    "    gotenINDEX = TYPE(1);\n"
25065                                                                    "    if (vec4(0) == result)\n"
25066                                                                    "    {\n"
25067                                                                    "        gohanINDEX = TYPE(1);\n"
25068                                                                    "        gotenINDEX = TYPE(0);\n"
25069                                                                    "    }\n";
25070         static const GLchar* fs = "#version 430 core\n"
25071                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25072                                                           "\n"
25073                                                           "in  vec4 gs_fs;\n"
25074                                                           "out vec4 fs_out;\n"
25075                                                           "\n"
25076                                                           "void main()\n"
25077                                                           "{\n"
25078                                                           "    fs_out = gs_fs;\n"
25079                                                           "}\n"
25080                                                           "\n";
25081         static const GLchar* gs_tested = "#version 430 core\n"
25082                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25083                                                                          "\n"
25084                                                                          "layout(points)                           in;\n"
25085                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25086                                                                          "\n"
25087                                                                          "VAR_DEFINITION"
25088                                                                          "\n"
25089                                                                          "in  vec4 tes_gs[];\n"
25090                                                                          "out vec4 gs_fs;\n"
25091                                                                          "\n"
25092                                                                          "void main()\n"
25093                                                                          "{\n"
25094                                                                          "    vec4 result = tes_gs[0];\n"
25095                                                                          "\n"
25096                                                                          "VARIABLE_USE"
25097                                                                          "\n"
25098                                                                          "    gs_fs = result;\n"
25099                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25100                                                                          "    EmitVertex();\n"
25101                                                                          "    gs_fs = result;\n"
25102                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25103                                                                          "    EmitVertex();\n"
25104                                                                          "    gs_fs = result;\n"
25105                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25106                                                                          "    EmitVertex();\n"
25107                                                                          "    gs_fs = result;\n"
25108                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25109                                                                          "    EmitVertex();\n"
25110                                                                          "}\n"
25111                                                                          "\n";
25112         static const GLchar* tcs = "#version 430 core\n"
25113                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25114                                                            "\n"
25115                                                            "layout(vertices = 1) out;\n"
25116                                                            "\n"
25117                                                            "in  vec4 vs_tcs[];\n"
25118                                                            "out vec4 tcs_tes[];\n"
25119                                                            "\n"
25120                                                            "void main()\n"
25121                                                            "{\n"
25122                                                            "\n"
25123                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25124                                                            "\n"
25125                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25126                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25127                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25128                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25129                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25130                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25131                                                            "}\n"
25132                                                            "\n";
25133         static const GLchar* tcs_tested = "#version 430 core\n"
25134                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25135                                                                           "\n"
25136                                                                           "layout(vertices = 1) out;\n"
25137                                                                           "\n"
25138                                                                           "VAR_DEFINITION"
25139                                                                           "\n"
25140                                                                           "in  vec4 vs_tcs[];\n"
25141                                                                           "out vec4 tcs_tes[];\n"
25142                                                                           "\n"
25143                                                                           "void main()\n"
25144                                                                           "{\n"
25145                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25146                                                                           "\n"
25147                                                                           "VARIABLE_USE"
25148                                                                           "\n"
25149                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25150                                                                           "\n"
25151                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25152                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25153                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25154                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25155                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25156                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25157                                                                           "}\n"
25158                                                                           "\n";
25159         static const GLchar* tes_tested = "#version 430 core\n"
25160                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25161                                                                           "\n"
25162                                                                           "layout(isolines, point_mode) in;\n"
25163                                                                           "\n"
25164                                                                           "VAR_DEFINITION"
25165                                                                           "\n"
25166                                                                           "in  vec4 tcs_tes[];\n"
25167                                                                           "out vec4 tes_gs;\n"
25168                                                                           "\n"
25169                                                                           "void main()\n"
25170                                                                           "{\n"
25171                                                                           "    vec4 result = tcs_tes[0];\n"
25172                                                                           "\n"
25173                                                                           "VARIABLE_USE"
25174                                                                           "\n"
25175                                                                           "    tes_gs += result;\n"
25176                                                                           "}\n"
25177                                                                           "\n";
25178         static const GLchar* vs = "#version 430 core\n"
25179                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25180                                                           "\n"
25181                                                           "in  vec4 in_vs;\n"
25182                                                           "out vec4 vs_tcs;\n"
25183                                                           "\n"
25184                                                           "void main()\n"
25185                                                           "{\n"
25186                                                           "    vs_tcs = in_vs;\n"
25187                                                           "}\n"
25188                                                           "\n";
25189         static const GLchar* vs_tested = "#version 430 core\n"
25190                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25191                                                                          "\n"
25192                                                                          "VAR_DEFINITION"
25193                                                                          "\n"
25194                                                                          "in  vec4 in_vs;\n"
25195                                                                          "out vec4 vs_tcs;\n"
25196                                                                          "\n"
25197                                                                          "void main()\n"
25198                                                                          "{\n"
25199                                                                          "    vec4 result = in_vs;\n"
25200                                                                          "\n"
25201                                                                          "VARIABLE_USE"
25202                                                                          "\n"
25203                                                                          "    vs_tcs = result;\n"
25204                                                                          "}\n"
25205                                                                          "\n";
25206
25207         std::string source;
25208         testCase&   test_case = m_test_cases[test_case_index];
25209
25210         if (test_case.m_stage == stage)
25211         {
25212                 const GLchar* array = "";
25213                 GLchar            buffer_gohan[16];
25214                 GLchar            buffer_goten[16];
25215                 const GLchar* index                      = "";
25216                 size_t            position               = 0;
25217                 size_t            position_start = 0;
25218                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25219
25220                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25221                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25222
25223                 switch (stage)
25224                 {
25225                 case Utils::Shader::GEOMETRY:
25226                         source = gs_tested;
25227                         array  = "[]";
25228                         index  = "[0]";
25229                         break;
25230                 case Utils::Shader::TESS_CTRL:
25231                         source = tcs_tested;
25232                         array  = "[]";
25233                         index  = "[gl_InvocationID]";
25234                         break;
25235                 case Utils::Shader::TESS_EVAL:
25236                         source = tes_tested;
25237                         array  = "[]";
25238                         index  = "[0]";
25239                         break;
25240                 case Utils::Shader::VERTEX:
25241                         source = vs_tested;
25242                         break;
25243                 default:
25244                         TCU_FAIL("Invalid enum");
25245                 }
25246
25247                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25248                 position = 0;
25249                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25250                 Utils::replaceToken("TYPE", position, type_name, source);
25251                 Utils::replaceToken("ARRAY", position, array, source);
25252                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25253                 Utils::replaceToken("TYPE", position, type_name, source);
25254                 Utils::replaceToken("ARRAY", position, array, source);
25255                 position_start = position;
25256                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25257                 position = position_start;
25258                 Utils::replaceToken("INDEX", position, index, source);
25259                 Utils::replaceToken("TYPE", position, type_name, source);
25260                 Utils::replaceToken("INDEX", position, index, source);
25261                 Utils::replaceToken("TYPE", position, type_name, source);
25262                 Utils::replaceToken("INDEX", position, index, source);
25263                 Utils::replaceToken("TYPE", position, type_name, source);
25264                 Utils::replaceToken("INDEX", position, index, source);
25265                 Utils::replaceToken("TYPE", position, type_name, source);
25266         }
25267         else
25268         {
25269                 switch (test_case.m_stage)
25270                 {
25271                 case Utils::Shader::GEOMETRY:
25272                         switch (stage)
25273                         {
25274                         case Utils::Shader::FRAGMENT:
25275                                 source = fs;
25276                                 break;
25277                         case Utils::Shader::VERTEX:
25278                                 source = vs;
25279                                 break;
25280                         default:
25281                                 source = "";
25282                         }
25283                         break;
25284                 case Utils::Shader::TESS_CTRL:
25285                         switch (stage)
25286                         {
25287                         case Utils::Shader::FRAGMENT:
25288                                 source = fs;
25289                                 break;
25290                         case Utils::Shader::VERTEX:
25291                                 source = vs;
25292                                 break;
25293                         default:
25294                                 source = "";
25295                         }
25296                         break;
25297                 case Utils::Shader::TESS_EVAL:
25298                         switch (stage)
25299                         {
25300                         case Utils::Shader::FRAGMENT:
25301                                 source = fs;
25302                                 break;
25303                         case Utils::Shader::TESS_CTRL:
25304                                 source = tcs;
25305                                 break;
25306                         case Utils::Shader::VERTEX:
25307                                 source = vs;
25308                                 break;
25309                         default:
25310                                 source = "";
25311                         }
25312                         break;
25313                 case Utils::Shader::VERTEX:
25314                         switch (stage)
25315                         {
25316                         case Utils::Shader::FRAGMENT:
25317                                 source = fs;
25318                                 break;
25319                         default:
25320                                 source = "";
25321                         }
25322                         break;
25323                 default:
25324                         TCU_FAIL("Invalid enum");
25325                         break;
25326                 }
25327         }
25328
25329         return source;
25330 }
25331
25332 /** Get description of test case
25333  *
25334  * @param test_case_index Index of test case
25335  *
25336  * @return Test case description
25337  **/
25338 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25339 {
25340         std::stringstream stream;
25341         testCase&                 test_case = m_test_cases[test_case_index];
25342
25343         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25344                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25345                    << test_case.m_offset_goten;
25346
25347         return stream.str();
25348 }
25349
25350 /** Get number of test cases
25351  *
25352  * @return Number of test cases
25353  **/
25354 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25355 {
25356         return static_cast<GLuint>(m_test_cases.size());
25357 }
25358
25359 /** Selects if "compute" stage is relevant for test
25360  *
25361  * @param ignored
25362  *
25363  * @return false
25364  **/
25365 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25366 {
25367         return false;
25368 }
25369
25370 /** Prepare all test cases
25371  *
25372  **/
25373 void XFBOutputOverlappingTest::testInit()
25374 {
25375         const GLuint n_types = getTypesNumber();
25376
25377         for (GLuint i = 0; i < n_types; ++i)
25378         {
25379                 const Utils::Type& type                   = getType(i);
25380                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25381
25382                 /* Skip scalars, not applicable as:
25383                  *
25384                  *     The offset must be a multiple of the size of the first component of the first
25385                  *     qualified variable or block member, or a compile-time error results.
25386                  */
25387                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25388                 {
25389                         continue;
25390                 }
25391
25392                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25393                 {
25394                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25395                                 (Utils::Shader::FRAGMENT == stage))
25396                         {
25397                                 continue;
25398                         }
25399
25400                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25401                                                                    (Utils::Shader::STAGES)stage, type };
25402
25403                         m_test_cases.push_back(test_case);
25404                 }
25405         }
25406 }
25407
25408 /** Constructor
25409  *
25410  * @param context Test framework context
25411  **/
25412 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25413         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25414                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25415 {
25416 }
25417
25418 /** Source for given test case and stage
25419  *
25420  * @param test_case_index Index of test case
25421  * @param stage           Shader stage
25422  *
25423  * @return Shader source
25424  **/
25425 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25426 {
25427         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25428         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25429                                                                    "    if (vec4(0) == result)\n"
25430                                                                    "    {\n"
25431                                                                    "        gohanINDEX = TYPE(1);\n"
25432                                                                    "    }\n";
25433         static const GLchar* fs = "#version 430 core\n"
25434                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25435                                                           "\n"
25436                                                           "in  vec4 gs_fs;\n"
25437                                                           "out vec4 fs_out;\n"
25438                                                           "\n"
25439                                                           "void main()\n"
25440                                                           "{\n"
25441                                                           "    fs_out = gs_fs;\n"
25442                                                           "}\n"
25443                                                           "\n";
25444         static const GLchar* gs_tested = "#version 430 core\n"
25445                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25446                                                                          "\n"
25447                                                                          "layout(points)                           in;\n"
25448                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25449                                                                          "\n"
25450                                                                          "VAR_DEFINITION"
25451                                                                          "\n"
25452                                                                          "in  vec4 tes_gs[];\n"
25453                                                                          "out vec4 gs_fs;\n"
25454                                                                          "\n"
25455                                                                          "void main()\n"
25456                                                                          "{\n"
25457                                                                          "    vec4 result = tes_gs[0];\n"
25458                                                                          "\n"
25459                                                                          "VARIABLE_USE"
25460                                                                          "\n"
25461                                                                          "    gs_fs = result;\n"
25462                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25463                                                                          "    EmitVertex();\n"
25464                                                                          "    gs_fs = result;\n"
25465                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25466                                                                          "    EmitVertex();\n"
25467                                                                          "    gs_fs = result;\n"
25468                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25469                                                                          "    EmitVertex();\n"
25470                                                                          "    gs_fs = result;\n"
25471                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25472                                                                          "    EmitVertex();\n"
25473                                                                          "}\n"
25474                                                                          "\n";
25475         static const GLchar* tcs = "#version 430 core\n"
25476                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25477                                                            "\n"
25478                                                            "layout(vertices = 1) out;\n"
25479                                                            "\n"
25480                                                            "in  vec4 vs_tcs[];\n"
25481                                                            "out vec4 tcs_tes[];\n"
25482                                                            "\n"
25483                                                            "void main()\n"
25484                                                            "{\n"
25485                                                            "\n"
25486                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25487                                                            "\n"
25488                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25489                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25490                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25491                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25492                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25493                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25494                                                            "}\n"
25495                                                            "\n";
25496         static const GLchar* tcs_tested = "#version 430 core\n"
25497                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25498                                                                           "\n"
25499                                                                           "layout(vertices = 1) out;\n"
25500                                                                           "\n"
25501                                                                           "VAR_DEFINITION"
25502                                                                           "\n"
25503                                                                           "in  vec4 vs_tcs[];\n"
25504                                                                           "out vec4 tcs_tes[];\n"
25505                                                                           "\n"
25506                                                                           "void main()\n"
25507                                                                           "{\n"
25508                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25509                                                                           "\n"
25510                                                                           "VARIABLE_USE"
25511                                                                           "\n"
25512                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25513                                                                           "\n"
25514                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25515                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25516                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25517                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25518                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25519                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25520                                                                           "}\n"
25521                                                                           "\n";
25522         static const GLchar* tes_tested = "#version 430 core\n"
25523                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25524                                                                           "\n"
25525                                                                           "layout(isolines, point_mode) in;\n"
25526                                                                           "\n"
25527                                                                           "VAR_DEFINITION"
25528                                                                           "\n"
25529                                                                           "in  vec4 tcs_tes[];\n"
25530                                                                           "out vec4 tes_gs;\n"
25531                                                                           "\n"
25532                                                                           "void main()\n"
25533                                                                           "{\n"
25534                                                                           "    vec4 result = tcs_tes[0];\n"
25535                                                                           "\n"
25536                                                                           "VARIABLE_USE"
25537                                                                           "\n"
25538                                                                           "    tes_gs += result;\n"
25539                                                                           "}\n"
25540                                                                           "\n";
25541         static const GLchar* vs = "#version 430 core\n"
25542                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25543                                                           "\n"
25544                                                           "in  vec4 in_vs;\n"
25545                                                           "out vec4 vs_tcs;\n"
25546                                                           "\n"
25547                                                           "void main()\n"
25548                                                           "{\n"
25549                                                           "    vs_tcs = in_vs;\n"
25550                                                           "}\n"
25551                                                           "\n";
25552         static const GLchar* vs_tested = "#version 430 core\n"
25553                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25554                                                                          "\n"
25555                                                                          "VAR_DEFINITION"
25556                                                                          "\n"
25557                                                                          "in  vec4 in_vs;\n"
25558                                                                          "out vec4 vs_tcs;\n"
25559                                                                          "\n"
25560                                                                          "void main()\n"
25561                                                                          "{\n"
25562                                                                          "    vec4 result = in_vs;\n"
25563                                                                          "\n"
25564                                                                          "VARIABLE_USE"
25565                                                                          "\n"
25566                                                                          "    vs_tcs = result;\n"
25567                                                                          "}\n"
25568                                                                          "\n";
25569
25570         std::string source;
25571         testCase&   test_case = m_test_cases[test_case_index];
25572
25573         if (test_case.m_stage == stage)
25574         {
25575                 const GLchar* array = "";
25576                 GLchar            buffer[16];
25577                 const GLchar* index                      = "";
25578                 size_t            position               = 0;
25579                 size_t            position_start = 0;
25580                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25581
25582                 sprintf(buffer, "%d", test_case.m_offset);
25583
25584                 switch (stage)
25585                 {
25586                 case Utils::Shader::GEOMETRY:
25587                         source = gs_tested;
25588                         array  = "[]";
25589                         index  = "[0]";
25590                         break;
25591                 case Utils::Shader::TESS_CTRL:
25592                         source = tcs_tested;
25593                         array  = "[]";
25594                         index  = "[gl_InvocationID]";
25595                         break;
25596                 case Utils::Shader::TESS_EVAL:
25597                         source = tes_tested;
25598                         array  = "[]";
25599                         index  = "[0]";
25600                         break;
25601                 case Utils::Shader::VERTEX:
25602                         source = vs_tested;
25603                         break;
25604                 default:
25605                         TCU_FAIL("Invalid enum");
25606                 }
25607
25608                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25609                 position = 0;
25610                 Utils::replaceToken("OFFSET", position, buffer, source);
25611                 Utils::replaceToken("TYPE", position, type_name, source);
25612                 Utils::replaceToken("ARRAY", position, array, source);
25613                 position_start = position;
25614                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25615                 position = position_start;
25616                 Utils::replaceToken("INDEX", position, index, source);
25617                 Utils::replaceToken("TYPE", position, type_name, source);
25618                 Utils::replaceToken("INDEX", position, index, source);
25619                 Utils::replaceToken("TYPE", position, type_name, source);
25620         }
25621         else
25622         {
25623                 switch (test_case.m_stage)
25624                 {
25625                 case Utils::Shader::GEOMETRY:
25626                         switch (stage)
25627                         {
25628                         case Utils::Shader::FRAGMENT:
25629                                 source = fs;
25630                                 break;
25631                         case Utils::Shader::VERTEX:
25632                                 source = vs;
25633                                 break;
25634                         default:
25635                                 source = "";
25636                         }
25637                         break;
25638                 case Utils::Shader::TESS_CTRL:
25639                         switch (stage)
25640                         {
25641                         case Utils::Shader::FRAGMENT:
25642                                 source = fs;
25643                                 break;
25644                         case Utils::Shader::VERTEX:
25645                                 source = vs;
25646                                 break;
25647                         default:
25648                                 source = "";
25649                         }
25650                         break;
25651                 case Utils::Shader::TESS_EVAL:
25652                         switch (stage)
25653                         {
25654                         case Utils::Shader::FRAGMENT:
25655                                 source = fs;
25656                                 break;
25657                         case Utils::Shader::TESS_CTRL:
25658                                 source = tcs;
25659                                 break;
25660                         case Utils::Shader::VERTEX:
25661                                 source = vs;
25662                                 break;
25663                         default:
25664                                 source = "";
25665                         }
25666                         break;
25667                 case Utils::Shader::VERTEX:
25668                         switch (stage)
25669                         {
25670                         case Utils::Shader::FRAGMENT:
25671                                 source = fs;
25672                                 break;
25673                         default:
25674                                 source = "";
25675                         }
25676                         break;
25677                 default:
25678                         TCU_FAIL("Invalid enum");
25679                         break;
25680                 }
25681         }
25682
25683         return source;
25684 }
25685
25686 /** Get description of test case
25687  *
25688  * @param test_case_index Index of test case
25689  *
25690  * @return Test case description
25691  **/
25692 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25693 {
25694         std::stringstream stream;
25695         testCase&                 test_case = m_test_cases[test_case_index];
25696
25697         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25698                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25699
25700         return stream.str();
25701 }
25702
25703 /** Get number of test cases
25704  *
25705  * @return Number of test cases
25706  **/
25707 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25708 {
25709         return static_cast<GLuint>(m_test_cases.size());
25710 }
25711
25712 /** Selects if "compute" stage is relevant for test
25713  *
25714  * @param ignored
25715  *
25716  * @return false
25717  **/
25718 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25719 {
25720         return false;
25721 }
25722
25723 /** Prepare all test cases
25724  *
25725  **/
25726 void XFBInvalidOffsetAlignmentTest::testInit()
25727 {
25728         const GLuint n_types = getTypesNumber();
25729
25730         for (GLuint i = 0; i < n_types; ++i)
25731         {
25732                 const Utils::Type& type                   = getType(i);
25733                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25734
25735                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25736                 {
25737                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25738                                 (Utils::Shader::FRAGMENT == stage))
25739                         {
25740                                 continue;
25741                         }
25742
25743                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25744                         {
25745                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25746
25747                                 m_test_cases.push_back(test_case);
25748                         }
25749                 }
25750         }
25751 }
25752
25753 /** Constructor
25754  *
25755  * @param context Test context
25756  **/
25757 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25758         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25759                                          "Test verifies that inactive variables are captured")
25760 {
25761         /* Nothing to be done here */
25762 }
25763
25764 /** Execute drawArrays for single vertex
25765  *
25766  * @param test_case_index
25767  *
25768  * @return true
25769  **/
25770 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(GLuint test_case_index)
25771 {
25772         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25773         GLenum                   primitive_type = GL_PATCHES;
25774
25775         if (TEST_VS == test_case_index)
25776         {
25777                 primitive_type = GL_POINTS;
25778         }
25779
25780         gl.disable(GL_RASTERIZER_DISCARD);
25781         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25782
25783         gl.beginTransformFeedback(GL_POINTS);
25784         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25785
25786         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25787         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25788
25789         gl.endTransformFeedback();
25790         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25791
25792         return true;
25793 }
25794
25795 /** Get descriptors of buffers necessary for test
25796  *
25797  * @param ignored
25798  * @param out_descriptors Descriptors of buffers used by test
25799  **/
25800 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25801                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25802 {
25803         const Utils::Type& type = Utils::Type::vec4;
25804
25805         /* Test needs single uniform and xfb */
25806         out_descriptors.resize(2);
25807
25808         /* Get references */
25809         bufferDescriptor& uniform = out_descriptors[0];
25810         bufferDescriptor& xfb    = out_descriptors[1];
25811
25812         /* Index */
25813         uniform.m_index = 0;
25814         xfb.m_index             = 0;
25815
25816         /* Target */
25817         uniform.m_target = Utils::Buffer::Uniform;
25818         xfb.m_target     = Utils::Buffer::Transform_feedback;
25819
25820         /* Data */
25821         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25822         const std::vector<GLubyte>& goten_data = type.GenerateData();
25823
25824         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25825
25826         /* Uniform data */
25827         uniform.m_initial_data.resize(2 * type_size);
25828         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25829         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25830
25831         /* XFB data */
25832         xfb.m_initial_data.resize(3 * type_size);
25833         xfb.m_expected_data.resize(3 * type_size);
25834
25835         for (GLuint i = 0; i < 3 * type_size; ++i)
25836         {
25837                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25838                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25839         }
25840
25841         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25842         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25843 }
25844
25845 /** Get body of main function for given shader stage
25846  *
25847  * @param test_case_index  Index of test case
25848  * @param stage            Shader stage
25849  * @param out_assignments  Set to empty
25850  * @param out_calculations Set to empty
25851  **/
25852 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25853                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25854 {
25855         out_calculations = "";
25856
25857         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25858                                                                          "    gohan = uni_gohan;\n";
25859         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25860
25861         const GLchar* assignments = "";
25862
25863         switch (stage)
25864         {
25865         case Utils::Shader::FRAGMENT:
25866                 assignments = fs;
25867                 break;
25868
25869         case Utils::Shader::GEOMETRY:
25870                 if (TEST_GS == test_case_index)
25871                 {
25872                         assignments = vs_tes_gs;
25873                 }
25874                 break;
25875
25876         case Utils::Shader::TESS_CTRL:
25877                 break;
25878
25879         case Utils::Shader::TESS_EVAL:
25880                 if (TEST_TES == test_case_index)
25881                 {
25882                         assignments = vs_tes_gs;
25883                 }
25884                 break;
25885
25886         case Utils::Shader::VERTEX:
25887                 if (TEST_VS == test_case_index)
25888                 {
25889                         assignments = vs_tes_gs;
25890                 }
25891                 break;
25892
25893         default:
25894                 TCU_FAIL("Invalid enum");
25895         }
25896
25897         out_assignments = assignments;
25898 }
25899
25900 /** Get interface of shader
25901  *
25902  * @param test_case_index  Index of test case
25903  * @param stage            Shader stage
25904  * @param out_interface    Set to ""
25905  **/
25906 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
25907                                                                                                                           std::string& out_interface)
25908 {
25909         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
25910                                                                          "\n"
25911                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
25912                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
25913                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
25914                                                                          "\n"
25915                                                                          "layout(binding = 0) uniform block {\n"
25916                                                                          "    vec4 uni_gohan;\n"
25917                                                                          "    vec4 uni_goten;\n"
25918                                                                          "};\n";
25919         static const GLchar* fs = "in vec4 goku;\n"
25920                                                           "in vec4 gohan;\n"
25921                                                           "in vec4 goten;\n"
25922                                                           "out vec4 fs_out;\n";
25923
25924         const GLchar* interface = "";
25925
25926         switch (stage)
25927         {
25928         case Utils::Shader::FRAGMENT:
25929                 interface = fs;
25930                 break;
25931
25932         case Utils::Shader::GEOMETRY:
25933                 if (TEST_GS == test_case_index)
25934                 {
25935                         interface = vs_tes_gs;
25936                 }
25937                 break;
25938
25939         case Utils::Shader::TESS_CTRL:
25940                 break;
25941
25942         case Utils::Shader::TESS_EVAL:
25943                 if (TEST_TES == test_case_index)
25944                 {
25945                         interface = vs_tes_gs;
25946                 }
25947                 break;
25948
25949         case Utils::Shader::VERTEX:
25950                 if (TEST_VS == test_case_index)
25951                 {
25952                         interface = vs_tes_gs;
25953                 }
25954                 break;
25955
25956         default:
25957                 TCU_FAIL("Invalid enum");
25958         }
25959
25960         out_interface = interface;
25961 }
25962
25963 /** Get source code of shader
25964  *
25965  * @param test_case_index Index of test case
25966  * @param stage           Shader stage
25967  *
25968  * @return Source
25969  **/
25970 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25971 {
25972         std::string source;
25973
25974         switch (test_case_index)
25975         {
25976         case TEST_VS:
25977                 switch (stage)
25978                 {
25979                 case Utils::Shader::FRAGMENT:
25980                 case Utils::Shader::VERTEX:
25981                         source = BufferTestBase::getShaderSource(test_case_index, stage);
25982                         break;
25983                 default:
25984                         break;
25985                 }
25986                 break;
25987
25988         case TEST_TES:
25989                 switch (stage)
25990                 {
25991                 case Utils::Shader::FRAGMENT:
25992                 case Utils::Shader::TESS_CTRL:
25993                 case Utils::Shader::TESS_EVAL:
25994                 case Utils::Shader::VERTEX:
25995                         source = BufferTestBase::getShaderSource(test_case_index, stage);
25996                         break;
25997                 default:
25998                         break;
25999                 }
26000                 break;
26001
26002         case TEST_GS:
26003                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26004                 break;
26005
26006         default:
26007                 TCU_FAIL("Invalid enum");
26008                 break;
26009         }
26010
26011         /* */
26012         return source;
26013 }
26014
26015 /** Get name of test case
26016  *
26017  * @param test_case_index Index of test case
26018  *
26019  * @return Name of tested stage
26020  **/
26021 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26022 {
26023         const GLchar* name = 0;
26024
26025         switch (test_case_index)
26026         {
26027         case TEST_VS:
26028                 name = "vertex";
26029                 break;
26030         case TEST_TES:
26031                 name = "tesselation evaluation";
26032                 break;
26033         case TEST_GS:
26034                 name = "geometry";
26035                 break;
26036         default:
26037                 TCU_FAIL("Invalid enum");
26038         }
26039
26040         return name;
26041 }
26042
26043 /** Returns number of test cases
26044  *
26045  * @return TEST_MAX
26046  **/
26047 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26048 {
26049         return TEST_MAX;
26050 }
26051
26052 /** Inspects program to check if all resources are as expected
26053  *
26054  * @param ignored
26055  * @param program         Program instance
26056  * @param out_stream      Error message
26057  *
26058  * @return true if everything is ok, false otherwise
26059  **/
26060 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26061                                                                                                                   std::stringstream& out_stream)
26062 {
26063         GLint                      stride       = 0;
26064         const Utils::Type& type          = Utils::Type::vec4;
26065         const GLuint       type_size = type.GetSize();
26066
26067         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26068                                                 1 /* buf_size */, &stride);
26069
26070         if ((GLint)(3 * type_size) != stride)
26071         {
26072                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26073
26074                 return false;
26075         }
26076
26077         return true;
26078 }
26079
26080 /** Verify contents of buffers
26081  *
26082  * @param buffers Collection of buffers to be verified
26083  *
26084  * @return true if everything is as expected, false otherwise
26085  **/
26086 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26087 {
26088         bool result = true;
26089
26090         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26091         Utils::Buffer*                  buffer   = pair.m_buffer;
26092         bufferDescriptor*               descriptor = pair.m_descriptor;
26093
26094         /* Get pointer to contents of buffer */
26095         buffer->Bind();
26096         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26097
26098         /* Get pointer to expected data */
26099         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26100
26101         /* Compare */
26102         static const GLuint vec4_size = 16;
26103
26104         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26105         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26106
26107         if ((0 != res_gohan) || (0 != res_goten))
26108         {
26109                 m_context.getTestContext().getLog()
26110                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26111                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26112
26113                 result = false;
26114         }
26115
26116         /* Release buffer mapping */
26117         buffer->UnMap();
26118
26119         return result;
26120 }
26121
26122 /** Constructor
26123  *
26124  * @param context Test context
26125  **/
26126 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26127         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26128                                          "Test verifies that inactive components are not modified")
26129 {
26130         /* Nothing to be done here */
26131 }
26132
26133 /** Execute drawArrays for single vertex
26134  *
26135  * @param test_case_index
26136  *
26137  * @return true
26138  **/
26139 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(GLuint test_case_index)
26140 {
26141         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26142         GLenum                   primitive_type = GL_PATCHES;
26143
26144         if (TEST_VS == test_case_index)
26145         {
26146                 primitive_type = GL_POINTS;
26147         }
26148
26149         gl.disable(GL_RASTERIZER_DISCARD);
26150         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26151
26152         gl.beginTransformFeedback(GL_POINTS);
26153         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26154
26155         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26156         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26157
26158         gl.endTransformFeedback();
26159         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26160
26161         return true;
26162 }
26163
26164 /** Get descriptors of buffers necessary for test
26165  *
26166  * @param ignored
26167  * @param out_descriptors Descriptors of buffers used by test
26168  **/
26169 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26170                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26171 {
26172         const Utils::Type& type = Utils::Type::vec4;
26173
26174         /* Test needs single uniform and xfb */
26175         out_descriptors.resize(2);
26176
26177         /* Get references */
26178         bufferDescriptor& uniform = out_descriptors[0];
26179         bufferDescriptor& xfb    = out_descriptors[1];
26180
26181         /* Index */
26182         uniform.m_index = 0;
26183         xfb.m_index             = 0;
26184
26185         /* Target */
26186         uniform.m_target = Utils::Buffer::Uniform;
26187         xfb.m_target     = Utils::Buffer::Transform_feedback;
26188
26189         /* Data */
26190         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26191         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26192         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26193         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26194         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26195         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26196         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26197         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26198
26199         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26200         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26201
26202         /* Uniform data */
26203         uniform.m_initial_data.resize(8 * type_size);
26204         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26205         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26206         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26207         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26208         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26209         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26210         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26211         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26212
26213         /* XFB data */
26214         xfb.m_initial_data.resize(8 * type_size);
26215         xfb.m_expected_data.resize(8 * type_size);
26216
26217         for (GLuint i = 0; i < 8 * type_size; ++i)
26218         {
26219                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26220                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26221         }
26222
26223         /* goku - x, z - 32 */
26224         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26225         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26226
26227         /* gohan - y, w - 0 */
26228         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26229         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26230
26231         /* goten - x, y - 16 */
26232         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26233         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26234
26235         /* chichi - z, w - 48 */
26236         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26237         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26238
26239         /* vegeta - x - 112 */
26240         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26241
26242         /* trunks - y - 96 */
26243         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26244
26245         /* bra - z - 80 */
26246         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26247
26248         /* bulma - w - 64 */
26249         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26250 }
26251
26252 /** Get body of main function for given shader stage
26253  *
26254  * @param test_case_index  Index of test case
26255  * @param stage            Shader stage
26256  * @param out_assignments  Set to empty
26257  * @param out_calculations Set to empty
26258  **/
26259 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26260                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26261 {
26262         out_calculations = "";
26263
26264         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26265                                                                          "    goku.z    = uni_goku.z   ;\n"
26266                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26267                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26268                                                                          "    goten.x   = uni_goten.x  ;\n"
26269                                                                          "    goten.y   = uni_goten.y  ;\n"
26270                                                                          "    chichi.z  = uni_chichi.z ;\n"
26271                                                                          "    chichi.w  = uni_chichi.w ;\n"
26272                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26273                                                                          "    trunks.y  = uni_trunks.y ;\n"
26274                                                                          "    bra.z     = uni_bra.z    ;\n"
26275                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26276         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26277
26278         const GLchar* assignments = "";
26279
26280         switch (stage)
26281         {
26282         case Utils::Shader::FRAGMENT:
26283                 assignments = fs;
26284                 break;
26285
26286         case Utils::Shader::GEOMETRY:
26287                 if (TEST_GS == test_case_index)
26288                 {
26289                         assignments = vs_tes_gs;
26290                 }
26291                 break;
26292
26293         case Utils::Shader::TESS_CTRL:
26294                 break;
26295
26296         case Utils::Shader::TESS_EVAL:
26297                 if (TEST_TES == test_case_index)
26298                 {
26299                         assignments = vs_tes_gs;
26300                 }
26301                 break;
26302
26303         case Utils::Shader::VERTEX:
26304                 if (TEST_VS == test_case_index)
26305                 {
26306                         assignments = vs_tes_gs;
26307                 }
26308                 break;
26309
26310         default:
26311                 TCU_FAIL("Invalid enum");
26312         }
26313
26314         out_assignments = assignments;
26315 }
26316
26317 /** Get interface of shader
26318  *
26319  * @param test_case_index  Index of test case
26320  * @param stage            Shader stage
26321  * @param out_interface    Set to ""
26322  **/
26323 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26324                                                                                                                            std::string& out_interface)
26325 {
26326         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26327                                                                          "\n"
26328                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26329                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26330                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26331                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26332                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26333                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26334                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26335                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26336                                                                          "\n"
26337                                                                          "layout(binding = 0) uniform block {\n"
26338                                                                          "    vec4 uni_goku;\n"
26339                                                                          "    vec4 uni_gohan;\n"
26340                                                                          "    vec4 uni_goten;\n"
26341                                                                          "    vec4 uni_chichi;\n"
26342                                                                          "    vec4 uni_vegeta;\n"
26343                                                                          "    vec4 uni_trunks;\n"
26344                                                                          "    vec4 uni_bra;\n"
26345                                                                          "    vec4 uni_bulma;\n"
26346                                                                          "};\n";
26347         static const GLchar* fs = "in vec4 vegeta;\n"
26348                                                           "in vec4 trunks;\n"
26349                                                           "in vec4 bra;\n"
26350                                                           "in vec4 bulma;\n"
26351                                                           "in vec4 goku;\n"
26352                                                           "in vec4 gohan;\n"
26353                                                           "in vec4 goten;\n"
26354                                                           "in vec4 chichi;\n"
26355                                                           "\n"
26356                                                           "out vec4 fs_out;\n";
26357
26358         const GLchar* interface = "";
26359
26360         switch (stage)
26361         {
26362         case Utils::Shader::FRAGMENT:
26363                 interface = fs;
26364                 break;
26365
26366         case Utils::Shader::GEOMETRY:
26367                 if (TEST_GS == test_case_index)
26368                 {
26369                         interface = vs_tes_gs;
26370                 }
26371                 break;
26372
26373         case Utils::Shader::TESS_CTRL:
26374                 break;
26375
26376         case Utils::Shader::TESS_EVAL:
26377                 if (TEST_TES == test_case_index)
26378                 {
26379                         interface = vs_tes_gs;
26380                 }
26381                 break;
26382
26383         case Utils::Shader::VERTEX:
26384                 if (TEST_VS == test_case_index)
26385                 {
26386                         interface = vs_tes_gs;
26387                 }
26388                 break;
26389
26390         default:
26391                 TCU_FAIL("Invalid enum");
26392         }
26393
26394         out_interface = interface;
26395 }
26396
26397 /** Get source code of shader
26398  *
26399  * @param test_case_index Index of test case
26400  * @param stage           Shader stage
26401  *
26402  * @return Source
26403  **/
26404 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26405 {
26406         std::string source;
26407
26408         switch (test_case_index)
26409         {
26410         case TEST_VS:
26411                 switch (stage)
26412                 {
26413                 case Utils::Shader::FRAGMENT:
26414                 case Utils::Shader::VERTEX:
26415                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26416                         break;
26417                 default:
26418                         break;
26419                 }
26420                 break;
26421
26422         case TEST_TES:
26423                 switch (stage)
26424                 {
26425                 case Utils::Shader::FRAGMENT:
26426                 case Utils::Shader::TESS_CTRL:
26427                 case Utils::Shader::TESS_EVAL:
26428                 case Utils::Shader::VERTEX:
26429                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26430                         break;
26431                 default:
26432                         break;
26433                 }
26434                 break;
26435
26436         case TEST_GS:
26437                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26438                 break;
26439
26440         default:
26441                 TCU_FAIL("Invalid enum");
26442                 break;
26443         }
26444
26445         /* */
26446         return source;
26447 }
26448
26449 /** Get name of test case
26450  *
26451  * @param test_case_index Index of test case
26452  *
26453  * @return Name of tested stage
26454  **/
26455 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26456 {
26457         const GLchar* name = 0;
26458
26459         switch (test_case_index)
26460         {
26461         case TEST_VS:
26462                 name = "vertex";
26463                 break;
26464         case TEST_TES:
26465                 name = "tesselation evaluation";
26466                 break;
26467         case TEST_GS:
26468                 name = "geometry";
26469                 break;
26470         default:
26471                 TCU_FAIL("Invalid enum");
26472         }
26473
26474         return name;
26475 }
26476
26477 /** Returns number of test cases
26478  *
26479  * @return TEST_MAX
26480  **/
26481 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26482 {
26483         return TEST_MAX;
26484 }
26485
26486 /** Verify contents of buffers
26487  *
26488  * @param buffers Collection of buffers to be verified
26489  *
26490  * @return true if everything is as expected, false otherwise
26491  **/
26492 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26493 {
26494         bool result = true;
26495
26496         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26497         Utils::Buffer*                  buffer   = pair.m_buffer;
26498         bufferDescriptor*               descriptor = pair.m_descriptor;
26499
26500         /* Get pointer to contents of buffer */
26501         buffer->Bind();
26502         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26503
26504         /* Get pointer to expected data */
26505         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26506
26507         /* Compare */
26508         static const GLuint comp_size = 4;
26509         static const GLuint vec4_size = 16;
26510
26511         int res_goku_x =
26512                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26513         int res_goku_z =
26514                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26515
26516         int res_gohan_y =
26517                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26518         int res_gohan_w =
26519                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26520
26521         int res_goten_x =
26522                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26523         int res_goten_y =
26524                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26525
26526         int res_chichi_z =
26527                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26528         int res_chichi_w =
26529                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26530
26531         int res_vegeta_x =
26532                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26533
26534         int res_trunks_y =
26535                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26536
26537         int res_bra_z =
26538                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26539
26540         int res_bulma_w =
26541                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26542
26543         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26544                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26545                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26546         {
26547                 m_context.getTestContext().getLog()
26548                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26549                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26550
26551                 result = false;
26552         }
26553
26554         /* Release buffer mapping */
26555         buffer->UnMap();
26556
26557         return result;
26558 }
26559
26560 /** Constructor
26561  *
26562  * @param context Test context
26563  **/
26564 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26565         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26566                                          "Test verifies that inactive block members are captured")
26567 {
26568         /* Nothing to be done here */
26569 }
26570
26571 /** Execute drawArrays for single vertex
26572  *
26573  * @param test_case_index
26574  *
26575  * @return true
26576  **/
26577 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(GLuint test_case_index)
26578 {
26579         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26580         GLenum                   primitive_type = GL_PATCHES;
26581
26582         if (TEST_VS == test_case_index)
26583         {
26584                 primitive_type = GL_POINTS;
26585         }
26586
26587         gl.disable(GL_RASTERIZER_DISCARD);
26588         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26589
26590         gl.beginTransformFeedback(GL_POINTS);
26591         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26592
26593         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26594         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26595
26596         gl.endTransformFeedback();
26597         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26598
26599         return true;
26600 }
26601
26602 /** Get descriptors of buffers necessary for test
26603  *
26604  * @param ignored
26605  * @param out_descriptors Descriptors of buffers used by test
26606  **/
26607 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26608                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26609 {
26610         const Utils::Type& type = Utils::Type::vec4;
26611
26612         /* Test needs single uniform and xfb */
26613         out_descriptors.resize(2);
26614
26615         /* Get references */
26616         bufferDescriptor& uniform = out_descriptors[0];
26617         bufferDescriptor& xfb    = out_descriptors[1];
26618
26619         /* Index */
26620         uniform.m_index = 0;
26621         xfb.m_index             = 0;
26622
26623         /* Target */
26624         uniform.m_target = Utils::Buffer::Uniform;
26625         xfb.m_target     = Utils::Buffer::Transform_feedback;
26626
26627         /* Data */
26628         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26629         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26630
26631         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26632
26633         /* Uniform data */
26634         uniform.m_initial_data.resize(2 * type_size);
26635         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26636         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26637
26638         /* XFB data */
26639         xfb.m_initial_data.resize(4 * type_size);
26640         xfb.m_expected_data.resize(4 * type_size);
26641
26642         for (GLuint i = 0; i < 4 * type_size; ++i)
26643         {
26644                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26645                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26646         }
26647
26648         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26649         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26650 }
26651
26652 /** Get body of main function for given shader stage
26653  *
26654  * @param test_case_index  Index of test case
26655  * @param stage            Shader stage
26656  * @param out_assignments  Set to empty
26657  * @param out_calculations Set to empty
26658  **/
26659 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26660                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26661 {
26662         out_calculations = "";
26663
26664         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26665                                                                          "    gohan  = uni_gohan;\n";
26666         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26667
26668         const GLchar* assignments = "";
26669
26670         switch (stage)
26671         {
26672         case Utils::Shader::FRAGMENT:
26673                 assignments = fs;
26674                 break;
26675
26676         case Utils::Shader::GEOMETRY:
26677                 if (TEST_GS == test_case_index)
26678                 {
26679                         assignments = vs_tes_gs;
26680                 }
26681                 break;
26682
26683         case Utils::Shader::TESS_CTRL:
26684                 break;
26685
26686         case Utils::Shader::TESS_EVAL:
26687                 if (TEST_TES == test_case_index)
26688                 {
26689                         assignments = vs_tes_gs;
26690                 }
26691                 break;
26692
26693         case Utils::Shader::VERTEX:
26694                 if (TEST_VS == test_case_index)
26695                 {
26696                         assignments = vs_tes_gs;
26697                 }
26698                 break;
26699
26700         default:
26701                 TCU_FAIL("Invalid enum");
26702         }
26703
26704         out_assignments = assignments;
26705 }
26706
26707 /** Get interface of shader
26708  *
26709  * @param test_case_index  Index of test case
26710  * @param stage            Shader stage
26711  * @param out_interface    Set to ""
26712  **/
26713 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26714                                                                                                                                  std::string& out_interface)
26715 {
26716         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26717                                                                          "\n"
26718                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26719                                                                          "    vec4 gohan;\n"
26720                                                                          "    vec4 goten;\n"
26721                                                                          "    vec4 chichi;\n"
26722                                                                          "};\n"
26723                                                                          "\n"
26724                                                                          "layout(binding = 0) uniform block {\n"
26725                                                                          "    vec4 uni_gohan;\n"
26726                                                                          "    vec4 uni_chichi;\n"
26727                                                                          "};\n";
26728         static const GLchar* fs = "in Goku {\n"
26729                                                           "    vec4 gohan;\n"
26730                                                           "    vec4 goten;\n"
26731                                                           "    vec4 chichi;\n"
26732                                                           "};\n"
26733                                                           "out vec4 fs_out;\n";
26734
26735         const GLchar* interface = "";
26736
26737         switch (stage)
26738         {
26739         case Utils::Shader::FRAGMENT:
26740                 interface = fs;
26741                 break;
26742
26743         case Utils::Shader::GEOMETRY:
26744                 if (TEST_GS == test_case_index)
26745                 {
26746                         interface = vs_tes_gs;
26747                 }
26748                 break;
26749
26750         case Utils::Shader::TESS_CTRL:
26751                 break;
26752
26753         case Utils::Shader::TESS_EVAL:
26754                 if (TEST_TES == test_case_index)
26755                 {
26756                         interface = vs_tes_gs;
26757                 }
26758                 break;
26759
26760         case Utils::Shader::VERTEX:
26761                 if (TEST_VS == test_case_index)
26762                 {
26763                         interface = vs_tes_gs;
26764                 }
26765                 break;
26766
26767         default:
26768                 TCU_FAIL("Invalid enum");
26769         }
26770
26771         out_interface = interface;
26772 }
26773
26774 /** Get source code of shader
26775  *
26776  * @param test_case_index Index of test case
26777  * @param stage           Shader stage
26778  *
26779  * @return Source
26780  **/
26781 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26782                                                                                                                                          Utils::Shader::STAGES stage)
26783 {
26784         std::string source;
26785
26786         switch (test_case_index)
26787         {
26788         case TEST_VS:
26789                 switch (stage)
26790                 {
26791                 case Utils::Shader::FRAGMENT:
26792                 case Utils::Shader::VERTEX:
26793                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26794                         break;
26795                 default:
26796                         break;
26797                 }
26798                 break;
26799
26800         case TEST_TES:
26801                 switch (stage)
26802                 {
26803                 case Utils::Shader::FRAGMENT:
26804                 case Utils::Shader::TESS_CTRL:
26805                 case Utils::Shader::TESS_EVAL:
26806                 case Utils::Shader::VERTEX:
26807                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26808                         break;
26809                 default:
26810                         break;
26811                 }
26812                 break;
26813
26814         case TEST_GS:
26815                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26816                 break;
26817
26818         default:
26819                 TCU_FAIL("Invalid enum");
26820                 break;
26821         }
26822
26823         /* */
26824         return source;
26825 }
26826
26827 /** Get name of test case
26828  *
26829  * @param test_case_index Index of test case
26830  *
26831  * @return Name of tested stage
26832  **/
26833 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26834 {
26835         const GLchar* name = 0;
26836
26837         switch (test_case_index)
26838         {
26839         case TEST_VS:
26840                 name = "vertex";
26841                 break;
26842         case TEST_TES:
26843                 name = "tesselation evaluation";
26844                 break;
26845         case TEST_GS:
26846                 name = "geometry";
26847                 break;
26848         default:
26849                 TCU_FAIL("Invalid enum");
26850         }
26851
26852         return name;
26853 }
26854
26855 /** Returns number of test cases
26856  *
26857  * @return TEST_MAX
26858  **/
26859 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26860 {
26861         return TEST_MAX;
26862 }
26863
26864 /** Verify contents of buffers
26865  *
26866  * @param buffers Collection of buffers to be verified
26867  *
26868  * @return true if everything is as expected, false otherwise
26869  **/
26870 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26871 {
26872         bool result = true;
26873
26874         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26875         Utils::Buffer*                  buffer   = pair.m_buffer;
26876         bufferDescriptor*               descriptor = pair.m_descriptor;
26877
26878         /* Get pointer to contents of buffer */
26879         buffer->Bind();
26880         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26881
26882         /* Get pointer to expected data */
26883         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26884
26885         /* Compare */
26886         static const GLuint vec4_size = 16;
26887
26888         int res_before = memcmp(buffer_data, expected_data, vec4_size);
26889         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
26890         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
26891
26892         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
26893         {
26894                 m_context.getTestContext().getLog()
26895                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26896                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26897
26898                 result = false;
26899         }
26900
26901         /* Release buffer mapping */
26902         buffer->UnMap();
26903
26904         return result;
26905 }
26906
26907 /** Constructor
26908  *
26909  * @param context Test context
26910  **/
26911 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
26912         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
26913 {
26914         /* Nothing to be done here */
26915 }
26916
26917 /** Execute drawArrays for single vertex
26918  *
26919  * @param test_case_index
26920  *
26921  * @return true
26922  **/
26923 bool XFBCaptureStructTest::executeDrawCall(GLuint test_case_index)
26924 {
26925         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26926         GLenum                   primitive_type = GL_PATCHES;
26927
26928         if (TEST_VS == test_case_index)
26929         {
26930                 primitive_type = GL_POINTS;
26931         }
26932
26933         gl.disable(GL_RASTERIZER_DISCARD);
26934         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26935
26936         gl.beginTransformFeedback(GL_POINTS);
26937         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26938
26939         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26940         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26941
26942         gl.endTransformFeedback();
26943         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26944
26945         return true;
26946 }
26947
26948 /** Get descriptors of buffers necessary for test
26949  *
26950  * @param ignored
26951  * @param out_descriptors Descriptors of buffers used by test
26952  **/
26953 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26954                                                                                                 bufferDescriptor::Vector& out_descriptors)
26955 {
26956         const Utils::Type& type = Utils::Type::vec4;
26957
26958         /* Test needs single uniform and xfb */
26959         out_descriptors.resize(2);
26960
26961         /* Get references */
26962         bufferDescriptor& uniform = out_descriptors[0];
26963         bufferDescriptor& xfb    = out_descriptors[1];
26964
26965         /* Index */
26966         uniform.m_index = 0;
26967         xfb.m_index             = 0;
26968
26969         /* Target */
26970         uniform.m_target = Utils::Buffer::Uniform;
26971         xfb.m_target     = Utils::Buffer::Transform_feedback;
26972
26973         /* Data */
26974         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26975         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26976
26977         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26978
26979         /* Uniform data */
26980         uniform.m_initial_data.resize(2 * type_size);
26981         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26982         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26983
26984         /* XFB data */
26985         xfb.m_initial_data.resize(4 * type_size);
26986         xfb.m_expected_data.resize(4 * type_size);
26987
26988         for (GLuint i = 0; i < 4 * type_size; ++i)
26989         {
26990                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26991                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26992         }
26993
26994         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26995         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26996 }
26997
26998 /** Get body of main function for given shader stage
26999  *
27000  * @param test_case_index  Index of test case
27001  * @param stage            Shader stage
27002  * @param out_assignments  Set to empty
27003  * @param out_calculations Set to empty
27004  **/
27005 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27006                                                                                  std::string& out_assignments, std::string& out_calculations)
27007 {
27008         out_calculations = "";
27009
27010         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27011                                                                          "    goku.gohan  = uni_gohan;\n";
27012         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27013
27014         const GLchar* assignments = "";
27015
27016         switch (stage)
27017         {
27018         case Utils::Shader::FRAGMENT:
27019                 assignments = fs;
27020                 break;
27021
27022         case Utils::Shader::GEOMETRY:
27023                 if (TEST_GS == test_case_index)
27024                 {
27025                         assignments = vs_tes_gs;
27026                 }
27027                 break;
27028
27029         case Utils::Shader::TESS_CTRL:
27030                 break;
27031
27032         case Utils::Shader::TESS_EVAL:
27033                 if (TEST_TES == test_case_index)
27034                 {
27035                         assignments = vs_tes_gs;
27036                 }
27037                 break;
27038
27039         case Utils::Shader::VERTEX:
27040                 if (TEST_VS == test_case_index)
27041                 {
27042                         assignments = vs_tes_gs;
27043                 }
27044                 break;
27045
27046         default:
27047                 TCU_FAIL("Invalid enum");
27048         }
27049
27050         out_assignments = assignments;
27051 }
27052
27053 /** Get interface of shader
27054  *
27055  * @param test_case_index  Index of test case
27056  * @param stage            Shader stage
27057  * @param out_interface    Set to ""
27058  **/
27059 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27060                                                                                           std::string& out_interface)
27061 {
27062         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27063                                                                          "\n"
27064                                                                          "struct Goku {\n"
27065                                                                          "    vec4 gohan;\n"
27066                                                                          "    vec4 goten;\n"
27067                                                                          "    vec4 chichi;\n"
27068                                                                          "};\n"
27069                                                                          "\n"
27070                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27071                                                                          "\n"
27072                                                                          "layout(binding = 0, std140) uniform block {\n"
27073                                                                          "    vec4 uni_gohan;\n"
27074                                                                          "    vec4 uni_chichi;\n"
27075                                                                          "};\n";
27076         static const GLchar* fs = "struct Goku {\n"
27077                                                           "    vec4 gohan;\n"
27078                                                           "    vec4 goten;\n"
27079                                                           "    vec4 chichi;\n"
27080                                                           "};\n"
27081                                                           "\n"
27082                                                           "in Goku goku;\n"
27083                                                           "\n"
27084                                                           "out vec4 fs_out;\n";
27085
27086         const GLchar* interface = "";
27087
27088         switch (stage)
27089         {
27090         case Utils::Shader::FRAGMENT:
27091                 interface = fs;
27092                 break;
27093
27094         case Utils::Shader::GEOMETRY:
27095                 if (TEST_GS == test_case_index)
27096                 {
27097                         interface = vs_tes_gs;
27098                 }
27099                 break;
27100
27101         case Utils::Shader::TESS_CTRL:
27102                 break;
27103
27104         case Utils::Shader::TESS_EVAL:
27105                 if (TEST_TES == test_case_index)
27106                 {
27107                         interface = vs_tes_gs;
27108                 }
27109                 break;
27110
27111         case Utils::Shader::VERTEX:
27112                 if (TEST_VS == test_case_index)
27113                 {
27114                         interface = vs_tes_gs;
27115                 }
27116                 break;
27117
27118         default:
27119                 TCU_FAIL("Invalid enum");
27120         }
27121
27122         out_interface = interface;
27123 }
27124
27125 /** Get source code of shader
27126  *
27127  * @param test_case_index Index of test case
27128  * @param stage           Shader stage
27129  *
27130  * @return Source
27131  **/
27132 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27133 {
27134         std::string source;
27135
27136         switch (test_case_index)
27137         {
27138         case TEST_VS:
27139                 switch (stage)
27140                 {
27141                 case Utils::Shader::FRAGMENT:
27142                 case Utils::Shader::VERTEX:
27143                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27144                         break;
27145                 default:
27146                         break;
27147                 }
27148                 break;
27149
27150         case TEST_TES:
27151                 switch (stage)
27152                 {
27153                 case Utils::Shader::FRAGMENT:
27154                 case Utils::Shader::TESS_CTRL:
27155                 case Utils::Shader::TESS_EVAL:
27156                 case Utils::Shader::VERTEX:
27157                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27158                         break;
27159                 default:
27160                         break;
27161                 }
27162                 break;
27163
27164         case TEST_GS:
27165                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27166                 break;
27167
27168         default:
27169                 TCU_FAIL("Invalid enum");
27170                 break;
27171         }
27172
27173         /* */
27174         return source;
27175 }
27176
27177 /** Get name of test case
27178  *
27179  * @param test_case_index Index of test case
27180  *
27181  * @return Name of tested stage
27182  **/
27183 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27184 {
27185         const GLchar* name = 0;
27186
27187         switch (test_case_index)
27188         {
27189         case TEST_VS:
27190                 name = "vertex";
27191                 break;
27192         case TEST_TES:
27193                 name = "tesselation evaluation";
27194                 break;
27195         case TEST_GS:
27196                 name = "geometry";
27197                 break;
27198         default:
27199                 TCU_FAIL("Invalid enum");
27200         }
27201
27202         return name;
27203 }
27204
27205 /** Returns number of test cases
27206  *
27207  * @return TEST_MAX
27208  **/
27209 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27210 {
27211         return TEST_MAX;
27212 }
27213
27214 /** Verify contents of buffers
27215  *
27216  * @param buffers Collection of buffers to be verified
27217  *
27218  * @return true if everything is as expected, false otherwise
27219  **/
27220 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27221 {
27222         bool result = true;
27223
27224         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27225         Utils::Buffer*                  buffer   = pair.m_buffer;
27226         bufferDescriptor*               descriptor = pair.m_descriptor;
27227
27228         /* Get pointer to contents of buffer */
27229         buffer->Bind();
27230         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27231
27232         /* Get pointer to expected data */
27233         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27234
27235         /* Compare */
27236         static const GLuint vec4_size = 16;
27237
27238         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27239         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27240         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27241
27242         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27243         {
27244                 m_context.getTestContext().getLog()
27245                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27246                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27247
27248                 result = false;
27249         }
27250
27251         /* Release buffer mapping */
27252         buffer->UnMap();
27253
27254         return result;
27255 }
27256
27257 /** Constructor
27258  *
27259  * @param context Test framework context
27260  **/
27261 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27262         : NegativeTestBase(context, "xfb_capture_unsized_array",
27263                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27264 {
27265 }
27266
27267 /** Source for given test case and stage
27268  *
27269  * @param test_case_index Index of test case
27270  * @param stage           Shader stage
27271  *
27272  * @return Shader source
27273  **/
27274 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27275 {
27276         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27277         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27278         static const GLchar* fs                         = "#version 430 core\n"
27279                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27280                                                           "\n"
27281                                                           "in  vec4 gs_fs;\n"
27282                                                           "out vec4 fs_out;\n"
27283                                                           "\n"
27284                                                           "void main()\n"
27285                                                           "{\n"
27286                                                           "    fs_out = gs_fs;\n"
27287                                                           "}\n"
27288                                                           "\n";
27289         static const GLchar* gs_tested = "#version 430 core\n"
27290                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27291                                                                          "\n"
27292                                                                          "layout(points)                           in;\n"
27293                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27294                                                                          "\n"
27295                                                                          "VAR_DEFINITION"
27296                                                                          "\n"
27297                                                                          "in  vec4 tes_gs[];\n"
27298                                                                          "out vec4 gs_fs;\n"
27299                                                                          "\n"
27300                                                                          "void main()\n"
27301                                                                          "{\n"
27302                                                                          "    vec4 result = tes_gs[0];\n"
27303                                                                          "\n"
27304                                                                          "VARIABLE_USE"
27305                                                                          "\n"
27306                                                                          "    gs_fs = result;\n"
27307                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27308                                                                          "    EmitVertex();\n"
27309                                                                          "    gs_fs = result;\n"
27310                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27311                                                                          "    EmitVertex();\n"
27312                                                                          "    gs_fs = result;\n"
27313                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27314                                                                          "    EmitVertex();\n"
27315                                                                          "    gs_fs = result;\n"
27316                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27317                                                                          "    EmitVertex();\n"
27318                                                                          "}\n"
27319                                                                          "\n";
27320         static const GLchar* tcs = "#version 430 core\n"
27321                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27322                                                            "\n"
27323                                                            "layout(vertices = 1) out;\n"
27324                                                            "\n"
27325                                                            "in  vec4 vs_tcs[];\n"
27326                                                            "out vec4 tcs_tes[];\n"
27327                                                            "\n"
27328                                                            "void main()\n"
27329                                                            "{\n"
27330                                                            "\n"
27331                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27332                                                            "\n"
27333                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27334                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27335                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27336                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27337                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27338                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27339                                                            "}\n"
27340                                                            "\n";
27341         static const GLchar* tcs_tested = "#version 430 core\n"
27342                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27343                                                                           "\n"
27344                                                                           "layout(vertices = 1) out;\n"
27345                                                                           "\n"
27346                                                                           "VAR_DEFINITION"
27347                                                                           "\n"
27348                                                                           "in  vec4 vs_tcs[];\n"
27349                                                                           "out vec4 tcs_tes[];\n"
27350                                                                           "\n"
27351                                                                           "void main()\n"
27352                                                                           "{\n"
27353                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27354                                                                           "\n"
27355                                                                           "VARIABLE_USE"
27356                                                                           "\n"
27357                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27358                                                                           "\n"
27359                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27360                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27361                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27362                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27363                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27364                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27365                                                                           "}\n"
27366                                                                           "\n";
27367         static const GLchar* tes_tested = "#version 430 core\n"
27368                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27369                                                                           "\n"
27370                                                                           "layout(isolines, point_mode) in;\n"
27371                                                                           "\n"
27372                                                                           "VAR_DEFINITION"
27373                                                                           "\n"
27374                                                                           "in  vec4 tcs_tes[];\n"
27375                                                                           "out vec4 tes_gs;\n"
27376                                                                           "\n"
27377                                                                           "void main()\n"
27378                                                                           "{\n"
27379                                                                           "    vec4 result = tcs_tes[0];\n"
27380                                                                           "\n"
27381                                                                           "VARIABLE_USE"
27382                                                                           "\n"
27383                                                                           "    tes_gs += result;\n"
27384                                                                           "}\n"
27385                                                                           "\n";
27386         static const GLchar* vs = "#version 430 core\n"
27387                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27388                                                           "\n"
27389                                                           "in  vec4 in_vs;\n"
27390                                                           "out vec4 vs_tcs;\n"
27391                                                           "\n"
27392                                                           "void main()\n"
27393                                                           "{\n"
27394                                                           "    vs_tcs = in_vs;\n"
27395                                                           "}\n"
27396                                                           "\n";
27397         static const GLchar* vs_tested = "#version 430 core\n"
27398                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27399                                                                          "\n"
27400                                                                          "VAR_DEFINITION"
27401                                                                          "\n"
27402                                                                          "in  vec4 in_vs;\n"
27403                                                                          "out vec4 vs_tcs;\n"
27404                                                                          "\n"
27405                                                                          "void main()\n"
27406                                                                          "{\n"
27407                                                                          "    vec4 result = in_vs;\n"
27408                                                                          "\n"
27409                                                                          "VARIABLE_USE"
27410                                                                          "\n"
27411                                                                          "    vs_tcs = result;\n"
27412                                                                          "}\n"
27413                                                                          "\n";
27414
27415         std::string source;
27416         testCase&   test_case = m_test_cases[test_case_index];
27417
27418         if (test_case.m_stage == stage)
27419         {
27420                 const GLchar* array     = "";
27421                 const GLchar* index     = "";
27422                 size_t            position = 0;
27423
27424                 switch (stage)
27425                 {
27426                 case Utils::Shader::GEOMETRY:
27427                         source = gs_tested;
27428                         array  = "[]";
27429                         index  = "[0]";
27430                         break;
27431                 case Utils::Shader::TESS_CTRL:
27432                         source = tcs_tested;
27433                         array  = "[]";
27434                         index  = "[gl_InvocationID]";
27435                         break;
27436                 case Utils::Shader::TESS_EVAL:
27437                         source = tes_tested;
27438                         array  = "[]";
27439                         index  = "[0]";
27440                         break;
27441                 case Utils::Shader::VERTEX:
27442                         source = vs_tested;
27443                         break;
27444                 default:
27445                         TCU_FAIL("Invalid enum");
27446                 }
27447
27448                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27449                 position = 0;
27450                 Utils::replaceToken("ARRAY", position, array, source);
27451                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27452
27453                 Utils::replaceAllTokens("INDEX", index, source);
27454         }
27455         else
27456         {
27457                 switch (test_case.m_stage)
27458                 {
27459                 case Utils::Shader::GEOMETRY:
27460                         switch (stage)
27461                         {
27462                         case Utils::Shader::FRAGMENT:
27463                                 source = fs;
27464                                 break;
27465                         case Utils::Shader::VERTEX:
27466                                 source = vs;
27467                                 break;
27468                         default:
27469                                 source = "";
27470                         }
27471                         break;
27472                 case Utils::Shader::TESS_CTRL:
27473                         switch (stage)
27474                         {
27475                         case Utils::Shader::FRAGMENT:
27476                                 source = fs;
27477                                 break;
27478                         case Utils::Shader::VERTEX:
27479                                 source = vs;
27480                                 break;
27481                         default:
27482                                 source = "";
27483                         }
27484                         break;
27485                 case Utils::Shader::TESS_EVAL:
27486                         switch (stage)
27487                         {
27488                         case Utils::Shader::FRAGMENT:
27489                                 source = fs;
27490                                 break;
27491                         case Utils::Shader::TESS_CTRL:
27492                                 source = tcs;
27493                                 break;
27494                         case Utils::Shader::VERTEX:
27495                                 source = vs;
27496                                 break;
27497                         default:
27498                                 source = "";
27499                         }
27500                         break;
27501                 case Utils::Shader::VERTEX:
27502                         switch (stage)
27503                         {
27504                         case Utils::Shader::FRAGMENT:
27505                                 source = fs;
27506                                 break;
27507                         default:
27508                                 source = "";
27509                         }
27510                         break;
27511                 default:
27512                         TCU_FAIL("Invalid enum");
27513                         break;
27514                 }
27515         }
27516
27517         return source;
27518 }
27519
27520 /** Get description of test case
27521  *
27522  * @param test_case_index Index of test case
27523  *
27524  * @return Test case description
27525  **/
27526 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27527 {
27528         std::stringstream stream;
27529         testCase&                 test_case = m_test_cases[test_case_index];
27530
27531         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27532
27533         return stream.str();
27534 }
27535
27536 /** Get number of test cases
27537  *
27538  * @return Number of test cases
27539  **/
27540 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27541 {
27542         return static_cast<GLuint>(m_test_cases.size());
27543 }
27544
27545 /** Selects if "compute" stage is relevant for test
27546  *
27547  * @param ignored
27548  *
27549  * @return false
27550  **/
27551 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27552 {
27553         return false;
27554 }
27555
27556 /** Prepare all test cases
27557  *
27558  **/
27559 void XFBCaptureUnsizedArrayTest::testInit()
27560 {
27561         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27562         {
27563                 /* Not aplicable for */
27564                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27565                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27566                 {
27567                         continue;
27568                 }
27569
27570                 testCase test_case = { (Utils::Shader::STAGES)stage };
27571
27572                 m_test_cases.push_back(test_case);
27573         }
27574 }
27575 } /* EnhancedLayouts namespace */
27576
27577 /** Constructor.
27578  *
27579  *  @param context Rendering context.
27580  **/
27581 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27582         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27583 {
27584         /* Left blank on purpose */
27585 }
27586
27587 /** Initializes a texture_storage_multisample test group.
27588  *
27589  **/
27590 void EnhancedLayoutsTests::init(void)
27591 {
27592         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27593         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27594         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27595         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27596         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27597         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27598         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27599         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27600         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27601         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27602         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27603         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27604         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27605         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27606         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27607         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27608         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27609         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27610
27611         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27612         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27613         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27614         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27615         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27616         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27617         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27618         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27619         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27620         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27621         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27622         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27623         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27624         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27625         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27626         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27627         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27628         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27629         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27630         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27631         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27632         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27633         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27634         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27635         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27636         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27637         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27638         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27639         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27640         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27641         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27642         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27643         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27644         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27645         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27646         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27647         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27648         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27649         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27650         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27651         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27652         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27653         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27654         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27655         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27656 }
27657
27658 } /* gl4cts namespace */