Merge vk-gl-cts/aosp-deqp-dev into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cEnhancedLayoutsTests.cpp
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23
24 /**
25  * \file  gl4cEnhancedLayoutsTests.cpp
26  * \brief Implements conformance tests for "Enhanced Layouts" functionality.
27  */ /*-------------------------------------------------------------------*/
28
29 #include "gl4cEnhancedLayoutsTests.hpp"
30
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "gluStrUtil.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuTestLog.hpp"
37
38 #include <algorithm>
39 #include <iomanip>
40 #include <string>
41 #include <vector>
42
43 /* DEBUG */
44 #define USE_NSIGHT 0
45 #define DEBUG_ENBALE_MESSAGE_CALLBACK 0
46 #define DEBUG_NEG_LOG_ERROR 0
47 #define DEBUG_REPLACE_TOKEN 0
48 #define DEBUG_REPEAT_TEST_CASE 0
49 #define DEBUG_REPEATED_TEST_CASE 0
50
51 /* Texture test base */
52 #define DEBUG_TTB_VERIFICATION_SNIPPET_STAGE 0
53 #define DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE 0
54
55 /* Tests */
56 #define DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE 0
57
58 /* WORKAROUNDS */
59 #define WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST 0
60 #define WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST 0
61 #define WRKARD_UNIFORMBLOCKALIGNMENT 0
62 #define WRKARD_VARYINGLOCATIONSTEST 0
63
64 using namespace glw;
65
66 namespace gl4cts
67 {
68 namespace EnhancedLayouts
69 {
70 namespace Utils
71 {
72 /** Constants used by "random" generators **/
73 static const GLuint s_rand_start        = 3;
74 static const GLuint s_rand_max          = 16;
75 static const GLuint s_rand_max_half = s_rand_max / 2;
76
77 /** Seed used by "random" generators **/
78 static GLuint s_rand = s_rand_start;
79
80 /** Get "random" unsigned int value
81  *
82  * @return Value
83  **/
84 static GLuint GetRandUint()
85 {
86         const GLuint rand = s_rand++;
87
88         if (s_rand_max <= s_rand)
89         {
90                 s_rand = s_rand_start;
91         }
92
93         return rand;
94 }
95
96 /** Get "random" int value
97  *
98  * @return Value
99  **/
100 GLint GetRandInt()
101 {
102         const GLint rand = GetRandUint() - s_rand_max_half;
103
104         return rand;
105 }
106
107 /** Get "random" double value
108  *
109  * @return Value
110  **/
111 GLdouble GetRandDouble()
112 {
113         const GLint rand = GetRandInt();
114
115         GLdouble result = (GLfloat)rand / (GLdouble)s_rand_max_half;
116
117         return result;
118 }
119
120 /** Get "random" float value
121  *
122  * @return Value
123  **/
124 GLfloat GetRandFloat()
125 {
126         const GLint rand = GetRandInt();
127
128         GLfloat result = (GLfloat)rand / (GLfloat)s_rand_max_half;
129
130         return result;
131 }
132
133 /** String used by list routines **/
134 static const GLchar* const g_list = "LIST";
135
136 /** Type constants **/
137 const Type Type::_double = Type::GetType(Type::Double, 1, 1);
138 const Type Type::dmat2   = Type::GetType(Type::Double, 2, 2);
139 const Type Type::dmat2x3 = Type::GetType(Type::Double, 2, 3);
140 const Type Type::dmat2x4 = Type::GetType(Type::Double, 2, 4);
141 const Type Type::dmat3x2 = Type::GetType(Type::Double, 3, 2);
142 const Type Type::dmat3   = Type::GetType(Type::Double, 3, 3);
143 const Type Type::dmat3x4 = Type::GetType(Type::Double, 3, 4);
144 const Type Type::dmat4x2 = Type::GetType(Type::Double, 4, 2);
145 const Type Type::dmat4x3 = Type::GetType(Type::Double, 4, 3);
146 const Type Type::dmat4   = Type::GetType(Type::Double, 4, 4);
147 const Type Type::dvec2   = Type::GetType(Type::Double, 1, 2);
148 const Type Type::dvec3   = Type::GetType(Type::Double, 1, 3);
149 const Type Type::dvec4   = Type::GetType(Type::Double, 1, 4);
150 const Type Type::_int   = Type::GetType(Type::Int, 1, 1);
151 const Type Type::ivec2   = Type::GetType(Type::Int, 1, 2);
152 const Type Type::ivec3   = Type::GetType(Type::Int, 1, 3);
153 const Type Type::ivec4   = Type::GetType(Type::Int, 1, 4);
154 const Type Type::_float  = Type::GetType(Type::Float, 1, 1);
155 const Type Type::mat2   = Type::GetType(Type::Float, 2, 2);
156 const Type Type::mat2x3  = Type::GetType(Type::Float, 2, 3);
157 const Type Type::mat2x4  = Type::GetType(Type::Float, 2, 4);
158 const Type Type::mat3x2  = Type::GetType(Type::Float, 3, 2);
159 const Type Type::mat3   = Type::GetType(Type::Float, 3, 3);
160 const Type Type::mat3x4  = Type::GetType(Type::Float, 3, 4);
161 const Type Type::mat4x2  = Type::GetType(Type::Float, 4, 2);
162 const Type Type::mat4x3  = Type::GetType(Type::Float, 4, 3);
163 const Type Type::mat4   = Type::GetType(Type::Float, 4, 4);
164 const Type Type::vec2   = Type::GetType(Type::Float, 1, 2);
165 const Type Type::vec3   = Type::GetType(Type::Float, 1, 3);
166 const Type Type::vec4   = Type::GetType(Type::Float, 1, 4);
167 const Type Type::uint   = Type::GetType(Type::Uint, 1, 1);
168 const Type Type::uvec2   = Type::GetType(Type::Uint, 1, 2);
169 const Type Type::uvec3   = Type::GetType(Type::Uint, 1, 3);
170 const Type Type::uvec4   = Type::GetType(Type::Uint, 1, 4);
171
172 /** Generate data for type. This routine follows STD140 rules
173  *
174  * @return Vector of bytes filled with data
175  **/
176 std::vector<GLubyte> Type::GenerateData() const
177 {
178         const GLuint alignment = GetActualAlignment(0, false);
179
180         std::vector<GLubyte> data;
181         data.resize(alignment * m_n_columns);
182
183         for (GLuint column = 0; column < m_n_columns; ++column)
184         {
185                 GLvoid* ptr = (GLvoid*)&data[column * alignment];
186
187                 switch (m_basic_type)
188                 {
189                 case Double:
190                 {
191                         GLdouble* d_ptr = (GLdouble*)ptr;
192
193                         for (GLuint i = 0; i < m_n_rows; ++i)
194                         {
195                                 d_ptr[i] = GetRandDouble();
196                         }
197                 }
198                 break;
199                 case Float:
200                 {
201                         GLfloat* f_ptr = (GLfloat*)ptr;
202
203                         for (GLuint i = 0; i < m_n_rows; ++i)
204                         {
205                                 f_ptr[i] = GetRandFloat();
206                         }
207                 }
208                 break;
209                 case Int:
210                 {
211                         GLint* i_ptr = (GLint*)ptr;
212
213                         for (GLuint i = 0; i < m_n_rows; ++i)
214                         {
215                                 i_ptr[i] = GetRandInt();
216                         }
217                 }
218                 break;
219                 case Uint:
220                 {
221                         GLuint* ui_ptr = (GLuint*)ptr;
222
223                         for (GLuint i = 0; i < m_n_rows; ++i)
224                         {
225                                 ui_ptr[i] = GetRandUint();
226                         }
227                 }
228                 break;
229                 }
230         }
231
232         return data;
233 }
234
235 /** Generate data for type. This routine packs data tightly.
236  *
237  * @return Vector of bytes filled with data
238  **/
239 std::vector<GLubyte> Type::GenerateDataPacked() const
240 {
241         const GLuint basic_size = GetTypeSize(m_basic_type);
242         const GLuint n_elements = m_n_columns * m_n_rows;
243         const GLuint size               = basic_size * n_elements;
244
245         std::vector<GLubyte> data;
246         data.resize(size);
247
248         GLvoid* ptr = (GLvoid*)&data[0];
249
250         switch (m_basic_type)
251         {
252         case Double:
253         {
254                 GLdouble* d_ptr = (GLdouble*)ptr;
255
256                 for (GLuint i = 0; i < n_elements; ++i)
257                 {
258                         d_ptr[i] = GetRandDouble();
259                 }
260         }
261         break;
262         case Float:
263         {
264                 GLfloat* f_ptr = (GLfloat*)ptr;
265
266                 for (GLuint i = 0; i < n_elements; ++i)
267                 {
268                         f_ptr[i] = GetRandFloat();
269                 }
270         }
271         break;
272         case Int:
273         {
274                 GLint* i_ptr = (GLint*)ptr;
275
276                 for (GLuint i = 0; i < n_elements; ++i)
277                 {
278                         i_ptr[i] = GetRandInt();
279                 }
280         }
281         break;
282         case Uint:
283         {
284                 GLuint* ui_ptr = (GLuint*)ptr;
285
286                 for (GLuint i = 0; i < n_elements; ++i)
287                 {
288                         ui_ptr[i] = GetRandUint();
289                 }
290         }
291         break;
292         }
293
294         return data;
295 }
296
297 /** Calculate "actual alignment". It work under assumption that align value is valid
298  *
299  * @param align    Requested alignment, eg with "align" qualifier
300  * @param is_array Selects if an array of type or single instance should be considered
301  *
302  * @return Calculated value
303  **/
304 GLuint Type::GetActualAlignment(GLuint align, bool is_array) const
305 {
306         const GLuint base_alignment = GetBaseAlignment(is_array);
307
308         return std::max(align, base_alignment);
309 }
310
311 /** Align given ofset with specified alignment
312  *
313  * @param offset    Offset
314  * @param alignment Alignment
315  *
316  * @return Calculated value
317  **/
318 GLuint align(GLuint offset, GLuint alignment)
319 {
320         const GLuint rest = offset % alignment;
321
322         if (0 != rest)
323         {
324                 GLuint missing = alignment - rest;
325                 offset += missing;
326         }
327
328         return offset;
329 }
330
331 /** Calculate "actual offset"
332  *
333  * @param start_offset     Requested offset
334  * @param actual_alignment Actual alignemnt
335  *
336  * @return Calculated value
337  **/
338 GLuint Type::GetActualOffset(GLuint start_offset, GLuint actual_alignment)
339 {
340         GLuint offset = align(start_offset, actual_alignment);
341
342         return offset;
343 }
344
345 /** Calculate "base alignment" for given type
346  *
347  * @param is_array Select if array or single instance should be considered
348  *
349  * @return Calculated value
350  **/
351 GLuint Type::GetBaseAlignment(bool is_array) const
352 {
353         GLuint elements = 1;
354
355         switch (m_n_rows)
356         {
357         case 2:
358                 elements = 2;
359                 break;
360         case 3:
361         case 4:
362                 elements = 4;
363                 break;
364         default:
365                 break;
366         }
367
368         GLuint N                 = GetTypeSize(m_basic_type);
369         GLuint alignment = N * elements;
370
371         if ((true == is_array) || (1 != m_n_columns))
372         {
373                 alignment = align(alignment, 16 /* vec4 alignment */);
374         }
375
376         return alignment;
377 }
378
379 /** Returns string representing GLSL constructor of type with arguments provided in data
380  *
381  * @param data Array of values that will be used as construcotr arguments.
382  *             It is interpreted as tightly packed array of type matching this type.
383  *
384  * @return String in form "Type(args)"
385  **/
386 std::string Type::GetGLSLConstructor(const GLvoid* data) const
387 {
388         const GLchar* type = GetGLSLTypeName();
389
390         std::stringstream stream;
391
392         stream << type << "(";
393
394         /* Scalar or vector */
395         if (1 == m_n_columns)
396         {
397                 for (GLuint row = 0; row < m_n_rows; ++row)
398                 {
399                         switch (m_basic_type)
400                         {
401                         case Double:
402                                 stream << ((GLdouble*)data)[row];
403                                 break;
404                         case Float:
405                                 stream << ((GLfloat*)data)[row];
406                                 break;
407                         case Int:
408                                 stream << ((GLint*)data)[row];
409                                 break;
410                         case Uint:
411                                 stream << ((GLuint*)data)[row];
412                                 break;
413                         }
414
415                         if (row + 1 != m_n_rows)
416                         {
417                                 stream << ", ";
418                         }
419                 }
420         }
421         else /* Matrix: mat(vec(), vec() .. ) */
422         {
423                 const GLuint basic_size = GetTypeSize(m_basic_type);
424                 // Very indescoverable defect, the column stride should be calculated by rows, such as mat2x3, which is 2, columns 3 rows, its column stride should be 3 * sizeof(float)
425                 const GLuint column_stride = m_n_rows * basic_size;
426                 const Type   column_type   = GetType(m_basic_type, 1, m_n_rows);
427
428                 for (GLuint column = 0; column < m_n_columns; ++column)
429                 {
430                         const GLuint  column_offset = column * column_stride;
431                         const GLvoid* column_data   = (GLubyte*)data + column_offset;
432
433                         stream << column_type.GetGLSLConstructor(column_data);
434
435                         if (column + 1 != m_n_columns)
436                         {
437                                 stream << ", ";
438                         }
439                 }
440         }
441
442         stream << ")";
443
444         return stream.str();
445 }
446
447 /** Get glsl name of the type
448  *
449  * @return Name of glsl type
450  **/
451 const glw::GLchar* Type::GetGLSLTypeName() const
452 {
453         static const GLchar* float_lut[4][4] = {
454                 { "float", "vec2", "vec3", "vec4" },
455                 { 0, "mat2", "mat2x3", "mat2x4" },
456                 { 0, "mat3x2", "mat3", "mat3x4" },
457                 { 0, "mat4x2", "mat4x3", "mat4" },
458         };
459
460         static const GLchar* double_lut[4][4] = {
461                 { "double", "dvec2", "dvec3", "dvec4" },
462                 { 0, "dmat2", "dmat2x3", "dmat2x4" },
463                 { 0, "dmat3x2", "dmat3", "dmat3x4" },
464                 { 0, "dmat4x2", "dmat4x3", "dmat4" },
465         };
466
467         static const GLchar* int_lut[4] = { "int", "ivec2", "ivec3", "ivec4" };
468
469         static const GLchar* uint_lut[4] = { "uint", "uvec2", "uvec3", "uvec4" };
470
471         const GLchar* result = 0;
472
473         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
474         {
475                 return 0;
476         }
477
478         switch (m_basic_type)
479         {
480         case Float:
481                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
482                 break;
483         case Double:
484                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
485                 break;
486         case Int:
487                 result = int_lut[m_n_rows - 1];
488                 break;
489         case Uint:
490                 result = uint_lut[m_n_rows - 1];
491                 break;
492         default:
493                 TCU_FAIL("Invliad enum");
494         }
495
496         return result;
497 }
498
499 /** Get number of locations required for the type
500  *
501  * @return Number of columns times:
502  *          - 2 when type is double with 3 or 4 rows,
503  *          - 1 otherwise.
504  **/
505 GLuint Type::GetLocations() const
506 {
507         GLuint n_loc_per_column;
508
509         /* 1 or 2 doubles any for rest */
510         if ((2 >= m_n_rows) || (Double != m_basic_type))
511         {
512                 n_loc_per_column = 1;
513         }
514         else
515         {
516                 /* 3 and 4 doubles */
517                 n_loc_per_column = 2;
518         }
519
520         return n_loc_per_column * m_n_columns;
521 }
522
523 /** Get size of the type in bytes. Note that this routine assumes tightly packing
524  *
525  * @return Formula Number of columns * number of rows * sizeof(base_type)
526  **/
527 GLuint Type::GetSize() const
528 {
529         const GLuint basic_type_size = GetTypeSize(m_basic_type);
530         const GLuint n_elements          = m_n_columns * m_n_rows;
531
532         return basic_type_size * n_elements;
533 }
534
535 /** Get GLenum representing the type
536  *
537  * @return GLenum
538  **/
539 GLenum Type::GetTypeGLenum() const
540 {
541         static const GLenum float_lut[4][4] = {
542                 { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 },
543                 { 0, GL_FLOAT_MAT2, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4 },
544                 { 0, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3, GL_FLOAT_MAT3x4 },
545                 { 0, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3, GL_FLOAT_MAT4 },
546         };
547
548         static const GLenum double_lut[4][4] = {
549                 { GL_DOUBLE, GL_DOUBLE_VEC2, GL_DOUBLE_VEC3, GL_DOUBLE_VEC4 },
550                 { 0, GL_DOUBLE_MAT2, GL_DOUBLE_MAT2x3, GL_DOUBLE_MAT2x4 },
551                 { 0, GL_DOUBLE_MAT3x2, GL_DOUBLE_MAT3, GL_DOUBLE_MAT3x4 },
552                 { 0, GL_DOUBLE_MAT4x2, GL_DOUBLE_MAT4x3, GL_DOUBLE_MAT4 },
553         };
554
555         static const GLenum int_lut[4] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
556
557         static const GLenum uint_lut[4] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3,
558                                                                                 GL_UNSIGNED_INT_VEC4 };
559
560         GLenum result = 0;
561
562         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
563         {
564                 return 0;
565         }
566
567         switch (m_basic_type)
568         {
569         case Float:
570                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
571                 break;
572         case Double:
573                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
574                 break;
575         case Int:
576                 result = int_lut[m_n_rows - 1];
577                 break;
578         case Uint:
579                 result = uint_lut[m_n_rows - 1];
580                 break;
581         default:
582                 TCU_FAIL("Invliad enum");
583         }
584
585         return result;
586 }
587
588 /** Calculate the numbe of components consumed by a type
589  *   according to 11.1.2.1 Output Variables
590  *
591  * @return Calculated number of components for the type
592  **/
593 GLuint Type::GetNumComponents() const
594 {
595         // Rule 3 of Section 7.6.2.2
596         // If the member is a three-component vector with components consuming N
597         // basic machine units, the base alignment is 4N.
598         GLuint num_components = (m_n_rows == 3 ? 4 : m_n_rows) * m_n_columns;
599
600         if (m_basic_type == Double)
601         {
602                 num_components *= 2;
603         }
604
605         return num_components;
606 }
607
608 /** Calculate stride for the type according to std140 rules
609  *
610  * @param alignment        Alignment of type
611  * @param n_columns        Number of columns
612  * @param n_array_elements Number of elements in array
613  *
614  * @return Calculated value
615  **/
616 GLuint Type::CalculateStd140Stride(GLuint alignment, GLuint n_columns, GLuint n_array_elements)
617 {
618         GLuint stride = alignment * n_columns;
619         if (0 != n_array_elements)
620         {
621                 stride *= n_array_elements;
622         }
623
624         return stride;
625 }
626
627 /** Check if glsl support matrices for specific basic type
628  *
629  * @param type Basic type
630  *
631  * @return true if matrices of <type> are supported, false otherwise
632  **/
633 bool Type::DoesTypeSupportMatrix(TYPES type)
634 {
635         bool result = false;
636
637         switch (type)
638         {
639         case Float:
640         case Double:
641                 result = true;
642                 break;
643         case Int:
644         case Uint:
645                 result = false;
646                 break;
647         default:
648                 TCU_FAIL("Invliad enum");
649         }
650
651         return result;
652 }
653
654 /** Creates instance of Type
655  *
656  * @param basic_type Select basic type of instance
657  * @param n_columns  Number of columns
658  * @param n_rows     Number of rows
659  *
660  * @return Type instance
661  **/
662 Type Type::GetType(TYPES basic_type, glw::GLuint n_columns, glw::GLuint n_rows)
663 {
664         Type type = { basic_type, n_columns, n_rows };
665
666         return type;
667 }
668
669 /** Get Size of given type in bytes
670  *
671  * @param type
672  *
673  * @return Size of type
674  **/
675 GLuint Type::GetTypeSize(TYPES type)
676 {
677         GLuint result = 0;
678
679         switch (type)
680         {
681         case Float:
682                 result = sizeof(GLfloat);
683                 break;
684         case Double:
685                 result = sizeof(GLdouble);
686                 break;
687         case Int:
688                 result = sizeof(GLint);
689                 break;
690         case Uint:
691                 result = sizeof(GLuint);
692                 break;
693         default:
694                 TCU_FAIL("Invalid enum");
695         }
696
697         return result;
698 }
699
700 /** Get GLenum representing given type
701  *
702  * @param type
703  *
704  * @return GLenum value
705  **/
706 GLenum Type::GetTypeGLenum(TYPES type)
707 {
708         GLenum result = 0;
709
710         switch (type)
711         {
712         case Float:
713                 result = GL_FLOAT;
714                 break;
715         case Double:
716                 result = GL_DOUBLE;
717                 break;
718         case Int:
719                 result = GL_INT;
720                 break;
721         case Uint:
722                 result = GL_UNSIGNED_INT;
723                 break;
724         default:
725                 TCU_FAIL("Invalid enum");
726         }
727
728         return result;
729 }
730
731 /** Get proper glUniformNdv routine for vectors with specified number of rows
732  *
733  * @param gl     GL functions
734  * @param n_rows Number of rows
735  *
736  * @return Function address
737  **/
738 uniformNdv getUniformNdv(const glw::Functions& gl, glw::GLuint n_rows)
739 {
740         uniformNdv result = 0;
741
742         switch (n_rows)
743         {
744         case 1:
745                 result = gl.uniform1dv;
746                 break;
747         case 2:
748                 result = gl.uniform2dv;
749                 break;
750         case 3:
751                 result = gl.uniform3dv;
752                 break;
753         case 4:
754                 result = gl.uniform4dv;
755                 break;
756         default:
757                 TCU_FAIL("Invalid number of rows");
758         }
759
760         return result;
761 }
762
763 /** Get proper glUniformNfv routine for vectors with specified number of rows
764  *
765  * @param gl     GL functions
766  * @param n_rows Number of rows
767  *
768  * @return Function address
769  **/
770 uniformNfv getUniformNfv(const glw::Functions& gl, glw::GLuint n_rows)
771 {
772         uniformNfv result = 0;
773
774         switch (n_rows)
775         {
776         case 1:
777                 result = gl.uniform1fv;
778                 break;
779         case 2:
780                 result = gl.uniform2fv;
781                 break;
782         case 3:
783                 result = gl.uniform3fv;
784                 break;
785         case 4:
786                 result = gl.uniform4fv;
787                 break;
788         default:
789                 TCU_FAIL("Invalid number of rows");
790         }
791
792         return result;
793 }
794
795 /** Get proper glUniformNiv routine for vectors with specified number of rows
796  *
797  * @param gl     GL functions
798  * @param n_rows Number of rows
799  *
800  * @return Function address
801  **/
802 uniformNiv getUniformNiv(const glw::Functions& gl, glw::GLuint n_rows)
803 {
804         uniformNiv result = 0;
805
806         switch (n_rows)
807         {
808         case 1:
809                 result = gl.uniform1iv;
810                 break;
811         case 2:
812                 result = gl.uniform2iv;
813                 break;
814         case 3:
815                 result = gl.uniform3iv;
816                 break;
817         case 4:
818                 result = gl.uniform4iv;
819                 break;
820         default:
821                 TCU_FAIL("Invalid number of rows");
822         }
823
824         return result;
825 }
826
827 /** Get proper glUniformNuiv routine for vectors with specified number of rows
828  *
829  * @param gl     GL functions
830  * @param n_rows Number of rows
831  *
832  * @return Function address
833  **/
834 uniformNuiv getUniformNuiv(const glw::Functions& gl, glw::GLuint n_rows)
835 {
836         uniformNuiv result = 0;
837
838         switch (n_rows)
839         {
840         case 1:
841                 result = gl.uniform1uiv;
842                 break;
843         case 2:
844                 result = gl.uniform2uiv;
845                 break;
846         case 3:
847                 result = gl.uniform3uiv;
848                 break;
849         case 4:
850                 result = gl.uniform4uiv;
851                 break;
852         default:
853                 TCU_FAIL("Invalid number of rows");
854         }
855
856         return result;
857 }
858
859 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
860  *
861  * @param gl     GL functions
862  * @param n_rows Number of rows
863  *
864  * @return Function address
865  **/
866 uniformMatrixNdv getUniformMatrixNdv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
867 {
868         uniformMatrixNdv result = 0;
869
870         switch (n_columns)
871         {
872         case 2:
873                 switch (n_rows)
874                 {
875                 case 2:
876                         result = gl.uniformMatrix2dv;
877                         break;
878                 case 3:
879                         result = gl.uniformMatrix2x3dv;
880                         break;
881                 case 4:
882                         result = gl.uniformMatrix2x4dv;
883                         break;
884                 default:
885                         TCU_FAIL("Invalid number of rows");
886                 }
887                 break;
888         case 3:
889                 switch (n_rows)
890                 {
891                 case 2:
892                         result = gl.uniformMatrix3x2dv;
893                         break;
894                 case 3:
895                         result = gl.uniformMatrix3dv;
896                         break;
897                 case 4:
898                         result = gl.uniformMatrix3x4dv;
899                         break;
900                 default:
901                         TCU_FAIL("Invalid number of rows");
902                 }
903                 break;
904         case 4:
905                 switch (n_rows)
906                 {
907                 case 2:
908                         result = gl.uniformMatrix4x2dv;
909                         break;
910                 case 3:
911                         result = gl.uniformMatrix4x3dv;
912                         break;
913                 case 4:
914                         result = gl.uniformMatrix4dv;
915                         break;
916                 default:
917                         TCU_FAIL("Invalid number of rows");
918                 }
919                 break;
920         default:
921                 TCU_FAIL("Invalid number of columns");
922         }
923
924         return result;
925 }
926
927 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
928  *
929  * @param gl     GL functions
930  * @param n_rows Number of rows
931  *
932  * @return Function address
933  **/
934 uniformMatrixNfv getUniformMatrixNfv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
935 {
936         uniformMatrixNfv result = 0;
937
938         switch (n_columns)
939         {
940         case 2:
941                 switch (n_rows)
942                 {
943                 case 2:
944                         result = gl.uniformMatrix2fv;
945                         break;
946                 case 3:
947                         result = gl.uniformMatrix2x3fv;
948                         break;
949                 case 4:
950                         result = gl.uniformMatrix2x4fv;
951                         break;
952                 default:
953                         TCU_FAIL("Invalid number of rows");
954                 }
955                 break;
956         case 3:
957                 switch (n_rows)
958                 {
959                 case 2:
960                         result = gl.uniformMatrix3x2fv;
961                         break;
962                 case 3:
963                         result = gl.uniformMatrix3fv;
964                         break;
965                 case 4:
966                         result = gl.uniformMatrix3x4fv;
967                         break;
968                 default:
969                         TCU_FAIL("Invalid number of rows");
970                 }
971                 break;
972         case 4:
973                 switch (n_rows)
974                 {
975                 case 2:
976                         result = gl.uniformMatrix4x2fv;
977                         break;
978                 case 3:
979                         result = gl.uniformMatrix4x3fv;
980                         break;
981                 case 4:
982                         result = gl.uniformMatrix4fv;
983                         break;
984                 default:
985                         TCU_FAIL("Invalid number of rows");
986                 }
987                 break;
988         default:
989                 TCU_FAIL("Invalid number of columns");
990         }
991
992         return result;
993 }
994
995 bool verifyVarying(Program& program, const std::string& parent_name, const Variable::Descriptor& desc,
996                                    std::stringstream& stream, bool is_input)
997 {
998         GLint  component = 0;
999         GLuint index     = 0;
1000         GLenum interface = GL_PROGRAM_INPUT;
1001         GLint  location  = 0;
1002
1003         if (false == is_input)
1004         {
1005                 interface = GL_PROGRAM_OUTPUT;
1006         }
1007
1008         const std::string& name = Utils::Variable::GetReference(parent_name, desc, Utils::Variable::BASIC, 0);
1009
1010         try
1011         {
1012                 index = program.GetResourceIndex(name, interface);
1013
1014                 program.GetResource(interface, index, GL_LOCATION, 1 /* size */, &location);
1015                 program.GetResource(interface, index, GL_LOCATION_COMPONENT, 1 /* size */, &component);
1016         }
1017         catch (std::exception& exc)
1018         {
1019                 stream << "Failed to query program for varying: " << desc.m_name << ". Reason: " << exc.what() << "\n";
1020
1021                 return false;
1022         }
1023
1024         bool result = true;
1025
1026         if (location != desc.m_expected_location)
1027         {
1028                 stream << "Attribute: " << desc.m_name << " - invalid location: " << location
1029                            << " expected: " << desc.m_expected_location << std::endl;
1030                 result = false;
1031         }
1032         if (component != desc.m_expected_component)
1033         {
1034                 stream << "Attribute: " << desc.m_name << " - invalid component: " << component
1035                            << " expected: " << desc.m_expected_component << std::endl;
1036                 result = false;
1037         }
1038
1039         return result;
1040 }
1041
1042 /** Query program resource for given variable and verify that everything is as expected
1043  *
1044  * @param program  Program object
1045  * @param variable Variable object
1046  * @param stream   Stream that will be used to log any error
1047  * @param is_input Selects if varying is input or output
1048  *
1049  * @return true if verification is positive, false otherwise
1050  **/
1051 bool checkVarying(Program& program, const Variable& variable, std::stringstream& stream, bool is_input)
1052 {
1053         bool result = true;
1054
1055         if (variable.IsBlock())
1056         {
1057                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1058                 const size_t      n_members = interface->m_members.size();
1059
1060                 for (size_t i = 0; i < n_members; ++i)
1061                 {
1062                         const Variable::Descriptor& member = interface->m_members[i];
1063                         bool member_result                                 = verifyVarying(program, interface->m_name, member, stream, is_input);
1064
1065                         if (false == member_result)
1066                         {
1067                                 result = false;
1068                         }
1069                 }
1070         }
1071         /*
1072          To query the the location of struct member by glGetProgramResource, we need pass the variable name "gs_fs_output[0].single",
1073          but in original implementation, the test pass the name "Data.single", which can't get any valid result.
1074          struct Data {
1075          dmat2 single;
1076          dmat2 array[1];
1077          };
1078          layout (location = 0) in Data gs_fs_output[1];
1079          */
1080         else if (variable.IsStruct())
1081         {
1082                 Utils::Interface* interface              = variable.m_descriptor.m_interface;
1083                 const size_t      n_members              = interface->m_members.size();
1084                 std::string               structVariable = variable.m_descriptor.m_name;
1085                 // If struct variable is an array
1086                 if (0 != variable.m_descriptor.m_n_array_elements)
1087                 {
1088                         for (GLuint i = 0; i < variable.m_descriptor.m_n_array_elements; i++)
1089                         {
1090                                 GLchar buffer[16];
1091                                 sprintf(buffer, "%d", i);
1092                                 structVariable.append("[");
1093                                 structVariable.append(buffer);
1094                                 structVariable.append("]");
1095                                 for (size_t j = 0; j < n_members; ++j)
1096                                 {
1097                                         const Variable::Descriptor& member = interface->m_members[j];
1098                                         bool member_result = verifyVarying(program, structVariable, member, stream, is_input);
1099
1100                                         if (false == member_result)
1101                                         {
1102                                                 result = false;
1103                                         }
1104                                 }
1105                         }
1106                 }
1107                 else
1108                 {
1109                         for (GLuint i = 0; i < n_members; ++i)
1110                         {
1111                                 const Variable::Descriptor& member = interface->m_members[i];
1112                                 bool member_result                                 = verifyVarying(program, structVariable, member, stream, is_input);
1113
1114                                 if (false == member_result)
1115                                 {
1116                                         result = false;
1117                                 }
1118                         }
1119                 }
1120         }
1121         else
1122         {
1123                 result = verifyVarying(program, "", variable.m_descriptor, stream, is_input);
1124         }
1125         return result;
1126 }
1127
1128 /** Query program resource for given variable and verify that everything is as expected
1129  *
1130  * @param program  Program object
1131  * @param variable Variable object
1132  * @param stream   Stream that will be used to log any error
1133  *
1134  * @return true if verification is positive, false otherwise
1135  **/
1136 bool checkUniform(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1137 {
1138         bool result = true;
1139
1140         if (false == variable.IsBlock())
1141         {
1142                 TCU_FAIL("Not implemented");
1143         }
1144         else
1145         {
1146                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1147
1148                 size_t size = interface->m_members.size();
1149
1150                 std::vector<GLuint>              indices;
1151                 std::vector<const char*> names;
1152                 std::vector<std::string> names_str;
1153                 std::vector<GLint>               offsets;
1154
1155                 indices.resize(size);
1156                 names.resize(size);
1157                 names_str.resize(size);
1158                 offsets.resize(size);
1159
1160                 for (size_t i = 0; i < size; ++i)
1161                 {
1162                         indices[i] = 0;
1163                         offsets[i] = 0;
1164
1165                         const std::string& name =
1166                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1167
1168                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1169                         {
1170                                 const std::string& member_name = Utils::Variable::GetReference(
1171                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1172
1173                                 names_str[i] = member_name;
1174                         }
1175                         else
1176                         {
1177                                 names_str[i] = name;
1178                         }
1179
1180                         names[i] = names_str[i].c_str();
1181                 }
1182
1183                 try
1184                 {
1185                         program.GetUniformIndices(static_cast<glw::GLsizei>(size), &names[0], &indices[0]);
1186                         program.GetActiveUniformsiv(static_cast<glw::GLsizei>(size), &indices[0], GL_UNIFORM_OFFSET, &offsets[0]);
1187                 }
1188                 catch (std::exception& exc)
1189                 {
1190                         stream << "Failed to query program for uniforms in block: " << variable.m_descriptor.m_name
1191                                    << ". Reason: " << exc.what() << "\n";
1192
1193                         return false;
1194                 }
1195
1196                 for (size_t i = 0; i < size; ++i)
1197                 {
1198                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1199
1200                         if (offsets[i] != (GLint)desc.m_offset)
1201                         {
1202                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offsets[i]
1203                                            << " expected: " << desc.m_offset << std::endl;
1204                                 result = false;
1205                         }
1206                 }
1207         }
1208
1209         return result;
1210 }
1211
1212 /** Query program resource for given variable and verify that everything is as expected
1213  *
1214  * @param program  Program object
1215  * @param variable Variable object
1216  * @param stream   Stream that will be used to log any error
1217  *
1218  * @return true if verification is positive, false otherwise
1219  **/
1220 bool checkSSB(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1221 {
1222         bool result = true;
1223
1224         if (false == variable.IsBlock())
1225         {
1226                 TCU_FAIL("Not implemented");
1227         }
1228         else
1229         {
1230                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1231
1232                 size_t size = interface->m_members.size();
1233
1234                 for (size_t i = 0; i < size; ++i)
1235                 {
1236                         GLuint          index   = 0;
1237                         std::string name_str = "";
1238                         GLint           offset   = 0;
1239
1240                         const std::string& name =
1241                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1242
1243                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1244                         {
1245                                 const std::string& member_name = Utils::Variable::GetReference(
1246                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1247
1248                                 name_str = member_name;
1249                         }
1250                         else
1251                         {
1252                                 name_str = name;
1253                         }
1254
1255                         try
1256                         {
1257                                 index = program.GetResourceIndex(name_str, GL_BUFFER_VARIABLE);
1258
1259                                 program.GetResource(GL_BUFFER_VARIABLE, index, GL_OFFSET, 1, &offset);
1260                         }
1261                         catch (std::exception& exc)
1262                         {
1263                                 stream << "Failed to query program for buffer variable: " << variable.m_descriptor.m_name
1264                                            << ". Reason: " << exc.what() << "\n";
1265
1266                                 return false;
1267                         }
1268
1269                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1270
1271                         if (offset != (GLint)desc.m_offset)
1272                         {
1273                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offset
1274                                            << " expected: " << desc.m_offset << std::endl;
1275                                 result = false;
1276                         }
1277                 }
1278         }
1279
1280         return result;
1281 }
1282
1283 /** Query program resources at given stage and verifies results
1284  *
1285  * @param program           Program object
1286  * @param program_interface Definition of program interface
1287  * @param stage             Stage to be verified
1288  * @param check_inputs      Select if inputs should be verified
1289  * @param check_outputs     Select if output should be verified
1290  * @param check_uniforms    Select if uniforms should be verified
1291  * @param check_ssbs        Select if buffers should be verified
1292  * @param stream            Stream that will be used to log any error
1293  *
1294  * @return true if verification is positive, false otherwise
1295  **/
1296 bool checkProgramStage(Program& program, const ProgramInterface& program_interface, Utils::Shader::STAGES stage,
1297                                            bool check_inputs, bool check_outputs, bool check_uniforms, bool check_ssbs,
1298                                            std::stringstream& stream)
1299 {
1300         typedef Variable::PtrVector::const_iterator const_iterator;
1301
1302         const ShaderInterface& interface = program_interface.GetShaderInterface(stage);
1303
1304         bool result = true;
1305
1306         /* Inputs */
1307         if (true == check_inputs)
1308         {
1309                 const Variable::PtrVector& inputs = interface.m_inputs;
1310
1311                 for (const_iterator it = inputs.begin(); it != inputs.end(); ++it)
1312                 {
1313                         if (false == checkVarying(program, **it, stream, true))
1314                         {
1315                                 result = false;
1316                         }
1317                 }
1318         }
1319
1320         /* Outputs */
1321         if (true == check_outputs)
1322         {
1323                 const Variable::PtrVector& outputs = interface.m_outputs;
1324
1325                 for (const_iterator it = outputs.begin(); it != outputs.end(); ++it)
1326                 {
1327                         if (false == checkVarying(program, **it, stream, false))
1328                         {
1329                                 result = false;
1330                         }
1331                 }
1332         }
1333
1334         /* Uniforms */
1335         if (true == check_uniforms)
1336         {
1337                 const Variable::PtrVector& uniforms = interface.m_uniforms;
1338
1339                 for (const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
1340                 {
1341                         if (false == checkUniform(program, **it, stream))
1342                         {
1343                                 result = false;
1344                         }
1345                 }
1346         }
1347
1348         /* SSBs */
1349         if (true == check_ssbs)
1350         {
1351                 const Variable::PtrVector& ssbs = interface.m_ssb_blocks;
1352
1353                 for (const_iterator it = ssbs.begin(); it != ssbs.end(); ++it)
1354                 {
1355                         if (false == checkSSB(program, **it, stream))
1356                         {
1357                                 result = false;
1358                         }
1359                 }
1360         }
1361
1362         return result;
1363 }
1364
1365 /** Query resources of monolithic compute program and verifies results
1366  *
1367  * @param program           Program object
1368  * @param program_interface Definition of program interface
1369  * @param stream            Stream that will be used to log any error
1370  *
1371  * @return true if verification is positive, false otherwise
1372  **/
1373 bool checkMonolithicComputeProgramInterface(Program& program, const ProgramInterface& program_interface,
1374                                                                                         std::stringstream& stream)
1375 {
1376         bool result = true;
1377
1378         if (false == checkProgramStage(program, program_interface, Shader::COMPUTE, false, false, true, true, stream))
1379         {
1380                 result = false;
1381         }
1382
1383         /* Done */
1384         return result;
1385 }
1386
1387 /** Query resources of monolithic draw program and verifies results
1388  *
1389  * @param program           Program object
1390  * @param program_interface Definition of program interface
1391  * @param stream            Stream that will be used to log any error
1392  *
1393  * @return true if verification is positive, false otherwise
1394  **/
1395 bool checkMonolithicDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1396                                                                                  std::stringstream& stream)
1397 {
1398         bool result = true;
1399
1400         if (false == checkProgramStage(program, program_interface, Shader::VERTEX, true, false, true, true, stream))
1401         {
1402                 result = false;
1403         }
1404
1405         /* Done */
1406         return result;
1407 }
1408
1409 /** Query resources of separable draw program and verifies results
1410  *
1411  * @param program           Program object
1412  * @param program_interface Definition of program interface
1413  * @param stream            Stream that will be used to log any error
1414  *
1415  * @return true if verification is positive, false otherwise
1416  **/
1417 bool checkSeparableDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1418                                                                                 Utils::Shader::STAGES stage, std::stringstream& stream)
1419 {
1420         bool result = true;
1421
1422         if (false == checkProgramStage(program, program_interface, stage, true, true, true, true, stream))
1423         {
1424                 result = false;
1425         }
1426
1427         /* Done */
1428         return result;
1429 }
1430
1431 /** Check if extension is supported
1432  *
1433  * @param context        Test context
1434  * @param extension_name Name of extension
1435  *
1436  * @return true if extension is supported, false otherwise
1437  **/
1438 bool isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1439 {
1440         const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1441
1442         if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1443         {
1444                 return false;
1445         }
1446
1447         return true;
1448 }
1449
1450 /** Check if GL context meets version requirements
1451  *
1452  * @param gl             Functions
1453  * @param required_major Minimum required MAJOR_VERSION
1454  * @param required_minor Minimum required MINOR_VERSION
1455  *
1456  * @return true if GL context version is at least as requested, false otherwise
1457  **/
1458 bool isGLVersionAtLeast(const Functions& gl, GLint required_major, GLint required_minor)
1459 {
1460         glw::GLint major = 0;
1461         glw::GLint minor = 0;
1462
1463         gl.getIntegerv(GL_MAJOR_VERSION, &major);
1464         gl.getIntegerv(GL_MINOR_VERSION, &minor);
1465
1466         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1467
1468         if (major > required_major)
1469         {
1470                 /* Major is higher than required one */
1471                 return true;
1472         }
1473         else if (major == required_major)
1474         {
1475                 if (minor >= required_minor)
1476                 {
1477                         /* Major is equal to required one */
1478                         /* Minor is higher than or equal to required one */
1479                         return true;
1480                 }
1481                 else
1482                 {
1483                         /* Major is equal to required one */
1484                         /* Minor is lower than required one */
1485                         return false;
1486                 }
1487         }
1488         else
1489         {
1490                 /* Major is lower than required one */
1491                 return false;
1492         }
1493 }
1494
1495 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1496  *
1497  * @param token           Token string
1498  * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1499  * @param text            String that will be used as replacement for <token>
1500  * @param string          String to work on
1501  **/
1502 void replaceToken(const GLchar* token, size_t& search_position, const GLchar* text, std::string& string)
1503 {
1504         const size_t text_length        = strlen(text);
1505         const size_t token_length   = strlen(token);
1506         const size_t token_position = string.find(token, search_position);
1507
1508 #if DEBUG_REPLACE_TOKEN
1509         if (std::string::npos == token_position)
1510         {
1511                 string.append("\n\nInvalid token: ");
1512                 string.append(token);
1513
1514                 TCU_FAIL(string.c_str());
1515         }
1516 #endif /* DEBUG_REPLACE_TOKEN */
1517
1518         string.replace(token_position, token_length, text, text_length);
1519
1520         search_position = token_position + text_length;
1521 }
1522
1523 /** Replace all occurances of <token> with <text> in <string>
1524  *
1525  * @param token           Token string
1526  * @param text            String that will be used as replacement for <token>
1527  * @param string          String to work on
1528  **/
1529 void replaceAllTokens(const GLchar* token, const GLchar* text, std::string& string)
1530 {
1531         const size_t text_length  = strlen(text);
1532         const size_t token_length = strlen(token);
1533
1534         size_t search_position = 0;
1535
1536         while (1)
1537         {
1538                 const size_t token_position = string.find(token, search_position);
1539
1540                 if (std::string::npos == token_position)
1541                 {
1542                         break;
1543                 }
1544
1545                 search_position = token_position + text_length;
1546
1547                 string.replace(token_position, token_length, text, text_length);
1548         }
1549 }
1550
1551 /** Rounds up the value to the next power of 2.
1552  * This routine does not work for 0, see the url for explanations.
1553  *
1554  * @param value Starting point
1555  *
1556  * @return Calculated value
1557  **/
1558 glw::GLuint roundUpToPowerOf2(glw::GLuint value)
1559 {
1560         /* Taken from: graphics.stanford.edu/~seander/bithacks.html */
1561         --value;
1562
1563         value |= value >> 1;
1564         value |= value >> 2;
1565         value |= value >> 4;
1566         value |= value >> 8;
1567         value |= value >> 16;
1568
1569         ++value;
1570
1571         return value;
1572 }
1573
1574 /** Insert elements of list into string.
1575  * List in string is represented either by token "LIST" or "SEPARATORLIST".
1576  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>.
1577  * LIST is replaced with <element>SEPARATORLIST
1578  *
1579  * @param element         Element to be inserted
1580  * @param separator       Separator inserted between elements
1581  * @param search_position Position in string, where search for list should start
1582  * @param string          String
1583  **/
1584 void insertElementOfList(const GLchar* element, const GLchar* separator, size_t& search_position, std::string& string)
1585 {
1586         static const char* list         = g_list;
1587         static const char* sep_list = "SEPARATORLIST";
1588
1589         /* Try to get "list" positions */
1590         const size_t list_position       = string.find(list, search_position);
1591         const size_t sep_list_position = string.find(sep_list, search_position);
1592
1593         /* There is no list in string */
1594         if (std::string::npos == list_position)
1595         {
1596                 return;
1597         }
1598
1599         if (9 /* strlen(SEPARATOR) */ == list_position - sep_list_position)
1600         {
1601                 replaceToken("SEPARATOR", search_position, separator, string);
1602         }
1603
1604         /* Save search_position */
1605         const size_t start_position = search_position;
1606
1607         /* Prepare new element */
1608         replaceToken("LIST", search_position, "ELEMENTSEPARATORLIST", string);
1609
1610         /* Restore search_position */
1611         search_position = start_position;
1612
1613         /* Replace element and separator */
1614         replaceToken("ELEMENT", search_position, element, string);
1615 }
1616
1617 /** Close list in string.
1618  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>
1619  * LIST is replaced with ""
1620  *
1621  * @param separator       Separator inserted between elements
1622  * @param search_position Position in string, where search for list should start
1623  * @param string          String
1624  **/
1625 void endList(const glw::GLchar* separator, size_t& search_position, std::string& string)
1626 {
1627         const size_t sep_position = string.find("SEPARATOR", search_position);
1628         if (std::string::npos != sep_position)
1629         {
1630                 replaceToken("SEPARATOR", search_position, separator, string);
1631         }
1632
1633         replaceToken("LIST", search_position, "", string);
1634 }
1635
1636 /* Buffer constants */
1637 const GLuint Buffer::m_invalid_id = -1;
1638
1639 /** Constructor.
1640  *
1641  * @param context CTS context.
1642  **/
1643 Buffer::Buffer(deqp::Context& context) : m_id(m_invalid_id), m_buffer(Array), m_context(context)
1644 {
1645 }
1646
1647 /** Destructor
1648  *
1649  **/
1650 Buffer::~Buffer()
1651 {
1652         Release();
1653 }
1654
1655 /** Initialize buffer instance
1656  *
1657  * @param buffer Buffer type
1658  * @param usage  Buffer usage enum
1659  * @param size   <size> parameter
1660  * @param data   <data> parameter
1661  **/
1662 void Buffer::Init(BUFFERS buffer, USAGE usage, GLsizeiptr size, GLvoid* data)
1663 {
1664         /* Delete previous buffer instance */
1665         Release();
1666
1667         m_buffer = buffer;
1668
1669         const Functions& gl = m_context.getRenderContext().getFunctions();
1670
1671         Generate(gl, m_id);
1672         Bind(gl, m_id, m_buffer);
1673         Data(gl, m_buffer, usage, size, data);
1674 }
1675
1676 /** Release buffer instance
1677  *
1678  **/
1679 void Buffer::Release()
1680 {
1681         if (m_invalid_id != m_id)
1682         {
1683                 const Functions& gl = m_context.getRenderContext().getFunctions();
1684
1685                 gl.deleteBuffers(1, &m_id);
1686                 m_id = m_invalid_id;
1687         }
1688 }
1689
1690 /** Binds buffer to its target
1691  *
1692  **/
1693 void Buffer::Bind() const
1694 {
1695         const Functions& gl = m_context.getRenderContext().getFunctions();
1696
1697         Bind(gl, m_id, m_buffer);
1698 }
1699
1700 /** Binds indexed buffer
1701  *
1702  * @param index <index> parameter
1703  **/
1704 void Buffer::BindBase(GLuint index) const
1705 {
1706         const Functions& gl = m_context.getRenderContext().getFunctions();
1707
1708         BindBase(gl, m_id, m_buffer, index);
1709 }
1710
1711 /** Binds range of buffer
1712  *
1713  * @param index  <index> parameter
1714  * @param offset <offset> parameter
1715  * @param size   <size> parameter
1716  **/
1717 void Buffer::BindRange(GLuint index, GLintptr offset, GLsizeiptr size) const
1718 {
1719         const Functions& gl = m_context.getRenderContext().getFunctions();
1720
1721         BindRange(gl, m_id, m_buffer, index, offset, size);
1722 }
1723
1724 /** Allocate memory for buffer and sends initial content
1725  *
1726  * @param usage  Buffer usage enum
1727  * @param size   <size> parameter
1728  * @param data   <data> parameter
1729  **/
1730 void Buffer::Data(USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1731 {
1732         const Functions& gl = m_context.getRenderContext().getFunctions();
1733
1734         Data(gl, m_buffer, usage, size, data);
1735 }
1736
1737 /** Maps contents of buffer into CPU space
1738  *
1739  * @param access Requested access
1740  *
1741  * @return Pointer to memory region available for CPU
1742  **/
1743 GLvoid* Buffer::Map(ACCESS access)
1744 {
1745         const Functions& gl = m_context.getRenderContext().getFunctions();
1746
1747         return Map(gl, m_buffer, access);
1748 }
1749
1750 /** Allocate memory for buffer and sends initial content
1751  *
1752  * @param offset Offset in buffer
1753  * @param size   <size> parameter
1754  * @param data   <data> parameter
1755  **/
1756 void Buffer::SubData(glw::GLintptr offset, glw::GLsizeiptr size, glw::GLvoid* data)
1757 {
1758         const Functions& gl = m_context.getRenderContext().getFunctions();
1759
1760         SubData(gl, m_buffer, offset, size, data);
1761 }
1762
1763 /** Maps contents of buffer into CPU space
1764  **/
1765 void Buffer::UnMap()
1766 {
1767         const Functions& gl = m_context.getRenderContext().getFunctions();
1768
1769         return UnMap(gl, m_buffer);
1770 }
1771
1772 /** Bind buffer to given target
1773  *
1774  * @param gl     GL functions
1775  * @param id     Id of buffer
1776  * @param buffer Buffer enum
1777  **/
1778 void Buffer::Bind(const Functions& gl, GLuint id, BUFFERS buffer)
1779 {
1780         GLenum target = GetBufferGLenum(buffer);
1781
1782         gl.bindBuffer(target, id);
1783         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
1784 }
1785
1786 /** Binds indexed buffer
1787  *
1788  * @param gl     GL functions
1789  * @param id     Id of buffer
1790  * @param buffer Buffer enum
1791  * @param index  <index> parameter
1792  **/
1793 void Buffer::BindBase(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index)
1794 {
1795         GLenum target = GetBufferGLenum(buffer);
1796
1797         gl.bindBufferBase(target, index, id);
1798         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferBase");
1799 }
1800
1801 /** Binds buffer range
1802  *
1803  * @param gl     GL functions
1804  * @param id     Id of buffer
1805  * @param buffer Buffer enum
1806  * @param index  <index> parameter
1807  * @param offset <offset> parameter
1808  * @param size   <size> parameter
1809  **/
1810 void Buffer::BindRange(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1811 {
1812         GLenum target = GetBufferGLenum(buffer);
1813
1814         gl.bindBufferRange(target, index, id, offset, size);
1815         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
1816 }
1817
1818 /** Allocate memory for buffer and sends initial content
1819  *
1820  * @param gl     GL functions
1821  * @param buffer Buffer enum
1822  * @param usage  Buffer usage enum
1823  * @param size   <size> parameter
1824  * @param data   <data> parameter
1825  **/
1826 void Buffer::Data(const glw::Functions& gl, BUFFERS buffer, USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1827 {
1828         GLenum target   = GetBufferGLenum(buffer);
1829         GLenum gl_usage = GetUsageGLenum(usage);
1830
1831         gl.bufferData(target, size, data, gl_usage);
1832         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferData");
1833 }
1834
1835 /** Allocate memory for buffer and sends initial content
1836  *
1837  * @param gl     GL functions
1838  * @param buffer Buffer enum
1839  * @param offset Offset in buffer
1840  * @param size   <size> parameter
1841  * @param data   <data> parameter
1842  **/
1843 void Buffer::SubData(const glw::Functions& gl, BUFFERS buffer, glw::GLintptr offset, glw::GLsizeiptr size,
1844                                          glw::GLvoid* data)
1845 {
1846         GLenum target = GetBufferGLenum(buffer);
1847
1848         gl.bufferSubData(target, offset, size, data);
1849         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferSubData");
1850 }
1851
1852 /** Generate buffer
1853  *
1854  * @param gl     GL functions
1855  * @param out_id Id of buffer
1856  **/
1857 void Buffer::Generate(const Functions& gl, GLuint& out_id)
1858 {
1859         GLuint id = m_invalid_id;
1860
1861         gl.genBuffers(1, &id);
1862         GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
1863
1864         if (m_invalid_id == id)
1865         {
1866                 TCU_FAIL("Got invalid id");
1867         }
1868
1869         out_id = id;
1870 }
1871
1872 /** Maps buffer content
1873  *
1874  * @param gl     GL functions
1875  * @param buffer Buffer enum
1876  * @param access Access rights for mapped region
1877  *
1878  * @return Mapped memory
1879  **/
1880 void* Buffer::Map(const Functions& gl, BUFFERS buffer, ACCESS access)
1881 {
1882         GLenum target   = GetBufferGLenum(buffer);
1883         GLenum gl_access = GetAccessGLenum(access);
1884
1885         void* result = gl.mapBuffer(target, gl_access);
1886         GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
1887
1888         return result;
1889 }
1890
1891 /** Unmaps buffer
1892  *
1893  **/
1894 void Buffer::UnMap(const Functions& gl, BUFFERS buffer)
1895 {
1896         GLenum target = GetBufferGLenum(buffer);
1897
1898         gl.unmapBuffer(target);
1899         GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
1900 }
1901
1902 /** Return GLenum representation of requested access
1903  *
1904  * @param access Requested access
1905  *
1906  * @return GLenum value
1907  **/
1908 GLenum Buffer::GetAccessGLenum(ACCESS access)
1909 {
1910         GLenum result = 0;
1911
1912         switch (access)
1913         {
1914         case ReadOnly:
1915                 result = GL_READ_ONLY;
1916                 break;
1917         case WriteOnly:
1918                 result = GL_WRITE_ONLY;
1919                 break;
1920         case ReadWrite:
1921                 result = GL_READ_WRITE;
1922                 break;
1923         default:
1924                 TCU_FAIL("Invalid enum");
1925         }
1926
1927         return result;
1928 }
1929
1930 /** Return GLenum representation of requested buffer type
1931  *
1932  * @param buffer Requested buffer type
1933  *
1934  * @return GLenum value
1935  **/
1936 GLenum Buffer::GetBufferGLenum(BUFFERS buffer)
1937 {
1938         GLenum result = 0;
1939
1940         switch (buffer)
1941         {
1942         case Array:
1943                 result = GL_ARRAY_BUFFER;
1944                 break;
1945         case Element:
1946                 result = GL_ELEMENT_ARRAY_BUFFER;
1947                 break;
1948         case Shader_Storage:
1949                 result = GL_SHADER_STORAGE_BUFFER;
1950                 break;
1951         case Texture:
1952                 result = GL_TEXTURE_BUFFER;
1953                 break;
1954         case Transform_feedback:
1955                 result = GL_TRANSFORM_FEEDBACK_BUFFER;
1956                 break;
1957         case Uniform:
1958                 result = GL_UNIFORM_BUFFER;
1959                 break;
1960         default:
1961                 TCU_FAIL("Invalid enum");
1962         }
1963
1964         return result;
1965 }
1966
1967 /** Return GLenum representation of requested usage
1968  *
1969  * @param usage Requested usage
1970  *
1971  * @return GLenum value
1972  **/
1973 GLenum Buffer::GetUsageGLenum(USAGE usage)
1974 {
1975         GLenum result = 0;
1976
1977         switch (usage)
1978         {
1979         case DynamicCopy:
1980                 result = GL_DYNAMIC_COPY;
1981                 break;
1982         case DynamicDraw:
1983                 result = GL_DYNAMIC_DRAW;
1984                 break;
1985         case DynamicRead:
1986                 result = GL_DYNAMIC_READ;
1987                 break;
1988         case StaticCopy:
1989                 result = GL_STATIC_COPY;
1990                 break;
1991         case StaticDraw:
1992                 result = GL_STATIC_DRAW;
1993                 break;
1994         case StaticRead:
1995                 result = GL_STATIC_READ;
1996                 break;
1997         case StreamCopy:
1998                 result = GL_STREAM_COPY;
1999                 break;
2000         case StreamDraw:
2001                 result = GL_STREAM_DRAW;
2002                 break;
2003         case StreamRead:
2004                 result = GL_STREAM_READ;
2005                 break;
2006         default:
2007                 TCU_FAIL("Invalid enum");
2008         }
2009
2010         return result;
2011 }
2012
2013 /** Returns name of buffer target
2014  *
2015  * @param buffer Target enum
2016  *
2017  * @return Name of target
2018  **/
2019 const GLchar* Buffer::GetBufferName(BUFFERS buffer)
2020 {
2021         const GLchar* name = 0;
2022
2023         switch (buffer)
2024         {
2025         case Array:
2026                 name = "Array";
2027                 break;
2028         case Element:
2029                 name = "Element";
2030                 break;
2031         case Shader_Storage:
2032                 name = "Shader_Storage";
2033                 break;
2034         case Texture:
2035                 name = "Texture";
2036                 break;
2037         case Transform_feedback:
2038                 name = "Transform_feedback";
2039                 break;
2040         case Uniform:
2041                 name = "Uniform";
2042                 break;
2043         default:
2044                 TCU_FAIL("Invalid enum");
2045         }
2046
2047         return name;
2048 }
2049
2050 /* Framebuffer constants */
2051 const GLuint Framebuffer::m_invalid_id = -1;
2052
2053 /** Constructor
2054  *
2055  * @param context CTS context
2056  **/
2057 Framebuffer::Framebuffer(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2058 {
2059         /* Nothing to be done here */
2060 }
2061
2062 /** Destructor
2063  *
2064  **/
2065 Framebuffer::~Framebuffer()
2066 {
2067         Release();
2068 }
2069
2070 /** Initialize framebuffer instance
2071  *
2072  **/
2073 void Framebuffer::Init()
2074 {
2075         /* Delete previous instance */
2076         Release();
2077
2078         const Functions& gl = m_context.getRenderContext().getFunctions();
2079
2080         Generate(gl, m_id);
2081 }
2082
2083 /** Release framebuffer instance
2084  *
2085  **/
2086 void Framebuffer::Release()
2087 {
2088         if (m_invalid_id != m_id)
2089         {
2090                 const Functions& gl = m_context.getRenderContext().getFunctions();
2091
2092                 gl.deleteFramebuffers(1, &m_id);
2093                 m_id = m_invalid_id;
2094         }
2095 }
2096
2097 /** Attach texture to specified attachment
2098  *
2099  * @param attachment Attachment
2100  * @param texture_id Texture id
2101  * @param width      Texture width
2102  * @param height     Texture height
2103  **/
2104 void Framebuffer::AttachTexture(GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2105 {
2106         const Functions& gl = m_context.getRenderContext().getFunctions();
2107
2108         AttachTexture(gl, attachment, texture_id, width, height);
2109 }
2110
2111 /** Binds framebuffer to DRAW_FRAMEBUFFER
2112  *
2113  **/
2114 void Framebuffer::Bind()
2115 {
2116         const Functions& gl = m_context.getRenderContext().getFunctions();
2117
2118         Bind(gl, m_id);
2119 }
2120
2121 /** Clear framebuffer
2122  *
2123  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2124  **/
2125 void Framebuffer::Clear(GLenum mask)
2126 {
2127         const Functions& gl = m_context.getRenderContext().getFunctions();
2128
2129         Clear(gl, mask);
2130 }
2131
2132 /** Specifies clear color
2133  *
2134  * @param red   Red channel
2135  * @param green Green channel
2136  * @param blue  Blue channel
2137  * @param alpha Alpha channel
2138  **/
2139 void Framebuffer::ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2140 {
2141         const Functions& gl = m_context.getRenderContext().getFunctions();
2142
2143         ClearColor(gl, red, green, blue, alpha);
2144 }
2145
2146 /** Attach texture to specified attachment
2147  *
2148  * @param gl         GL functions
2149  * @param attachment Attachment
2150  * @param texture_id Texture id
2151  * @param width      Texture width
2152  * @param height     Texture height
2153  **/
2154 void Framebuffer::AttachTexture(const Functions& gl, GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2155 {
2156         gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, attachment, texture_id, 0 /* level */);
2157         GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture");
2158
2159         gl.viewport(0 /* x */, 0 /* y */, width, height);
2160         GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
2161 }
2162
2163 /** Binds framebuffer to DRAW_FRAMEBUFFER
2164  *
2165  * @param gl GL functions
2166  * @param id ID of framebuffer
2167  **/
2168 void Framebuffer::Bind(const Functions& gl, GLuint id)
2169 {
2170         gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, id);
2171         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
2172 }
2173
2174 /** Clear framebuffer
2175  *
2176  * @param gl   GL functions
2177  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2178  **/
2179 void Framebuffer::Clear(const Functions& gl, GLenum mask)
2180 {
2181         gl.clear(mask);
2182         GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
2183 }
2184
2185 /** Specifies clear color
2186  *
2187  * @param gl    GL functions
2188  * @param red   Red channel
2189  * @param green Green channel
2190  * @param blue  Blue channel
2191  * @param alpha Alpha channel
2192  **/
2193 void Framebuffer::ClearColor(const Functions& gl, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2194 {
2195         gl.clearColor(red, green, blue, alpha);
2196         GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
2197 }
2198
2199 /** Generate framebuffer
2200  *
2201  **/
2202 void Framebuffer::Generate(const Functions& gl, GLuint& out_id)
2203 {
2204         GLuint id = m_invalid_id;
2205
2206         gl.genFramebuffers(1, &id);
2207         GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
2208
2209         if (m_invalid_id == id)
2210         {
2211                 TCU_FAIL("Invalid id");
2212         }
2213
2214         out_id = id;
2215 }
2216
2217 /* Shader's constants */
2218 const GLuint Shader::m_invalid_id = 0;
2219
2220 /** Constructor.
2221  *
2222  * @param context CTS context.
2223  **/
2224 Shader::Shader(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2225 {
2226         /* Nothing to be done here */
2227 }
2228
2229 /** Destructor
2230  *
2231  **/
2232 Shader::~Shader()
2233 {
2234         Release();
2235 }
2236
2237 /** Initialize shader instance
2238  *
2239  * @param stage  Shader stage
2240  * @param source Source code
2241  **/
2242 void Shader::Init(STAGES stage, const std::string& source)
2243 {
2244         if (true == source.empty())
2245         {
2246                 /* No source == no shader */
2247                 return;
2248         }
2249
2250         /* Delete any previous shader */
2251         Release();
2252
2253         /* Create, set source and compile */
2254         const Functions& gl = m_context.getRenderContext().getFunctions();
2255
2256         Create(gl, stage, m_id);
2257         Source(gl, m_id, source);
2258
2259         try
2260         {
2261                 Compile(gl, m_id);
2262         }
2263         catch (const CompilationException& exc)
2264         {
2265                 throw InvalidSourceException(exc.what(), source, stage);
2266         }
2267 }
2268
2269 /** Release shader instance
2270  *
2271  **/
2272 void Shader::Release()
2273 {
2274         if (m_invalid_id != m_id)
2275         {
2276                 const Functions& gl = m_context.getRenderContext().getFunctions();
2277
2278                 gl.deleteShader(m_id);
2279                 m_id = m_invalid_id;
2280         }
2281 }
2282
2283 /** Compile shader
2284  *
2285  * @param gl GL functions
2286  * @param id Shader id
2287  **/
2288 void Shader::Compile(const Functions& gl, GLuint id)
2289 {
2290         GLint status = GL_FALSE;
2291
2292         /* Compile */
2293         gl.compileShader(id);
2294         GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
2295
2296         /* Get compilation status */
2297         gl.getShaderiv(id, GL_COMPILE_STATUS, &status);
2298         GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2299
2300         /* Log compilation error */
2301         if (GL_TRUE != status)
2302         {
2303                 glw::GLint  length = 0;
2304                 std::string message;
2305
2306                 /* Error log length */
2307                 gl.getShaderiv(id, GL_INFO_LOG_LENGTH, &length);
2308                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2309
2310                 /* Prepare storage */
2311                 message.resize(length, 0);
2312
2313                 /* Get error log */
2314                 gl.getShaderInfoLog(id, length, 0, &message[0]);
2315                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
2316
2317                 throw CompilationException(message.c_str());
2318         }
2319 }
2320
2321 /** Create shader
2322  *
2323  * @param gl     GL functions
2324  * @param stage  Shader stage
2325  * @param out_id Shader id
2326  **/
2327 void Shader::Create(const Functions& gl, STAGES stage, GLuint& out_id)
2328 {
2329         const GLenum shaderType = GetShaderStageGLenum(stage);
2330         const GLuint id                 = gl.createShader(shaderType);
2331         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
2332
2333         if (m_invalid_id == id)
2334         {
2335                 TCU_FAIL("Failed to create shader");
2336         }
2337
2338         out_id = id;
2339 }
2340
2341 /** Set shader's source code
2342  *
2343  * @param gl     GL functions
2344  * @param id     Shader id
2345  * @param source Shader source code
2346  **/
2347 void Shader::Source(const Functions& gl, GLuint id, const std::string& source)
2348 {
2349         const GLchar* code = source.c_str();
2350
2351         gl.shaderSource(id, 1 /* count */, &code, 0 /* lengths */);
2352         GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
2353 }
2354
2355 /** Get GLenum repesenting shader stage
2356  *
2357  * @param stage Shader stage
2358  *
2359  * @return GLenum
2360  **/
2361 GLenum Shader::GetShaderStageGLenum(STAGES stage)
2362 {
2363         GLenum result = 0;
2364
2365         switch (stage)
2366         {
2367         case COMPUTE:
2368                 result = GL_COMPUTE_SHADER;
2369                 break;
2370         case FRAGMENT:
2371                 result = GL_FRAGMENT_SHADER;
2372                 break;
2373         case GEOMETRY:
2374                 result = GL_GEOMETRY_SHADER;
2375                 break;
2376         case TESS_CTRL:
2377                 result = GL_TESS_CONTROL_SHADER;
2378                 break;
2379         case TESS_EVAL:
2380                 result = GL_TESS_EVALUATION_SHADER;
2381                 break;
2382         case VERTEX:
2383                 result = GL_VERTEX_SHADER;
2384                 break;
2385         default:
2386                 TCU_FAIL("Invalid enum");
2387         }
2388
2389         return result;
2390 }
2391
2392 /** Get string representing name of shader stage
2393  *
2394  * @param stage Shader stage
2395  *
2396  * @return String with name of shader stage
2397  **/
2398 const glw::GLchar* Shader::GetStageName(STAGES stage)
2399 {
2400         const GLchar* result = 0;
2401
2402         switch (stage)
2403         {
2404         case COMPUTE:
2405                 result = "compute";
2406                 break;
2407         case VERTEX:
2408                 result = "vertex";
2409                 break;
2410         case TESS_CTRL:
2411                 result = "tessellation control";
2412                 break;
2413         case TESS_EVAL:
2414                 result = "tessellation evaluation";
2415                 break;
2416         case GEOMETRY:
2417                 result = "geometry";
2418                 break;
2419         case FRAGMENT:
2420                 result = "fragment";
2421                 break;
2422         default:
2423                 TCU_FAIL("Invalid enum");
2424         }
2425
2426         return result;
2427 }
2428
2429 /** Logs shader source
2430  *
2431  * @param context CTS context
2432  * @param source  Source of shader
2433  * @param stage   Shader stage
2434  **/
2435 void Shader::LogSource(deqp::Context& context, const std::string& source, STAGES stage)
2436 {
2437         /* Skip empty shaders */
2438         if (true == source.empty())
2439         {
2440                 return;
2441         }
2442
2443         context.getTestContext().getLog() << tcu::TestLog::Message
2444                                                                           << "Shader source. Stage: " << Shader::GetStageName(stage)
2445                                                                           << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(source);
2446 }
2447
2448 /** Constructor
2449  *
2450  * @param message Compilation error message
2451  **/
2452 Shader::CompilationException::CompilationException(const GLchar* message)
2453 {
2454         m_message = message;
2455 }
2456
2457 /** Returns error messages
2458  *
2459  * @return Compilation error message
2460  **/
2461 const char* Shader::CompilationException::what() const throw()
2462 {
2463         return m_message.c_str();
2464 }
2465
2466 /** Constructor
2467  *
2468  * @param message Compilation error message
2469  **/
2470 Shader::InvalidSourceException::InvalidSourceException(const GLchar* error_message, const std::string& source,
2471                                                                                                            STAGES stage)
2472         : m_message(error_message), m_source(source), m_stage(stage)
2473 {
2474 }
2475
2476 /** Returns error messages
2477  *
2478  * @return Compilation error message
2479  **/
2480 const char* Shader::InvalidSourceException::what() const throw()
2481 {
2482         return "Compilation error";
2483 }
2484
2485 /** Logs error message and shader sources **/
2486 void Shader::InvalidSourceException::log(deqp::Context& context) const
2487 {
2488         context.getTestContext().getLog() << tcu::TestLog::Message << "Failed to compile shader: " << m_message.c_str()
2489                                                                           << tcu::TestLog::EndMessage;
2490
2491         LogSource(context, m_source, m_stage);
2492 }
2493
2494 /* Program constants */
2495 const GLuint Pipeline::m_invalid_id = 0;
2496
2497 /** Constructor.
2498  *
2499  * @param context CTS context.
2500  **/
2501 Pipeline::Pipeline(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2502 {
2503         /* Nothing to be done here */
2504 }
2505
2506 /** Destructor
2507  *
2508  **/
2509 Pipeline::~Pipeline()
2510 {
2511         Release();
2512 }
2513
2514 /** Initialize pipline object
2515  *
2516  **/
2517 void Pipeline::Init()
2518 {
2519         Release();
2520
2521         const Functions& gl = m_context.getRenderContext().getFunctions();
2522
2523         /* Generate */
2524         gl.genProgramPipelines(1, &m_id);
2525         GLU_EXPECT_NO_ERROR(gl.getError(), "GenProgramPipelines");
2526 }
2527
2528 /** Release pipeline object
2529  *
2530  **/
2531 void Pipeline::Release()
2532 {
2533         if (m_invalid_id != m_id)
2534         {
2535                 const Functions& gl = m_context.getRenderContext().getFunctions();
2536
2537                 /* Generate */
2538                 gl.deleteProgramPipelines(1, &m_id);
2539                 GLU_EXPECT_NO_ERROR(gl.getError(), "DeleteProgramPipelines");
2540
2541                 m_id = m_invalid_id;
2542         }
2543 }
2544
2545 /** Bind pipeline
2546  *
2547  **/
2548 void Pipeline::Bind()
2549 {
2550         const Functions& gl = m_context.getRenderContext().getFunctions();
2551
2552         Bind(gl, m_id);
2553 }
2554
2555 /** Set which stages should be active
2556  *
2557  * @param program_id Id of program
2558  * @param stages     Logical combination of enums representing stages
2559  **/
2560 void Pipeline::UseProgramStages(GLuint program_id, GLenum stages)
2561 {
2562         const Functions& gl = m_context.getRenderContext().getFunctions();
2563
2564         UseProgramStages(gl, m_id, program_id, stages);
2565 }
2566
2567 /** Bind pipeline
2568  *
2569  * @param gl Functiions
2570  * @param id Pipeline id
2571  **/
2572 void Pipeline::Bind(const Functions& gl, GLuint id)
2573 {
2574         gl.bindProgramPipeline(id);
2575         GLU_EXPECT_NO_ERROR(gl.getError(), "BindProgramPipeline");
2576 }
2577
2578 /** Set which stages should be active
2579  *
2580  * @param gl         Functiions
2581  * @param id         Pipeline id
2582  * @param program_id Id of program
2583  * @param stages     Logical combination of enums representing stages
2584  **/
2585 void Pipeline::UseProgramStages(const Functions& gl, GLuint id, GLuint program_id, GLenum stages)
2586 {
2587         gl.useProgramStages(id, stages, program_id);
2588         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgramStages");
2589 }
2590
2591 /* Program constants */
2592 const GLuint Program::m_invalid_id = 0;
2593
2594 /** Constructor.
2595  *
2596  * @param context CTS context.
2597  **/
2598 Program::Program(deqp::Context& context)
2599         : m_id(m_invalid_id)
2600         , m_compute(context)
2601         , m_fragment(context)
2602         , m_geometry(context)
2603         , m_tess_ctrl(context)
2604         , m_tess_eval(context)
2605         , m_vertex(context)
2606         , m_context(context)
2607 {
2608         /* Nothing to be done here */
2609 }
2610
2611 /** Destructor
2612  *
2613  **/
2614 Program::~Program()
2615 {
2616         Release();
2617 }
2618
2619 /** Initialize program instance
2620  *
2621  * @param compute_shader                    Compute shader source code
2622  * @param fragment_shader                   Fragment shader source code
2623  * @param geometry_shader                   Geometry shader source code
2624  * @param tessellation_control_shader       Tessellation control shader source code
2625  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2626  * @param vertex_shader                     Vertex shader source code
2627  * @param captured_varyings                 Vector of variables to be captured with transfrom feedback
2628  * @param capture_interleaved               Select mode of transform feedback (separate or interleaved)
2629  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2630  **/
2631 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2632                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2633                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2634                                    const NameVector& captured_varyings, bool capture_interleaved, bool is_separable)
2635 {
2636         /* Delete previous program */
2637         Release();
2638
2639         /* GL entry points */
2640         const Functions& gl = m_context.getRenderContext().getFunctions();
2641
2642         /* Initialize shaders */
2643         m_compute.Init(Shader::COMPUTE, compute_shader);
2644         m_fragment.Init(Shader::FRAGMENT, fragment_shader);
2645         m_geometry.Init(Shader::GEOMETRY, geometry_shader);
2646         m_tess_ctrl.Init(Shader::TESS_CTRL, tessellation_control_shader);
2647         m_tess_eval.Init(Shader::TESS_EVAL, tessellation_evaluation_shader);
2648         m_vertex.Init(Shader::VERTEX, vertex_shader);
2649
2650         /* Create program, set up transform feedback and attach shaders */
2651         Create(gl, m_id);
2652         Capture(gl, m_id, captured_varyings, capture_interleaved);
2653         Attach(gl, m_id, m_compute.m_id);
2654         Attach(gl, m_id, m_fragment.m_id);
2655         Attach(gl, m_id, m_geometry.m_id);
2656         Attach(gl, m_id, m_tess_ctrl.m_id);
2657         Attach(gl, m_id, m_tess_eval.m_id);
2658         Attach(gl, m_id, m_vertex.m_id);
2659
2660         /* Set separable parameter */
2661         if (true == is_separable)
2662         {
2663                 gl.programParameteri(m_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
2664                 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
2665         }
2666
2667         try
2668         {
2669                 /* Link program */
2670                 Link(gl, m_id);
2671         }
2672         catch (const LinkageException& exc)
2673         {
2674                 throw BuildException(exc.what(), compute_shader, fragment_shader, geometry_shader, tessellation_control_shader,
2675                                                          tessellation_evaluation_shader, vertex_shader);
2676         }
2677 }
2678
2679 /** Initialize program instance
2680  *
2681  * @param compute_shader                    Compute shader source code
2682  * @param fragment_shader                   Fragment shader source code
2683  * @param geometry_shader                   Geometry shader source code
2684  * @param tessellation_control_shader       Tessellation control shader source code
2685  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2686  * @param vertex_shader                     Vertex shader source code
2687  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2688  **/
2689 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2690                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2691                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2692                                    bool is_separable)
2693 {
2694         NameVector captured_varying;
2695
2696         Init(compute_shader, fragment_shader, geometry_shader, tessellation_control_shader, tessellation_evaluation_shader,
2697                  vertex_shader, captured_varying, true, is_separable);
2698 }
2699
2700 /** Release program instance
2701  *
2702  **/
2703 void Program::Release()
2704 {
2705         const Functions& gl = m_context.getRenderContext().getFunctions();
2706
2707         if (m_invalid_id != m_id)
2708         {
2709                 Use(gl, m_invalid_id);
2710
2711                 gl.deleteProgram(m_id);
2712                 m_id = m_invalid_id;
2713         }
2714
2715         m_compute.Release();
2716         m_fragment.Release();
2717         m_geometry.Release();
2718         m_tess_ctrl.Release();
2719         m_tess_eval.Release();
2720         m_vertex.Release();
2721 }
2722
2723 /** Get <pname> for a set of active uniforms
2724  *
2725  * @param count   Number of indices
2726  * @param indices Indices of uniforms
2727  * @param pname   Queired pname
2728  * @param params  Array that will be filled with values of parameters
2729  **/
2730 void Program::GetActiveUniformsiv(GLsizei count, const GLuint* indices, GLenum pname, GLint* params) const
2731 {
2732         const Functions& gl = m_context.getRenderContext().getFunctions();
2733
2734         GetActiveUniformsiv(gl, m_id, count, indices, pname, params);
2735 }
2736
2737 /** Get location of attribute
2738  *
2739  * @param name Name of attribute
2740  *
2741  * @return Result of query
2742  **/
2743 glw::GLint Program::GetAttribLocation(const std::string& name) const
2744 {
2745         const Functions& gl = m_context.getRenderContext().getFunctions();
2746
2747         return GetAttribLocation(gl, m_id, name);
2748 }
2749
2750 /** Query resource
2751  *
2752  * @param interface Interface to be queried
2753  * @param index     Index of resource
2754  * @param property  Property to be queried
2755  * @param buf_size  Size of <params> buffer
2756  * @param params    Results of query
2757  **/
2758 void Program::GetResource(GLenum interface, GLuint index, GLenum property, GLsizei buf_size, GLint* params) const
2759 {
2760         const Functions& gl = m_context.getRenderContext().getFunctions();
2761
2762         GetResource(gl, m_id, interface, index, property, buf_size, params);
2763 }
2764
2765 /** Query for index of resource
2766  *
2767  * @param name      Name of resource
2768  * @param interface Interface to be queried
2769  *
2770  * @return Result of query
2771  **/
2772 glw::GLuint Program::GetResourceIndex(const std::string& name, GLenum interface) const
2773 {
2774         const Functions& gl = m_context.getRenderContext().getFunctions();
2775
2776         return GetResourceIndex(gl, m_id, name, interface);
2777 }
2778
2779 /** Get indices for a set of uniforms
2780  *
2781  * @param count   Count number of uniforms
2782  * @param names   Names of uniforms
2783  * @param indices Buffer that will be filled with indices
2784  **/
2785 void Program::GetUniformIndices(GLsizei count, const GLchar** names, GLuint* indices) const
2786 {
2787         const Functions& gl = m_context.getRenderContext().getFunctions();
2788
2789         GetUniformIndices(gl, m_id, count, names, indices);
2790 }
2791
2792 /** Get uniform location
2793  *
2794  * @param name Name of uniform
2795  *
2796  * @return Results of query
2797  **/
2798 glw::GLint Program::GetUniformLocation(const std::string& name) const
2799 {
2800         const Functions& gl = m_context.getRenderContext().getFunctions();
2801
2802         return GetUniformLocation(gl, m_id, name);
2803 }
2804
2805 /** Set program as active
2806  *
2807  **/
2808 void Program::Use() const
2809 {
2810         const Functions& gl = m_context.getRenderContext().getFunctions();
2811
2812         Use(gl, m_id);
2813 }
2814
2815 /** Attach shader to program
2816  *
2817  * @param gl         GL functions
2818  * @param program_id Id of program
2819  * @param shader_id  Id of shader
2820  **/
2821 void Program::Attach(const Functions& gl, GLuint program_id, GLuint shader_id)
2822 {
2823         /* Sanity checks */
2824         if ((m_invalid_id == program_id) || (Shader::m_invalid_id == shader_id))
2825         {
2826                 return;
2827         }
2828
2829         gl.attachShader(program_id, shader_id);
2830         GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
2831 }
2832
2833 /** Set up captured varyings
2834  *
2835  * @param gl                  GL functions
2836  * @param id                  Id of program
2837  * @param captured_varyings   Vector of varyings
2838  * @param capture_interleaved Selects if interleaved or separate mode should be used
2839  **/
2840 void Program::Capture(const Functions& gl, GLuint id, const NameVector& captured_varyings, bool capture_interleaved)
2841 {
2842         const size_t n_varyings = captured_varyings.size();
2843
2844         if (0 == n_varyings)
2845         {
2846                 /* empty list, skip */
2847                 return;
2848         }
2849
2850         std::vector<const GLchar*> varying_names;
2851         varying_names.resize(n_varyings);
2852
2853         for (size_t i = 0; i < n_varyings; ++i)
2854         {
2855                 varying_names[i] = captured_varyings[i].c_str();
2856         }
2857
2858         GLenum mode = 0;
2859         if (true == capture_interleaved)
2860         {
2861                 mode = GL_INTERLEAVED_ATTRIBS;
2862         }
2863         else
2864         {
2865                 mode = GL_SEPARATE_ATTRIBS;
2866         }
2867
2868         gl.transformFeedbackVaryings(id, static_cast<GLsizei>(n_varyings), &varying_names[0], mode);
2869         GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
2870 }
2871
2872 /** Create program instance
2873  *
2874  * @param gl     GL functions
2875  * @param out_id Id of program
2876  **/
2877 void Program::Create(const Functions& gl, GLuint& out_id)
2878 {
2879         const GLuint id = gl.createProgram();
2880         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
2881
2882         if (m_invalid_id == id)
2883         {
2884                 TCU_FAIL("Failed to create program");
2885         }
2886
2887         out_id = id;
2888 }
2889
2890 /** Get <pname> for a set of active uniforms
2891  *
2892  * @param gl         Functions
2893  * @param program_id Id of program
2894  * @param count      Number of indices
2895  * @param indices    Indices of uniforms
2896  * @param pname      Queired pname
2897  * @param params     Array that will be filled with values of parameters
2898  **/
2899 void Program::GetActiveUniformsiv(const Functions& gl, GLuint program_id, GLsizei count, const GLuint* indices,
2900                                                                   GLenum pname, GLint* params)
2901 {
2902         gl.getActiveUniformsiv(program_id, count, indices, pname, params);
2903         GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformsiv");
2904 }
2905
2906 /** Get indices for a set of uniforms
2907  *
2908  * @param gl         Functions
2909  * @param program_id Id of program
2910  * @param count      Count number of uniforms
2911  * @param names      Names of uniforms
2912  * @param indices    Buffer that will be filled with indices
2913  **/
2914 void Program::GetUniformIndices(const Functions& gl, GLuint program_id, GLsizei count, const GLchar** names,
2915                                                                 GLuint* indices)
2916 {
2917         gl.getUniformIndices(program_id, count, names, indices);
2918         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformIndices");
2919 }
2920
2921 /** Link program
2922  *
2923  * @param gl GL functions
2924  * @param id Id of program
2925  **/
2926 void Program::Link(const Functions& gl, GLuint id)
2927 {
2928         GLint status = GL_FALSE;
2929
2930         gl.linkProgram(id);
2931         GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
2932
2933         /* Get link status */
2934         gl.getProgramiv(id, GL_LINK_STATUS, &status);
2935         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2936
2937         /* Log link error */
2938         if (GL_TRUE != status)
2939         {
2940                 glw::GLint  length = 0;
2941                 std::string message;
2942
2943                 /* Get error log length */
2944                 gl.getProgramiv(id, GL_INFO_LOG_LENGTH, &length);
2945                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2946
2947                 message.resize(length, 0);
2948
2949                 /* Get error log */
2950                 gl.getProgramInfoLog(id, length, 0, &message[0]);
2951                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
2952
2953                 throw LinkageException(message.c_str());
2954         }
2955 }
2956
2957 /** Set generic uniform
2958  *
2959  * @param gl       Functions
2960  * @param type     Type of uniform
2961  * @param count    Length of array
2962  * @param location Location of uniform
2963  * @param data     Data that will be used
2964  **/
2965 void Program::Uniform(const Functions& gl, const Type& type, GLsizei count, GLint location, const GLvoid* data)
2966 {
2967         if (-1 == location)
2968         {
2969                 TCU_FAIL("Uniform is inactive");
2970         }
2971
2972         switch (type.m_basic_type)
2973         {
2974         case Type::Double:
2975                 if (1 == type.m_n_columns)
2976                 {
2977                         getUniformNdv(gl, type.m_n_rows)(location, count, (const GLdouble*)data);
2978                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
2979                 }
2980                 else
2981                 {
2982                         getUniformMatrixNdv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLdouble*)data);
2983                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
2984                 }
2985                 break;
2986         case Type::Float:
2987                 if (1 == type.m_n_columns)
2988                 {
2989                         getUniformNfv(gl, type.m_n_rows)(location, count, (const GLfloat*)data);
2990                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
2991                 }
2992                 else
2993                 {
2994                         getUniformMatrixNfv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLfloat*)data);
2995                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
2996                 }
2997                 break;
2998         case Type::Int:
2999                 getUniformNiv(gl, type.m_n_rows)(location, count, (const GLint*)data);
3000                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
3001                 break;
3002         case Type::Uint:
3003                 getUniformNuiv(gl, type.m_n_rows)(location, count, (const GLuint*)data);
3004                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
3005                 break;
3006         default:
3007                 TCU_FAIL("Invalid enum");
3008         }
3009 }
3010
3011 /** Use program
3012  *
3013  * @param gl GL functions
3014  * @param id Id of program
3015  **/
3016 void Program::Use(const Functions& gl, GLuint id)
3017 {
3018         gl.useProgram(id);
3019         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
3020 }
3021
3022 /** Get location of attribute
3023  *
3024  * @param gl   GL functions
3025  * @param id   Id of program
3026  * @param name Name of attribute
3027  *
3028  * @return Location of attribute
3029  **/
3030 GLint Program::GetAttribLocation(const Functions& gl, GLuint id, const std::string& name)
3031 {
3032         GLint location = gl.getAttribLocation(id, name.c_str());
3033         GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
3034
3035         return location;
3036 }
3037
3038 /** Query resource
3039  *
3040  * @param gl        GL functions
3041  * @param id        Id of program
3042  * @param interface Interface to be queried
3043  * @param index     Index of resource
3044  * @param property  Property to be queried
3045  * @param buf_size  Size of <params> buffer
3046  * @param params    Results of query
3047  **/
3048 void Program::GetResource(const Functions& gl, GLuint id, GLenum interface, GLuint index, GLenum property,
3049                                                   GLsizei buf_size, GLint* params)
3050 {
3051         gl.getProgramResourceiv(id, interface, index, 1 /* propCount */, &property, buf_size /* bufSize */, 0 /* length */,
3052                                                         params);
3053         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceiv");
3054 }
3055
3056 /** Get index of resource
3057  *
3058  * @param gl        GL functions
3059  * @param id        Id of program
3060  * @param name      Name of resource
3061  * @param interface Program interface to queried
3062  *
3063  * @return Location of attribute
3064  **/
3065 GLuint Program::GetResourceIndex(const Functions& gl, GLuint id, const std::string& name, GLenum interface)
3066 {
3067         GLuint index = gl.getProgramResourceIndex(id, interface, name.c_str());
3068         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceIndex");
3069
3070         return index;
3071 }
3072
3073 /** Get location of attribute
3074  *
3075  * @param gl   GL functions
3076  * @param id   Id of program
3077  * @param name Name of attribute
3078  *
3079  * @return Location of uniform
3080  **/
3081 GLint Program::GetUniformLocation(const Functions& gl, GLuint id, const std::string& name)
3082 {
3083         GLint location = gl.getUniformLocation(id, name.c_str());
3084         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
3085
3086         return location;
3087 }
3088
3089 /** Constructor
3090  *
3091  * @param error_message    Error message
3092  * @param compute_shader   Source code for compute stage
3093  * @param fragment_shader  Source code for fragment stage
3094  * @param geometry_shader  Source code for geometry stage
3095  * @param tess_ctrl_shader Source code for tessellation control stage
3096  * @param tess_eval_shader Source code for tessellation evaluation stage
3097  * @param vertex_shader    Source code for vertex stage
3098  **/
3099 Program::BuildException::BuildException(const glw::GLchar* error_message, const std::string compute_shader,
3100                                                                                 const std::string fragment_shader, const std::string geometry_shader,
3101                                                                                 const std::string tess_ctrl_shader, const std::string tess_eval_shader,
3102                                                                                 const std::string vertex_shader)
3103         : m_error_message(error_message)
3104         , m_compute_shader(compute_shader)
3105         , m_fragment_shader(fragment_shader)
3106         , m_geometry_shader(geometry_shader)
3107         , m_tess_ctrl_shader(tess_ctrl_shader)
3108         , m_tess_eval_shader(tess_eval_shader)
3109         , m_vertex_shader(vertex_shader)
3110 {
3111 }
3112
3113 /** Overwrites std::exception::what method
3114  *
3115  * @return Message compossed from error message and shader sources
3116  **/
3117 const char* Program::BuildException::what() const throw()
3118 {
3119         return "Failed to link program";
3120 }
3121
3122 /** Logs error message and shader sources **/
3123 void Program::BuildException::log(deqp::Context& context) const
3124 {
3125         context.getTestContext().getLog() << tcu::TestLog::Message << "Link failure: " << m_error_message
3126                                                                           << tcu::TestLog::EndMessage;
3127
3128         Shader::LogSource(context, m_vertex_shader, Shader::VERTEX);
3129         Shader::LogSource(context, m_tess_ctrl_shader, Shader::TESS_CTRL);
3130         Shader::LogSource(context, m_tess_eval_shader, Shader::TESS_EVAL);
3131         Shader::LogSource(context, m_geometry_shader, Shader::GEOMETRY);
3132         Shader::LogSource(context, m_fragment_shader, Shader::FRAGMENT);
3133         Shader::LogSource(context, m_compute_shader, Shader::COMPUTE);
3134 }
3135
3136 /** Constructor
3137  *
3138  * @param message Linking error message
3139  **/
3140 Program::LinkageException::LinkageException(const glw::GLchar* message) : m_error_message(message)
3141 {
3142         /* Nothing to be done */
3143 }
3144
3145 /** Returns error messages
3146  *
3147  * @return Linking error message
3148  **/
3149 const char* Program::LinkageException::what() const throw()
3150 {
3151         return m_error_message.c_str();
3152 }
3153
3154 /* Texture constants */
3155 const GLuint Texture::m_invalid_id = -1;
3156
3157 /** Constructor.
3158  *
3159  * @param context CTS context.
3160  **/
3161 Texture::Texture(deqp::Context& context) : m_id(m_invalid_id), m_context(context), m_type(TEX_2D)
3162 {
3163         /* Nothing to done here */
3164 }
3165
3166 /** Destructor
3167  *
3168  **/
3169 Texture::~Texture()
3170 {
3171         Release();
3172 }
3173
3174 /** Initialize texture instance
3175  *
3176  * @param tex_type        Type of texture
3177  * @param width           Width of texture
3178  * @param height          Height of texture
3179  * @param depth           Depth of texture
3180  * @param internal_format Internal format of texture
3181  * @param format          Format of texture data
3182  * @param type            Type of texture data
3183  * @param data            Texture data
3184  **/
3185 void Texture::Init(TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum internal_format, GLenum format,
3186                                    GLenum type, GLvoid* data)
3187 {
3188         const Functions& gl = m_context.getRenderContext().getFunctions();
3189
3190         /* Delete previous texture */
3191         Release();
3192
3193         m_type = tex_type;
3194
3195         /* Generate, bind, allocate storage and upload data */
3196         Generate(gl, m_id);
3197         Bind(gl, m_id, tex_type);
3198         Storage(gl, tex_type, width, height, depth, internal_format);
3199         Update(gl, tex_type, width, height, depth, format, type, data);
3200 }
3201
3202 /** Initialize buffer texture
3203  *
3204  * @param internal_format Internal format of texture
3205  * @param buffer_id       Id of buffer that will be used as data source
3206  **/
3207 void Texture::Init(GLenum internal_format, GLuint buffer_id)
3208 {
3209         const Functions& gl = m_context.getRenderContext().getFunctions();
3210
3211         /* Delete previous texture */
3212         Release();
3213
3214         m_type = TEX_BUFFER;
3215
3216         /* Generate, bind and attach buffer */
3217         Generate(gl, m_id);
3218         Bind(gl, m_id, TEX_BUFFER);
3219         TexBuffer(gl, buffer_id, internal_format);
3220 }
3221
3222 /** Release texture instance
3223  *
3224  **/
3225 void Texture::Release()
3226 {
3227         if (m_invalid_id != m_id)
3228         {
3229                 const Functions& gl = m_context.getRenderContext().getFunctions();
3230
3231                 gl.deleteTextures(1, &m_id);
3232                 m_id = m_invalid_id;
3233         }
3234 }
3235
3236 /** Bind texture to its target
3237  *
3238  **/
3239 void Texture::Bind() const
3240 {
3241         const Functions& gl = m_context.getRenderContext().getFunctions();
3242
3243         Bind(gl, m_id, m_type);
3244 }
3245
3246 /** Get texture data
3247  *
3248  * @param format   Format of data
3249  * @param type     Type of data
3250  * @param out_data Buffer for data
3251  **/
3252 void Texture::Get(GLenum format, GLenum type, GLvoid* out_data) const
3253 {
3254         const Functions& gl = m_context.getRenderContext().getFunctions();
3255
3256         Bind(gl, m_id, m_type);
3257         Get(gl, m_type, format, type, out_data);
3258 }
3259
3260 /** Bind texture to target
3261  *
3262  * @param gl       GL functions
3263  * @param id       Id of texture
3264  * @param tex_type Type of texture
3265  **/
3266 void Texture::Bind(const Functions& gl, GLuint id, TYPES tex_type)
3267 {
3268         GLenum target = GetTargetGLenum(tex_type);
3269
3270         gl.bindTexture(target, id);
3271         GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
3272 }
3273
3274 /** Generate texture instance
3275  *
3276  * @param gl     GL functions
3277  * @param out_id Id of texture
3278  **/
3279 void Texture::Generate(const Functions& gl, GLuint& out_id)
3280 {
3281         GLuint id = m_invalid_id;
3282
3283         gl.genTextures(1, &id);
3284         GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
3285
3286         if (m_invalid_id == id)
3287         {
3288                 TCU_FAIL("Invalid id");
3289         }
3290
3291         out_id = id;
3292 }
3293
3294 /** Get texture data
3295  *
3296  * @param gl       GL functions
3297  * @param format   Format of data
3298  * @param type     Type of data
3299  * @param out_data Buffer for data
3300  **/
3301 void Texture::Get(const Functions& gl, TYPES tex_type, GLenum format, GLenum type, GLvoid* out_data)
3302 {
3303         GLenum target = GetTargetGLenum(tex_type);
3304
3305         if (TEX_CUBE != tex_type)
3306         {
3307                 gl.getTexImage(target, 0 /* level */, format, type, out_data);
3308                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3309         }
3310         else
3311         {
3312                 GLint width;
3313                 GLint height;
3314
3315                 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
3316                 {
3317                         TCU_FAIL("Not implemented");
3318                 }
3319
3320                 GLuint texel_size = 4;
3321
3322                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
3323                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3324
3325                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
3326                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3327
3328                 const GLuint image_size = width * height * texel_size;
3329
3330                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
3331                                            (GLvoid*)((GLchar*)out_data + (image_size * 0)));
3332                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
3333                                            (GLvoid*)((GLchar*)out_data + (image_size * 1)));
3334                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
3335                                            (GLvoid*)((GLchar*)out_data + (image_size * 2)));
3336                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
3337                                            (GLvoid*)((GLchar*)out_data + (image_size * 3)));
3338                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
3339                                            (GLvoid*)((GLchar*)out_data + (image_size * 4)));
3340                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
3341                                            (GLvoid*)((GLchar*)out_data + (image_size * 5)));
3342                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3343         }
3344 }
3345
3346 /** Allocate storage for texture
3347  *
3348  * @param gl              GL functions
3349  * @param tex_type        Type of texture
3350  * @param width           Width of texture
3351  * @param height          Height of texture
3352  * @param depth           Depth of texture
3353  * @param internal_format Internal format of texture
3354  **/
3355 void Texture::Storage(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth,
3356                                           GLenum internal_format)
3357 {
3358         static const GLuint levels = 1;
3359
3360         GLenum target = GetTargetGLenum(tex_type);
3361
3362         switch (tex_type)
3363         {
3364         case TEX_1D:
3365                 gl.texStorage1D(target, levels, internal_format, width);
3366                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3367                 break;
3368         case TEX_2D:
3369         case TEX_1D_ARRAY:
3370         case TEX_2D_RECT:
3371         case TEX_CUBE:
3372                 gl.texStorage2D(target, levels, internal_format, width, height);
3373                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3374                 break;
3375         case TEX_3D:
3376         case TEX_2D_ARRAY:
3377                 gl.texStorage3D(target, levels, internal_format, width, height, depth);
3378                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3379                 break;
3380         default:
3381                 TCU_FAIL("Invliad enum");
3382                 break;
3383         }
3384 }
3385
3386 /** Attach buffer as source of texture buffer data
3387  *
3388  * @param gl              GL functions
3389  * @param internal_format Internal format of texture
3390  * @param buffer_id       Id of buffer that will be used as data source
3391  **/
3392 void Texture::TexBuffer(const Functions& gl, GLenum internal_format, GLuint& buffer_id)
3393 {
3394         gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
3395         GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
3396 }
3397
3398 /** Update contents of texture
3399  *
3400  * @param gl       GL functions
3401  * @param tex_type Type of texture
3402  * @param width    Width of texture
3403  * @param height   Height of texture
3404  * @param format   Format of data
3405  * @param type     Type of data
3406  * @param data     Buffer with image data
3407  **/
3408 void Texture::Update(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum format,
3409                                          GLenum type, GLvoid* data)
3410 {
3411         static const GLuint level = 0;
3412
3413         GLenum target = GetTargetGLenum(tex_type);
3414
3415         switch (tex_type)
3416         {
3417         case TEX_1D:
3418                 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
3419                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3420                 break;
3421         case TEX_2D:
3422         case TEX_1D_ARRAY:
3423         case TEX_2D_RECT:
3424                 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
3425                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3426                 break;
3427         case TEX_CUBE:
3428                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3429                                                  data);
3430                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3431                                                  data);
3432                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3433                                                  data);
3434                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3435                                                  data);
3436                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3437                                                  data);
3438                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3439                                                  data);
3440                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3441                 break;
3442         case TEX_3D:
3443         case TEX_2D_ARRAY:
3444                 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
3445                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3446                 break;
3447         default:
3448                 TCU_FAIL("Invliad enum");
3449                 break;
3450         }
3451 }
3452
3453 /** Get target for given texture type
3454  *
3455  * @param type Type of texture
3456  *
3457  * @return Target
3458  **/
3459 GLenum Texture::GetTargetGLenum(TYPES type)
3460 {
3461         GLenum result = 0;
3462
3463         switch (type)
3464         {
3465         case TEX_BUFFER:
3466                 result = GL_TEXTURE_BUFFER;
3467                 break;
3468         case TEX_2D:
3469                 result = GL_TEXTURE_2D;
3470                 break;
3471         case TEX_2D_RECT:
3472                 result = GL_TEXTURE_RECTANGLE;
3473                 break;
3474         case TEX_2D_ARRAY:
3475                 result = GL_TEXTURE_2D_ARRAY;
3476                 break;
3477         case TEX_3D:
3478                 result = GL_TEXTURE_3D;
3479                 break;
3480         case TEX_CUBE:
3481                 result = GL_TEXTURE_CUBE_MAP;
3482                 break;
3483         case TEX_1D:
3484                 result = GL_TEXTURE_1D;
3485                 break;
3486         case TEX_1D_ARRAY:
3487                 result = GL_TEXTURE_1D_ARRAY;
3488                 break;
3489         }
3490
3491         return result;
3492 }
3493
3494 /* VertexArray constants */
3495 const GLuint VertexArray::m_invalid_id = -1;
3496
3497 /** Constructor.
3498  *
3499  * @param context CTS context.
3500  **/
3501 VertexArray::VertexArray(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
3502 {
3503 }
3504
3505 /** Destructor
3506  *
3507  **/
3508 VertexArray::~VertexArray()
3509 {
3510         Release();
3511 }
3512
3513 /** Initialize vertex array instance
3514  *
3515  **/
3516 void VertexArray::Init()
3517 {
3518         /* Delete previous instance */
3519         Release();
3520
3521         const Functions& gl = m_context.getRenderContext().getFunctions();
3522
3523         Generate(gl, m_id);
3524 }
3525
3526 /** Release vertex array object instance
3527  *
3528  **/
3529 void VertexArray::Release()
3530 {
3531         if (m_invalid_id != m_id)
3532         {
3533                 const Functions& gl = m_context.getRenderContext().getFunctions();
3534
3535                 gl.deleteVertexArrays(1, &m_id);
3536
3537                 m_id = m_invalid_id;
3538         }
3539 }
3540
3541 /** Set attribute in VAO
3542  *
3543  * @param index            Index of attribute
3544  * @param type             Type of attribute
3545  * @param n_array_elements Arary length
3546  * @param normalized       Selectis if values should be normalized
3547  * @param stride           Stride
3548  * @param pointer          Pointer to data, or offset in buffer
3549  **/
3550 void VertexArray::Attribute(GLuint index, const Type& type, GLuint n_array_elements, GLboolean normalized,
3551                                                         GLsizei stride, const GLvoid* pointer)
3552 {
3553         const Functions& gl = m_context.getRenderContext().getFunctions();
3554
3555         AttribPointer(gl, index, type, n_array_elements, normalized, stride, pointer);
3556         Enable(gl, index, type, n_array_elements);
3557 }
3558
3559 /** Binds Vertex array object
3560  *
3561  **/
3562 void VertexArray::Bind()
3563 {
3564         const Functions& gl = m_context.getRenderContext().getFunctions();
3565
3566         Bind(gl, m_id);
3567 }
3568
3569 /** Set attribute in VAO
3570  *
3571  * @param gl               Functions
3572  * @param index            Index of attribute
3573  * @param type             Type of attribute
3574  * @param n_array_elements Arary length
3575  * @param normalized       Selectis if values should be normalized
3576  * @param stride           Stride
3577  * @param pointer          Pointer to data, or offset in buffer
3578  **/
3579 void VertexArray::AttribPointer(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements,
3580                                                                 GLboolean normalized, GLsizei stride, const GLvoid* pointer)
3581 {
3582         const GLuint basic_type_size = Type::GetTypeSize(type.m_basic_type);
3583         const GLint  size                        = (GLint)type.m_n_rows;
3584         const GLuint column_size         = (GLuint)size * basic_type_size;
3585         const GLenum gl_type             = Type::GetTypeGLenum(type.m_basic_type);
3586
3587         GLuint offset = 0;
3588
3589         /* If attribute is not an array */
3590         if (0 == n_array_elements)
3591         {
3592                 n_array_elements = 1;
3593         }
3594
3595         /* For each element in array */
3596         for (GLuint element = 0; element < n_array_elements; ++element)
3597         {
3598                 /* For each column in matrix */
3599                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3600                 {
3601                         /* Calculate offset */
3602                         const GLvoid* ptr = (GLubyte*)pointer + offset;
3603
3604                         /* Set up attribute */
3605                         switch (type.m_basic_type)
3606                         {
3607                         case Type::Float:
3608                                 gl.vertexAttribPointer(index, size, gl_type, normalized, stride, ptr);
3609                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3610                                 break;
3611                         case Type::Int:
3612                         case Type::Uint:
3613                                 gl.vertexAttribIPointer(index, size, gl_type, stride, ptr);
3614                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
3615                                 break;
3616                         case Type::Double:
3617                                 gl.vertexAttribLPointer(index, size, gl_type, stride, ptr);
3618                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribLPointer");
3619                                 break;
3620                         default:
3621                                 TCU_FAIL("Invalid enum");
3622                         }
3623
3624                         /* Next location */
3625                         offset += column_size;
3626                         index += 1;
3627                 }
3628         }
3629 }
3630
3631 /** Binds Vertex array object
3632  *
3633  * @param gl GL functions
3634  * @param id ID of vertex array object
3635  **/
3636 void VertexArray::Bind(const glw::Functions& gl, glw::GLuint id)
3637 {
3638         gl.bindVertexArray(id);
3639         GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
3640 }
3641
3642 /** Disable attribute in VAO
3643  *
3644  * @param gl               Functions
3645  * @param index            Index of attribute
3646  * @param type             Type of attribute
3647  * @param n_array_elements Arary length
3648  **/
3649 void VertexArray::Disable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3650 {
3651         /* If attribute is not an array */
3652         if (0 == n_array_elements)
3653         {
3654                 n_array_elements = 1;
3655         }
3656
3657         /* For each element in array */
3658         for (GLuint element = 0; element < n_array_elements; ++element)
3659         {
3660                 /* For each column in matrix */
3661                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3662                 {
3663                         /* Enable attribute array */
3664                         gl.disableVertexAttribArray(index);
3665                         GLU_EXPECT_NO_ERROR(gl.getError(), "DisableVertexAttribArray");
3666
3667                         /* Next location */
3668                         index += 1;
3669                 }
3670         }
3671 }
3672
3673 /** Set divisor for attribute
3674  *
3675  * @param gl               Functions
3676  * @param index            Index of attribute
3677  * @param divisor          New divisor value
3678  **/
3679 void VertexArray::Divisor(const Functions& gl, GLuint index, GLuint divisor)
3680 {
3681         gl.vertexAttribDivisor(index, divisor);
3682         GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribDivisor");
3683 }
3684
3685 /** Enables attribute in VAO
3686  *
3687  * @param gl               Functions
3688  * @param index            Index of attribute
3689  * @param type             Type of attribute
3690  * @param n_array_elements Arary length
3691  **/
3692 void VertexArray::Enable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3693 {
3694         /* If attribute is not an array */
3695         if (0 == n_array_elements)
3696         {
3697                 n_array_elements = 1;
3698         }
3699
3700         /* For each element in array */
3701         for (GLuint element = 0; element < n_array_elements; ++element)
3702         {
3703                 /* For each column in matrix */
3704                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3705                 {
3706                         /* Enable attribute array */
3707                         gl.enableVertexAttribArray(index);
3708                         GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3709
3710                         /* Next location */
3711                         index += 1;
3712                 }
3713         }
3714 }
3715
3716 /** Generates Vertex array object
3717  *
3718  * @param gl     GL functions
3719  * @param out_id ID of vertex array object
3720  **/
3721 void VertexArray::Generate(const glw::Functions& gl, glw::GLuint& out_id)
3722 {
3723         GLuint id = m_invalid_id;
3724
3725         gl.genVertexArrays(1, &id);
3726         GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
3727
3728         if (m_invalid_id == id)
3729         {
3730                 TCU_FAIL("Invalid id");
3731         }
3732
3733         out_id = id;
3734 }
3735
3736 /* Constatns used by Variable */
3737 const GLint Variable::m_automatic_location = -1;
3738
3739 /** Copy constructor
3740  *
3741  **/
3742 Variable::Variable(const Variable& var)
3743         : m_data(var.m_data)
3744         , m_data_size(var.m_data_size)
3745         , m_descriptor(var.m_descriptor.m_name.c_str(), var.m_descriptor.m_qualifiers.c_str(),
3746                                    var.m_descriptor.m_expected_component, var.m_descriptor.m_expected_location,
3747                                    var.m_descriptor.m_builtin, var.m_descriptor.m_normalized, var.m_descriptor.m_n_array_elements,
3748                                    var.m_descriptor.m_expected_stride_of_element, var.m_descriptor.m_offset)
3749         , m_storage(var.m_storage)
3750 {
3751         m_descriptor.m_type = var.m_descriptor.m_type;
3752
3753         if (BUILTIN != var.m_descriptor.m_type)
3754         {
3755                 m_descriptor.m_interface = var.m_descriptor.m_interface;
3756         }
3757 }
3758
3759 /** Get code that defines variable
3760  *
3761  * @param flavour Provides info if variable is array or not
3762  *
3763  * @return String with code
3764  **/
3765 std::string Variable::GetDefinition(FLAVOUR flavour) const
3766 {
3767         return m_descriptor.GetDefinition(flavour, m_storage);
3768 }
3769
3770 /** Calcualtes stride of variable
3771  *
3772  * @return Calculated value
3773  **/
3774 GLuint Variable::GetStride() const
3775 {
3776         GLint variable_stride = 0;
3777
3778         if (0 == m_descriptor.m_n_array_elements)
3779         {
3780                 variable_stride = m_descriptor.m_expected_stride_of_element;
3781         }
3782         else
3783         {
3784                 variable_stride = m_descriptor.m_expected_stride_of_element * m_descriptor.m_n_array_elements;
3785         }
3786
3787         return variable_stride;
3788 }
3789
3790 /** Check if variable is block
3791  *
3792  * @return true if variable type is block, false otherwise
3793  **/
3794 bool Variable::IsBlock() const
3795 {
3796         if (BUILTIN == m_descriptor.m_type)
3797         {
3798                 return false;
3799         }
3800
3801         const Interface* interface = m_descriptor.m_interface;
3802         if (0 == interface)
3803         {
3804                 TCU_FAIL("Nullptr");
3805         }
3806
3807         return (Interface::BLOCK == interface->m_type);
3808 }
3809
3810 /** Check if variable is struct
3811  *
3812  * @return true if variable type is struct, false otherwise
3813  **/
3814 bool Variable::IsStruct() const
3815 {
3816         if (BUILTIN == m_descriptor.m_type)
3817         {
3818                 return false;
3819         }
3820
3821         const Interface* interface = m_descriptor.m_interface;
3822         if (0 == interface)
3823         {
3824                 TCU_FAIL("Nullptr");
3825         }
3826
3827         return (Interface::STRUCT == interface->m_type);
3828 }
3829 /** Get code that reference variable
3830  *
3831  * @param parent_name Name of parent
3832  * @param variable    Descriptor of variable
3833  * @param flavour     Provides info about how variable should be referenced
3834  * @param array_index Index of array, ignored when variable is not array
3835  *
3836  * @return String with code
3837  **/
3838 std::string Variable::GetReference(const std::string& parent_name, const Descriptor& variable, FLAVOUR flavour,
3839                                                                    GLuint array_index)
3840 {
3841         std::string name;
3842
3843         /* Prepare name */
3844         if (false == parent_name.empty())
3845         {
3846                 name = parent_name;
3847                 name.append(".");
3848                 name.append(variable.m_name);
3849         }
3850         else
3851         {
3852                 name = variable.m_name;
3853         }
3854
3855         /* */
3856         switch (flavour)
3857         {
3858         case Utils::Variable::BASIC:
3859                 break;
3860
3861         case Utils::Variable::ARRAY:
3862                 name.append("[0]");
3863                 break;
3864
3865         case Utils::Variable::INDEXED_BY_INVOCATION_ID:
3866                 name.append("[gl_InvocationID]");
3867                 break;
3868         }
3869
3870         /* Assumption that both variables have same lengths */
3871         if (0 != variable.m_n_array_elements)
3872         {
3873                 GLchar buffer[16];
3874                 sprintf(buffer, "%d", array_index);
3875                 name.append("[");
3876                 name.append(buffer);
3877                 name.append("]");
3878         }
3879
3880         return name;
3881 }
3882
3883 /** Get "flavour" of varying
3884  *
3885  * @param stage     Stage of shader
3886  * @param direction Selects if varying is in or out
3887  *
3888  * @return Flavour
3889  **/
3890 Variable::FLAVOUR Variable::GetFlavour(Shader::STAGES stage, VARYING_DIRECTION direction)
3891 {
3892         FLAVOUR result = BASIC;
3893
3894         switch (stage)
3895         {
3896         case Shader::GEOMETRY:
3897         case Shader::TESS_EVAL:
3898                 if (INPUT == direction)
3899                 {
3900                         result = ARRAY;
3901                 }
3902                 break;
3903         case Shader::TESS_CTRL:
3904                 result = INDEXED_BY_INVOCATION_ID;
3905                 break;
3906         default:
3907                 break;
3908         }
3909
3910         return result;
3911 }
3912
3913 /** Constructor, for built-in types
3914  *
3915  * @param name                       Name
3916  * @param qualifiers                 Qualifiers
3917  * @param expected_component         Expected component of variable
3918  * @param expected_location          Expected location
3919  * @param type                       Type
3920  * @param normalized                 Selects if data should be normalized
3921  * @param n_array_elements           Length of array
3922  * @param expected_stride_of_element Expected stride of element
3923  * @param offset                     Offset
3924  **/
3925 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
3926                                                                  GLint expected_location, const Type& type, GLboolean normalized,
3927                                                                  GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
3928         : m_expected_component(expected_component)
3929         , m_expected_location(expected_location)
3930         , m_expected_stride_of_element(expected_stride_of_element)
3931         , m_n_array_elements(n_array_elements)
3932         , m_name(name)
3933         , m_normalized(normalized)
3934         , m_offset(offset)
3935         , m_qualifiers(qualifiers)
3936         , m_type(BUILTIN)
3937         , m_builtin(type)
3938 {
3939 }
3940
3941 /** Constructor, for interface types
3942  *
3943  * @param name                       Name
3944  * @param qualifiers                 Qualifiers
3945  * @param expected_component         Expected component of variable
3946  * @param expected_location          Expected location
3947  * @param interface                  Interface of variable
3948  * @param n_array_elements           Length of array
3949  * @param expected_stride_of_element Expected stride of element
3950  * @param offset                     Offset
3951  **/
3952 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_componenet,
3953                                                                  GLint expected_location, Interface* interface, GLuint n_array_elements,
3954                                                                  GLint expected_stride_of_element, GLuint offset)
3955         : m_expected_component(expected_componenet)
3956         , m_expected_location(expected_location)
3957         , m_expected_stride_of_element(expected_stride_of_element)
3958         , m_n_array_elements(n_array_elements)
3959         , m_name(name)
3960         , m_normalized(GL_FALSE)
3961         , m_offset(offset)
3962         , m_qualifiers(qualifiers)
3963         , m_type(INTERFACE)
3964         , m_interface(interface)
3965 {
3966 }
3967
3968 /** Get definition of variable
3969  *
3970  * @param flavour Flavour of variable
3971  * @param storage Storage used for variable
3972  *
3973  * @return code with defintion
3974  **/
3975 std::string Variable::Descriptor::GetDefinition(FLAVOUR flavour, STORAGE storage) const
3976 {
3977         static const GLchar* basic_template = "QUALIFIERS STORAGETYPE NAMEARRAY;";
3978         static const GLchar* array_template = "QUALIFIERS STORAGETYPE NAME[]ARRAY;";
3979         const GLchar*            storage_str    = 0;
3980
3981         std::string definition;
3982         size_t          position = 0;
3983
3984         /* Select definition template */
3985         switch (flavour)
3986         {
3987         case BASIC:
3988                 definition = basic_template;
3989                 break;
3990         case ARRAY:
3991         case INDEXED_BY_INVOCATION_ID:
3992                 definition = array_template;
3993                 break;
3994         default:
3995                 TCU_FAIL("Invliad enum");
3996                 break;
3997         }
3998
3999         if (BUILTIN != m_type)
4000         {
4001                 if (0 == m_interface)
4002                 {
4003                         TCU_FAIL("Nullptr");
4004                 }
4005         }
4006
4007         /* Qualifiers */
4008         if (true == m_qualifiers.empty())
4009         {
4010                 replaceToken("QUALIFIERS ", position, "", definition);
4011         }
4012         else
4013         {
4014                 replaceToken("QUALIFIERS", position, m_qualifiers.c_str(), definition);
4015         }
4016
4017         // According to spec: integer or unsigned integer type must always be declared with flat qualifier
4018         bool flat_qualifier = false;
4019         if (m_type != BUILTIN && m_interface != NULL)
4020         {
4021                 if (m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Int ||
4022                         m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Uint)
4023                 {
4024                         flat_qualifier = true;
4025                 }
4026         }
4027         /* Storage */
4028         switch (storage)
4029         {
4030         case VARYING_INPUT:
4031                 storage_str = flat_qualifier ? "flat in " : "in ";
4032                 break;
4033         case VARYING_OUTPUT:
4034                 storage_str = "out ";
4035                 break;
4036         case UNIFORM:
4037                 storage_str = "uniform ";
4038                 break;
4039         case SSB:
4040                 storage_str = "buffer ";
4041                 break;
4042         case MEMBER:
4043                 storage_str = "";
4044                 break;
4045         default:
4046                 TCU_FAIL("Invalid enum");
4047                 break;
4048         }
4049
4050         replaceToken("STORAGE", position, storage_str, definition);
4051
4052         /* Type */
4053         if (BUILTIN == m_type)
4054         {
4055                 replaceToken("TYPE", position, m_builtin.GetGLSLTypeName(), definition);
4056         }
4057         else
4058         {
4059                 if (Interface::STRUCT == m_interface->m_type)
4060                 {
4061                         replaceToken("TYPE", position, m_interface->m_name.c_str(), definition);
4062                 }
4063                 else
4064                 {
4065                         const std::string& block_definition = m_interface->GetDefinition();
4066
4067                         replaceToken("TYPE", position, block_definition.c_str(), definition);
4068                 }
4069         }
4070
4071         /* Name */
4072         replaceToken("NAME", position, m_name.c_str(), definition);
4073
4074         /* Array size */
4075         if (0 == m_n_array_elements)
4076         {
4077                 replaceToken("ARRAY", position, "", definition);
4078         }
4079         else
4080         {
4081                 char buffer[16];
4082                 sprintf(buffer, "[%d]", m_n_array_elements);
4083
4084                 replaceToken("ARRAY", position, buffer, definition);
4085         }
4086
4087         /* Done */
4088         return definition;
4089 }
4090
4091 /** Get definitions for variables collected in vector
4092  *
4093  * @param vector  Collection of variables
4094  * @param flavour Flavour of variables
4095  *
4096  * @return Code with definitions
4097  **/
4098 std::string GetDefinitions(const Variable::PtrVector& vector, Variable::FLAVOUR flavour)
4099 {
4100         std::string list         = Utils::g_list;
4101         size_t          position = 0;
4102
4103         for (GLuint i = 0; i < vector.size(); ++i)
4104         {
4105                 Utils::insertElementOfList(vector[i]->GetDefinition(flavour).c_str(), "\n", position, list);
4106         }
4107
4108         Utils::endList("", position, list);
4109
4110         return list;
4111 }
4112
4113 /** Get definitions for interfaces collected in vector
4114  *
4115  * @param vector Collection of interfaces
4116  *
4117  * @return Code with definitions
4118  **/
4119 std::string GetDefinitions(const Interface::PtrVector& vector)
4120 {
4121         std::string list         = Utils::g_list;
4122         size_t          position = 0;
4123
4124         for (GLuint i = 0; i < vector.size(); ++i)
4125         {
4126                 Utils::insertElementOfList(vector[i]->GetDefinition().c_str(), "\n", position, list);
4127         }
4128
4129         Utils::endList("", position, list);
4130
4131         return list;
4132 }
4133
4134 /** Constructor
4135  *
4136  * @param name Name
4137  * @param type Type of interface
4138  **/
4139 Interface::Interface(const GLchar* name, Interface::TYPE type) : m_name(name), m_type(type)
4140 {
4141 }
4142
4143 /** Adds member to interface
4144  *
4145  * @param member Descriptor of new member
4146  *
4147  * @return Pointer to just created member
4148  **/
4149 Variable::Descriptor* Interface::AddMember(const Variable::Descriptor& member)
4150 {
4151         m_members.push_back(member);
4152
4153         return &m_members.back();
4154 }
4155
4156 /** Get definition of interface
4157  *
4158  * @param Code with definition
4159  **/
4160 std::string Interface::GetDefinition() const
4161 {
4162         std::string definition;
4163         size_t          position = 0;
4164
4165         const GLchar* member_list = "    MEMBER_DEFINITION\nMEMBER_LIST";
4166
4167         if (STRUCT == m_type)
4168         {
4169                 definition = "struct NAME {\nMEMBER_LIST};";
4170         }
4171         else
4172         {
4173                 definition = "NAME {\nMEMBER_LIST}";
4174         }
4175
4176         /* Name */
4177         replaceToken("NAME", position, m_name.c_str(), definition);
4178
4179         /* Member list */
4180         for (GLuint i = 0; i < m_members.size(); ++i)
4181         {
4182                 const size_t       start_position       = position;
4183                 const std::string& member_definition = m_members[i].GetDefinition(Variable::BASIC, Variable::MEMBER);
4184
4185                 /* Member list */
4186                 replaceToken("MEMBER_LIST", position, member_list, definition);
4187
4188                 /* Move back position */
4189                 position = start_position;
4190
4191                 /* Member definition */
4192                 replaceToken("MEMBER_DEFINITION", position, member_definition.c_str(), definition);
4193         }
4194
4195         /* Remove last member list */
4196         replaceToken("MEMBER_LIST", position, "", definition);
4197
4198         /* Done */
4199         return definition;
4200 }
4201
4202 /** Adds member of built-in type to interface
4203  *
4204  * @param name                       Name
4205  * @param qualifiers                 Qualifiers
4206  * @param expected_component         Expected component of variable
4207  * @param expected_location          Expected location
4208  * @param type                       Type
4209  * @param normalized                 Selects if data should be normalized
4210  * @param n_array_elements           Length of array
4211  * @param expected_stride_of_element Expected stride of element
4212  * @param offset                     Offset
4213  *
4214  * @return Pointer to just created member
4215  **/
4216 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4217                                                                                 GLint expected_location, const Type& type, GLboolean normalized,
4218                                                                                 GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
4219 {
4220         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, type, normalized,
4221                                                                                   n_array_elements, expected_stride_of_element, offset));
4222 }
4223
4224 /** Adds member of interface type to interface
4225  *
4226  * @param name                       Name
4227  * @param qualifiers                 Qualifiers
4228  * @param expected_component         Expected component of variable
4229  * @param expected_location          Expected location
4230  * @param type                       Type
4231  * @param normalized                 Selects if data should be normalized
4232  * @param n_array_elements           Length of array
4233  * @param expected_stride_of_element Expected stride of element
4234  * @param offset                     Offset
4235  *
4236  * @return Pointer to just created member
4237  **/
4238 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4239                                                                                 GLint expected_location, Interface* nterface, GLuint n_array_elements,
4240                                                                                 GLint expected_stride_of_element, GLuint offset)
4241 {
4242         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, nterface,
4243                                                                                   n_array_elements, expected_stride_of_element, offset));
4244 }
4245
4246 /** Clears contents of vector of pointers
4247  *
4248  * @tparam T Type of elements
4249  *
4250  * @param vector Collection to be cleared
4251  **/
4252 template <typename T>
4253 void clearPtrVector(std::vector<T*>& vector)
4254 {
4255         for (size_t i = 0; i < vector.size(); ++i)
4256         {
4257                 T* t = vector[i];
4258
4259                 vector[i] = 0;
4260
4261                 if (0 != t)
4262                 {
4263                         delete t;
4264                 }
4265         }
4266
4267         vector.clear();
4268 }
4269
4270 /** Constructor
4271  *
4272  * @param stage Stage described by that interface
4273  **/
4274 ShaderInterface::ShaderInterface(Shader::STAGES stage) : m_stage(stage)
4275 {
4276         /* Nothing to be done */
4277 }
4278
4279 /** Get definitions of globals
4280  *
4281  * @return Code with definitions
4282  **/
4283 std::string ShaderInterface::GetDefinitionsGlobals() const
4284 {
4285         return m_globals;
4286 }
4287
4288 /** Get definitions of inputs
4289  *
4290  * @return Code with definitions
4291  **/
4292 std::string ShaderInterface::GetDefinitionsInputs() const
4293 {
4294         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::INPUT);
4295
4296         return GetDefinitions(m_inputs, flavour);
4297 }
4298
4299 /** Get definitions of outputs
4300  *
4301  * @return Code with definitions
4302  **/
4303 std::string ShaderInterface::GetDefinitionsOutputs() const
4304 {
4305         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::OUTPUT);
4306
4307         return GetDefinitions(m_outputs, flavour);
4308 }
4309
4310 /** Get definitions of buffers
4311  *
4312  * @return Code with definitions
4313  **/
4314 std::string ShaderInterface::GetDefinitionsSSBs() const
4315 {
4316         return GetDefinitions(m_ssb_blocks, Variable::BASIC);
4317 }
4318
4319 /** Get definitions of uniforms
4320  *
4321  * @return Code with definitions
4322  **/
4323 std::string ShaderInterface::GetDefinitionsUniforms() const
4324 {
4325         return GetDefinitions(m_uniforms, Variable::BASIC);
4326 }
4327
4328 /** Constructor
4329  *
4330  * @param in  Input variable
4331  * @param out Output variable
4332  **/
4333 VaryingConnection::VaryingConnection(Variable* in, Variable* out) : m_in(in), m_out(out)
4334 {
4335         /* NBothing to be done here */
4336 }
4337
4338 /** Adds new varying connection to given stage
4339  *
4340  * @param stage Shader stage
4341  * @param in    In varying
4342  * @param out   Out varying
4343  **/
4344 void VaryingPassthrough::Add(Shader::STAGES stage, Variable* in, Variable* out)
4345 {
4346         VaryingConnection::Vector& vector = Get(stage);
4347
4348         vector.push_back(VaryingConnection(in, out));
4349 }
4350
4351 /** Get all passthrough connections for given stage
4352  *
4353  * @param stage Shader stage
4354  *
4355  * @return Vector of connections
4356  **/
4357 VaryingConnection::Vector& VaryingPassthrough::Get(Shader::STAGES stage)
4358 {
4359         VaryingConnection::Vector* result = 0;
4360
4361         switch (stage)
4362         {
4363         case Shader::FRAGMENT:
4364                 result = &m_fragment;
4365                 break;
4366         case Shader::GEOMETRY:
4367                 result = &m_geometry;
4368                 break;
4369         case Shader::TESS_CTRL:
4370                 result = &m_tess_ctrl;
4371                 break;
4372         case Shader::TESS_EVAL:
4373                 result = &m_tess_eval;
4374                 break;
4375         case Shader::VERTEX:
4376                 result = &m_vertex;
4377                 break;
4378         default:
4379                 TCU_FAIL("Invalid enum");
4380         }
4381
4382         return *result;
4383 }
4384
4385 /** Constructor
4386  *
4387  **/
4388 ProgramInterface::ProgramInterface()
4389         : m_compute(Shader::COMPUTE)
4390         , m_vertex(Shader::VERTEX)
4391         , m_tess_ctrl(Shader::TESS_CTRL)
4392         , m_tess_eval(Shader::TESS_EVAL)
4393         , m_geometry(Shader::GEOMETRY)
4394         , m_fragment(Shader::FRAGMENT)
4395 {
4396 }
4397
4398 /** Destructor
4399  *
4400  **/
4401 ProgramInterface::~ProgramInterface()
4402 {
4403         clearPtrVector(m_blocks);
4404         clearPtrVector(m_structures);
4405 }
4406
4407 /** Adds new interface
4408  *
4409  * @param name
4410  * @param type
4411  *
4412  * @return Pointer to created interface
4413  **/
4414 Interface* ProgramInterface::AddInterface(const GLchar* name, Interface::TYPE type)
4415 {
4416         Interface* interface = 0;
4417
4418         if (Interface::STRUCT == type)
4419         {
4420                 interface = new Interface(name, type);
4421
4422                 m_structures.push_back(interface);
4423         }
4424         else
4425         {
4426                 interface = new Interface(name, type);
4427
4428                 m_blocks.push_back(interface);
4429         }
4430
4431         return interface;
4432 }
4433
4434 /** Adds new block interface
4435  *
4436  * @param name
4437  *
4438  * @return Pointer to created interface
4439  **/
4440 Interface* ProgramInterface::Block(const GLchar* name)
4441 {
4442         return AddInterface(name, Interface::BLOCK);
4443 }
4444
4445 /** Get interface of given shader stage
4446  *
4447  * @param stage Shader stage
4448  *
4449  * @return Reference to stage interface
4450  **/
4451 ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage)
4452 {
4453         ShaderInterface* interface = 0;
4454
4455         switch (stage)
4456         {
4457         case Shader::COMPUTE:
4458                 interface = &m_compute;
4459                 break;
4460         case Shader::FRAGMENT:
4461                 interface = &m_fragment;
4462                 break;
4463         case Shader::GEOMETRY:
4464                 interface = &m_geometry;
4465                 break;
4466         case Shader::TESS_CTRL:
4467                 interface = &m_tess_ctrl;
4468                 break;
4469         case Shader::TESS_EVAL:
4470                 interface = &m_tess_eval;
4471                 break;
4472         case Shader::VERTEX:
4473                 interface = &m_vertex;
4474                 break;
4475         default:
4476                 TCU_FAIL("Invalid enum");
4477         }
4478
4479         return *interface;
4480 }
4481
4482 /** Get interface of given shader stage
4483  *
4484  * @param stage Shader stage
4485  *
4486  * @return Reference to stage interface
4487  **/
4488 const ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage) const
4489 {
4490         const ShaderInterface* interface = 0;
4491
4492         switch (stage)
4493         {
4494         case Shader::COMPUTE:
4495                 interface = &m_compute;
4496                 break;
4497         case Shader::FRAGMENT:
4498                 interface = &m_fragment;
4499                 break;
4500         case Shader::GEOMETRY:
4501                 interface = &m_geometry;
4502                 break;
4503         case Shader::TESS_CTRL:
4504                 interface = &m_tess_ctrl;
4505                 break;
4506         case Shader::TESS_EVAL:
4507                 interface = &m_tess_eval;
4508                 break;
4509         case Shader::VERTEX:
4510                 interface = &m_vertex;
4511                 break;
4512         default:
4513                 TCU_FAIL("Invalid enum");
4514         }
4515
4516         return *interface;
4517 }
4518
4519 /** Clone interface of Vertex shader stage to other stages
4520  * It creates matching inputs, outputs, uniforms and buffers in other stages.
4521  * There are no additional outputs for FRAGMENT shader generated.
4522  *
4523  * @param varying_passthrough Collection of varyings connections
4524  **/
4525 void ProgramInterface::CloneVertexInterface(VaryingPassthrough& varying_passthrough)
4526 {
4527         /* VS outputs >> TCS inputs >> TCS outputs >> ..  >> FS inputs */
4528         for (size_t i = 0; i < m_vertex.m_outputs.size(); ++i)
4529         {
4530                 const Variable& vs_var = *m_vertex.m_outputs[i];
4531                 const GLchar*   prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4532
4533                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4534                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4535                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4536                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4537         }
4538
4539         /* Copy uniforms from VS to other stages */
4540         for (size_t i = 0; i < m_vertex.m_uniforms.size(); ++i)
4541         {
4542                 Variable&        vs_var = *m_vertex.m_uniforms[i];
4543                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4544
4545                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4546                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4547                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4548                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4549                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4550
4551                 /* Uniform blocks needs unique binding */
4552                 if (true == vs_var.IsBlock())
4553                 {
4554                         replaceBinding(vs_var, Shader::VERTEX);
4555                 }
4556         }
4557
4558         /* Copy SSBs from VS to other stages */
4559         for (size_t i = 0; i < m_vertex.m_ssb_blocks.size(); ++i)
4560         {
4561                 Variable&        vs_var = *m_vertex.m_ssb_blocks[i];
4562                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4563
4564                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4565                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4566                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4567                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4568                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4569
4570                 /* SSBs blocks needs unique binding */
4571                 if (true == vs_var.IsBlock())
4572                 {
4573                         replaceBinding(vs_var, Shader::VERTEX);
4574                 }
4575         }
4576
4577         m_compute.m_globals   = m_vertex.m_globals;
4578         m_fragment.m_globals  = m_vertex.m_globals;
4579         m_geometry.m_globals  = m_vertex.m_globals;
4580         m_tess_ctrl.m_globals = m_vertex.m_globals;
4581         m_tess_eval.m_globals = m_vertex.m_globals;
4582 }
4583
4584 /** Clone variable for specific stage
4585  *
4586  * @param variable            Variable
4587  * @param stage               Requested stage
4588  * @param prefix              Prefix used in variable name that is specific for original stage
4589  * @param varying_passthrough Collection of varyings connections
4590  **/
4591 void ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage, const GLchar* prefix,
4592                                                                                          VaryingPassthrough& varying_passthrough)
4593 {
4594         switch (variable.m_storage)
4595         {
4596         case Variable::VARYING_OUTPUT:
4597         {
4598                 Variable* in = cloneVariableForStage(variable, stage, Variable::VARYING_INPUT, prefix);
4599
4600                 if (Shader::FRAGMENT != stage)
4601                 {
4602                         Variable* out = cloneVariableForStage(variable, stage, Variable::VARYING_OUTPUT, prefix);
4603                         varying_passthrough.Add(stage, in, out);
4604                 }
4605         }
4606         break;
4607         case Variable::UNIFORM:
4608         case Variable::SSB:
4609                 cloneVariableForStage(variable, stage, variable.m_storage, prefix);
4610                 break;
4611         default:
4612                 TCU_FAIL("Invalid enum");
4613                 break;
4614         }
4615 }
4616
4617 /** Clone variable for specific stage
4618  *
4619  * @param variable Variable
4620  * @param stage    Requested stage
4621  * @param storage  Storage used by variable
4622  * @param prefix   Prefix used in variable name that is specific for original stage
4623  *
4624  * @return New variable
4625  **/
4626 Variable* ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage,
4627                                                                                                   Variable::STORAGE storage, const GLchar* prefix)
4628 {
4629         /* Initialize with original variable */
4630         Variable* var = new Variable(variable);
4631         if (0 == var)
4632         {
4633                 TCU_FAIL("Memory allocation");
4634         }
4635
4636         /* Set up storage */
4637         var->m_storage = storage;
4638
4639         /* Get name */
4640         std::string name = variable.m_descriptor.m_name;
4641
4642         /* Prefix name with stage ID, empty means default block */
4643         if (false == name.empty())
4644         {
4645                 size_t            position       = 0;
4646                 const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4647                 Utils::replaceToken(prefix, position, stage_prefix, name);
4648         }
4649         var->m_descriptor.m_name = name;
4650
4651         /* Clone block */
4652         const bool is_block = variable.IsBlock();
4653         if (true == is_block)
4654         {
4655                 const Interface* interface = variable.m_descriptor.m_interface;
4656
4657                 Interface* block = CloneBlockForStage(*interface, stage, storage, prefix);
4658
4659                 var->m_descriptor.m_interface = block;
4660         }
4661
4662         /* Store variable */
4663         ShaderInterface& si             = GetShaderInterface(stage);
4664         Variable*                result = 0;
4665
4666         switch (storage)
4667         {
4668         case Variable::VARYING_INPUT:
4669                 si.m_inputs.push_back(var);
4670                 result = si.m_inputs.back();
4671                 break;
4672         case Variable::VARYING_OUTPUT:
4673                 si.m_outputs.push_back(var);
4674                 result = si.m_outputs.back();
4675                 break;
4676         case Variable::UNIFORM:
4677                 /* Uniform blocks needs unique binding */
4678                 if (true == is_block)
4679                 {
4680                         replaceBinding(*var, stage);
4681                 }
4682
4683                 si.m_uniforms.push_back(var);
4684                 result = si.m_uniforms.back();
4685                 break;
4686         case Variable::SSB:
4687                 /* SSBs needs unique binding */
4688                 if (true == is_block)
4689                 {
4690                         replaceBinding(*var, stage);
4691                 }
4692
4693                 si.m_ssb_blocks.push_back(var);
4694                 result = si.m_ssb_blocks.back();
4695                 break;
4696         default:
4697                 TCU_FAIL("Invalid enum");
4698                 break;
4699         }
4700
4701         return result;
4702 }
4703
4704 /** clone block to specific stage
4705  *
4706  * @param block   Block to be copied
4707  * @param stage   Specific stage
4708  * @param storage Storage used by block
4709  * @param prefix  Prefix used in block name
4710  *
4711  * @return New interface
4712  **/
4713 Interface* ProgramInterface::CloneBlockForStage(const Interface& block, Shader::STAGES stage, Variable::STORAGE storage,
4714                                                                                                 const GLchar* prefix)
4715 {
4716         /* Get name */
4717         std::string name = block.m_name;
4718
4719         /* Prefix name with stage ID */
4720         size_t            position       = 0;
4721         const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4722         Utils::replaceToken(prefix, position, stage_prefix, name);
4723
4724         Interface* ptr = GetBlock(name.c_str());
4725
4726         if (0 == ptr)
4727         {
4728                 ptr = AddInterface(name.c_str(), Interface::BLOCK);
4729         }
4730
4731         ptr->m_members = block.m_members;
4732
4733         return ptr;
4734 }
4735
4736 /** Get stage specific prefix used in names
4737  *
4738  * @param stage   Stage
4739  * @param storage Storage class
4740  *
4741  * @return String
4742  **/
4743 const GLchar* ProgramInterface::GetStagePrefix(Shader::STAGES stage, Variable::STORAGE storage)
4744 {
4745         static const GLchar* lut[Shader::STAGE_MAX][Variable::STORAGE_MAX] = {
4746                 /*          IN          OUT         UNIFORM     SSB        MEMBER       */
4747                 /* CS  */ { 0, 0, "cs_uni_", "cs_buf_", "" },
4748                 /* VS  */ { "in_vs_", "vs_tcs_", "vs_uni_", "vs_buf_", "" },
4749                 /* TCS */ { "vs_tcs_", "tcs_tes_", "tcs_uni_", "tcs_buf_", "" },
4750                 /* TES */ { "tcs_tes_", "tes_gs_", "tes_uni_", "tes_buf_", "" },
4751                 /* GS  */ { "tes_gs_", "gs_fs_", "gs_uni_", "gs_buf_", "" },
4752                 /* FS  */ { "gs_fs_", "fs_out_", "fs_uni_", "fs_buf_", "" },
4753         };
4754
4755         const GLchar* result = 0;
4756
4757         result = lut[stage][storage];
4758
4759         return result;
4760 }
4761
4762 /** Get definitions of all structures used in program interface
4763  *
4764  * @return String with code
4765  **/
4766 std::string ProgramInterface::GetDefinitionsStructures() const
4767 {
4768         return GetDefinitions(m_structures);
4769 }
4770
4771 /** Get interface code for stage
4772  *
4773  * @param stage Specific stage
4774  *
4775  * @return String with code
4776  **/
4777 std::string ProgramInterface::GetInterfaceForStage(Shader::STAGES stage) const
4778 {
4779         size_t          position  = 0;
4780         std::string interface = "/* Globals */\n"
4781                                                         "GLOBALS\n"
4782                                                         "\n"
4783                                                         "/* Structures */\n"
4784                                                         "STRUCTURES\n"
4785                                                         "\n"
4786                                                         "/* Uniforms */\n"
4787                                                         "UNIFORMS\n"
4788                                                         "\n"
4789                                                         "/* Inputs */\n"
4790                                                         "INPUTS\n"
4791                                                         "\n"
4792                                                         "/* Outputs */\n"
4793                                                         "OUTPUTS\n"
4794                                                         "\n"
4795                                                         "/* Storage */\n"
4796                                                         "STORAGE\n";
4797
4798         const ShaderInterface& si = GetShaderInterface(stage);
4799
4800         const std::string& structures = GetDefinitionsStructures();
4801
4802         const std::string& globals  = si.GetDefinitionsGlobals();
4803         const std::string& inputs   = si.GetDefinitionsInputs();
4804         const std::string& outputs  = si.GetDefinitionsOutputs();
4805         const std::string& uniforms = si.GetDefinitionsUniforms();
4806         const std::string& ssbs         = si.GetDefinitionsSSBs();
4807
4808         replaceToken("GLOBALS", position, globals.c_str(), interface);
4809         replaceToken("STRUCTURES", position, structures.c_str(), interface);
4810         replaceToken("UNIFORMS", position, uniforms.c_str(), interface);
4811         replaceToken("INPUTS", position, inputs.c_str(), interface);
4812         replaceToken("OUTPUTS", position, outputs.c_str(), interface);
4813         replaceToken("STORAGE", position, ssbs.c_str(), interface);
4814
4815         return interface;
4816 }
4817
4818 /** Functional object used in find_if algorithm, in search for interface of given name
4819  *
4820  **/
4821 struct matchInterfaceName
4822 {
4823         matchInterfaceName(const GLchar* name) : m_name(name)
4824         {
4825         }
4826
4827         bool operator()(const Interface* interface)
4828         {
4829                 return 0 == interface->m_name.compare(m_name);
4830         }
4831
4832         const GLchar* m_name;
4833 };
4834
4835 /** Finds interface of given name in given vector of interfaces
4836  *
4837  * @param vector Collection of interfaces
4838  * @param name   Requested name
4839  *
4840  * @return Pointer to interface if available, 0 otherwise
4841  **/
4842 static Interface* findInterfaceByName(Interface::PtrVector& vector, const GLchar* name)
4843 {
4844         Interface::PtrVector::iterator it = std::find_if(vector.begin(), vector.end(), matchInterfaceName(name));
4845
4846         if (vector.end() != it)
4847         {
4848                 return *it;
4849         }
4850         else
4851         {
4852                 return 0;
4853         }
4854 }
4855
4856 /** Search for block of given name
4857  *
4858  * @param name Name of block
4859  *
4860  * @return Pointer to block or 0
4861  **/
4862 Interface* ProgramInterface::GetBlock(const GLchar* name)
4863 {
4864         return findInterfaceByName(m_blocks, name);
4865 }
4866
4867 /** Search for structure of given name
4868  *
4869  * @param name Name of structure
4870  *
4871  * @return Pointer to structure or 0
4872  **/
4873 Interface* ProgramInterface::GetStructure(const GLchar* name)
4874 {
4875         return findInterfaceByName(m_structures, name);
4876 }
4877
4878 /** Adds new sturcture to interface
4879  *
4880  * @param name Name of structure
4881  *
4882  * @return Created structure
4883  **/
4884 Interface* ProgramInterface::Structure(const GLchar* name)
4885 {
4886         return AddInterface(name, Interface::STRUCT);
4887 }
4888
4889 /** Replace "BINDING" token in qualifiers string to value specific for given stage
4890  *
4891  * @param variable Variable to modify
4892  * @param stage    Requested stage
4893  **/
4894 void ProgramInterface::replaceBinding(Variable& variable, Shader::STAGES stage)
4895 {
4896         GLchar binding[16];
4897         sprintf(binding, "%d", stage);
4898         replaceAllTokens("BINDING", binding, variable.m_descriptor.m_qualifiers);
4899 }
4900 } /* Utils namespace */
4901
4902 /** Debuging procedure. Logs parameters.
4903  *
4904  * @param source   As specified in GL spec.
4905  * @param type     As specified in GL spec.
4906  * @param id       As specified in GL spec.
4907  * @param severity As specified in GL spec.
4908  * @param ignored
4909  * @param message  As specified in GL spec.
4910  * @param info     Pointer to instance of Context used by test.
4911  */
4912 void GLW_APIENTRY debug_proc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /* length */,
4913                                                          const GLchar* message, void* info)
4914 {
4915         deqp::Context* ctx = (deqp::Context*)info;
4916
4917         const GLchar* source_str   = "Unknown";
4918         const GLchar* type_str   = "Unknown";
4919         const GLchar* severity_str = "Unknown";
4920
4921         switch (source)
4922         {
4923         case GL_DEBUG_SOURCE_API:
4924                 source_str = "API";
4925                 break;
4926         case GL_DEBUG_SOURCE_APPLICATION:
4927                 source_str = "APP";
4928                 break;
4929         case GL_DEBUG_SOURCE_OTHER:
4930                 source_str = "OTR";
4931                 break;
4932         case GL_DEBUG_SOURCE_SHADER_COMPILER:
4933                 source_str = "COM";
4934                 break;
4935         case GL_DEBUG_SOURCE_THIRD_PARTY:
4936                 source_str = "3RD";
4937                 break;
4938         case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
4939                 source_str = "WS";
4940                 break;
4941         default:
4942                 break;
4943         }
4944
4945         switch (type)
4946         {
4947         case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
4948                 type_str = "DEPRECATED_BEHAVIOR";
4949                 break;
4950         case GL_DEBUG_TYPE_ERROR:
4951                 type_str = "ERROR";
4952                 break;
4953         case GL_DEBUG_TYPE_MARKER:
4954                 type_str = "MARKER";
4955                 break;
4956         case GL_DEBUG_TYPE_OTHER:
4957                 type_str = "OTHER";
4958                 break;
4959         case GL_DEBUG_TYPE_PERFORMANCE:
4960                 type_str = "PERFORMANCE";
4961                 break;
4962         case GL_DEBUG_TYPE_POP_GROUP:
4963                 type_str = "POP_GROUP";
4964                 break;
4965         case GL_DEBUG_TYPE_PORTABILITY:
4966                 type_str = "PORTABILITY";
4967                 break;
4968         case GL_DEBUG_TYPE_PUSH_GROUP:
4969                 type_str = "PUSH_GROUP";
4970                 break;
4971         case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
4972                 type_str = "UNDEFINED_BEHAVIOR";
4973                 break;
4974         default:
4975                 break;
4976         }
4977
4978         switch (severity)
4979         {
4980         case GL_DEBUG_SEVERITY_HIGH:
4981                 severity_str = "H";
4982                 break;
4983         case GL_DEBUG_SEVERITY_LOW:
4984                 severity_str = "L";
4985                 break;
4986         case GL_DEBUG_SEVERITY_MEDIUM:
4987                 severity_str = "M";
4988                 break;
4989         case GL_DEBUG_SEVERITY_NOTIFICATION:
4990                 severity_str = "N";
4991                 break;
4992         default:
4993                 break;
4994         }
4995
4996         ctx->getTestContext().getLog() << tcu::TestLog::Message << "DEBUG_INFO: " << std::setw(3) << source_str << "|"
4997                                                                    << severity_str << "|" << std::setw(18) << type_str << "|" << std::setw(12) << id
4998                                                                    << ": " << message << tcu::TestLog::EndMessage;
4999 }
5000
5001 /** Constructor
5002  *
5003  * @param context          Test context
5004  * @param test_name        Test name
5005  * @param test_description Test description
5006  **/
5007 TestBase::TestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5008         : TestCase(context, test_name, test_description)
5009 {
5010         /* Nothing to be done here */
5011 }
5012
5013 /** Execute test
5014  *
5015  * @return tcu::TestNode::STOP otherwise
5016  **/
5017 tcu::TestNode::IterateResult TestBase::iterate()
5018 {
5019         bool test_result;
5020
5021 #if DEBUG_ENBALE_MESSAGE_CALLBACK
5022         const Functions& gl = m_context.getRenderContext().getFunctions();
5023
5024         gl.debugMessageCallback(debug_proc, &m_context);
5025         GLU_EXPECT_NO_ERROR(gl.getError(), "DebugMessageCallback");
5026 #endif /* DEBUG_ENBALE_MESSAGE_CALLBACK */
5027
5028         try
5029         {
5030                 /* Execute test */
5031                 test_result = test();
5032         }
5033         catch (std::exception& exc)
5034         {
5035                 TCU_FAIL(exc.what());
5036         }
5037
5038         /* Set result */
5039         if (true == test_result)
5040         {
5041                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
5042         }
5043         else
5044         {
5045                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5046         }
5047
5048         /* Done */
5049         return tcu::TestNode::STOP;
5050 }
5051
5052 /** Get last input location available for given type at specific stage
5053  *
5054  * @param stage        Shader stage
5055  * @param type         Input type
5056  * @param array_length Length of input array
5057  *
5058  * @return Last location index
5059  **/
5060 GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5061 {
5062         GLint  divide = 4; /* 4 components per location */
5063         GLint  param  = 0;
5064         GLenum pname  = 0;
5065
5066         /* Select pnmae */
5067         switch (stage)
5068         {
5069         case Utils::Shader::FRAGMENT:
5070                 pname = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
5071                 break;
5072         case Utils::Shader::GEOMETRY:
5073                 pname = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
5074                 break;
5075         case Utils::Shader::TESS_CTRL:
5076                 pname = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
5077                 break;
5078         case Utils::Shader::TESS_EVAL:
5079                 pname = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
5080                 break;
5081         case Utils::Shader::VERTEX:
5082                 pname  = GL_MAX_VERTEX_ATTRIBS;
5083                 divide = 1;
5084                 break;
5085         default:
5086                 TCU_FAIL("Invalid enum");
5087                 break;
5088         }
5089
5090         /* Zero means no array, but 1 slot is required */
5091         if (0 == array_length)
5092         {
5093                 array_length += 1;
5094         }
5095
5096         /* Get MAX */
5097         const Functions& gl = m_context.getRenderContext().getFunctions();
5098
5099         gl.getIntegerv(pname, &param);
5100         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5101
5102 /* Calculate */
5103 #if WRKARD_VARYINGLOCATIONSTEST
5104
5105         const GLint n_avl_locations = 16;
5106
5107 #else
5108
5109         const GLint n_avl_locations = param / divide;
5110
5111 #endif
5112
5113         const GLuint n_req_location = type.GetLocations() * array_length;
5114
5115         return n_avl_locations - n_req_location; /* last is max - 1 */
5116 }
5117
5118 /** Get last input location available for given type at specific stage
5119  *
5120  * @param stage        Shader stage
5121  * @param type         Input type
5122  * @param array_length Length of input array
5123  *
5124  * @return Last location index
5125  **/
5126 GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5127 {
5128         GLint  param = 0;
5129         GLenum pname = 0;
5130
5131         /* Select pnmae */
5132         switch (stage)
5133         {
5134         case Utils::Shader::GEOMETRY:
5135                 pname = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
5136                 break;
5137         case Utils::Shader::TESS_CTRL:
5138                 pname = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
5139                 break;
5140         case Utils::Shader::TESS_EVAL:
5141                 pname = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
5142                 break;
5143         case Utils::Shader::VERTEX:
5144                 pname = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
5145                 break;
5146         default:
5147                 TCU_FAIL("Invalid enum");
5148                 break;
5149         }
5150
5151         /* Zero means no array, but 1 slot is required */
5152         if (0 == array_length)
5153         {
5154                 array_length += 1;
5155         }
5156
5157         /* Get MAX */
5158         const Functions& gl = m_context.getRenderContext().getFunctions();
5159
5160         gl.getIntegerv(pname, &param);
5161         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5162
5163 /* Calculate */
5164 #if WRKARD_VARYINGLOCATIONSTEST
5165
5166         const GLint n_avl_locations = 16;
5167
5168 #else
5169
5170         const GLint n_avl_locations = param / 4; /* 4 components per location */
5171
5172 #endif
5173
5174         const GLuint n_req_location = type.GetLocations() * array_length;
5175
5176         return n_avl_locations - n_req_location; /* last is max - 1 */
5177 }
5178
5179 /** Basic implementation
5180  *
5181  * @param ignored
5182  *
5183  * @return Empty string
5184  **/
5185 std::string TestBase::getTestCaseName(GLuint /* test_case_index */)
5186 {
5187         std::string result;
5188
5189         return result;
5190 }
5191
5192 /** Basic implementation
5193  *
5194  * @return 1
5195  **/
5196 GLuint TestBase::getTestCaseNumber()
5197 {
5198         return 1;
5199 }
5200
5201 /** Check if flat qualifier is required for given type, stage and storage
5202  *
5203  * @param stage        Shader stage
5204  * @param type         Input type
5205  * @param storage      Storage of variable
5206  *
5207  * @return Last location index
5208  **/
5209 bool TestBase::isFlatRequired(Utils::Shader::STAGES stage, const Utils::Type& type,
5210                                                           Utils::Variable::STORAGE storage) const
5211 {
5212         /* Float types do not need flat at all */
5213         if (Utils::Type::Float == type.m_basic_type)
5214         {
5215                 return false;
5216         }
5217
5218         /* Inputs to fragment shader */
5219         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_INPUT == storage))
5220         {
5221                 return true;
5222         }
5223
5224         /* Outputs from geometry shader */
5225         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_OUTPUT == storage))
5226         {
5227                 return true;
5228         }
5229
5230         return false;
5231 }
5232
5233 /** Basic implementation of testInit method
5234  *
5235  **/
5236 void TestBase::testInit()
5237 {
5238 }
5239
5240 /** Calculate stride for interface
5241  *
5242  * @param interface Interface
5243  *
5244  * @return Calculated value
5245  **/
5246 GLuint TestBase::calculateStride(const Utils::Interface& interface) const
5247 {
5248         const size_t n_members = interface.m_members.size();
5249
5250         GLuint stride = 0;
5251
5252         for (size_t i = 0; i < n_members; ++i)
5253         {
5254                 const Utils::Variable::Descriptor& member                 = interface.m_members[i];
5255                 const GLuint                                       member_offset  = member.m_offset;
5256                 const GLuint                                       member_stride  = member.m_expected_stride_of_element;
5257                 const GLuint                                       member_ends_at = member_offset + member_stride;
5258
5259                 stride = std::max(stride, member_ends_at);
5260         }
5261
5262         return stride;
5263 }
5264
5265 /** Generate data for interface. This routine is recursive
5266  *
5267  * @param interface Interface
5268  * @param offset    Offset in out_data
5269  * @param out_data  Buffer to be filled
5270  **/
5271 void TestBase::generateData(const Utils::Interface& interface, GLuint offset, std::vector<GLubyte>& out_data) const
5272 {
5273         const size_t n_members = interface.m_members.size();
5274         GLubyte*         ptr       = &out_data[offset];
5275
5276         for (size_t i = 0; i < n_members; ++i)
5277         {
5278                 const Utils::Variable::Descriptor& member                = interface.m_members[i];
5279                 const GLuint                                       member_offset = member.m_offset;
5280                 const GLuint n_elements = (0 == member.m_n_array_elements) ? 1 : member.m_n_array_elements;
5281
5282                 for (GLuint element = 0; element < n_elements; ++element)
5283                 {
5284                         const GLuint element_offset = element * member.m_expected_stride_of_element;
5285                         const GLuint data_offfset   = member_offset + element_offset;
5286
5287                         if (Utils::Variable::BUILTIN == member.m_type)
5288                         {
5289                                 const std::vector<GLubyte>& data = member.m_builtin.GenerateData();
5290
5291                                 memcpy(ptr + data_offfset, &data[0], data.size());
5292                         }
5293                         else
5294                         {
5295                                 generateData(*member.m_interface, offset + data_offfset, out_data);
5296                         }
5297                 }
5298         }
5299 }
5300
5301 /** Get type at index
5302  *
5303  * @param index Index of requested type
5304  *
5305  * @return Type
5306  **/
5307 Utils::Type TestBase::getType(GLuint index) const
5308 {
5309         Utils::Type type;
5310
5311         switch (index)
5312         {
5313         case 0:
5314                 type = Utils::Type::_double;
5315                 break;
5316         case 1:
5317                 type = Utils::Type::dmat2;
5318                 break;
5319         case 2:
5320                 type = Utils::Type::dmat2x3;
5321                 break;
5322         case 3:
5323                 type = Utils::Type::dmat2x4;
5324                 break;
5325         case 4:
5326                 type = Utils::Type::dmat3;
5327                 break;
5328         case 5:
5329                 type = Utils::Type::dmat3x2;
5330                 break;
5331         case 6:
5332                 type = Utils::Type::dmat3x4;
5333                 break;
5334         case 7:
5335                 type = Utils::Type::dmat4;
5336                 break;
5337         case 8:
5338                 type = Utils::Type::dmat4x2;
5339                 break;
5340         case 9:
5341                 type = Utils::Type::dmat4x3;
5342                 break;
5343         case 10:
5344                 type = Utils::Type::dvec2;
5345                 break;
5346         case 11:
5347                 type = Utils::Type::dvec3;
5348                 break;
5349         case 12:
5350                 type = Utils::Type::dvec4;
5351                 break;
5352         case 13:
5353                 type = Utils::Type::_float;
5354                 break;
5355         case 14:
5356                 type = Utils::Type::mat2;
5357                 break;
5358         case 15:
5359                 type = Utils::Type::mat2x3;
5360                 break;
5361         case 16:
5362                 type = Utils::Type::mat2x4;
5363                 break;
5364         case 17:
5365                 type = Utils::Type::mat3;
5366                 break;
5367         case 18:
5368                 type = Utils::Type::mat3x2;
5369                 break;
5370         case 19:
5371                 type = Utils::Type::mat3x4;
5372                 break;
5373         case 20:
5374                 type = Utils::Type::mat4;
5375                 break;
5376         case 21:
5377                 type = Utils::Type::mat4x2;
5378                 break;
5379         case 22:
5380                 type = Utils::Type::mat4x3;
5381                 break;
5382         case 23:
5383                 type = Utils::Type::vec2;
5384                 break;
5385         case 24:
5386                 type = Utils::Type::vec3;
5387                 break;
5388         case 25:
5389                 type = Utils::Type::vec4;
5390                 break;
5391         case 26:
5392                 type = Utils::Type::_int;
5393                 break;
5394         case 27:
5395                 type = Utils::Type::ivec2;
5396                 break;
5397         case 28:
5398                 type = Utils::Type::ivec3;
5399                 break;
5400         case 29:
5401                 type = Utils::Type::ivec4;
5402                 break;
5403         case 30:
5404                 type = Utils::Type::uint;
5405                 break;
5406         case 31:
5407                 type = Utils::Type::uvec2;
5408                 break;
5409         case 32:
5410                 type = Utils::Type::uvec3;
5411                 break;
5412         case 33:
5413                 type = Utils::Type::uvec4;
5414                 break;
5415         default:
5416                 TCU_FAIL("invalid enum");
5417         }
5418
5419         return type;
5420 }
5421
5422 /** Get name of type at index
5423  *
5424  * @param index Index of type
5425  *
5426  * @return Name
5427  **/
5428 std::string TestBase::getTypeName(GLuint index) const
5429 {
5430         std::string name = getType(index).GetGLSLTypeName();
5431
5432         return name;
5433 }
5434
5435 /** Get number of types
5436  *
5437  * @return 34
5438  **/
5439 glw::GLuint TestBase::getTypesNumber() const
5440 {
5441         return 34;
5442 }
5443
5444 /** Execute test
5445  *
5446  * @return true if test pass, false otherwise
5447  **/
5448 bool TestBase::test()
5449 {
5450         bool   result           = true;
5451         GLuint n_test_cases = 0;
5452
5453         /* Prepare test */
5454         testInit();
5455
5456         /* GL entry points */
5457         const Functions& gl = m_context.getRenderContext().getFunctions();
5458
5459         /* Tessellation patch set up */
5460         gl.patchParameteri(GL_PATCH_VERTICES, 1);
5461         GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
5462
5463         /* Get number of test cases */
5464         n_test_cases = getTestCaseNumber();
5465
5466 #if DEBUG_REPEAT_TEST_CASE
5467
5468         while (1)
5469         {
5470                 GLuint test_case = DEBUG_REPEATED_TEST_CASE;
5471
5472 #else /* DEBUG_REPEAT_TEST_CASE */
5473
5474         for (GLuint test_case = 0; test_case < n_test_cases; ++test_case)
5475         {
5476
5477 #endif /* DEBUG_REPEAT_TEST_CASE */
5478
5479                 bool case_result = true;
5480
5481                 /* Execute case */
5482                 if (false == testCase(test_case))
5483                 {
5484                         case_result = false;
5485                 }
5486
5487                 /* Log failure */
5488                 if (false == case_result)
5489                 {
5490                         const std::string& test_case_name = getTestCaseName(test_case);
5491
5492                         if (false == test_case_name.empty())
5493                         {
5494                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case_name
5495                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5496                         }
5497                         else
5498                         {
5499                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case
5500                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5501                         }
5502
5503                         result = false;
5504                 }
5505         }
5506
5507         /* Done */
5508         return result;
5509 }
5510
5511 /* Constants used by BufferTestBase */
5512 const GLuint BufferTestBase::bufferDescriptor::m_non_indexed = -1;
5513
5514 /** Constructor
5515  *
5516  * @param context          Test context
5517  * @param test_name        Name of test
5518  * @param test_description Description of test
5519  **/
5520 BufferTestBase::BufferTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5521         : TestBase(context, test_name, test_description)
5522 {
5523 }
5524
5525 /** Execute drawArrays for single vertex
5526  *
5527  * @param ignored
5528  *
5529  * @return true
5530  **/
5531 bool BufferTestBase::executeDrawCall(bool tesEnabled, GLuint /* test_case_index */)
5532 {
5533         const Functions& gl = m_context.getRenderContext().getFunctions();
5534
5535         gl.disable(GL_RASTERIZER_DISCARD);
5536         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
5537
5538         gl.beginTransformFeedback(GL_POINTS);
5539         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
5540
5541         // Only TES is existed, glDrawArray can use the parameter GL_PATCHES
5542         if (tesEnabled == false)
5543         {
5544                 gl.drawArrays(GL_POINTS, 0 /* first */, 1 /* count */);
5545         }
5546         else
5547         {
5548                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
5549         }
5550
5551         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
5552
5553         gl.endTransformFeedback();
5554         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
5555
5556         return true;
5557 }
5558
5559 /** Get descriptors of buffers necessary for test
5560  *
5561  * @param ignored
5562  * @param ignored
5563  **/
5564 void BufferTestBase::getBufferDescriptors(glw::GLuint /* test_case_index */,
5565                                                                                   bufferDescriptor::Vector& /* out_descriptors */)
5566 {
5567         /* Nothhing to be done */
5568 }
5569
5570 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
5571  *
5572  * @param ignored
5573  * @param ignored
5574  **/
5575 void BufferTestBase::getCapturedVaryings(glw::GLuint /* test_case_index */,
5576                                                                                  Utils::Program::NameVector& /* captured_varyings */)
5577 {
5578         /* Nothing to be done */
5579 }
5580
5581 /** Get body of main function for given shader stage
5582  *
5583  * @param ignored
5584  * @param ignored
5585  * @param out_assignments  Set to empty
5586  * @param out_calculations Set to empty
5587  **/
5588 void BufferTestBase::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5589                                                                    std::string& out_assignments, std::string& out_calculations)
5590 {
5591         out_assignments  = "";
5592         out_calculations = "";
5593 }
5594
5595 /** Get interface of shader
5596  *
5597  * @param ignored
5598  * @param ignored
5599  * @param out_interface Set to ""
5600  **/
5601 void BufferTestBase::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5602                                                                                 std::string& out_interface)
5603 {
5604         out_interface = "";
5605 }
5606
5607 /** Get source code of shader
5608  *
5609  * @param test_case_index Index of test case
5610  * @param stage           Shader stage
5611  *
5612  * @return Source
5613  **/
5614 std::string BufferTestBase::getShaderSource(glw::GLuint test_case_index, Utils::Shader::STAGES stage)
5615 {
5616         std::string assignments;
5617         std::string calculations;
5618         std::string interface;
5619
5620         /* */
5621         getShaderBody(test_case_index, stage, assignments, calculations);
5622         getShaderInterface(test_case_index, stage, interface);
5623
5624         /* */
5625         std::string source = getShaderTemplate(stage);
5626
5627         /* */
5628         size_t position = 0;
5629         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
5630         Utils::replaceToken("CALCULATIONS", position, calculations.c_str(), source);
5631         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
5632
5633         /* */
5634         return source;
5635 }
5636
5637 /** Inspects program to check if all resources are as expected
5638  *
5639  * @param ignored
5640  * @param ignored
5641  * @param ignored
5642  *
5643  * @return true
5644  **/
5645 bool BufferTestBase::inspectProgram(GLuint /* test_case_index */, Utils::Program& /* program */,
5646                                                                         std::stringstream& /* out_stream */)
5647 {
5648         return true;
5649 }
5650
5651 /** Runs test case
5652  *
5653  * @param test_case_index Id of test case
5654  *
5655  * @return true if test case pass, false otherwise
5656  **/
5657 bool BufferTestBase::testCase(GLuint test_case_index)
5658 {
5659         try
5660         {
5661                 bufferCollection                   buffers;
5662                 Utils::Program::NameVector captured_varyings;
5663                 bufferDescriptor::Vector   descriptors;
5664                 Utils::Program                     program(m_context);
5665                 Utils::VertexArray                 vao(m_context);
5666
5667                 /* Get captured varyings */
5668                 getCapturedVaryings(test_case_index, captured_varyings);
5669
5670                 /* Get shader sources */
5671                 const std::string& fragment_shader  = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
5672                 const std::string& geometry_shader  = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
5673                 const std::string& tess_ctrl_shader = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
5674                 const std::string& tess_eval_shader = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
5675                 const std::string& vertex_shader        = getShaderSource(test_case_index, Utils::Shader::VERTEX);
5676
5677                 /* Set up program */
5678                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
5679                                          vertex_shader, captured_varyings, true, false /* is_separable */);
5680
5681                 /* Inspection */
5682                 {
5683                         std::stringstream stream;
5684                         if (false == inspectProgram(test_case_index, program, stream))
5685                         {
5686                                 m_context.getTestContext().getLog()
5687                                         << tcu::TestLog::Message
5688                                         << "Program inspection failed. Test case: " << getTestCaseName(test_case_index)
5689                                         << ". Reason: " << stream.str() << tcu::TestLog::EndMessage
5690                                         << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5691                                         << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5692                                         << tcu::TestLog::KernelSource(fragment_shader);
5693
5694                                 return false;
5695                         }
5696                 }
5697
5698                 program.Use();
5699
5700                 /* Set up buffers */
5701                 getBufferDescriptors(test_case_index, descriptors);
5702                 cleanBuffers();
5703                 prepareBuffers(descriptors, buffers);
5704
5705                 /* Set up vao */
5706                 vao.Init();
5707                 vao.Bind();
5708
5709                 /* Draw */
5710                 bool result = executeDrawCall((program.m_tess_eval.m_id != 0), test_case_index);
5711
5712 #if USE_NSIGHT
5713                 m_context.getRenderContext().postIterate();
5714 #endif
5715
5716                 if (false == result)
5717                 {
5718                         m_context.getTestContext().getLog()
5719                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5720                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5721                                 << tcu::TestLog::KernelSource(fragment_shader);
5722
5723                         return false;
5724                 }
5725
5726                 /* Verify result */
5727                 if (false == verifyBuffers(buffers))
5728                 {
5729                         m_context.getTestContext().getLog()
5730                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5731                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5732                                 << tcu::TestLog::KernelSource(fragment_shader);
5733
5734                         return false;
5735                 }
5736         }
5737         catch (Utils::Shader::InvalidSourceException& exc)
5738         {
5739                 exc.log(m_context);
5740                 TCU_FAIL(exc.what());
5741         }
5742         catch (Utils::Program::BuildException& exc)
5743         {
5744                 exc.log(m_context);
5745                 TCU_FAIL(exc.what());
5746         }
5747
5748         /* Done */
5749         return true;
5750 }
5751
5752 /** Verify contents of buffers
5753  *
5754  * @param buffers Collection of buffers to be verified
5755  *
5756  * @return true if everything is as expected, false otherwise
5757  **/
5758 bool BufferTestBase::verifyBuffers(bufferCollection& buffers)
5759 {
5760         bool result = true;
5761
5762         for (bufferCollection::Vector::iterator it = buffers.m_vector.begin(), end = buffers.m_vector.end(); end != it;
5763                  ++it)
5764         {
5765                 bufferCollection::pair& pair       = *it;
5766                 Utils::Buffer*                  buffer   = pair.m_buffer;
5767                 bufferDescriptor*               descriptor = pair.m_descriptor;
5768                 size_t                                  size       = descriptor->m_expected_data.size();
5769
5770                 /* Skip buffers that have no expected data */
5771                 if (0 == size)
5772                 {
5773                         continue;
5774                 }
5775
5776                 /* Get pointer to contents of buffer */
5777                 buffer->Bind();
5778                 GLvoid* buffer_data = buffer->Map(Utils::Buffer::ReadOnly);
5779
5780                 /* Get pointer to expected data */
5781                 GLvoid* expected_data = &descriptor->m_expected_data[0];
5782
5783                 /* Compare */
5784                 int res = memcmp(buffer_data, expected_data, size);
5785
5786                 if (0 != res)
5787                 {
5788                         m_context.getTestContext().getLog()
5789                                 << tcu::TestLog::Message
5790                                 << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
5791                                 << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
5792
5793                         result = false;
5794                 }
5795
5796                 /* Release buffer mapping */
5797                 buffer->UnMap();
5798         }
5799
5800         return result;
5801 }
5802
5803 /** Unbinds all uniforms and xfb
5804  *
5805  **/
5806 void BufferTestBase::cleanBuffers()
5807 {
5808         const Functions& gl = m_context.getRenderContext().getFunctions();
5809
5810         GLint max_uni = 0;
5811         GLint max_xfb = 0;
5812
5813         gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uni);
5814         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
5815         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5816
5817         for (GLint i = 0; i < max_uni; ++i)
5818         {
5819                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Uniform, i);
5820         }
5821
5822         for (GLint i = 0; i < max_xfb; ++i)
5823         {
5824                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Transform_feedback, i);
5825         }
5826 }
5827
5828 /** Get template of shader for given stage
5829  *
5830  * @param stage Stage
5831  *
5832  * @return Template of shader source
5833  **/
5834 std::string BufferTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
5835 {
5836         static const GLchar* compute_shader_template = "#version 430 core\n"
5837                                                                                                    "#extension GL_ARB_enhanced_layouts : require\n"
5838                                                                                                    "\n"
5839                                                                                                    "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5840                                                                                                    "\n"
5841                                                                                                    "writeonly uniform uimage2D uni_image;\n"
5842                                                                                                    "\n"
5843                                                                                                    "INTERFACE"
5844                                                                                                    "\n"
5845                                                                                                    "void main()\n"
5846                                                                                                    "{\n"
5847                                                                                                    "CALCULATIONS"
5848                                                                                                    "\n"
5849                                                                                                    "ASSIGNMENTS"
5850                                                                                                    "}\n"
5851                                                                                                    "\n";
5852
5853         static const GLchar* fragment_shader_template = "#version 430 core\n"
5854                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5855                                                                                                         "\n"
5856                                                                                                         "INTERFACE"
5857                                                                                                         "\n"
5858                                                                                                         "void main()\n"
5859                                                                                                         "{\n"
5860                                                                                                         "CALCULATIONS"
5861                                                                                                         "\n"
5862                                                                                                         "ASSIGNMENTS"
5863                                                                                                         "}\n"
5864                                                                                                         "\n";
5865
5866         // max_vertices is set to 3 for the test case "xfb_vertex_streams" declares 3 streams in geometry shader,
5867         // according to spec, max_vertices should be no less than 3 if there are 3 streams in GS.
5868         static const GLchar* geometry_shader_template = "#version 430 core\n"
5869                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5870                                                                                                         "\n"
5871                                                                                                         "layout(points)                   in;\n"
5872                                                                                                         "layout(points, max_vertices = 3) out;\n"
5873                                                                                                         "\n"
5874                                                                                                         "INTERFACE"
5875                                                                                                         "\n"
5876                                                                                                         "void main()\n"
5877                                                                                                         "{\n"
5878                                                                                                         "CALCULATIONS"
5879                                                                                                         "\n"
5880                                                                                                         "\n"
5881                                                                                                         "ASSIGNMENTS"
5882                                                                                                         "    gl_Position  = vec4(0, 0, 0, 1);\n"
5883                                                                                                         "    EmitVertex();\n"
5884                                                                                                         "}\n"
5885                                                                                                         "\n";
5886
5887         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
5888                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5889                                                                                                          "\n"
5890                                                                                                          "layout(vertices = 1) out;\n"
5891                                                                                                          "\n"
5892                                                                                                          "INTERFACE"
5893                                                                                                          "\n"
5894                                                                                                          "void main()\n"
5895                                                                                                          "{\n"
5896                                                                                                          "CALCULATIONS"
5897                                                                                                          "\n"
5898                                                                                                          "ASSIGNMENTS"
5899                                                                                                          "\n"
5900                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
5901                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
5902                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
5903                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
5904                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
5905                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
5906                                                                                                          "}\n"
5907                                                                                                          "\n";
5908
5909         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
5910                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5911                                                                                                          "\n"
5912                                                                                                          "layout(isolines, point_mode) in;\n"
5913                                                                                                          "\n"
5914                                                                                                          "INTERFACE"
5915                                                                                                          "\n"
5916                                                                                                          "void main()\n"
5917                                                                                                          "{\n"
5918                                                                                                          "CALCULATIONS"
5919                                                                                                          "\n"
5920                                                                                                          "ASSIGNMENTS"
5921                                                                                                          "}\n"
5922                                                                                                          "\n";
5923
5924         static const GLchar* vertex_shader_template = "#version 430 core\n"
5925                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
5926                                                                                                   "\n"
5927                                                                                                   "INTERFACE"
5928                                                                                                   "\n"
5929                                                                                                   "void main()\n"
5930                                                                                                   "{\n"
5931                                                                                                   "CALCULATIONS"
5932                                                                                                   "\n"
5933                                                                                                   "ASSIGNMENTS"
5934                                                                                                   "}\n"
5935                                                                                                   "\n";
5936
5937         const GLchar* result = 0;
5938
5939         switch (stage)
5940         {
5941         case Utils::Shader::COMPUTE:
5942                 result = compute_shader_template;
5943                 break;
5944         case Utils::Shader::FRAGMENT:
5945                 result = fragment_shader_template;
5946                 break;
5947         case Utils::Shader::GEOMETRY:
5948                 result = geometry_shader_template;
5949                 break;
5950         case Utils::Shader::TESS_CTRL:
5951                 result = tess_ctrl_shader_template;
5952                 break;
5953         case Utils::Shader::TESS_EVAL:
5954                 result = tess_eval_shader_template;
5955                 break;
5956         case Utils::Shader::VERTEX:
5957                 result = vertex_shader_template;
5958                 break;
5959         default:
5960                 TCU_FAIL("Invalid enum");
5961         }
5962
5963         return result;
5964 }
5965
5966 /** Prepare buffer according to descriptor
5967  *
5968  * @param buffer Buffer to prepare
5969  * @param desc   Descriptor
5970  **/
5971 void BufferTestBase::prepareBuffer(Utils::Buffer& buffer, bufferDescriptor& desc)
5972 {
5973         GLsizeiptr size = 0;
5974         GLvoid* data = 0;
5975
5976         if (false == desc.m_initial_data.empty())
5977         {
5978                 size = desc.m_initial_data.size();
5979                 data = &desc.m_initial_data[0];
5980         }
5981         else if (false == desc.m_expected_data.empty())
5982         {
5983                 size = desc.m_expected_data.size();
5984         }
5985
5986         buffer.Init(desc.m_target, Utils::Buffer::StaticDraw, size, data);
5987
5988         if (bufferDescriptor::m_non_indexed != desc.m_index)
5989         {
5990                 buffer.BindBase(desc.m_index);
5991         }
5992         else
5993         {
5994                 buffer.Bind();
5995         }
5996 }
5997
5998 /** Prepare collection of buffer
5999  *
6000  * @param descriptors Collection of descriptors
6001  * @param out_buffers Collection of buffers
6002  **/
6003 void BufferTestBase::prepareBuffers(bufferDescriptor::Vector& descriptors, bufferCollection& out_buffers)
6004 {
6005         for (bufferDescriptor::Vector::iterator it = descriptors.begin(), end = descriptors.end(); end != it; ++it)
6006         {
6007                 bufferCollection::pair pair;
6008
6009                 pair.m_buffer = new Utils::Buffer(m_context);
6010                 if (0 == pair.m_buffer)
6011                 {
6012                         TCU_FAIL("Memory allocation failed");
6013                 }
6014
6015                 pair.m_descriptor = &(*it);
6016
6017                 prepareBuffer(*pair.m_buffer, *pair.m_descriptor);
6018
6019                 out_buffers.m_vector.push_back(pair);
6020         }
6021 }
6022
6023 /** Destructor
6024  *
6025  **/
6026 BufferTestBase::bufferCollection::~bufferCollection()
6027 {
6028         for (Vector::iterator it = m_vector.begin(), end = m_vector.end(); end != it; ++it)
6029         {
6030                 if (0 != it->m_buffer)
6031                 {
6032                         delete it->m_buffer;
6033                         it->m_buffer = 0;
6034                 }
6035         }
6036 }
6037
6038 /** Constructor
6039  *
6040  * @param context          Test context
6041  * @param test_name        Name of test
6042  * @param test_description Description of test
6043  **/
6044 NegativeTestBase::NegativeTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6045         : TestBase(context, test_name, test_description)
6046 {
6047 }
6048
6049 /** Selects if "compute" stage is relevant for test
6050  *
6051  * @param ignored
6052  *
6053  * @return true
6054  **/
6055 bool NegativeTestBase::isComputeRelevant(GLuint /* test_case_index */)
6056 {
6057         return true;
6058 }
6059
6060 /** Selects if compilation failure is expected result
6061  *
6062  * @param ignored
6063  *
6064  * @return true
6065  **/
6066 bool NegativeTestBase::isFailureExpected(GLuint /* test_case_index */)
6067 {
6068         return true;
6069 }
6070
6071 /** Runs test case
6072  *
6073  * @param test_case_index Id of test case
6074  *
6075  * @return true if test case pass, false otherwise
6076  **/
6077 bool NegativeTestBase::testCase(GLuint test_case_index)
6078 {
6079         bool test_case_result = true;
6080
6081         /* Compute */
6082         if (true == isComputeRelevant(test_case_index))
6083         {
6084                 const std::string& cs_source               = getShaderSource(test_case_index, Utils::Shader::COMPUTE);
6085                 bool                       is_build_error         = false;
6086                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6087                 Utils::Program   program(m_context);
6088
6089                 try
6090                 {
6091                         program.Init(cs_source, "" /* fs */, "" /* gs */, "" /* tcs */, "" /* tes */, "" /* vs */,
6092                                                  false /* separable */);
6093                 }
6094                 catch (Utils::Shader::InvalidSourceException& exc)
6095                 {
6096                         if (false == is_failure_expected)
6097                         {
6098                                 m_context.getTestContext().getLog()
6099                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6100                                 exc.log(m_context);
6101                         }
6102
6103 #if DEBUG_NEG_LOG_ERROR
6104
6105                         else
6106                         {
6107                                 m_context.getTestContext().getLog()
6108                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6109                                         << tcu::TestLog::EndMessage;
6110                                 exc.log(m_context);
6111                         }
6112
6113 #endif /* DEBUG_NEG_LOG_ERROR */
6114
6115                         is_build_error = true;
6116                 }
6117                 catch (Utils::Program::BuildException& exc)
6118                 {
6119                         if (false == is_failure_expected)
6120                         {
6121                                 m_context.getTestContext().getLog()
6122                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6123                                 exc.log(m_context);
6124                         }
6125
6126 #if DEBUG_NEG_LOG_ERROR
6127
6128                         else
6129                         {
6130                                 m_context.getTestContext().getLog()
6131                                         << tcu::TestLog::Message
6132                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6133                                 exc.log(m_context);
6134                         }
6135
6136 #endif /* DEBUG_NEG_LOG_ERROR */
6137
6138                         is_build_error = true;
6139                 }
6140
6141                 if (is_build_error != is_failure_expected)
6142                 {
6143                         if (!is_build_error)
6144                         {
6145                                 m_context.getTestContext().getLog()
6146                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6147                                 Utils::Shader::LogSource(m_context, cs_source, Utils::Shader::COMPUTE);
6148                         }
6149                         test_case_result = false;
6150                 }
6151         }
6152         else /* Draw */
6153         {
6154                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6155                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6156                 bool                       is_build_error         = false;
6157                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6158                 Utils::Program   program(m_context);
6159                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6160                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6161                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6162
6163                 try
6164                 {
6165                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6166                 }
6167                 catch (Utils::Shader::InvalidSourceException& exc)
6168                 {
6169                         if (false == is_failure_expected)
6170                         {
6171                                 m_context.getTestContext().getLog()
6172                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6173                                 exc.log(m_context);
6174                         }
6175
6176 #if DEBUG_NEG_LOG_ERROR
6177
6178                         else
6179                         {
6180                                 m_context.getTestContext().getLog()
6181                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6182                                         << tcu::TestLog::EndMessage;
6183                                 exc.log(m_context);
6184                         }
6185
6186 #endif /* DEBUG_NEG_LOG_ERROR */
6187
6188                         is_build_error = true;
6189                 }
6190                 catch (Utils::Program::BuildException& exc)
6191                 {
6192                         if (false == is_failure_expected)
6193                         {
6194                                 m_context.getTestContext().getLog()
6195                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6196                                 exc.log(m_context);
6197                         }
6198
6199 #if DEBUG_NEG_LOG_ERROR
6200
6201                         else
6202                         {
6203                                 m_context.getTestContext().getLog()
6204                                         << tcu::TestLog::Message
6205                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6206                                 exc.log(m_context);
6207                         }
6208
6209 #endif /* DEBUG_NEG_LOG_ERROR */
6210
6211                         is_build_error = true;
6212                 }
6213
6214                 if (is_build_error != is_failure_expected)
6215                 {
6216                         if (!is_build_error)
6217                         {
6218                                 m_context.getTestContext().getLog()
6219                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6220                                 Utils::Shader::LogSource(m_context, vs_source, Utils::Shader::VERTEX);
6221                                 Utils::Shader::LogSource(m_context, tcs_source, Utils::Shader::TESS_CTRL);
6222                                 Utils::Shader::LogSource(m_context, tes_source, Utils::Shader::TESS_EVAL);
6223                                 Utils::Shader::LogSource(m_context, gs_source, Utils::Shader::GEOMETRY);
6224                                 Utils::Shader::LogSource(m_context, fs_source, Utils::Shader::FRAGMENT);
6225                         }
6226                         test_case_result = false;
6227                 }
6228         }
6229
6230         return test_case_result;
6231 }
6232
6233 /* Constants used by TextureTestBase */
6234 const glw::GLuint TextureTestBase::m_width  = 16;
6235 const glw::GLuint TextureTestBase::m_height = 16;
6236
6237 /** Constructor
6238  *
6239  * @param context          Test context
6240  * @param test_name        Name of test
6241  * @param test_description Description of test
6242  **/
6243 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6244         : TestBase(context, test_name, test_description)
6245 {
6246 }
6247
6248 /** Get locations for all inputs with automatic_location
6249  *
6250  * @param program           Program object
6251  * @param program_interface Interface of program
6252  **/
6253 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6254 {
6255         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6256
6257         Utils::Variable::PtrVector& inputs = si.m_inputs;
6258
6259         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6260         {
6261                 /* Test does not specify location, query value and set */
6262                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6263                 {
6264                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6265                         GLint  location = 0;
6266
6267                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6268
6269                         (*it)->m_descriptor.m_expected_location = location;
6270                 }
6271         }
6272 }
6273
6274 /** Verifies contents of drawn image
6275  *
6276  * @param ignored
6277  * @param color_0 Verified image
6278  *
6279  * @return true if image is filled with 1, false otherwise
6280  **/
6281 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6282 {
6283         static const GLuint size                   = m_width * m_height;
6284         static const GLuint expected_color = 1;
6285
6286         std::vector<GLuint> data;
6287         data.resize(size);
6288
6289         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6290
6291         for (GLuint i = 0; i < size; ++i)
6292         {
6293                 const GLuint color = data[i];
6294
6295                 if (expected_color != color)
6296                 {
6297                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6298                                                                                                 << tcu::TestLog::EndMessage;
6299                         return false;
6300                 }
6301         }
6302
6303         return true;
6304 }
6305
6306 /** Execute dispatch compute for 16x16x1
6307  *
6308  * @param ignored
6309  **/
6310 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6311 {
6312         const Functions& gl = m_context.getRenderContext().getFunctions();
6313
6314         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6315         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6316 }
6317
6318 /** Execute drawArrays for single vertex
6319  *
6320  * @param ignored
6321  **/
6322 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6323 {
6324         const Functions& gl = m_context.getRenderContext().getFunctions();
6325
6326         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6327         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6328 }
6329
6330 /** Prepare code snippet that will pass in variables to out variables
6331  *
6332  * @param ignored
6333  * @param varying_passthrough Collection of connections between in and out variables
6334  * @param stage               Shader stage
6335  *
6336  * @return Code that pass in variables to next stage
6337  **/
6338 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6339                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6340 {
6341         static const GLchar* separator = "\n    ";
6342
6343         /* Skip for compute shader */
6344         if (Utils::Shader::COMPUTE == stage)
6345         {
6346                 return "";
6347         }
6348
6349         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6350
6351         std::string result   = Utils::g_list;
6352         size_t          position = 0;
6353
6354         for (GLuint i = 0; i < vector.size(); ++i)
6355         {
6356
6357                 Utils::VaryingConnection& connection = vector[i];
6358
6359                 Utils::Variable* in  = connection.m_in;
6360                 Utils::Variable* out = connection.m_out;
6361
6362                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6363                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6364
6365                 const std::string passthrough =
6366                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6367
6368                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6369         }
6370
6371         Utils::endList("", position, result);
6372
6373         return result;
6374 }
6375
6376 /** Basic implementation of method getProgramInterface
6377  *
6378  * @param ignored
6379  * @param ignored
6380  * @param ignored
6381  **/
6382 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6383                                                                                   Utils::ProgramInterface& /* program_interface */,
6384                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6385 {
6386 }
6387
6388 /** Prepare code snippet that will verify in and uniform variables
6389  *
6390  * @param ignored
6391  * @param program_interface Interface of program
6392  * @param stage             Shader stage
6393  *
6394  * @return Code that verify variables
6395  **/
6396 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6397                                                                                                         Utils::ProgramInterface& program_interface,
6398                                                                                                         Utils::Shader::STAGES   stage)
6399 {
6400         static const GLchar* separator = " ||\n        ";
6401
6402         std::string verification = "if (LIST)\n"
6403                                                            "    {\n"
6404                                                            "        result = 0u;\n"
6405                                                            "    }\n";
6406
6407         /* Get flavour of in and out variables */
6408         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6409
6410         /* Get interface for shader stage */
6411         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6412
6413         /* There are no varialbes to verify */
6414         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6415         {
6416                 return "";
6417         }
6418
6419         /* For each in variable insert verification code */
6420         size_t position = 0;
6421
6422         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6423         {
6424                 const Utils::Variable& var                              = *si.m_inputs[i];
6425                 const std::string&       var_verification = getVariableVerifcation("", var.m_data, var.m_descriptor, in_flavour);
6426
6427                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6428         }
6429
6430         /* For each unifrom variable insert verification code */
6431         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6432         {
6433                 const Utils::Variable& var = *si.m_uniforms[i];
6434                 const std::string&       var_verification =
6435                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6436
6437                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6438         }
6439
6440         /* For each ssb variable insert verification code */
6441         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6442         {
6443                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6444                 const std::string&       var_verification =
6445                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6446
6447                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6448         }
6449
6450         Utils::endList("", position, verification);
6451
6452 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6453
6454         {
6455                 GLchar buffer[16];
6456                 sprintf(buffer, "%d", stage + 10);
6457                 Utils::replaceToken("0u", position, buffer, verification);
6458         }
6459
6460 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6461
6462         if (Utils::Shader::VERTEX == stage)
6463         {
6464                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6465         }
6466         else
6467         {
6468                 Utils::replaceToken("0u", position, "31u", verification);
6469         }
6470
6471 #endif
6472
6473         /* Done */
6474         return verification;
6475 }
6476
6477 /** Selects if "compute" stage is relevant for test
6478  *
6479  * @param ignored
6480  *
6481  * @return true
6482  **/
6483 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6484 {
6485         return true;
6486 }
6487
6488 /** Selects if "draw" stages are relevant for test
6489  *
6490  * @param ignored
6491  *
6492  * @return true
6493  **/
6494 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6495 {
6496         return true;
6497 }
6498
6499 /** Prepare code that will do assignment of single in to single out
6500  *
6501  * @param in_parent_name  Name of parent in variable
6502  * @param in_variable     Descriptor of in variable
6503  * @param in_flavour      Flavoud of in variable
6504  * @param out_parent_name Name of parent out variable
6505  * @param out_variable    Descriptor of out variable
6506  * @param out_flavour     Flavoud of out variable
6507  *
6508  * @return Code that does OUT = IN
6509  **/
6510 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6511                                                                                                         const Utils::Variable::Descriptor& in_variable,
6512                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6513                                                                                                         const std::string&                                 out_parent_name,
6514                                                                                                         const Utils::Variable::Descriptor& out_variable,
6515                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6516 {
6517         bool                             done             = false;
6518         GLuint                           index            = 0;
6519         GLuint                           member_index = 0;
6520         size_t                           position        = 0;
6521         std::string                      result           = Utils::g_list;
6522         static const GLchar* separator  = ";\n    ";
6523
6524         /* For each member of each array element */
6525         do
6526         {
6527                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6528                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6529                 std::string               passthrough;
6530
6531                 /* Prepare verification */
6532                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6533                 {
6534                         size_t pass_position = 0;
6535
6536                         passthrough = "OUT = IN;";
6537
6538                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6539                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6540
6541                         /* Increment index */
6542                         ++index;
6543                 }
6544                 else
6545                 {
6546                         const Utils::Interface* in_interface  = in_variable.m_interface;
6547                         const Utils::Interface* out_interface = out_variable.m_interface;
6548
6549                         if ((0 == in_interface) || (0 == out_interface))
6550                         {
6551                                 TCU_FAIL("Nullptr");
6552                         }
6553
6554                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6555                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6556
6557                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6558                                                                                                  Utils::Variable::BASIC);
6559
6560                         /* Increment member_index */
6561                         ++member_index;
6562
6563                         /* Increment index and reset member_index if all members were processed */
6564                         if (in_interface->m_members.size() == member_index)
6565                         {
6566                                 ++index;
6567                                 member_index = 0;
6568                         }
6569                 }
6570
6571                 /* Check if loop should end */
6572                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6573                 {
6574                         done = true;
6575                 }
6576
6577                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6578
6579         } while (true != done);
6580
6581         Utils::endList("", position, result);
6582
6583         /* Done */
6584         return result;
6585 }
6586
6587 /** Get verification of single variable
6588  *
6589  * @param parent_name Name of parent variable
6590  * @param data        Data that should be used as EXPECTED
6591  * @param variable    Descriptor of variable
6592  * @param flavour     Flavour of variable
6593  *
6594  * @return Code that does (EXPECTED != VALUE) ||
6595  **/
6596 std::string TextureTestBase::getVariableVerifcation(const std::string& parent_name, const GLvoid* data,
6597                                                                                                         const Utils::Variable::Descriptor& variable,
6598                                                                                                         Utils::Variable::FLAVOUR                   flavour)
6599 {
6600         static const GLchar* logic_op   = " ||\n        ";
6601         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6602         size_t                           position   = 0;
6603         std::string                      result         = Utils::g_list;
6604         GLint                            stride         = variable.m_expected_stride_of_element;
6605
6606         /* For each each array element */
6607         for (GLuint element = 0; element < n_elements; ++element)
6608         {
6609                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6610
6611                 /* Calculate data pointer */
6612                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6613
6614                 /* Prepare verification */
6615                 if (Utils::Variable::BUILTIN == variable.m_type)
6616                 {
6617                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6618                         std::string                verification;
6619                         size_t                     verification_position = 0;
6620
6621                         verification = "(EXPECTED != NAME)";
6622
6623                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6624                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6625
6626                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6627                 }
6628                 else
6629                 {
6630                         const Utils::Interface* interface = variable.m_interface;
6631
6632                         if (0 == interface)
6633                         {
6634                                 TCU_FAIL("Nullptr");
6635                         }
6636
6637                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6638
6639                         /* for each member */
6640                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6641                         {
6642                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6643
6644                                 /* Get verification of member */
6645                                 const std::string& verification =
6646                                         getVariableVerifcation(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6647
6648                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6649                         }
6650                 }
6651         }
6652
6653         Utils::endList("", position, result);
6654
6655         return result;
6656 }
6657
6658 /** Prepare attributes, vertex array object and array buffer
6659  *
6660  * @param test_case_index   Index of test case
6661  * @param program_interface Interface of program
6662  * @param buffer            Array buffer
6663  * @param vao               Vertex array object
6664  **/
6665 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6666                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6667 {
6668         bool use_component_qualifier = useComponentQualifier(test_case_index);
6669
6670         /* Get shader interface */
6671         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6672
6673         /* Bind vao and buffer */
6674         vao.Bind();
6675         buffer.Bind();
6676
6677         /* Skip if there are no input variables in vertex shader */
6678         if (0 == si.m_inputs.size())
6679         {
6680                 return;
6681         }
6682
6683         /* Calculate vertex stride and check */
6684         GLint vertex_stride = 0;
6685
6686         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6687         {
6688                 Utils::Variable& variable = *si.m_inputs[i];
6689
6690                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6691
6692                 GLint ends_at = variable_size + variable.m_descriptor.m_offset;
6693
6694                 vertex_stride = std::max(vertex_stride, ends_at);
6695         }
6696
6697         /* Prepare buffer data and set up vao */
6698         std::vector<GLubyte> buffer_data;
6699         buffer_data.resize(vertex_stride);
6700
6701         GLubyte* ptr = &buffer_data[0];
6702
6703         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6704         {
6705                 Utils::Variable& variable = *si.m_inputs[i];
6706
6707                 memcpy(ptr + variable.m_descriptor.m_offset, variable.m_data, variable.m_data_size);
6708
6709                 if (false == use_component_qualifier)
6710                 {
6711                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6712                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6713                                                   variable.GetStride(), (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6714                 }
6715                 else if (0 == variable.m_descriptor.m_expected_component)
6716                 {
6717                         /* Components can only be applied to vectors.
6718                          Assumption that test use all 4 components */
6719                         const Utils::Type& type =
6720                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6721
6722                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6723                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6724                                                   (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6725                 }
6726         }
6727
6728         /* Update buffer */
6729         buffer.Data(Utils::Buffer::StaticDraw, vertex_stride, ptr);
6730 }
6731
6732 /** Get locations for all outputs with automatic_location
6733  *
6734  * @param program           Program object
6735  * @param program_interface Interface of program
6736  **/
6737 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6738 {
6739         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6740         Utils::Variable::PtrVector& outputs = si.m_outputs;
6741
6742         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6743         {
6744                 /* Test does not specify location, query value and set */
6745                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6746                 {
6747                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6748                         GLint  location = 0;
6749
6750                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6751
6752                         (*it)->m_descriptor.m_expected_location = location;
6753                 }
6754         }
6755 }
6756
6757 /** Prepare framebuffer with single texture as color attachment
6758  *
6759  * @param framebuffer     Framebuffer
6760  * @param color_0_texture Texture that will used as color attachment
6761  **/
6762 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6763 {
6764         /* Prepare data */
6765         std::vector<GLuint> texture_data;
6766         texture_data.resize(m_width * m_height);
6767
6768         for (GLuint i = 0; i < texture_data.size(); ++i)
6769         {
6770                 texture_data[i] = 0x20406080;
6771         }
6772
6773         /* Prepare texture */
6774         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6775                                                  &texture_data[0]);
6776
6777         /* Prepare framebuffer */
6778         framebuffer.Init();
6779         framebuffer.Bind();
6780         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6781
6782         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6783         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6784 }
6785
6786 /** Prepare iamge unit for compute shader
6787  *
6788  * @param location      Uniform location
6789  * @param image_texture Texture that will used as color attachment
6790  **/
6791 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6792 {
6793         static const GLuint image_unit = 0;
6794
6795         std::vector<GLuint> texture_data;
6796         texture_data.resize(m_width * m_height);
6797
6798         for (GLuint i = 0; i < texture_data.size(); ++i)
6799         {
6800                 texture_data[i] = 0x20406080;
6801         }
6802
6803         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6804                                            &texture_data[0]);
6805
6806         const Functions& gl = m_context.getRenderContext().getFunctions();
6807
6808         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6809                                                 GL_WRITE_ONLY, GL_R32UI);
6810         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6811
6812         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6813 }
6814
6815 /** Basic implementation
6816  *
6817  * @param ignored
6818  * @param si        Shader interface
6819  * @param program   Program
6820  * @param cs_buffer Buffer for ssb blocks
6821  **/
6822 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6823                                                                   Utils::Buffer& buffer)
6824 {
6825         /* Skip if there are no input variables in vertex shader */
6826         if (0 == si.m_ssb_blocks.size())
6827         {
6828                 return;
6829         }
6830
6831         /* Calculate vertex stride */
6832         GLint ssbs_stride = 0;
6833
6834         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6835         {
6836                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6837
6838                 if (false == variable.IsBlock())
6839                 {
6840                         continue;
6841                 }
6842
6843                 GLint variable_stride = variable.GetStride();
6844
6845                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6846
6847                 ssbs_stride = std::max(ssbs_stride, ends_at);
6848         }
6849
6850         /* Set active program */
6851         program.Use();
6852
6853         /* Allocate */
6854         buffer.Bind();
6855         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6856
6857         /* Set up uniforms */
6858         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6859         {
6860                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6861
6862                 /* prepareUnifor should work fine for ssb blocks */
6863                 prepareUniform(program, variable, buffer);
6864         }
6865 }
6866
6867 /** Basic implementation
6868  *
6869  * @param test_case_index   Test case index
6870  * @param program_interface Program interface
6871  * @param program           Program
6872  * @param cs_buffer         Buffer for compute shader stage
6873  **/
6874 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6875                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6876 {
6877         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6878
6879         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6880
6881         prepareSSBs(test_case_index, cs, program, cs_buffer);
6882
6883         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6884 }
6885
6886 /** Basic implementation
6887  *
6888  * @param test_case_index   Test case index
6889  * @param program_interface Program interface
6890  * @param program           Program
6891  * @param fs_buffer         Buffer for fragment shader stage
6892  * @param gs_buffer         Buffer for geometry shader stage
6893  * @param tcs_buffer        Buffer for tessellation control shader stage
6894  * @param tes_buffer        Buffer for tessellation evaluation shader stage
6895  * @param vs_buffer         Buffer for vertex shader stage
6896  **/
6897 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6898                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6899                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6900 {
6901         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6902         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6903         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6904         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6905         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6906
6907         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6908         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6909         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6910         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6911         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6912
6913         prepareSSBs(test_case_index, fs, program, fs_buffer);
6914         prepareSSBs(test_case_index, gs, program, gs_buffer);
6915         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
6916         prepareSSBs(test_case_index, tes, program, tes_buffer);
6917         prepareSSBs(test_case_index, vs, program, vs_buffer);
6918
6919         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
6920         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
6921         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
6922         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
6923         vs_buffer.BindBase(Utils::Shader::VERTEX);
6924 }
6925
6926 /** Updates buffer data with variable
6927  *
6928  * @param program  Program object
6929  * @param variable Variable
6930  * @param buffer   Buffer
6931  **/
6932 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
6933 {
6934         const Functions& gl = m_context.getRenderContext().getFunctions();
6935
6936         GLsizei count = variable.m_descriptor.m_n_array_elements;
6937         if (0 == count)
6938         {
6939                 count = 1;
6940         }
6941
6942         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
6943         {
6944                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
6945                                                 variable.m_data);
6946         }
6947         else
6948         {
6949                 const bool is_block = variable.IsBlock();
6950
6951                 if (false == is_block)
6952                 {
6953                         TCU_FAIL("Not implemented");
6954                 }
6955                 else
6956                 {
6957                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
6958                                                    variable.m_data);
6959                 }
6960         }
6961 }
6962
6963 /** Basic implementation
6964  *
6965  * @param ignored
6966  * @param si        Shader interface
6967  * @param program   Program
6968  * @param cs_buffer Buffer for uniform blocks
6969  **/
6970 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6971                                                                           Utils::Buffer& buffer)
6972 {
6973         /* Skip if there are no input variables in vertex shader */
6974         if (0 == si.m_uniforms.size())
6975         {
6976                 return;
6977         }
6978
6979         /* Calculate vertex stride */
6980         GLint uniforms_stride = 0;
6981
6982         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6983         {
6984                 Utils::Variable& variable = *si.m_uniforms[i];
6985
6986                 if (false == variable.IsBlock())
6987                 {
6988                         continue;
6989                 }
6990
6991                 GLint variable_stride = variable.GetStride();
6992
6993                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6994
6995                 uniforms_stride = std::max(uniforms_stride, ends_at);
6996         }
6997
6998         /* Set active program */
6999         program.Use();
7000
7001         /* Allocate */
7002         buffer.Bind();
7003         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
7004
7005         /* Set up uniforms */
7006         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7007         {
7008                 Utils::Variable& variable = *si.m_uniforms[i];
7009
7010                 prepareUniform(program, variable, buffer);
7011         }
7012 }
7013
7014 /** Basic implementation
7015  *
7016  * @param test_case_index   Test case index
7017  * @param program_interface Program interface
7018  * @param program           Program
7019  * @param cs_buffer         Buffer for compute shader stage
7020  **/
7021 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7022                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7023 {
7024         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7025
7026         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7027
7028         prepareUniforms(test_case_index, cs, program, cs_buffer);
7029
7030         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7031 }
7032
7033 /** Basic implementation
7034  *
7035  * @param test_case_index   Test case index
7036  * @param program_interface Program interface
7037  * @param program           Program
7038  * @param fs_buffer         Buffer for fragment shader stage
7039  * @param gs_buffer         Buffer for geometry shader stage
7040  * @param tcs_buffer        Buffer for tessellation control shader stage
7041  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7042  * @param vs_buffer         Buffer for vertex shader stage
7043  **/
7044 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7045                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7046                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7047 {
7048         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7049         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7050         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7051         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7052         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7053
7054         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7055         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7056         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7057         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7058         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7059
7060         prepareUniforms(test_case_index, fs, program, fs_buffer);
7061         prepareUniforms(test_case_index, gs, program, gs_buffer);
7062         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7063         prepareUniforms(test_case_index, tes, program, tes_buffer);
7064         prepareUniforms(test_case_index, vs, program, vs_buffer);
7065
7066         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7067         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7068         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7069         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7070         vs_buffer.BindBase(Utils::Shader::VERTEX);
7071 }
7072
7073 /** Basic implementation
7074  *
7075  * @param test_case_index   Test case index
7076  * @param program_interface Program interface
7077  * @param program           Program
7078  * @param fs_buffer         Buffer for fragment shader stage
7079  * @param gs_buffer         Buffer for geometry shader stage
7080  * @param tcs_buffer        Buffer for tessellation control shader stage
7081  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7082  * @param vs_buffer         Buffer for vertex shader stage
7083  **/
7084 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7085                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7086                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7087                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7088                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7089 {
7090         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7091         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7092         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7093         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7094         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7095
7096         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7097         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7098         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7099         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7100         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7101
7102         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7103         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7104
7105         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7106         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7107
7108         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7109         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7110
7111         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7112         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7113
7114         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7115         vs_buffer.BindBase(Utils::Shader::VERTEX);
7116 }
7117
7118 /** Prepare source for shader
7119  *
7120  * @param test_case_index     Index of test case
7121  * @param program_interface   Interface of program
7122  * @param varying_passthrough Collection of connection between in and out variables
7123  * @param stage               Shader stage
7124  *
7125  * @return Source of shader
7126  **/
7127 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7128                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7129                                                                                          Utils::Shader::STAGES          stage)
7130 {
7131         /* Get strings */
7132         const GLchar*     shader_template  = getShaderTemplate(stage);
7133         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7134
7135         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7136
7137         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7138
7139         const GLchar* per_vertex = "";
7140
7141         std::string source   = shader_template;
7142         size_t          position = 0;
7143
7144         /* Replace tokens in template */
7145         if (Utils::Shader::GEOMETRY == stage)
7146         {
7147                 if (false == useMonolithicProgram(test_case_index))
7148                 {
7149                         per_vertex = "out gl_PerVertex {\n"
7150                                                  "vec4 gl_Position;\n"
7151                                                  "};\n"
7152                                                  "\n";
7153                 }
7154
7155                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7156         }
7157
7158         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7159         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7160
7161         if (false == verification.empty())
7162         {
7163                 Utils::replaceAllTokens("ELSE", "    else ", source);
7164         }
7165         else
7166         {
7167                 Utils::replaceAllTokens("ELSE", "", source);
7168         }
7169
7170         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7171
7172         /* Done */
7173         return source;
7174 }
7175
7176 /** Returns template of shader for given stage
7177  *
7178  * @param stage Shade stage
7179  *
7180  * @return Proper template
7181  **/
7182 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7183 {
7184
7185         static const GLchar* compute_shader_template =
7186                 "#version 430 core\n"
7187                 "#extension GL_ARB_enhanced_layouts : require\n"
7188                 "\n"
7189                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7190                 "\n"
7191                 "writeonly uniform uimage2D uni_image;\n"
7192                 "\n"
7193                 "INTERFACE"
7194                 "\n"
7195                 "void main()\n"
7196                 "{\n"
7197                 "    uint result = 1u;\n"
7198                 "\n"
7199                 "    VERIFICATION"
7200                 "\n"
7201                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7202                 "}\n"
7203                 "\n";
7204
7205         static const GLchar* fragment_shader_template = "#version 430 core\n"
7206                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7207                                                                                                         "\n"
7208                                                                                                         "flat in  uint gs_fs_result;\n"
7209                                                                                                         "     out uint fs_out_result;\n"
7210                                                                                                         "\n"
7211                                                                                                         "INTERFACE"
7212                                                                                                         "\n"
7213                                                                                                         "void main()\n"
7214                                                                                                         "{\n"
7215                                                                                                         "    uint result = 1u;\n"
7216                                                                                                         "\n"
7217                                                                                                         "    if (1u != gs_fs_result)\n"
7218                                                                                                         "    {\n"
7219                                                                                                         "         result = gs_fs_result;\n"
7220                                                                                                         "    }\n"
7221                                                                                                         "ELSEVERIFICATION"
7222                                                                                                         "\n"
7223                                                                                                         "    fs_out_result = result;\n"
7224                                                                                                         "    PASSTHROUGH\n"
7225                                                                                                         "}\n"
7226                                                                                                         "\n";
7227
7228         static const GLchar* geometry_shader_template =
7229                 "#version 430 core\n"
7230                 "#extension GL_ARB_enhanced_layouts : require\n"
7231                 "\n"
7232                 "layout(points)                           in;\n"
7233                 "layout(triangle_strip, max_vertices = 4) out;\n"
7234                 "\n"
7235                 "     in  uint tes_gs_result[];\n"
7236                 "flat out uint gs_fs_result;\n"
7237                 "\n"
7238                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7239                 "INTERFACE"
7240                 "\n"
7241                 "void main()\n"
7242                 "{\n"
7243                 "    uint result = 1u;\n"
7244                 "\n"
7245                 "    if (1u != tes_gs_result[0])\n"
7246                 "    {\n"
7247                 "         result = tes_gs_result[0];\n"
7248                 "    }\n"
7249                 "ELSEVERIFICATION"
7250                 "\n"
7251                 "    gs_fs_result = result;\n"
7252                 "    PASSTHROUGH\n"
7253                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7254                 "    EmitVertex();\n"
7255                 "    gs_fs_result = result;\n"
7256                 "    PASSTHROUGH\n"
7257                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7258                 "    EmitVertex();\n"
7259                 "    gs_fs_result = result;\n"
7260                 "    PASSTHROUGH\n"
7261                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7262                 "    EmitVertex();\n"
7263                 "    gs_fs_result = result;\n"
7264                 "    PASSTHROUGH\n"
7265                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7266                 "    EmitVertex();\n"
7267                 "}\n"
7268                 "\n";
7269
7270         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7271                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7272                                                                                                          "\n"
7273                                                                                                          "layout(vertices = 1) out;\n"
7274                                                                                                          "\n"
7275                                                                                                          "in  uint vs_tcs_result[];\n"
7276                                                                                                          "out uint tcs_tes_result[];\n"
7277                                                                                                          "\n"
7278                                                                                                          "INTERFACE"
7279                                                                                                          "\n"
7280                                                                                                          "void main()\n"
7281                                                                                                          "{\n"
7282                                                                                                          "    uint result = 1u;\n"
7283                                                                                                          "\n"
7284                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7285                                                                                                          "    {\n"
7286                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7287                                                                                                          "    }\n"
7288                                                                                                          "ELSEVERIFICATION"
7289                                                                                                          "\n"
7290                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7291                                                                                                          "\n"
7292                                                                                                          "    PASSTHROUGH\n"
7293                                                                                                          "\n"
7294                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7295                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7296                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7297                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7298                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7299                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7300                                                                                                          "}\n"
7301                                                                                                          "\n";
7302
7303         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7304                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7305                                                                                                          "\n"
7306                                                                                                          "layout(isolines, point_mode) in;\n"
7307                                                                                                          "\n"
7308                                                                                                          "in  uint tcs_tes_result[];\n"
7309                                                                                                          "out uint tes_gs_result;\n"
7310                                                                                                          "\n"
7311                                                                                                          "INTERFACE"
7312                                                                                                          "\n"
7313                                                                                                          "void main()\n"
7314                                                                                                          "{\n"
7315                                                                                                          "    uint result = 1u;\n"
7316                                                                                                          "\n"
7317                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7318                                                                                                          "    {\n"
7319                                                                                                          "         result = tcs_tes_result[0];\n"
7320                                                                                                          "    }\n"
7321                                                                                                          "ELSEVERIFICATION"
7322                                                                                                          "\n"
7323                                                                                                          "    tes_gs_result = result;\n"
7324                                                                                                          "\n"
7325                                                                                                          "    PASSTHROUGH\n"
7326                                                                                                          "}\n"
7327                                                                                                          "\n";
7328
7329         static const GLchar* vertex_shader_template = "#version 430 core\n"
7330                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7331                                                                                                   "\n"
7332                                                                                                   "out uint vs_tcs_result;\n"
7333                                                                                                   "\n"
7334                                                                                                   "INTERFACE"
7335                                                                                                   "\n"
7336                                                                                                   "void main()\n"
7337                                                                                                   "{\n"
7338                                                                                                   "    uint result = 1u;\n"
7339                                                                                                   "\n"
7340                                                                                                   "    VERIFICATION\n"
7341                                                                                                   "\n"
7342                                                                                                   "    vs_tcs_result = result;\n"
7343                                                                                                   "\n"
7344                                                                                                   "    PASSTHROUGH\n"
7345                                                                                                   "}\n"
7346                                                                                                   "\n";
7347
7348         const GLchar* result = 0;
7349
7350         switch (stage)
7351         {
7352         case Utils::Shader::COMPUTE:
7353                 result = compute_shader_template;
7354                 break;
7355         case Utils::Shader::FRAGMENT:
7356                 result = fragment_shader_template;
7357                 break;
7358         case Utils::Shader::GEOMETRY:
7359                 result = geometry_shader_template;
7360                 break;
7361         case Utils::Shader::TESS_CTRL:
7362                 result = tess_ctrl_shader_template;
7363                 break;
7364         case Utils::Shader::TESS_EVAL:
7365                 result = tess_eval_shader_template;
7366                 break;
7367         case Utils::Shader::VERTEX:
7368                 result = vertex_shader_template;
7369                 break;
7370         default:
7371                 TCU_FAIL("Invalid enum");
7372         }
7373
7374         return result;
7375 }
7376
7377 /** Runs test case
7378  *
7379  * @param test_case_index Id of test case
7380  *
7381  * @return true if test case pass, false otherwise
7382  **/
7383 bool TextureTestBase::testCase(GLuint test_case_index)
7384 {
7385         try
7386         {
7387                 if (true == useMonolithicProgram(test_case_index))
7388                 {
7389                         return testMonolithic(test_case_index);
7390                 }
7391                 else
7392                 {
7393                         return testSeparable(test_case_index);
7394                 }
7395         }
7396         catch (Utils::Shader::InvalidSourceException& exc)
7397         {
7398                 exc.log(m_context);
7399                 TCU_FAIL(exc.what());
7400         }
7401         catch (Utils::Program::BuildException& exc)
7402         {
7403                 TCU_FAIL(exc.what());
7404         }
7405 }
7406
7407 /** Runs "draw" test with monolithic program
7408  *
7409  * @param test_case_index Id of test case
7410  **/
7411 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7412 {
7413         Utils::ProgramInterface   program_interface;
7414         Utils::VaryingPassthrough varying_passthrough;
7415
7416         /* */
7417         const std::string& test_name = getTestCaseName(test_case_index);
7418
7419         /* */
7420         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7421
7422         bool result = true;
7423         /* Draw */
7424         if (true == isDrawRelevant(test_case_index))
7425         {
7426                 Utils::Buffer     buffer_attr(m_context);
7427                 Utils::Buffer     buffer_ssb_fs(m_context);
7428                 Utils::Buffer     buffer_ssb_gs(m_context);
7429                 Utils::Buffer     buffer_ssb_tcs(m_context);
7430                 Utils::Buffer     buffer_ssb_tes(m_context);
7431                 Utils::Buffer     buffer_ssb_vs(m_context);
7432                 Utils::Buffer     buffer_u_fs(m_context);
7433                 Utils::Buffer     buffer_u_gs(m_context);
7434                 Utils::Buffer     buffer_u_tcs(m_context);
7435                 Utils::Buffer     buffer_u_tes(m_context);
7436                 Utils::Buffer     buffer_u_vs(m_context);
7437                 Utils::Framebuffer framebuffer(m_context);
7438                 Utils::Program   program(m_context);
7439                 Utils::Texture   texture_fb(m_context);
7440                 Utils::VertexArray vao(m_context);
7441
7442                 /* */
7443                 const std::string& fragment_shader =
7444                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7445                 const std::string& geometry_shader =
7446                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7447                 const std::string& tess_ctrl_shader =
7448                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7449                 const std::string& tess_eval_shader =
7450                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7451                 const std::string& vertex_shader =
7452                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7453
7454                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7455                                          vertex_shader, false /* is_separable */);
7456
7457                 /* */
7458                 prepareAttribLocation(program, program_interface);
7459                 prepareFragmentDataLoc(program, program_interface);
7460
7461                 /* */
7462                 std::stringstream stream;
7463                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7464                 {
7465                         m_context.getTestContext().getLog()
7466                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7467                                 << ". Inspection of draw program interface failed:\n"
7468                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7469                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7470                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7471
7472                         return false;
7473                 }
7474
7475                 /* */
7476                 program.Use();
7477
7478                 /* */
7479                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7480                 vao.Init();
7481                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7482
7483                 /* */
7484                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7485                                                 buffer_u_tes, buffer_u_vs);
7486
7487                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7488                                         buffer_ssb_tes, buffer_ssb_vs);
7489
7490                 /* */
7491                 prepareFramebuffer(framebuffer, texture_fb);
7492
7493                 /* Draw */
7494                 executeDrawCall(test_case_index);
7495
7496 #if USE_NSIGHT
7497                 m_context.getRenderContext().postIterate();
7498 #endif
7499
7500                 /* Check results */
7501                 if (false == checkResults(test_case_index, texture_fb))
7502                 {
7503                         m_context.getTestContext().getLog()
7504                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7505                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7506                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7507                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7508
7509                         result = false;
7510                 }
7511         }
7512
7513         /* Compute */
7514         if (true == isComputeRelevant(test_case_index))
7515         {
7516                 Utils::Buffer     buffer_ssb_cs(m_context);
7517                 Utils::Buffer     buffer_u_cs(m_context);
7518                 Utils::Program   program(m_context);
7519                 Utils::Texture   texture_im(m_context);
7520                 Utils::VertexArray vao(m_context);
7521
7522                 /* */
7523                 const std::string& compute_shader =
7524                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7525
7526                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7527                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7528
7529                 /* */
7530                 {
7531                         std::stringstream stream;
7532
7533                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7534                         {
7535                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7536                                                                                                         << ". Inspection of compute program interface failed:\n"
7537                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7538
7539                                 return false;
7540                         }
7541                 }
7542
7543                 /* */
7544                 program.Use();
7545
7546                 /* */
7547                 vao.Init();
7548                 vao.Bind();
7549
7550                 /* */
7551                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7552
7553                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7554
7555                 /* */
7556                 GLint image_location = program.GetUniformLocation("uni_image");
7557                 prepareImage(image_location, texture_im);
7558
7559                 /* Draw */
7560                 executeDispatchCall(test_case_index);
7561
7562 #if USE_NSIGHT
7563                 m_context.getRenderContext().postIterate();
7564 #endif
7565
7566                 /* Check results */
7567                 if (false == checkResults(test_case_index, texture_im))
7568                 {
7569                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7570                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7571                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7572
7573                         result = false;
7574                 }
7575         }
7576
7577         return result;
7578 }
7579
7580 /** Runs "draw" test with separable program
7581  *
7582  * @param test_case_index Id of test case
7583  **/
7584 bool TextureTestBase::testSeparable(GLuint test_case_index)
7585 {
7586         Utils::ProgramInterface   program_interface;
7587         Utils::VaryingPassthrough varying_passthrough;
7588
7589         /* */
7590         const std::string& test_name = getTestCaseName(test_case_index);
7591
7592         /* */
7593         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7594
7595         bool result = true;
7596         /* Draw */
7597         if (true == isDrawRelevant(test_case_index))
7598         {
7599                 Utils::Buffer     buffer_attr(m_context);
7600                 Utils::Buffer     buffer_u_fs(m_context);
7601                 Utils::Buffer     buffer_u_gs(m_context);
7602                 Utils::Buffer     buffer_u_tcs(m_context);
7603                 Utils::Buffer     buffer_u_tes(m_context);
7604                 Utils::Buffer     buffer_u_vs(m_context);
7605                 Utils::Framebuffer framebuffer(m_context);
7606                 Utils::Pipeline pipeline(m_context);
7607                 Utils::Program   program_fs(m_context);
7608                 Utils::Program   program_gs(m_context);
7609                 Utils::Program   program_tcs(m_context);
7610                 Utils::Program   program_tes(m_context);
7611                 Utils::Program   program_vs(m_context);
7612                 Utils::Texture   texture_fb(m_context);
7613                 Utils::VertexArray vao(m_context);
7614
7615                 /* */
7616                 const std::string& fs =
7617                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7618                 const std::string& gs =
7619                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7620                 const std::string& tcs =
7621                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7622                 const std::string& tes =
7623                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7624                 const std::string& vs =
7625                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7626
7627                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7628                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7629                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7630                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7631                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7632
7633                 /* */
7634                 prepareAttribLocation(program_vs, program_interface);
7635                 prepareFragmentDataLoc(program_vs, program_interface);
7636
7637                 /* */
7638                 std::stringstream stream;
7639                 if ((false ==
7640                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7641                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7642                                                                                                                                 stream)) ||
7643                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7644                                                                                                                                 stream)) ||
7645                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7646                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7647                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7648                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7649                 {
7650                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7651                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7652                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7653                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7654                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7655                                                                                                 << tcu::TestLog::KernelSource(fs);
7656
7657                         return false;
7658                 }
7659
7660                 /* */
7661                 pipeline.Init();
7662                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7663                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7664                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7665                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7666                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7667                 pipeline.Bind();
7668
7669                 /* */
7670
7671                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7672                 vao.Init();
7673                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7674
7675                 /* */
7676                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7677                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7678
7679                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7680
7681                 /* */
7682                 prepareFramebuffer(framebuffer, texture_fb);
7683
7684                 /* Draw */
7685                 executeDrawCall(test_case_index);
7686
7687 #if USE_NSIGHT
7688                 m_context.getRenderContext().postIterate();
7689 #endif
7690
7691                 /* Check results */
7692                 if (false == checkResults(test_case_index, texture_fb))
7693                 {
7694                         m_context.getTestContext().getLog()
7695                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7696                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7697                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7698
7699                         result = false;
7700                 }
7701         }
7702
7703         /* Compute */
7704         if (true == isComputeRelevant(test_case_index))
7705         {
7706                 Utils::Buffer     buffer_u_cs(m_context);
7707                 Utils::Program   program(m_context);
7708                 Utils::Texture   texture_im(m_context);
7709                 Utils::VertexArray vao(m_context);
7710
7711                 /* */
7712                 const std::string& compute_shader =
7713                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7714
7715                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7716                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7717
7718                 /* */
7719                 {
7720                         std::stringstream stream;
7721
7722                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7723                         {
7724                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7725                                                                                                         << ". Inspection of compute program interface failed:\n"
7726                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7727
7728                                 return false;
7729                         }
7730                 }
7731
7732                 /* */
7733                 program.Use();
7734
7735                 /* */
7736                 vao.Init();
7737                 vao.Bind();
7738
7739                 /* */
7740                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7741
7742                 /* */
7743                 GLint image_location = program.GetUniformLocation("uni_image");
7744                 prepareImage(image_location, texture_im);
7745
7746                 /* Draw */
7747                 executeDispatchCall(test_case_index);
7748
7749 #if USE_NSIGHT
7750                 m_context.getRenderContext().postIterate();
7751 #endif
7752
7753                 /* Check results */
7754                 if (false == checkResults(test_case_index, texture_im))
7755                 {
7756                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7757                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7758                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7759
7760                         result = false;
7761                 }
7762         }
7763
7764         return result;
7765 }
7766
7767 /** Basic implementation
7768  *
7769  * @param ignored
7770  *
7771  * @return false
7772  **/
7773 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7774 {
7775         return false;
7776 }
7777
7778 /** Basic implementation
7779  *
7780  * @param ignored
7781  *
7782  * @return true
7783  **/
7784 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7785 {
7786         return true;
7787 }
7788
7789 /** Constructor
7790  *
7791  * @param context Test framework context
7792  **/
7793 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7794         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7795 {
7796         /* Nothing to be done here */
7797 }
7798
7799 /** Execute test
7800  *
7801  * @return tcu::TestNode::STOP otherwise
7802  **/
7803 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7804 {
7805         static const GLuint expected_comp = 64;
7806         static const GLuint expected_xfb  = 4;
7807         static const GLuint expected_sep  = 4;
7808         GLint                           max_comp          = 0;
7809         GLint                           max_xfb           = 0;
7810         GLint                           max_sep           = 0;
7811         bool                            test_result   = true;
7812
7813         const Functions& gl = m_context.getRenderContext().getFunctions();
7814
7815         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7816         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7817         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7818         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7819         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7820         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7821
7822         if (expected_xfb > (GLuint)max_xfb)
7823         {
7824                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7825                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7826                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7827
7828                 test_result = false;
7829         }
7830
7831         if (expected_comp > (GLuint)max_comp)
7832         {
7833                 m_context.getTestContext().getLog()
7834                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7835                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7836
7837                 test_result = false;
7838         }
7839
7840         if (expected_sep > (GLuint)max_sep)
7841         {
7842                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7843                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7844                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7845
7846                 test_result = false;
7847         }
7848
7849         /* Set result */
7850         if (true == test_result)
7851         {
7852                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7853         }
7854         else
7855         {
7856                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7857         }
7858
7859         /* Done */
7860         return tcu::TestNode::STOP;
7861 }
7862
7863 /** Constructor
7864  *
7865  * @param context Test framework context
7866  **/
7867 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7868         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7869 {
7870         /* Nothing to be done here */
7871 }
7872
7873 /** Execute test
7874  *
7875  * @return tcu::TestNode::STOP otherwise
7876  **/
7877 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7878 {
7879         GLint              length = 0;
7880         GLchar             name[64];
7881         GLint              param = 0;
7882         Utils::Program program(m_context);
7883         bool               test_result = true;
7884
7885         const Functions& gl = m_context.getRenderContext().getFunctions();
7886
7887         try
7888         {
7889                 program.Init("" /* cs */, "#version 430 core\n"
7890                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7891                                                                   "\n"
7892                                                                   "in  vec4 vs_fs;\n"
7893                                                                   "out vec4 fs_out;\n"
7894                                                                   "\n"
7895                                                                   "void main()\n"
7896                                                                   "{\n"
7897                                                                   "    fs_out = vs_fs;\n"
7898                                                                   "}\n"
7899                                                                   "\n" /* fs */,
7900                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7901                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7902                                                                                                                           "\n"
7903                                                                                                                           "in  vec4 in_vs;\n"
7904                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7905                                                                                                                           "\n"
7906                                                                                                                           "void main()\n"
7907                                                                                                                           "{\n"
7908                                                                                                                           "    vs_fs = in_vs;\n"
7909                                                                                                                           "}\n"
7910                                                                                                                           "\n" /* vs */,
7911                                          false /* separable */);
7912         }
7913         catch (Utils::Shader::InvalidSourceException& exc)
7914         {
7915                 exc.log(m_context);
7916                 TCU_FAIL(exc.what());
7917         }
7918         catch (Utils::Program::BuildException& exc)
7919         {
7920                 TCU_FAIL(exc.what());
7921         }
7922
7923         /*
7924          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
7925          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
7926          * following:
7927          *   * MAX_NAME_LENGTH,
7928          *   * MAX_NUM_ACTIVE_VARIABLES;
7929          */
7930         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
7931         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
7932                            test_result);
7933
7934         /*
7935          * - GetProgramResourceIndex should generate INVALID_ENUM when
7936          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7937          */
7938         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
7939         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7940         /*
7941          * - GetProgramResourceName should generate INVALID_ENUM when
7942          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7943          */
7944         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
7945                                                           name);
7946         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7947
7948         /* Set result */
7949         if (true == test_result)
7950         {
7951                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7952         }
7953         else
7954         {
7955                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7956         }
7957
7958         /* Done */
7959         return tcu::TestNode::STOP;
7960 }
7961
7962 /** Check if error is the expected one.
7963  *
7964  * @param expected_error Expected error
7965  * @param message        Message to log in case of error
7966  * @param test_result    Test result, set to false in case of invalid error
7967  **/
7968 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
7969 {
7970         const Functions& gl = m_context.getRenderContext().getFunctions();
7971
7972         GLenum error = gl.getError();
7973
7974         if (error != expected_error)
7975         {
7976                 m_context.getTestContext().getLog()
7977                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
7978                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
7979
7980                 test_result = false;
7981         }
7982 }
7983
7984 /** Constructor
7985  *
7986  * @param context Test framework context
7987  **/
7988 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
7989         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
7990 {
7991         /* Nothing to be done here */
7992 }
7993
7994 /** Source for given test case and stage
7995  *
7996  * @param test_case_index Index of test case
7997  * @param stage           Shader stage
7998  *
7999  * @return Shader source
8000  **/
8001 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
8002 {
8003         static const GLchar* cs = "#version 430 core\n"
8004                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8005                                                           "\n"
8006                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8007                                                           "\n"
8008                                                           "writeonly uniform uimage2D uni_image;\n"
8009                                                           "\n"
8010                                                           "void main()\n"
8011                                                           "{\n"
8012                                                           "    uint result = 1u;\n"
8013                                                           "    CONSTANT = 3;\n"
8014                                                           "\n"
8015                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8016                                                           "}\n"
8017                                                           "\n";
8018         static const GLchar* fs = "#version 430 core\n"
8019                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8020                                                           "\n"
8021                                                           "in  vec4 gs_fs;\n"
8022                                                           "out vec4 fs_out;\n"
8023                                                           "\n"
8024                                                           "void main()\n"
8025                                                           "{\n"
8026                                                           "ASSIGNMENT"
8027                                                           "    fs_out = gs_fs;\n"
8028                                                           "}\n"
8029                                                           "\n";
8030         static const GLchar* gs = "#version 430 core\n"
8031                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8032                                                           "\n"
8033                                                           "layout(points)                           in;\n"
8034                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8035                                                           "\n"
8036                                                           "in  vec4 tes_gs[];\n"
8037                                                           "out vec4 gs_fs;\n"
8038                                                           "\n"
8039                                                           "void main()\n"
8040                                                           "{\n"
8041                                                           "ASSIGNMENT"
8042                                                           "    gs_fs = tes_gs[0];\n"
8043                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8044                                                           "    EmitVertex();\n"
8045                                                           "    gs_fs = tes_gs[0];\n"
8046                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8047                                                           "    EmitVertex();\n"
8048                                                           "    gs_fs = tes_gs[0];\n"
8049                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8050                                                           "    EmitVertex();\n"
8051                                                           "    gs_fs = tes_gs[0];\n"
8052                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8053                                                           "    EmitVertex();\n"
8054                                                           "}\n"
8055                                                           "\n";
8056         static const GLchar* tcs = "#version 430 core\n"
8057                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8058                                                            "\n"
8059                                                            "layout(vertices = 1) out;\n"
8060                                                            "\n"
8061                                                            "in  vec4 vs_tcs[];\n"
8062                                                            "out vec4 tcs_tes[];\n"
8063                                                            "\n"
8064                                                            "void main()\n"
8065                                                            "{\n"
8066                                                            "\n"
8067                                                            "ASSIGNMENT"
8068                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8069                                                            "\n"
8070                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8071                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8072                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8073                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8074                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8075                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8076                                                            "}\n"
8077                                                            "\n";
8078         static const GLchar* tes = "#version 430 core\n"
8079                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8080                                                            "\n"
8081                                                            "layout(isolines, point_mode) in;\n"
8082                                                            "\n"
8083                                                            "in  vec4 tcs_tes[];\n"
8084                                                            "out vec4 tes_gs;\n"
8085                                                            "\n"
8086                                                            "void main()\n"
8087                                                            "{\n"
8088                                                            "ASSIGNMENT"
8089                                                            "    tes_gs = tcs_tes[0];\n"
8090                                                            "}\n"
8091                                                            "\n";
8092         static const GLchar* vs = "#version 430 core\n"
8093                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8094                                                           "\n"
8095                                                           "in  vec4 in_vs;\n"
8096                                                           "out vec4 vs_tcs;\n"
8097                                                           "\n"
8098                                                           "void main()\n"
8099                                                           "{\n"
8100                                                           "ASSIGNMENT"
8101                                                           "    vs_tcs = in_vs;\n"
8102                                                           "}\n"
8103                                                           "\n";
8104
8105         std::string source;
8106         testCase&   test_case = m_test_cases[test_case_index];
8107
8108         if (Utils::Shader::COMPUTE == test_case.m_stage)
8109         {
8110                 size_t position = 0;
8111
8112                 source = cs;
8113
8114                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8115         }
8116         else
8117         {
8118                 std::string assignment = "    CONSTANT = 3;\n";
8119                 size_t          position   = 0;
8120
8121                 switch (stage)
8122                 {
8123                 case Utils::Shader::FRAGMENT:
8124                         source = fs;
8125                         break;
8126                 case Utils::Shader::GEOMETRY:
8127                         source = gs;
8128                         break;
8129                 case Utils::Shader::TESS_CTRL:
8130                         source = tcs;
8131                         break;
8132                 case Utils::Shader::TESS_EVAL:
8133                         source = tes;
8134                         break;
8135                 case Utils::Shader::VERTEX:
8136                         source = vs;
8137                         break;
8138                 default:
8139                         TCU_FAIL("Invalid enum");
8140                 }
8141
8142                 if (test_case.m_stage == stage)
8143                 {
8144                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8145                 }
8146                 else
8147                 {
8148                         assignment = "";
8149                 }
8150
8151                 position = 0;
8152                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8153         }
8154
8155         return source;
8156 }
8157
8158 /** Get description of test case
8159  *
8160  * @param test_case_index Index of test case
8161  *
8162  * @return Constant name
8163  **/
8164 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8165 {
8166         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8167
8168         return result;
8169 }
8170
8171 /** Get number of test cases
8172  *
8173  * @return Number of test cases
8174  **/
8175 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8176 {
8177         return static_cast<GLuint>(m_test_cases.size());
8178 }
8179
8180 /** Selects if "compute" stage is relevant for test
8181  *
8182  * @param test_case_index Index of test case
8183  *
8184  * @return true when tested stage is compute
8185  **/
8186 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8187 {
8188         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8189 }
8190
8191 /** Prepare all test cases
8192  *
8193  **/
8194 void GLSLContantImmutablityTest::testInit()
8195 {
8196         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8197         {
8198                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8199                 {
8200                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8201
8202                         m_test_cases.push_back(test_case);
8203                 }
8204         }
8205 }
8206
8207 /** Get name of glsl constant
8208  *
8209  * @param Constant id
8210  *
8211  * @return Name of constant used in GLSL
8212  **/
8213 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8214 {
8215         const GLchar* name = "";
8216
8217         switch (constant)
8218         {
8219         case GL_ARB_ENHANCED_LAYOUTS:
8220                 name = "GL_ARB_enhanced_layouts";
8221                 break;
8222         case GL_MAX_XFB:
8223                 name = "gl_MaxTransformFeedbackBuffers";
8224                 break;
8225         case GL_MAX_XFB_INT_COMP:
8226                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8227                 break;
8228         default:
8229                 TCU_FAIL("Invalid enum");
8230         }
8231
8232         return name;
8233 }
8234
8235 /** Constructor
8236  *
8237  * @param context Test framework context
8238  **/
8239 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8240         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8241 {
8242 }
8243
8244 /** Selects if "compute" stage is relevant for test
8245  *
8246  * @param ignored
8247  *
8248  * @return false
8249  **/
8250 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8251 {
8252         return false;
8253 }
8254
8255 /** Prepare code snippet that will verify in and uniform variables
8256  *
8257  * @param ignored
8258  * @param ignored
8259  * @param stage   Shader stage
8260  *
8261  * @return Code that verify variables
8262  **/
8263 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8264                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8265                                                                                                                   Utils::Shader::STAGES stage)
8266 {
8267         /* Get constants */
8268         const Functions& gl = m_context.getRenderContext().getFunctions();
8269
8270         GLint max_transform_feedback_buffers                            = 0;
8271         GLint max_transform_feedback_interleaved_components = 0;
8272
8273         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8274         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8275         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8276         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8277
8278         std::string verification;
8279
8280         if (Utils::Shader::VERTEX == stage)
8281         {
8282                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8283                                            "    {\n"
8284                                            "        result = 0;\n"
8285                                            "    }\n"
8286                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8287                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8288                                            "    {\n"
8289                                            "        result = 0;\n"
8290                                            "    }\n"
8291                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8292                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8293                                            "    {\n"
8294                                            "        result = 0;\n"
8295                                            "    }\n";
8296
8297                 size_t position = 0;
8298                 GLchar buffer[16];
8299
8300                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8301                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8302
8303                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8304                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8305         }
8306         else
8307         {
8308                 verification = "";
8309         }
8310
8311         return verification;
8312 }
8313
8314 /** Constructor
8315  *
8316  * @param context Test framework context
8317  **/
8318 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8319         : TextureTestBase(context, "glsl_constant_integral_expression",
8320                                           "Test verifies that symbols can be used as constant integral expressions")
8321 {
8322 }
8323
8324 /** Get interface of program
8325  *
8326  * @param ignored
8327  * @param program_interface Interface of program
8328  * @param ignored
8329  **/
8330 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8331                                                                                                                          Utils::ProgramInterface& program_interface,
8332                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8333 {
8334         /* Get constants */
8335         const Functions& gl = m_context.getRenderContext().getFunctions();
8336
8337         GLint max_transform_feedback_buffers                            = 0;
8338         GLint max_transform_feedback_interleaved_components = 0;
8339
8340         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8341         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8342         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8343         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8344
8345         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8346         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8347
8348         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8349         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8350
8351         /* Globals */
8352         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8353                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8354                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8355
8356         size_t position = 0;
8357         GLchar buffer[16];
8358
8359         sprintf(buffer, "%d", gohan_div);
8360         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8361
8362         sprintf(buffer, "%d", goten_div);
8363         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8364
8365         program_interface.m_vertex.m_globals    = globals;
8366         program_interface.m_tess_ctrl.m_globals = globals;
8367         program_interface.m_tess_eval.m_globals = globals;
8368         program_interface.m_geometry.m_globals  = globals;
8369         program_interface.m_fragment.m_globals  = globals;
8370         program_interface.m_compute.m_globals   = globals;
8371 }
8372
8373 /** Prepare code snippet that will verify in and uniform variables
8374  *
8375  * @param ignored
8376  * @param ignored
8377  * @param ignored
8378  *
8379  * @return Code that verify variables
8380  **/
8381 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8382                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8383                                                                                                                                            Utils::Shader::STAGES /* stage */)
8384 {
8385         std::string verification = "{\n"
8386                                                            "        uint goku_sum = 0;\n"
8387                                                            "        uint gohan_sum = 0;\n"
8388                                                            "        uint goten_sum = 0;\n"
8389                                                            "\n"
8390                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8391                                                            "        {\n"
8392                                                            "            goku_sum += goku[i];\n"
8393                                                            "        }\n"
8394                                                            "\n"
8395                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8396                                                            "        {\n"
8397                                                            "            gohan_sum += gohan[i];\n"
8398                                                            "        }\n"
8399                                                            "\n"
8400                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8401                                                            "        {\n"
8402                                                            "            goten_sum += goten[i];\n"
8403                                                            "        }\n"
8404                                                            "\n"
8405                                                            "        if ( (1u != goku_sum)  &&\n"
8406                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8407                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8408                                                            "        {\n"
8409                                                            "            result = 0u;\n"
8410                                                            "        }\n"
8411                                                            "    }\n";
8412
8413         size_t position = 0;
8414         GLchar buffer[16];
8415
8416         sprintf(buffer, "%d", m_gohan_length);
8417         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8418
8419         sprintf(buffer, "%d", m_goten_length);
8420         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8421
8422         return verification;
8423 }
8424
8425 /** Prepare unifroms
8426  *
8427  * @param ignored
8428  * @param ignored
8429  * @param program Program object
8430  * @param ignored
8431  **/
8432 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8433                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8434                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8435 {
8436         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8437
8438         const Functions& gl = m_context.getRenderContext().getFunctions();
8439
8440         GLint goku_location  = program.GetUniformLocation("goku");
8441         GLint gohan_location = program.GetUniformLocation("gohan");
8442         GLint goten_location = program.GetUniformLocation("goten");
8443
8444         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8445         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8446         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8447 }
8448
8449 /** Prepare unifroms
8450  *
8451  * @param test_case_index   Pass as param to first implemetnation
8452  * @param program_interface Pass as param to first implemetnation
8453  * @param program           Pass as param to first implemetnation
8454  * @param ignored
8455  * @param ignored
8456  * @param ignored
8457  * @param ignored
8458  * @param vs_buffer         Pass as param to first implemetnation
8459  **/
8460 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8461                                                                                                                  Utils::ProgramInterface& program_interface,
8462                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8463                                                                                                                  Utils::Buffer& /* gs_buffer */,
8464                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8465                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8466 {
8467         /* Call first implementation */
8468         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8469 }
8470
8471 /** Constructor
8472  *
8473  * @param context Test framework context
8474  **/
8475 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8476         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8477                                           "Test verifies offsets and alignment of uniform buffer members")
8478 {
8479 }
8480
8481 /** Get interface of program
8482  *
8483  * @param test_case_index     Test case index
8484  * @param program_interface   Interface of program
8485  * @param varying_passthrough Collection of connections between in and out variables
8486  **/
8487 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8488                                                                                                                            Utils::ProgramInterface&   program_interface,
8489                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8490 {
8491         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8492                                                   "const int type_align = TYPE_ALIGN;\n"
8493                                                   "const int type_size  = TYPE_SIZE;\n";
8494
8495         Utils::Type  type                = getType(test_case_index);
8496         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8497         const GLuint base_align  = type.GetBaseAlignment(false);
8498         const GLuint array_align = type.GetBaseAlignment(true);
8499         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8500         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8501
8502         /* Calculate offsets */
8503         const GLuint first_offset  = 0;
8504         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8505
8506 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8507
8508         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8509         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8510         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8511         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8512         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8513         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8514
8515 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8516
8517         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8518         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
8519         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8520         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8521         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8522         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
8523
8524 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8525
8526         /* Prepare data */
8527         const std::vector<GLubyte>& first  = type.GenerateData();
8528         const std::vector<GLubyte>& second = type.GenerateData();
8529         const std::vector<GLubyte>& third  = type.GenerateData();
8530         const std::vector<GLubyte>& fourth = type.GenerateData();
8531
8532         m_data.resize(eigth_offset + base_stride);
8533         GLubyte* ptr = &m_data[0];
8534         memcpy(ptr + first_offset, &first[0], first.size());
8535         memcpy(ptr + second_offset, &second[0], second.size());
8536         memcpy(ptr + third_offset, &third[0], third.size());
8537         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8538         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8539         memcpy(ptr + sixth_offset, &third[0], third.size());
8540         memcpy(ptr + seventh_offset, &second[0], second.size());
8541         memcpy(ptr + eigth_offset, &first[0], first.size());
8542
8543         /* Prepare globals */
8544         size_t position = 0;
8545         GLchar buffer[16];
8546
8547         sprintf(buffer, "%d", basic_size);
8548         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8549
8550         sprintf(buffer, "%d", type_align);
8551         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8552
8553         sprintf(buffer, "%d", base_stride);
8554         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8555
8556         /* Prepare Block */
8557         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8558
8559         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8560                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8561                                                  first_offset);
8562
8563         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8564                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8565                                                  0 /* n_array_elements */, base_stride, second_offset);
8566
8567         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8568                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8569                                                  third_offset);
8570
8571         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8572                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8573                                                  fourth_offset);
8574
8575         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8576                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8577
8578         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8579                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8580
8581         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8582                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8583                                                  eigth_offset);
8584
8585         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8586
8587         /* Add globals */
8588         vs_si.m_globals = globals;
8589
8590         /* Add uniform BLOCK */
8591         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8592                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8593
8594         /* */
8595         program_interface.CloneVertexInterface(varying_passthrough);
8596 }
8597
8598 /** Get type name
8599  *
8600  * @param test_case_index Index of test case
8601  *
8602  * @return Name of type test in test_case_index
8603  **/
8604 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8605 {
8606         return getTypeName(test_case_index);
8607 }
8608
8609 /** Returns number of types to test
8610  *
8611  * @return Number of types, 34
8612  **/
8613 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8614 {
8615         return getTypesNumber();
8616 }
8617
8618 /** Prepare code snippet that will verify in and uniform variables
8619  *
8620  * @param ignored
8621  * @param ignored
8622  * @param stage   Shader stage
8623  *
8624  * @return Code that verify variables
8625  **/
8626 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8627         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8628 {
8629         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8630                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8631                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8632                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8633                                                            "    {\n"
8634                                                            "        result = 0;\n"
8635                                                            "    }";
8636
8637         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8638
8639         Utils::replaceAllTokens("PREFIX", prefix, verification);
8640
8641         return verification;
8642 }
8643
8644 /** Constructor
8645  *
8646  * @param context Test framework context
8647  **/
8648 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8649         : NegativeTestBase(
8650                   context, "uniform_block_layout_qualifier_conflict",
8651                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8652 {
8653         /* Nothing to be done here */
8654 }
8655
8656 /** Source for given test case and stage
8657  *
8658  * @param test_case_index Index of test case
8659  * @param stage           Shader stage
8660  *
8661  * @return Shader source
8662  **/
8663 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8664                                                                                                                                          Utils::Shader::STAGES stage)
8665 {
8666         static const GLchar* cs = "#version 430 core\n"
8667                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8668                                                           "\n"
8669                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8670                                                           "\n"
8671                                                           "LAYOUTuniform Block {\n"
8672                                                           "    layout(offset = 16) vec4 boy;\n"
8673                                                           "    layout(align  = 64) vec4 man;\n"
8674                                                           "} uni_block;\n"
8675                                                           "\n"
8676                                                           "writeonly uniform image2D uni_image;\n"
8677                                                           "\n"
8678                                                           "void main()\n"
8679                                                           "{\n"
8680                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8681                                                           "\n"
8682                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8683                                                           "}\n"
8684                                                           "\n";
8685         static const GLchar* fs = "#version 430 core\n"
8686                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8687                                                           "\n"
8688                                                           "LAYOUTuniform Block {\n"
8689                                                           "    layout(offset = 16) vec4 boy;\n"
8690                                                           "    layout(align  = 64) vec4 man;\n"
8691                                                           "} uni_block;\n"
8692                                                           "\n"
8693                                                           "in  vec4 gs_fs;\n"
8694                                                           "out vec4 fs_out;\n"
8695                                                           "\n"
8696                                                           "void main()\n"
8697                                                           "{\n"
8698                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8699                                                           "}\n"
8700                                                           "\n";
8701         static const GLchar* gs = "#version 430 core\n"
8702                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8703                                                           "\n"
8704                                                           "layout(points)                           in;\n"
8705                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8706                                                           "\n"
8707                                                           "LAYOUTuniform Block {\n"
8708                                                           "    layout(offset = 16) vec4 boy;\n"
8709                                                           "    layout(align  = 64) vec4 man;\n"
8710                                                           "} uni_block;\n"
8711                                                           "\n"
8712                                                           "in  vec4 tes_gs[];\n"
8713                                                           "out vec4 gs_fs;\n"
8714                                                           "\n"
8715                                                           "void main()\n"
8716                                                           "{\n"
8717                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8718                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8719                                                           "    EmitVertex();\n"
8720                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8721                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8722                                                           "    EmitVertex();\n"
8723                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8724                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8725                                                           "    EmitVertex();\n"
8726                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8727                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8728                                                           "    EmitVertex();\n"
8729                                                           "}\n"
8730                                                           "\n";
8731         static const GLchar* tcs =
8732                 "#version 430 core\n"
8733                 "#extension GL_ARB_enhanced_layouts : require\n"
8734                 "\n"
8735                 "layout(vertices = 1) out;\n"
8736                 "\n"
8737                 "LAYOUTuniform Block {\n"
8738                 "    layout(offset = 16) vec4 boy;\n"
8739                 "    layout(align  = 64) vec4 man;\n"
8740                 "} uni_block;\n"
8741                 "\n"
8742                 "in  vec4 vs_tcs[];\n"
8743                 "out vec4 tcs_tes[];\n"
8744                 "\n"
8745                 "void main()\n"
8746                 "{\n"
8747                 "\n"
8748                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8749                 "\n"
8750                 "    gl_TessLevelOuter[0] = 1.0;\n"
8751                 "    gl_TessLevelOuter[1] = 1.0;\n"
8752                 "    gl_TessLevelOuter[2] = 1.0;\n"
8753                 "    gl_TessLevelOuter[3] = 1.0;\n"
8754                 "    gl_TessLevelInner[0] = 1.0;\n"
8755                 "    gl_TessLevelInner[1] = 1.0;\n"
8756                 "}\n"
8757                 "\n";
8758         static const GLchar* tes = "#version 430 core\n"
8759                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8760                                                            "\n"
8761                                                            "layout(isolines, point_mode) in;\n"
8762                                                            "\n"
8763                                                            "LAYOUTuniform Block {\n"
8764                                                            "    layout(offset = 16) vec4 boy;\n"
8765                                                            "    layout(align  = 64) vec4 man;\n"
8766                                                            "} uni_block;\n"
8767                                                            "\n"
8768                                                            "in  vec4 tcs_tes[];\n"
8769                                                            "out vec4 tes_gs;\n"
8770                                                            "\n"
8771                                                            "void main()\n"
8772                                                            "{\n"
8773                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8774                                                            "}\n"
8775                                                            "\n";
8776         static const GLchar* vs = "#version 430 core\n"
8777                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8778                                                           "\n"
8779                                                           "LAYOUTuniform Block {\n"
8780                                                           "    layout(offset = 16) vec4 boy;\n"
8781                                                           "    layout(align  = 64) vec4 man;\n"
8782                                                           "} uni_block;\n"
8783                                                           "\n"
8784                                                           "in  vec4 in_vs;\n"
8785                                                           "out vec4 vs_tcs;\n"
8786                                                           "\n"
8787                                                           "void main()\n"
8788                                                           "{\n"
8789                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8790                                                           "}\n"
8791                                                           "\n";
8792
8793         std::string   layout    = "";
8794         size_t            position  = 0;
8795         testCase&        test_case = m_test_cases[test_case_index];
8796         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8797         std::string   source;
8798
8799         if (0 != qualifier[0])
8800         {
8801                 size_t layout_position = 0;
8802
8803                 layout = "layout (QUALIFIER) ";
8804
8805                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8806         }
8807
8808         switch (stage)
8809         {
8810         case Utils::Shader::COMPUTE:
8811                 source = cs;
8812                 break;
8813         case Utils::Shader::FRAGMENT:
8814                 source = fs;
8815                 break;
8816         case Utils::Shader::GEOMETRY:
8817                 source = gs;
8818                 break;
8819         case Utils::Shader::TESS_CTRL:
8820                 source = tcs;
8821                 break;
8822         case Utils::Shader::TESS_EVAL:
8823                 source = tes;
8824                 break;
8825         case Utils::Shader::VERTEX:
8826                 source = vs;
8827                 break;
8828         default:
8829                 TCU_FAIL("Invalid enum");
8830         }
8831
8832         if (test_case.m_stage == stage)
8833         {
8834                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8835         }
8836         else
8837         {
8838                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8839         }
8840
8841         return source;
8842 }
8843
8844 /** Get description of test case
8845  *
8846  * @param test_case_index Index of test case
8847  *
8848  * @return Qualifier name
8849  **/
8850 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8851 {
8852         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8853
8854         return result;
8855 }
8856
8857 /** Get number of test cases
8858  *
8859  * @return Number of test cases
8860  **/
8861 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8862 {
8863         return static_cast<GLuint>(m_test_cases.size());
8864 }
8865
8866 /** Selects if "compute" stage is relevant for test
8867  *
8868  * @param test_case_index Index of test case
8869  *
8870  * @return true when tested stage is compute
8871  **/
8872 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8873 {
8874         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8875 }
8876
8877 /** Selects if compilation failure is expected result
8878  *
8879  * @param test_case_index Index of test case
8880  *
8881  * @return false for STD140 cases, true otherwise
8882  **/
8883 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8884 {
8885         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8886 }
8887
8888 /** Prepare all test cases
8889  *
8890  **/
8891 void UniformBlockLayoutQualifierConflictTest::testInit()
8892 {
8893         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8894         {
8895                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8896                 {
8897                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8898
8899                         m_test_cases.push_back(test_case);
8900                 }
8901         }
8902 }
8903
8904 /** Get name of glsl constant
8905  *
8906  * @param Constant id
8907  *
8908  * @return Name of constant used in GLSL
8909  **/
8910 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8911 {
8912         const GLchar* name = "";
8913
8914         switch (qualifier)
8915         {
8916         case DEFAULT:
8917                 name = "";
8918                 break;
8919         case STD140:
8920                 name = "std140";
8921                 break;
8922         case SHARED:
8923                 name = "shared";
8924                 break;
8925         case PACKED:
8926                 name = "packed";
8927                 break;
8928         default:
8929                 TCU_FAIL("Invalid enum");
8930         }
8931
8932         return name;
8933 }
8934
8935 /** Constructor
8936  *
8937  * @param context Test framework context
8938  **/
8939 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
8940         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
8941                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
8942 {
8943         /* Nothing to be done here */
8944 }
8945
8946 /** Constructor
8947  *
8948  * @param context     Test framework context
8949  * @param name        Test name
8950  * @param description Test description
8951  **/
8952 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
8953         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
8954         : NegativeTestBase(context, name, description)
8955 {
8956         /* Nothing to be done here */
8957 }
8958
8959 /** Source for given test case and stage
8960  *
8961  * @param test_case_index Index of test case
8962  * @param stage           Shader stage
8963  *
8964  * @return Shader source
8965  **/
8966 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
8967                                                                                                                                                   Utils::Shader::STAGES stage)
8968 {
8969         static const GLchar* cs = "#version 430 core\n"
8970                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8971                                                           "\n"
8972                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8973                                                           "\n"
8974                                                           "layout (std140) uniform Block {\n"
8975                                                           "    layout (offset = OFFSET) TYPE member;\n"
8976                                                           "} block;\n"
8977                                                           "\n"
8978                                                           "writeonly uniform image2D uni_image;\n"
8979                                                           "\n"
8980                                                           "void main()\n"
8981                                                           "{\n"
8982                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
8983                                                           "\n"
8984                                                           "    if (TYPE(1) == block.member)\n"
8985                                                           "    {\n"
8986                                                           "        result = vec4(1, 1, 1, 1);\n"
8987                                                           "    }\n"
8988                                                           "\n"
8989                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8990                                                           "}\n"
8991                                                           "\n";
8992         static const GLchar* fs = "#version 430 core\n"
8993                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8994                                                           "\n"
8995                                                           "in  vec4 gs_fs;\n"
8996                                                           "out vec4 fs_out;\n"
8997                                                           "\n"
8998                                                           "void main()\n"
8999                                                           "{\n"
9000                                                           "    fs_out = gs_fs;\n"
9001                                                           "}\n"
9002                                                           "\n";
9003         static const GLchar* fs_tested = "#version 430 core\n"
9004                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9005                                                                          "\n"
9006                                                                          "layout (std140) uniform Block {\n"
9007                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9008                                                                          "} block;\n"
9009                                                                          "\n"
9010                                                                          "in  vec4 gs_fs;\n"
9011                                                                          "out vec4 fs_out;\n"
9012                                                                          "\n"
9013                                                                          "void main()\n"
9014                                                                          "{\n"
9015                                                                          "    if (TYPE(1) == block.member)\n"
9016                                                                          "    {\n"
9017                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9018                                                                          "    }\n"
9019                                                                          "\n"
9020                                                                          "    fs_out += gs_fs;\n"
9021                                                                          "}\n"
9022                                                                          "\n";
9023         static const GLchar* gs = "#version 430 core\n"
9024                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9025                                                           "\n"
9026                                                           "layout(points)                           in;\n"
9027                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9028                                                           "\n"
9029                                                           "in  vec4 tes_gs[];\n"
9030                                                           "out vec4 gs_fs;\n"
9031                                                           "\n"
9032                                                           "void main()\n"
9033                                                           "{\n"
9034                                                           "    gs_fs = tes_gs[0];\n"
9035                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9036                                                           "    EmitVertex();\n"
9037                                                           "    gs_fs = tes_gs[0];\n"
9038                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9039                                                           "    EmitVertex();\n"
9040                                                           "    gs_fs = tes_gs[0];\n"
9041                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9042                                                           "    EmitVertex();\n"
9043                                                           "    gs_fs = tes_gs[0];\n"
9044                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9045                                                           "    EmitVertex();\n"
9046                                                           "}\n"
9047                                                           "\n";
9048         static const GLchar* gs_tested = "#version 430 core\n"
9049                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9050                                                                          "\n"
9051                                                                          "layout(points)                           in;\n"
9052                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9053                                                                          "\n"
9054                                                                          "layout (std140) uniform Block {\n"
9055                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9056                                                                          "} block;\n"
9057                                                                          "\n"
9058                                                                          "in  vec4 tes_gs[];\n"
9059                                                                          "out vec4 gs_fs;\n"
9060                                                                          "\n"
9061                                                                          "void main()\n"
9062                                                                          "{\n"
9063                                                                          "    if (TYPE(1) == block.member)\n"
9064                                                                          "    {\n"
9065                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9066                                                                          "    }\n"
9067                                                                          "\n"
9068                                                                          "    gs_fs += tes_gs[0];\n"
9069                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9070                                                                          "    EmitVertex();\n"
9071                                                                          "    gs_fs += tes_gs[0];\n"
9072                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9073                                                                          "    EmitVertex();\n"
9074                                                                          "    gs_fs += tes_gs[0];\n"
9075                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9076                                                                          "    EmitVertex();\n"
9077                                                                          "    gs_fs += tes_gs[0];\n"
9078                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9079                                                                          "    EmitVertex();\n"
9080                                                                          "}\n"
9081                                                                          "\n";
9082         static const GLchar* tcs = "#version 430 core\n"
9083                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9084                                                            "\n"
9085                                                            "layout(vertices = 1) out;\n"
9086                                                            "\n"
9087                                                            "in  vec4 vs_tcs[];\n"
9088                                                            "out vec4 tcs_tes[];\n"
9089                                                            "\n"
9090                                                            "void main()\n"
9091                                                            "{\n"
9092                                                            "\n"
9093                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9094                                                            "\n"
9095                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9096                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9097                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9098                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9099                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9100                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9101                                                            "}\n"
9102                                                            "\n";
9103         static const GLchar* tcs_tested = "#version 430 core\n"
9104                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9105                                                                           "\n"
9106                                                                           "layout(vertices = 1) out;\n"
9107                                                                           "\n"
9108                                                                           "layout (std140) uniform Block {\n"
9109                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9110                                                                           "} block;\n"
9111                                                                           "\n"
9112                                                                           "in  vec4 vs_tcs[];\n"
9113                                                                           "out vec4 tcs_tes[];\n"
9114                                                                           "\n"
9115                                                                           "void main()\n"
9116                                                                           "{\n"
9117                                                                           "    if (TYPE(1) == block.member)\n"
9118                                                                           "    {\n"
9119                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9120                                                                           "    }\n"
9121                                                                           "\n"
9122                                                                           "\n"
9123                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9124                                                                           "\n"
9125                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9126                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9127                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9128                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9129                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9130                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9131                                                                           "}\n"
9132                                                                           "\n";
9133         static const GLchar* tes = "#version 430 core\n"
9134                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9135                                                            "\n"
9136                                                            "layout(isolines, point_mode) in;\n"
9137                                                            "\n"
9138                                                            "in  vec4 tcs_tes[];\n"
9139                                                            "out vec4 tes_gs;\n"
9140                                                            "\n"
9141                                                            "void main()\n"
9142                                                            "{\n"
9143                                                            "    tes_gs = tcs_tes[0];\n"
9144                                                            "}\n"
9145                                                            "\n";
9146         static const GLchar* tes_tested = "#version 430 core\n"
9147                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9148                                                                           "\n"
9149                                                                           "layout(isolines, point_mode) in;\n"
9150                                                                           "\n"
9151                                                                           "layout (std140) uniform Block {\n"
9152                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9153                                                                           "} block;\n"
9154                                                                           "\n"
9155                                                                           "in  vec4 tcs_tes[];\n"
9156                                                                           "out vec4 tes_gs;\n"
9157                                                                           "\n"
9158                                                                           "void main()\n"
9159                                                                           "{\n"
9160                                                                           "    if (TYPE(1) == block.member)\n"
9161                                                                           "    {\n"
9162                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9163                                                                           "    }\n"
9164                                                                           "\n"
9165                                                                           "    tes_gs += tcs_tes[0];\n"
9166                                                                           "}\n"
9167                                                                           "\n";
9168         static const GLchar* vs = "#version 430 core\n"
9169                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9170                                                           "\n"
9171                                                           "in  vec4 in_vs;\n"
9172                                                           "out vec4 vs_tcs;\n"
9173                                                           "\n"
9174                                                           "void main()\n"
9175                                                           "{\n"
9176                                                           "    vs_tcs = in_vs;\n"
9177                                                           "}\n"
9178                                                           "\n";
9179         static const GLchar* vs_tested = "#version 430 core\n"
9180                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9181                                                                          "\n"
9182                                                                          "layout (std140) uniform Block {\n"
9183                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9184                                                                          "} block;\n"
9185                                                                          "\n"
9186                                                                          "in  vec4 in_vs;\n"
9187                                                                          "out vec4 vs_tcs;\n"
9188                                                                          "\n"
9189                                                                          "void main()\n"
9190                                                                          "{\n"
9191                                                                          "    if (TYPE(1) == block.member)\n"
9192                                                                          "    {\n"
9193                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9194                                                                          "    }\n"
9195                                                                          "\n"
9196                                                                          "    vs_tcs += in_vs;\n"
9197                                                                          "}\n"
9198                                                                          "\n";
9199
9200         std::string source;
9201         testCase&   test_case = m_test_cases[test_case_index];
9202
9203         if (test_case.m_stage == stage)
9204         {
9205                 GLchar                     buffer[16];
9206                 const GLuint       offset       = test_case.m_offset;
9207                 size_t                     position  = 0;
9208                 const Utils::Type& type          = test_case.m_type;
9209                 const GLchar*     type_name = type.GetGLSLTypeName();
9210
9211                 sprintf(buffer, "%d", offset);
9212
9213                 switch (stage)
9214                 {
9215                 case Utils::Shader::COMPUTE:
9216                         source = cs;
9217                         break;
9218                 case Utils::Shader::FRAGMENT:
9219                         source = fs_tested;
9220                         break;
9221                 case Utils::Shader::GEOMETRY:
9222                         source = gs_tested;
9223                         break;
9224                 case Utils::Shader::TESS_CTRL:
9225                         source = tcs_tested;
9226                         break;
9227                 case Utils::Shader::TESS_EVAL:
9228                         source = tes_tested;
9229                         break;
9230                 case Utils::Shader::VERTEX:
9231                         source = vs_tested;
9232                         break;
9233                 default:
9234                         TCU_FAIL("Invalid enum");
9235                 }
9236
9237                 Utils::replaceToken("OFFSET", position, buffer, source);
9238                 Utils::replaceToken("TYPE", position, type_name, source);
9239                 Utils::replaceToken("TYPE", position, type_name, source);
9240         }
9241         else
9242         {
9243                 switch (stage)
9244                 {
9245                 case Utils::Shader::FRAGMENT:
9246                         source = fs;
9247                         break;
9248                 case Utils::Shader::GEOMETRY:
9249                         source = gs;
9250                         break;
9251                 case Utils::Shader::TESS_CTRL:
9252                         source = tcs;
9253                         break;
9254                 case Utils::Shader::TESS_EVAL:
9255                         source = tes;
9256                         break;
9257                 case Utils::Shader::VERTEX:
9258                         source = vs;
9259                         break;
9260                 default:
9261                         TCU_FAIL("Invalid enum");
9262                 }
9263         }
9264
9265         return source;
9266 }
9267
9268 /** Get description of test case
9269  *
9270  * @param test_case_index Index of test case
9271  *
9272  * @return Type name and offset
9273  **/
9274 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9275 {
9276         std::stringstream stream;
9277         testCase&                 test_case = m_test_cases[test_case_index];
9278
9279         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9280
9281         return stream.str();
9282 }
9283
9284 /** Get number of test cases
9285  *
9286  * @return Number of test cases
9287  **/
9288 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9289 {
9290         return static_cast<GLuint>(m_test_cases.size());
9291 }
9292
9293 /** Selects if "compute" stage is relevant for test
9294  *
9295  * @param test_case_index Index of test case
9296  *
9297  * @return true when tested stage is compute
9298  **/
9299 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9300 {
9301         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9302 }
9303
9304 /** Selects if compilation failure is expected result
9305  *
9306  * @param test_case_index Index of test case
9307  *
9308  * @return should_fail field from testCase
9309  **/
9310 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9311 {
9312         return m_test_cases[test_case_index].m_should_fail;
9313 }
9314
9315 /** Checks if stage is supported
9316  *
9317  * @param stage ignored
9318  *
9319  * @return true
9320  **/
9321 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9322 {
9323         return true;
9324 }
9325
9326 /** Prepare all test cases
9327  *
9328  **/
9329 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9330 {
9331         const Functions& gl               = m_context.getRenderContext().getFunctions();
9332         GLint                    max_size = 0;
9333         const GLuint     n_types  = getTypesNumber();
9334         bool                     stage_support[Utils::Shader::STAGE_MAX];
9335
9336         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9337         {
9338                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9339         }
9340
9341         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9342         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9343
9344         for (GLuint i = 0; i < n_types; ++i)
9345         {
9346                 const Utils::Type& type           = getType(i);
9347                 const GLuint       alignment  = type.GetBaseAlignment(false);
9348                 const GLuint       type_size  = type.GetSize();
9349                 const GLuint       sec_to_end = max_size - 2 * type_size;
9350
9351                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9352                 {
9353                         if (false == stage_support[stage])
9354                         {
9355                                 continue;
9356                         }
9357
9358                         for (GLuint offset = 0; offset <= type_size; ++offset)
9359                         {
9360                                 const GLuint modulo              = offset % alignment;
9361                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9362                                 const bool   should_fail = !is_aligned;
9363
9364                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9365
9366                                 m_test_cases.push_back(test_case);
9367                         }
9368
9369                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9370                         {
9371                                 const GLuint modulo              = offset % alignment;
9372                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9373                                 const bool   should_fail = !is_aligned;
9374
9375                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9376
9377                                 m_test_cases.push_back(test_case);
9378                         }
9379                 }
9380         }
9381 }
9382
9383 /** Constructor
9384  *
9385  * @param context Test framework context
9386  **/
9387 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9388         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9389                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9390 {
9391         /* Nothing to be done here */
9392 }
9393
9394 /** Constructor
9395  *
9396  * @param context Test framework context
9397  * @param name        Test name
9398  * @param description Test description
9399  **/
9400 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9401                                                                                                                                                                    const glw::GLchar* name,
9402                                                                                                                                                                    const glw::GLchar* description)
9403         : NegativeTestBase(context, name, description)
9404 {
9405         /* Nothing to be done here */
9406 }
9407
9408 /** Source for given test case and stage
9409  *
9410  * @param test_case_index Index of test case
9411  * @param stage           Shader stage
9412  *
9413  * @return Shader source
9414  **/
9415 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9416                                                                                                                                           Utils::Shader::STAGES stage)
9417 {
9418         static const GLchar* cs = "#version 430 core\n"
9419                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9420                                                           "\n"
9421                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9422                                                           "\n"
9423                                                           "layout (std140) uniform Block {\n"
9424                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9425                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9426                                                           "} block;\n"
9427                                                           "\n"
9428                                                           "writeonly uniform image2D uni_image;\n"
9429                                                           "\n"
9430                                                           "void main()\n"
9431                                                           "{\n"
9432                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9433                                                           "\n"
9434                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9435                                                           "        (MAN_TYPE(0) == block.man) )\n"
9436                                                           "    {\n"
9437                                                           "        result = vec4(1, 1, 1, 1);\n"
9438                                                           "    }\n"
9439                                                           "\n"
9440                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9441                                                           "}\n"
9442                                                           "\n";
9443         static const GLchar* fs = "#version 430 core\n"
9444                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9445                                                           "\n"
9446                                                           "in  vec4 gs_fs;\n"
9447                                                           "out vec4 fs_out;\n"
9448                                                           "\n"
9449                                                           "void main()\n"
9450                                                           "{\n"
9451                                                           "    fs_out = gs_fs;\n"
9452                                                           "}\n"
9453                                                           "\n";
9454         static const GLchar* fs_tested = "#version 430 core\n"
9455                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9456                                                                          "\n"
9457                                                                          "layout (std140) uniform Block {\n"
9458                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9459                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9460                                                                          "} block;\n"
9461                                                                          "\n"
9462                                                                          "in  vec4 gs_fs;\n"
9463                                                                          "out vec4 fs_out;\n"
9464                                                                          "\n"
9465                                                                          "void main()\n"
9466                                                                          "{\n"
9467                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9468                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9469                                                                          "    {\n"
9470                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9471                                                                          "    }\n"
9472                                                                          "\n"
9473                                                                          "    fs_out += gs_fs;\n"
9474                                                                          "}\n"
9475                                                                          "\n";
9476         static const GLchar* gs = "#version 430 core\n"
9477                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9478                                                           "\n"
9479                                                           "layout(points)                           in;\n"
9480                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9481                                                           "\n"
9482                                                           "in  vec4 tes_gs[];\n"
9483                                                           "out vec4 gs_fs;\n"
9484                                                           "\n"
9485                                                           "void main()\n"
9486                                                           "{\n"
9487                                                           "    gs_fs = tes_gs[0];\n"
9488                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9489                                                           "    EmitVertex();\n"
9490                                                           "    gs_fs = tes_gs[0];\n"
9491                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9492                                                           "    EmitVertex();\n"
9493                                                           "    gs_fs = tes_gs[0];\n"
9494                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9495                                                           "    EmitVertex();\n"
9496                                                           "    gs_fs = tes_gs[0];\n"
9497                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9498                                                           "    EmitVertex();\n"
9499                                                           "}\n"
9500                                                           "\n";
9501         static const GLchar* gs_tested = "#version 430 core\n"
9502                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9503                                                                          "\n"
9504                                                                          "layout(points)                           in;\n"
9505                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9506                                                                          "\n"
9507                                                                          "layout (std140) uniform Block {\n"
9508                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9509                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9510                                                                          "} block;\n"
9511                                                                          "\n"
9512                                                                          "in  vec4 tes_gs[];\n"
9513                                                                          "out vec4 gs_fs;\n"
9514                                                                          "\n"
9515                                                                          "void main()\n"
9516                                                                          "{\n"
9517                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9518                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9519                                                                          "    {\n"
9520                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9521                                                                          "    }\n"
9522                                                                          "\n"
9523                                                                          "    gs_fs += tes_gs[0];\n"
9524                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9525                                                                          "    EmitVertex();\n"
9526                                                                          "    gs_fs += tes_gs[0];\n"
9527                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9528                                                                          "    EmitVertex();\n"
9529                                                                          "    gs_fs += tes_gs[0];\n"
9530                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9531                                                                          "    EmitVertex();\n"
9532                                                                          "    gs_fs += tes_gs[0];\n"
9533                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9534                                                                          "    EmitVertex();\n"
9535                                                                          "}\n"
9536                                                                          "\n";
9537         static const GLchar* tcs = "#version 430 core\n"
9538                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9539                                                            "\n"
9540                                                            "layout(vertices = 1) out;\n"
9541                                                            "\n"
9542                                                            "in  vec4 vs_tcs[];\n"
9543                                                            "out vec4 tcs_tes[];\n"
9544                                                            "\n"
9545                                                            "void main()\n"
9546                                                            "{\n"
9547                                                            "\n"
9548                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9549                                                            "\n"
9550                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9551                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9552                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9553                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9554                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9555                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9556                                                            "}\n"
9557                                                            "\n";
9558         static const GLchar* tcs_tested = "#version 430 core\n"
9559                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9560                                                                           "\n"
9561                                                                           "layout(vertices = 1) out;\n"
9562                                                                           "\n"
9563                                                                           "layout (std140) uniform Block {\n"
9564                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9565                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9566                                                                           "} block;\n"
9567                                                                           "\n"
9568                                                                           "in  vec4 vs_tcs[];\n"
9569                                                                           "out vec4 tcs_tes[];\n"
9570                                                                           "\n"
9571                                                                           "void main()\n"
9572                                                                           "{\n"
9573                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9574                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9575                                                                           "    {\n"
9576                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9577                                                                           "    }\n"
9578                                                                           "\n"
9579                                                                           "\n"
9580                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9581                                                                           "\n"
9582                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9583                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9584                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9585                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9586                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9587                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9588                                                                           "}\n"
9589                                                                           "\n";
9590         static const GLchar* tes = "#version 430 core\n"
9591                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9592                                                            "\n"
9593                                                            "layout(isolines, point_mode) in;\n"
9594                                                            "\n"
9595                                                            "in  vec4 tcs_tes[];\n"
9596                                                            "out vec4 tes_gs;\n"
9597                                                            "\n"
9598                                                            "void main()\n"
9599                                                            "{\n"
9600                                                            "    tes_gs = tcs_tes[0];\n"
9601                                                            "}\n"
9602                                                            "\n";
9603         static const GLchar* tes_tested = "#version 430 core\n"
9604                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9605                                                                           "\n"
9606                                                                           "layout(isolines, point_mode) in;\n"
9607                                                                           "\n"
9608                                                                           "layout (std140) uniform Block {\n"
9609                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9610                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9611                                                                           "} block;\n"
9612                                                                           "\n"
9613                                                                           "in  vec4 tcs_tes[];\n"
9614                                                                           "out vec4 tes_gs;\n"
9615                                                                           "\n"
9616                                                                           "void main()\n"
9617                                                                           "{\n"
9618                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9619                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9620                                                                           "    {\n"
9621                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9622                                                                           "    }\n"
9623                                                                           "\n"
9624                                                                           "    tes_gs += tcs_tes[0];\n"
9625                                                                           "}\n"
9626                                                                           "\n";
9627         static const GLchar* vs = "#version 430 core\n"
9628                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9629                                                           "\n"
9630                                                           "in  vec4 in_vs;\n"
9631                                                           "out vec4 vs_tcs;\n"
9632                                                           "\n"
9633                                                           "void main()\n"
9634                                                           "{\n"
9635                                                           "    vs_tcs = in_vs;\n"
9636                                                           "}\n"
9637                                                           "\n";
9638         static const GLchar* vs_tested = "#version 430 core\n"
9639                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9640                                                                          "\n"
9641                                                                          "layout (std140) uniform Block {\n"
9642                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9643                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9644                                                                          "} block;\n"
9645                                                                          "\n"
9646                                                                          "in  vec4 in_vs;\n"
9647                                                                          "out vec4 vs_tcs;\n"
9648                                                                          "\n"
9649                                                                          "void main()\n"
9650                                                                          "{\n"
9651                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9652                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9653                                                                          "    {\n"
9654                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9655                                                                          "    }\n"
9656                                                                          "\n"
9657                                                                          "    vs_tcs += in_vs;\n"
9658                                                                          "}\n"
9659                                                                          "\n";
9660
9661         std::string source;
9662         testCase&   test_case = m_test_cases[test_case_index];
9663
9664         if (test_case.m_stage == stage)
9665         {
9666                 GLchar                     buffer[16];
9667                 const GLuint       boy_offset   = test_case.m_boy_offset;
9668                 const Utils::Type& boy_type              = test_case.m_boy_type;
9669                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9670                 const GLuint       man_offset   = test_case.m_man_offset;
9671                 const Utils::Type& man_type              = test_case.m_man_type;
9672                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9673                 size_t                     position              = 0;
9674
9675                 switch (stage)
9676                 {
9677                 case Utils::Shader::COMPUTE:
9678                         source = cs;
9679                         break;
9680                 case Utils::Shader::FRAGMENT:
9681                         source = fs_tested;
9682                         break;
9683                 case Utils::Shader::GEOMETRY:
9684                         source = gs_tested;
9685                         break;
9686                 case Utils::Shader::TESS_CTRL:
9687                         source = tcs_tested;
9688                         break;
9689                 case Utils::Shader::TESS_EVAL:
9690                         source = tes_tested;
9691                         break;
9692                 case Utils::Shader::VERTEX:
9693                         source = vs_tested;
9694                         break;
9695                 default:
9696                         TCU_FAIL("Invalid enum");
9697                 }
9698
9699                 sprintf(buffer, "%d", boy_offset);
9700                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9701                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9702                 sprintf(buffer, "%d", man_offset);
9703                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9704                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9705                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9706                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9707         }
9708         else
9709         {
9710                 switch (stage)
9711                 {
9712                 case Utils::Shader::FRAGMENT:
9713                         source = fs;
9714                         break;
9715                 case Utils::Shader::GEOMETRY:
9716                         source = gs;
9717                         break;
9718                 case Utils::Shader::TESS_CTRL:
9719                         source = tcs;
9720                         break;
9721                 case Utils::Shader::TESS_EVAL:
9722                         source = tes;
9723                         break;
9724                 case Utils::Shader::VERTEX:
9725                         source = vs;
9726                         break;
9727                 default:
9728                         TCU_FAIL("Invalid enum");
9729                 }
9730         }
9731
9732         return source;
9733 }
9734
9735 /** Get description of test case
9736  *
9737  * @param test_case_index Index of test case
9738  *
9739  * @return Type name and offset
9740  **/
9741 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9742 {
9743         std::stringstream stream;
9744         testCase&                 test_case = m_test_cases[test_case_index];
9745
9746         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9747                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9748
9749         return stream.str();
9750 }
9751
9752 /** Get number of test cases
9753  *
9754  * @return Number of test cases
9755  **/
9756 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9757 {
9758         return static_cast<GLuint>(m_test_cases.size());
9759 }
9760
9761 /** Selects if "compute" stage is relevant for test
9762  *
9763  * @param test_case_index Index of test case
9764  *
9765  * @return true when tested stage is compute
9766  **/
9767 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9768 {
9769         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9770 }
9771
9772 /** Checks if stage is supported
9773  *
9774  * @param stage ignored
9775  *
9776  * @return true
9777  **/
9778 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9779 {
9780         return true;
9781 }
9782
9783 /** Prepare all test cases
9784  *
9785  **/
9786 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9787 {
9788         const GLuint n_types = getTypesNumber();
9789         bool             stage_support[Utils::Shader::STAGE_MAX];
9790
9791         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9792         {
9793                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9794         }
9795
9796         for (GLuint i = 0; i < n_types; ++i)
9797         {
9798                 const Utils::Type& boy_type = getType(i);
9799                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9800
9801                 for (GLuint j = 0; j < n_types; ++j)
9802                 {
9803                         const Utils::Type& man_type  = getType(j);
9804                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9805                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9806
9807                         const GLuint boy_offset           = lcm(boy_size, man_size);
9808                         const GLuint man_after_start  = boy_offset + 1;
9809                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9810                         const GLuint man_before_start = boy_offset - man_align;
9811                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9812
9813                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9814                         {
9815                                 if (false == stage_support[stage])
9816                                 {
9817                                         continue;
9818                                 }
9819
9820                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9821                                 {
9822                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9823                                                                                    (Utils::Shader::STAGES)stage };
9824
9825                                         m_test_cases.push_back(test_case);
9826                                 }
9827
9828                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9829                                 {
9830                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9831                                                                                    (Utils::Shader::STAGES)stage };
9832
9833                                         m_test_cases.push_back(test_case);
9834                                 }
9835
9836                                 /* Boy offset, should be fine for both types */
9837                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9838
9839                                 m_test_cases.push_back(test_case);
9840                         }
9841                 }
9842         }
9843 }
9844
9845 /** Find greatest common divisor for a and b
9846  *
9847  * @param a A argument
9848  * @param b B argument
9849  *
9850  * @return Found gcd value
9851  **/
9852 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9853 {
9854         if ((0 != a) && (0 == b))
9855         {
9856                 return a;
9857         }
9858         else
9859         {
9860                 GLuint greater = std::max(a, b);
9861                 GLuint lesser  = std::min(a, b);
9862
9863                 return gcd(lesser, greater % lesser);
9864         }
9865 }
9866
9867 /** Find lowest common multiple for a and b
9868  *
9869  * @param a A argument
9870  * @param b B argument
9871  *
9872  * @return Found gcd value
9873  **/
9874 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9875 {
9876         return (a * b) / gcd(a, b);
9877 }
9878
9879 /** Constructor
9880  *
9881  * @param context Test framework context
9882  **/
9883 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9884         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9885                                            "Test verifies that align qualifier requires value that is a power of 2")
9886 {
9887         /* Nothing to be done here */
9888 }
9889
9890 /** Constructor
9891  *
9892  * @param context Test framework context
9893  * @param name        Test name
9894  * @param description Test description
9895  **/
9896 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9897                                                                                                                                                            const glw::GLchar* name,
9898                                                                                                                                                            const glw::GLchar* description)
9899         : NegativeTestBase(context, name, description)
9900 {
9901         /* Nothing to be done here */
9902 }
9903
9904 /** Source for given test case and stage
9905  *
9906  * @param test_case_index Index of test case
9907  * @param stage           Shader stage
9908  *
9909  * @return Shader source
9910  **/
9911 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
9912 {
9913         static const GLchar* cs = "#version 430 core\n"
9914                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9915                                                           "\n"
9916                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9917                                                           "\n"
9918                                                           "layout (std140) uniform Block {\n"
9919                                                           "    vec4 boy;\n"
9920                                                           "    layout (align = ALIGN) TYPE man;\n"
9921                                                           "} block;\n"
9922                                                           "\n"
9923                                                           "writeonly uniform image2D uni_image;\n"
9924                                                           "\n"
9925                                                           "void main()\n"
9926                                                           "{\n"
9927                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9928                                                           "\n"
9929                                                           "    if (TYPE(0) == block.man)\n"
9930                                                           "    {\n"
9931                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
9932                                                           "    }\n"
9933                                                           "\n"
9934                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9935                                                           "}\n"
9936                                                           "\n";
9937         static const GLchar* fs = "#version 430 core\n"
9938                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9939                                                           "\n"
9940                                                           "in  vec4 gs_fs;\n"
9941                                                           "out vec4 fs_out;\n"
9942                                                           "\n"
9943                                                           "void main()\n"
9944                                                           "{\n"
9945                                                           "    fs_out = gs_fs;\n"
9946                                                           "}\n"
9947                                                           "\n";
9948         static const GLchar* fs_tested = "#version 430 core\n"
9949                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9950                                                                          "\n"
9951                                                                          "layout (std140) uniform Block {\n"
9952                                                                          "    vec4 boy;\n"
9953                                                                          "    layout (align = ALIGN) TYPE man;\n"
9954                                                                          "} block;\n"
9955                                                                          "\n"
9956                                                                          "in  vec4 gs_fs;\n"
9957                                                                          "out vec4 fs_out;\n"
9958                                                                          "\n"
9959                                                                          "void main()\n"
9960                                                                          "{\n"
9961                                                                          "    if (TYPE(0) == block.man)\n"
9962                                                                          "    {\n"
9963                                                                          "        fs_out = block.boy;\n"
9964                                                                          "    }\n"
9965                                                                          "\n"
9966                                                                          "    fs_out += gs_fs;\n"
9967                                                                          "}\n"
9968                                                                          "\n";
9969         static const GLchar* gs = "#version 430 core\n"
9970                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9971                                                           "\n"
9972                                                           "layout(points)                           in;\n"
9973                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9974                                                           "\n"
9975                                                           "in  vec4 tes_gs[];\n"
9976                                                           "out vec4 gs_fs;\n"
9977                                                           "\n"
9978                                                           "void main()\n"
9979                                                           "{\n"
9980                                                           "    gs_fs = tes_gs[0];\n"
9981                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9982                                                           "    EmitVertex();\n"
9983                                                           "    gs_fs = tes_gs[0];\n"
9984                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9985                                                           "    EmitVertex();\n"
9986                                                           "    gs_fs = tes_gs[0];\n"
9987                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9988                                                           "    EmitVertex();\n"
9989                                                           "    gs_fs = tes_gs[0];\n"
9990                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9991                                                           "    EmitVertex();\n"
9992                                                           "}\n"
9993                                                           "\n";
9994         static const GLchar* gs_tested = "#version 430 core\n"
9995                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9996                                                                          "\n"
9997                                                                          "layout(points)                           in;\n"
9998                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9999                                                                          "\n"
10000                                                                          "layout (std140) uniform Block {\n"
10001                                                                          "    vec4 boy;\n"
10002                                                                          "    layout (align = ALIGN) TYPE man;\n"
10003                                                                          "} block;\n"
10004                                                                          "\n"
10005                                                                          "in  vec4 tes_gs[];\n"
10006                                                                          "out vec4 gs_fs;\n"
10007                                                                          "\n"
10008                                                                          "void main()\n"
10009                                                                          "{\n"
10010                                                                          "    if (TYPE(0) == block.man)\n"
10011                                                                          "    {\n"
10012                                                                          "        gs_fs = block.boy;\n"
10013                                                                          "    }\n"
10014                                                                          "\n"
10015                                                                          "    gs_fs += tes_gs[0];\n"
10016                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10017                                                                          "    EmitVertex();\n"
10018                                                                          "    gs_fs += tes_gs[0];\n"
10019                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10020                                                                          "    EmitVertex();\n"
10021                                                                          "    gs_fs += tes_gs[0];\n"
10022                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10023                                                                          "    EmitVertex();\n"
10024                                                                          "    gs_fs += tes_gs[0];\n"
10025                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10026                                                                          "    EmitVertex();\n"
10027                                                                          "}\n"
10028                                                                          "\n";
10029         static const GLchar* tcs = "#version 430 core\n"
10030                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10031                                                            "\n"
10032                                                            "layout(vertices = 1) out;\n"
10033                                                            "\n"
10034                                                            "in  vec4 vs_tcs[];\n"
10035                                                            "out vec4 tcs_tes[];\n"
10036                                                            "\n"
10037                                                            "void main()\n"
10038                                                            "{\n"
10039                                                            "\n"
10040                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10041                                                            "\n"
10042                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10043                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10044                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10045                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10046                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10047                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10048                                                            "}\n"
10049                                                            "\n";
10050         static const GLchar* tcs_tested = "#version 430 core\n"
10051                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10052                                                                           "\n"
10053                                                                           "layout(vertices = 1) out;\n"
10054                                                                           "\n"
10055                                                                           "layout (std140) uniform Block {\n"
10056                                                                           "    vec4 boy;\n"
10057                                                                           "    layout (align = ALIGN) TYPE man;\n"
10058                                                                           "} block;\n"
10059                                                                           "\n"
10060                                                                           "in  vec4 vs_tcs[];\n"
10061                                                                           "out vec4 tcs_tes[];\n"
10062                                                                           "\n"
10063                                                                           "void main()\n"
10064                                                                           "{\n"
10065                                                                           "    if (TYPE(0) == block.man)\n"
10066                                                                           "    {\n"
10067                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10068                                                                           "    }\n"
10069                                                                           "\n"
10070                                                                           "\n"
10071                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10072                                                                           "\n"
10073                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10074                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10075                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10076                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10077                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10078                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10079                                                                           "}\n"
10080                                                                           "\n";
10081         static const GLchar* tes = "#version 430 core\n"
10082                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10083                                                            "\n"
10084                                                            "layout(isolines, point_mode) in;\n"
10085                                                            "\n"
10086                                                            "in  vec4 tcs_tes[];\n"
10087                                                            "out vec4 tes_gs;\n"
10088                                                            "\n"
10089                                                            "void main()\n"
10090                                                            "{\n"
10091                                                            "    tes_gs = tcs_tes[0];\n"
10092                                                            "}\n"
10093                                                            "\n";
10094         static const GLchar* tes_tested = "#version 430 core\n"
10095                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10096                                                                           "\n"
10097                                                                           "layout(isolines, point_mode) in;\n"
10098                                                                           "\n"
10099                                                                           "layout (std140) uniform Block {\n"
10100                                                                           "    vec4 boy;\n"
10101                                                                           "    layout (align = ALIGN) TYPE man;\n"
10102                                                                           "} block;\n"
10103                                                                           "\n"
10104                                                                           "in  vec4 tcs_tes[];\n"
10105                                                                           "out vec4 tes_gs;\n"
10106                                                                           "\n"
10107                                                                           "void main()\n"
10108                                                                           "{\n"
10109                                                                           "    if (TYPE(0) == block.man)\n"
10110                                                                           "    {\n"
10111                                                                           "        tes_gs = block.boy;\n"
10112                                                                           "    }\n"
10113                                                                           "\n"
10114                                                                           "    tes_gs += tcs_tes[0];\n"
10115                                                                           "}\n"
10116                                                                           "\n";
10117         static const GLchar* vs = "#version 430 core\n"
10118                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10119                                                           "\n"
10120                                                           "in  vec4 in_vs;\n"
10121                                                           "out vec4 vs_tcs;\n"
10122                                                           "\n"
10123                                                           "void main()\n"
10124                                                           "{\n"
10125                                                           "    vs_tcs = in_vs;\n"
10126                                                           "}\n"
10127                                                           "\n";
10128         static const GLchar* vs_tested = "#version 430 core\n"
10129                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10130                                                                          "\n"
10131                                                                          "layout (std140) uniform Block {\n"
10132                                                                          "    vec4 boy;\n"
10133                                                                          "    layout (align = ALIGN) TYPE man;\n"
10134                                                                          "} block;\n"
10135                                                                          "\n"
10136                                                                          "in  vec4 in_vs;\n"
10137                                                                          "out vec4 vs_tcs;\n"
10138                                                                          "\n"
10139                                                                          "void main()\n"
10140                                                                          "{\n"
10141                                                                          "    if (TYPE(0) == block.man)\n"
10142                                                                          "    {\n"
10143                                                                          "        vs_tcs = block.boy;\n"
10144                                                                          "    }\n"
10145                                                                          "\n"
10146                                                                          "    vs_tcs += in_vs;\n"
10147                                                                          "}\n"
10148                                                                          "\n";
10149
10150         std::string source;
10151         testCase&   test_case = m_test_cases[test_case_index];
10152
10153         if (test_case.m_stage == stage)
10154         {
10155                 GLchar                     buffer[16];
10156                 const GLuint       alignment = test_case.m_alignment;
10157                 const Utils::Type& type          = test_case.m_type;
10158                 const GLchar*     type_name = type.GetGLSLTypeName();
10159                 size_t                     position  = 0;
10160
10161                 switch (stage)
10162                 {
10163                 case Utils::Shader::COMPUTE:
10164                         source = cs;
10165                         break;
10166                 case Utils::Shader::FRAGMENT:
10167                         source = fs_tested;
10168                         break;
10169                 case Utils::Shader::GEOMETRY:
10170                         source = gs_tested;
10171                         break;
10172                 case Utils::Shader::TESS_CTRL:
10173                         source = tcs_tested;
10174                         break;
10175                 case Utils::Shader::TESS_EVAL:
10176                         source = tes_tested;
10177                         break;
10178                 case Utils::Shader::VERTEX:
10179                         source = vs_tested;
10180                         break;
10181                 default:
10182                         TCU_FAIL("Invalid enum");
10183                 }
10184
10185                 sprintf(buffer, "%d", alignment);
10186                 Utils::replaceToken("ALIGN", position, buffer, source);
10187                 Utils::replaceToken("TYPE", position, type_name, source);
10188                 Utils::replaceToken("TYPE", position, type_name, source);
10189         }
10190         else
10191         {
10192                 switch (stage)
10193                 {
10194                 case Utils::Shader::FRAGMENT:
10195                         source = fs;
10196                         break;
10197                 case Utils::Shader::GEOMETRY:
10198                         source = gs;
10199                         break;
10200                 case Utils::Shader::TESS_CTRL:
10201                         source = tcs;
10202                         break;
10203                 case Utils::Shader::TESS_EVAL:
10204                         source = tes;
10205                         break;
10206                 case Utils::Shader::VERTEX:
10207                         source = vs;
10208                         break;
10209                 default:
10210                         TCU_FAIL("Invalid enum");
10211                 }
10212         }
10213
10214         return source;
10215 }
10216
10217 /** Get description of test case
10218  *
10219  * @param test_case_index Index of test case
10220  *
10221  * @return Type name and offset
10222  **/
10223 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10224 {
10225         std::stringstream stream;
10226         testCase&                 test_case = m_test_cases[test_case_index];
10227
10228         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10229
10230         return stream.str();
10231 }
10232
10233 /** Get number of test cases
10234  *
10235  * @return Number of test cases
10236  **/
10237 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10238 {
10239         return static_cast<GLuint>(m_test_cases.size());
10240 }
10241
10242 /** Selects if "compute" stage is relevant for test
10243  *
10244  * @param test_case_index Index of test case
10245  *
10246  * @return true when tested stage is compute
10247  **/
10248 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10249 {
10250         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10251 }
10252
10253 /** Checks if stage is supported
10254  *
10255  * @param ignored
10256  *
10257  * @return true
10258  **/
10259 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10260 {
10261         return true;
10262 }
10263
10264 /** Selects if compilation failure is expected result
10265  *
10266  * @param test_case_index Index of test case
10267  *
10268  * @return should_fail field from testCase
10269  **/
10270 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10271 {
10272         return m_test_cases[test_case_index].m_should_fail;
10273 }
10274
10275 /** Prepare all test cases
10276  *
10277  **/
10278 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10279 {
10280         static const GLuint dmat4_size = 128;
10281         const GLuint            n_types = getTypesNumber();
10282         bool                            stage_support[Utils::Shader::STAGE_MAX];
10283
10284         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10285         {
10286                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10287         }
10288
10289         for (GLuint j = 0; j < n_types; ++j)
10290         {
10291                 const Utils::Type& type = getType(j);
10292
10293                 for (GLuint align = 0; align <= dmat4_size; ++align)
10294                 {
10295
10296 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10297
10298                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10299
10300 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10301
10302                         const bool should_fail = !isPowerOf2(align);
10303
10304 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10305
10306                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10307                         {
10308                                 if (false == stage_support[stage])
10309                                 {
10310                                         continue;
10311                                 }
10312
10313                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10314
10315                                 m_test_cases.push_back(test_case);
10316                         }
10317                 }
10318         }
10319 }
10320
10321 /** Check if value is power of 2
10322  *
10323  * @param val Tested value
10324  *
10325  * @return true if val is power of 2, false otherwise
10326  **/
10327 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10328 {
10329         if (0 == val)
10330         {
10331                 return false;
10332         }
10333
10334         return (0 == (val & (val - 1)));
10335 }
10336
10337 /** Constructor
10338  *
10339  * @param context Test framework context
10340  **/
10341 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10342         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10343 {
10344 }
10345
10346 /** Get interface of program
10347  *
10348  * @param ignored
10349  * @param program_interface Interface of program
10350  * @param varying_passthrough Collection of connections between in and out variables
10351  **/
10352 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10353                                                                                                         Utils::ProgramInterface&   program_interface,
10354                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10355 {
10356         static const Utils::Type vec4 = Utils::Type::vec4;
10357
10358 #if WRKARD_UNIFORMBLOCKALIGNMENT
10359
10360         static const GLuint block_align = 16;
10361
10362 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10363
10364         static const GLuint block_align = 64;
10365
10366 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10367
10368         static const GLuint vec4_stride = 16;
10369         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10370
10371         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10372          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10373          */
10374         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10375         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10376         const GLuint third_offset =
10377                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10378         const GLuint fourth_offset =
10379                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10380         const GLuint fifth_offset =
10381                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10382         const GLuint sixth_offset =
10383                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10384
10385         Utils::Interface* structure = program_interface.Structure("Data");
10386
10387         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10388                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10389
10390         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10391                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10392                                           Utils::Type::vec4.GetSize() /* offset */);
10393
10394         /* Prepare Block */
10395         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10396
10397         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10398                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10399
10400         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10401                                                  0 /* n_array_elements */, data_stride, second_offset);
10402
10403         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10404                                                  2 /* n_array_elements */, data_stride, third_offset);
10405
10406         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10407                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10408
10409         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10410                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10411
10412         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10413                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10414
10415         const GLuint stride = calculateStride(*vs_uni_block);
10416         m_data.resize(stride);
10417         generateData(*vs_uni_block, 0, m_data);
10418
10419         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10420
10421 /* Add uniform BLOCK */
10422 #if WRKARD_UNIFORMBLOCKALIGNMENT
10423         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10424                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10425 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10426         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10427                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10428 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10429
10430         program_interface.CloneVertexInterface(varying_passthrough);
10431 }
10432
10433 /** Constructor
10434  *
10435  * @param context Test framework context
10436  **/
10437 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10438         : TextureTestBase(context, "ssb_member_offset_and_align",
10439                                           "Test verifies offsets and alignment of storage buffer members")
10440 {
10441 }
10442
10443 /** Get interface of program
10444  *
10445  * @param test_case_index     Test case index
10446  * @param program_interface   Interface of program
10447  * @param varying_passthrough Collection of connections between in and out variables
10448  **/
10449 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10450                                                                                                           Utils::ProgramInterface&   program_interface,
10451                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10452 {
10453         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10454                                                   "const int type_align = TYPE_ALIGN;\n"
10455                                                   "const int type_size  = TYPE_SIZE;\n";
10456
10457         Utils::Type  type                = getType(test_case_index);
10458         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10459         const GLuint base_align  = type.GetBaseAlignment(false);
10460         const GLuint array_align = type.GetBaseAlignment(true);
10461         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10462         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10463
10464         /* Calculate offsets */
10465         const GLuint first_offset  = 0;
10466         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10467
10468 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10469
10470         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10471         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10472         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10473         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10474         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10475         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10476
10477 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10478
10479         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10480         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
10481         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10482         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10483         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10484         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
10485
10486 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10487
10488         /* Prepare data */
10489         const std::vector<GLubyte>& first  = type.GenerateData();
10490         const std::vector<GLubyte>& second = type.GenerateData();
10491         const std::vector<GLubyte>& third  = type.GenerateData();
10492         const std::vector<GLubyte>& fourth = type.GenerateData();
10493
10494         m_data.resize(eigth_offset + base_stride);
10495         GLubyte* ptr = &m_data[0];
10496         memcpy(ptr + first_offset, &first[0], first.size());
10497         memcpy(ptr + second_offset, &second[0], second.size());
10498         memcpy(ptr + third_offset, &third[0], third.size());
10499         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10500         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10501         memcpy(ptr + sixth_offset, &third[0], third.size());
10502         memcpy(ptr + seventh_offset, &second[0], second.size());
10503         memcpy(ptr + eigth_offset, &first[0], first.size());
10504
10505         /* Prepare globals */
10506         size_t position = 0;
10507         GLchar buffer[16];
10508
10509         sprintf(buffer, "%d", basic_size);
10510         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10511
10512         sprintf(buffer, "%d", type_align);
10513         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10514
10515         sprintf(buffer, "%d", base_stride);
10516         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10517
10518         /* Prepare Block */
10519         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10520
10521         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10522                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10523                                                  first_offset);
10524
10525         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10526                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10527                                                  0 /* n_array_elements */, base_stride, second_offset);
10528
10529         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10530                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10531                                                  third_offset);
10532
10533         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10534                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10535                                                  fourth_offset);
10536
10537         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10538                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10539
10540         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10541                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10542
10543         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10544                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10545                                                  eigth_offset);
10546
10547         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10548
10549         /* Add globals */
10550         vs_si.m_globals = globals;
10551
10552         /* Add uniform BLOCK */
10553         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10554                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10555
10556         /* */
10557         program_interface.CloneVertexInterface(varying_passthrough);
10558 }
10559
10560 /** Get type name
10561  *
10562  * @param test_case_index Index of test case
10563  *
10564  * @return Name of type test in test_case_index
10565  **/
10566 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10567 {
10568         return getTypeName(test_case_index);
10569 }
10570
10571 /** Returns number of types to test
10572  *
10573  * @return Number of types, 34
10574  **/
10575 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10576 {
10577         return getTypesNumber();
10578 }
10579
10580 /** Prepare code snippet that will verify in and uniform variables
10581  *
10582  * @param ignored
10583  * @param ignored
10584  * @param stage   Shader stage
10585  *
10586  * @return Code that verify variables
10587  **/
10588 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10589                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10590                                                                                                                                 Utils::Shader::STAGES stage)
10591 {
10592         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10593                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10594                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10595                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10596                                                            "    {\n"
10597                                                            "        result = 0;\n"
10598                                                            "    }";
10599
10600         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10601
10602         Utils::replaceAllTokens("PREFIX", prefix, verification);
10603
10604         return verification;
10605 }
10606
10607 /** Selects if "draw" stages are relevant for test
10608  *
10609  * @param ignored
10610  *
10611  * @return true if all stages support shader storage buffers, false otherwise
10612  **/
10613 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10614 {
10615         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10616         GLint                    gs_supported_buffers  = 0;
10617         GLint                    tcs_supported_buffers = 0;
10618         GLint                    tes_supported_buffers = 0;
10619         GLint                    vs_supported_buffers  = 0;
10620
10621         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10622         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10623         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10624         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10625
10626         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10627
10628         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10629                         (1 <= vs_supported_buffers));
10630 }
10631
10632 /** Constructor
10633  *
10634  * @param context Test framework context
10635  **/
10636 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10637         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10638                                                                                                                                  "offset and/or align qualifiers are used with storage "
10639                                                                                                                                  "block")
10640 {
10641         /* Nothing to be done here */
10642 }
10643
10644 /** Source for given test case and stage
10645  *
10646  * @param test_case_index Index of test case
10647  * @param stage           Shader stage
10648  *
10649  * @return Shader source
10650  **/
10651 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10652 {
10653         static const GLchar* cs = "#version 430 core\n"
10654                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10655                                                           "\n"
10656                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10657                                                           "\n"
10658                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10659                                                           "    layout(offset = 16) vec4 boy;\n"
10660                                                           "    layout(align  = 64) vec4 man;\n"
10661                                                           "} uni_block;\n"
10662                                                           "\n"
10663                                                           "writeonly uniform image2D uni_image;\n"
10664                                                           "\n"
10665                                                           "void main()\n"
10666                                                           "{\n"
10667                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10668                                                           "\n"
10669                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10670                                                           "}\n"
10671                                                           "\n";
10672         static const GLchar* fs = "#version 430 core\n"
10673                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10674                                                           "\n"
10675                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10676                                                           "    layout(offset = 16) vec4 boy;\n"
10677                                                           "    layout(align  = 64) vec4 man;\n"
10678                                                           "} uni_block;\n"
10679                                                           "\n"
10680                                                           "in  vec4 gs_fs;\n"
10681                                                           "out vec4 fs_out;\n"
10682                                                           "\n"
10683                                                           "void main()\n"
10684                                                           "{\n"
10685                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10686                                                           "}\n"
10687                                                           "\n";
10688         static const GLchar* gs = "#version 430 core\n"
10689                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10690                                                           "\n"
10691                                                           "layout(points)                           in;\n"
10692                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10693                                                           "\n"
10694                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10695                                                           "    layout(offset = 16) vec4 boy;\n"
10696                                                           "    layout(align  = 64) vec4 man;\n"
10697                                                           "} uni_block;\n"
10698                                                           "\n"
10699                                                           "in  vec4 tes_gs[];\n"
10700                                                           "out vec4 gs_fs;\n"
10701                                                           "\n"
10702                                                           "void main()\n"
10703                                                           "{\n"
10704                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10705                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10706                                                           "    EmitVertex();\n"
10707                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10708                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10709                                                           "    EmitVertex();\n"
10710                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10711                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10712                                                           "    EmitVertex();\n"
10713                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10714                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10715                                                           "    EmitVertex();\n"
10716                                                           "}\n"
10717                                                           "\n";
10718         static const GLchar* tcs =
10719                 "#version 430 core\n"
10720                 "#extension GL_ARB_enhanced_layouts : require\n"
10721                 "\n"
10722                 "layout(vertices = 1) out;\n"
10723                 "\n"
10724                 "layout (QUALIFIERbinding = BINDING) buffer tcs_Block {\n"
10725                 "    layout(offset = 16) vec4 boy;\n"
10726                 "    layout(align  = 64) vec4 man;\n"
10727                 "} uni_block;\n"
10728                 "\n"
10729                 "in  vec4 vs_tcs[];\n"
10730                 "out vec4 tcs_tes[];\n"
10731                 "\n"
10732                 "void main()\n"
10733                 "{\n"
10734                 "\n"
10735                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10736                 "\n"
10737                 "    gl_TessLevelOuter[0] = 1.0;\n"
10738                 "    gl_TessLevelOuter[1] = 1.0;\n"
10739                 "    gl_TessLevelOuter[2] = 1.0;\n"
10740                 "    gl_TessLevelOuter[3] = 1.0;\n"
10741                 "    gl_TessLevelInner[0] = 1.0;\n"
10742                 "    gl_TessLevelInner[1] = 1.0;\n"
10743                 "}\n"
10744                 "\n";
10745         static const GLchar* tes = "#version 430 core\n"
10746                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10747                                                            "\n"
10748                                                            "layout(isolines, point_mode) in;\n"
10749                                                            "\n"
10750                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10751                                                            "    layout(offset = 16) vec4 boy;\n"
10752                                                            "    layout(align  = 64) vec4 man;\n"
10753                                                            "} uni_block;\n"
10754                                                            "\n"
10755                                                            "in  vec4 tcs_tes[];\n"
10756                                                            "out vec4 tes_gs;\n"
10757                                                            "\n"
10758                                                            "void main()\n"
10759                                                            "{\n"
10760                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10761                                                            "}\n"
10762                                                            "\n";
10763         static const GLchar* vs = "#version 430 core\n"
10764                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10765                                                           "\n"
10766                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_Block {\n"
10767                                                           "    layout(offset = 16) vec4 boy;\n"
10768                                                           "    layout(align  = 64) vec4 man;\n"
10769                                                           "} uni_block;\n"
10770                                                           "\n"
10771                                                           "in  vec4 in_vs;\n"
10772                                                           "out vec4 vs_tcs;\n"
10773                                                           "\n"
10774                                                           "void main()\n"
10775                                                           "{\n"
10776                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10777                                                           "}\n"
10778                                                           "\n";
10779
10780         GLchar          buffer[16];
10781         size_t          position = 0;
10782         std::string source;
10783         testCase&   test_case = m_test_cases[test_case_index];
10784         std::string qualifier = getQualifierName(test_case.m_qualifier);
10785
10786         if (false == qualifier.empty())
10787         {
10788                 qualifier.append(", ");
10789         }
10790
10791         sprintf(buffer, "%d", stage);
10792
10793         switch (stage)
10794         {
10795         case Utils::Shader::COMPUTE:
10796                 source = cs;
10797                 break;
10798         case Utils::Shader::FRAGMENT:
10799                 source = fs;
10800                 break;
10801         case Utils::Shader::GEOMETRY:
10802                 source = gs;
10803                 break;
10804         case Utils::Shader::TESS_CTRL:
10805                 source = tcs;
10806                 break;
10807         case Utils::Shader::TESS_EVAL:
10808                 source = tes;
10809                 break;
10810         case Utils::Shader::VERTEX:
10811                 source = vs;
10812                 break;
10813         default:
10814                 TCU_FAIL("Invalid enum");
10815         }
10816
10817         if (test_case.m_stage == stage)
10818         {
10819                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10820         }
10821         else
10822         {
10823                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10824         }
10825
10826         Utils::replaceToken("BINDING", position, buffer, source);
10827
10828         return source;
10829 }
10830
10831 /** Get description of test case
10832  *
10833  * @param test_case_index Index of test case
10834  *
10835  * @return Qualifier name
10836  **/
10837 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10838 {
10839         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10840
10841         return result;
10842 }
10843
10844 /** Get number of test cases
10845  *
10846  * @return Number of test cases
10847  **/
10848 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10849 {
10850         return static_cast<GLuint>(m_test_cases.size());
10851 }
10852
10853 /** Selects if "compute" stage is relevant for test
10854  *
10855  * @param test_case_index Index of test case
10856  *
10857  * @return true when tested stage is compute
10858  **/
10859 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10860 {
10861         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10862 }
10863
10864 /** Selects if compilation failure is expected result
10865  *
10866  * @param test_case_index Index of test case
10867  *
10868  * @return false for STD140 and STD430 cases, true otherwise
10869  **/
10870 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10871 {
10872         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10873
10874         return !((STD140 == qualifier) || (STD430 == qualifier));
10875 }
10876
10877 /** Checks if stage is supported
10878  *
10879  * @param stage Shader stage
10880  *
10881  * @return true if supported, false otherwise
10882  **/
10883 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10884 {
10885         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10886         GLint                    max_supported_buffers = 0;
10887         GLenum                   pname                             = 0;
10888
10889         switch (stage)
10890         {
10891         case Utils::Shader::COMPUTE:
10892                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10893                 break;
10894         case Utils::Shader::FRAGMENT:
10895                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10896                 break;
10897         case Utils::Shader::GEOMETRY:
10898                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10899                 break;
10900         case Utils::Shader::TESS_CTRL:
10901                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10902                 break;
10903         case Utils::Shader::TESS_EVAL:
10904                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
10905                 break;
10906         case Utils::Shader::VERTEX:
10907                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
10908                 break;
10909         default:
10910                 TCU_FAIL("Invalid enum");
10911         }
10912
10913         gl.getIntegerv(pname, &max_supported_buffers);
10914         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10915
10916         return 1 <= max_supported_buffers;
10917 }
10918
10919 /** Prepare all test cases
10920  *
10921  **/
10922 void SSBLayoutQualifierConflictTest::testInit()
10923 {
10924         bool stage_support[Utils::Shader::STAGE_MAX];
10925
10926         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10927         {
10928                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10929         }
10930
10931         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
10932         {
10933                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10934                 {
10935                         if (false == stage_support[stage])
10936                         {
10937                                 continue;
10938                         }
10939
10940                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
10941
10942                         m_test_cases.push_back(test_case);
10943                 }
10944         }
10945 }
10946
10947 /** Get name of glsl constant
10948  *
10949  * @param Constant id
10950  *
10951  * @return Name of constant used in GLSL
10952  **/
10953 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
10954 {
10955         const GLchar* name = "";
10956
10957         switch (qualifier)
10958         {
10959         case DEFAULT:
10960                 name = "";
10961                 break;
10962         case STD140:
10963                 name = "std140";
10964                 break;
10965         case STD430:
10966                 name = "std430";
10967                 break;
10968         case SHARED:
10969                 name = "shared";
10970                 break;
10971         case PACKED:
10972                 name = "packed";
10973                 break;
10974         default:
10975                 TCU_FAIL("Invalid enum");
10976         }
10977
10978         return name;
10979 }
10980
10981 /** Constructor
10982  *
10983  * @param context Test framework context
10984  **/
10985 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
10986         : UniformBlockMemberInvalidOffsetAlignmentTest(
10987                   context, "ssb_member_invalid_offset_alignment",
10988                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
10989 {
10990         /* Nothing to be done here */
10991 }
10992
10993 /** Source for given test case and stage
10994  *
10995  * @param test_case_index Index of test case
10996  * @param stage           Shader stage
10997  *
10998  * @return Shader source
10999  **/
11000 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11001 {
11002         static const GLchar* cs = "#version 430 core\n"
11003                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11004                                                           "\n"
11005                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11006                                                           "\n"
11007                                                           "layout (std140) buffer Block {\n"
11008                                                           "    layout (offset = OFFSET) TYPE member;\n"
11009                                                           "} block;\n"
11010                                                           "\n"
11011                                                           "writeonly uniform image2D uni_image;\n"
11012                                                           "\n"
11013                                                           "void main()\n"
11014                                                           "{\n"
11015                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11016                                                           "\n"
11017                                                           "    if (TYPE(1) == block.member)\n"
11018                                                           "    {\n"
11019                                                           "        result = vec4(1, 1, 1, 1);\n"
11020                                                           "    }\n"
11021                                                           "\n"
11022                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11023                                                           "}\n"
11024                                                           "\n";
11025         static const GLchar* fs = "#version 430 core\n"
11026                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11027                                                           "\n"
11028                                                           "in  vec4 gs_fs;\n"
11029                                                           "out vec4 fs_out;\n"
11030                                                           "\n"
11031                                                           "void main()\n"
11032                                                           "{\n"
11033                                                           "    fs_out = gs_fs;\n"
11034                                                           "}\n"
11035                                                           "\n";
11036         static const GLchar* fs_tested = "#version 430 core\n"
11037                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11038                                                                          "\n"
11039                                                                          "layout (std140) buffer Block {\n"
11040                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11041                                                                          "} block;\n"
11042                                                                          "\n"
11043                                                                          "in  vec4 gs_fs;\n"
11044                                                                          "out vec4 fs_out;\n"
11045                                                                          "\n"
11046                                                                          "void main()\n"
11047                                                                          "{\n"
11048                                                                          "    if (TYPE(1) == block.member)\n"
11049                                                                          "    {\n"
11050                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11051                                                                          "    }\n"
11052                                                                          "\n"
11053                                                                          "    fs_out += gs_fs;\n"
11054                                                                          "}\n"
11055                                                                          "\n";
11056         static const GLchar* gs = "#version 430 core\n"
11057                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11058                                                           "\n"
11059                                                           "layout(points)                           in;\n"
11060                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11061                                                           "\n"
11062                                                           "in  vec4 tes_gs[];\n"
11063                                                           "out vec4 gs_fs;\n"
11064                                                           "\n"
11065                                                           "void main()\n"
11066                                                           "{\n"
11067                                                           "    gs_fs = tes_gs[0];\n"
11068                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11069                                                           "    EmitVertex();\n"
11070                                                           "    gs_fs = tes_gs[0];\n"
11071                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11072                                                           "    EmitVertex();\n"
11073                                                           "    gs_fs = tes_gs[0];\n"
11074                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11075                                                           "    EmitVertex();\n"
11076                                                           "    gs_fs = tes_gs[0];\n"
11077                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11078                                                           "    EmitVertex();\n"
11079                                                           "}\n"
11080                                                           "\n";
11081         static const GLchar* gs_tested = "#version 430 core\n"
11082                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11083                                                                          "\n"
11084                                                                          "layout(points)                           in;\n"
11085                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11086                                                                          "\n"
11087                                                                          "layout (std140) buffer Block {\n"
11088                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11089                                                                          "} block;\n"
11090                                                                          "\n"
11091                                                                          "in  vec4 tes_gs[];\n"
11092                                                                          "out vec4 gs_fs;\n"
11093                                                                          "\n"
11094                                                                          "void main()\n"
11095                                                                          "{\n"
11096                                                                          "    if (TYPE(1) == block.member)\n"
11097                                                                          "    {\n"
11098                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11099                                                                          "    }\n"
11100                                                                          "\n"
11101                                                                          "    gs_fs += tes_gs[0];\n"
11102                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11103                                                                          "    EmitVertex();\n"
11104                                                                          "    gs_fs += tes_gs[0];\n"
11105                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11106                                                                          "    EmitVertex();\n"
11107                                                                          "    gs_fs += tes_gs[0];\n"
11108                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11109                                                                          "    EmitVertex();\n"
11110                                                                          "    gs_fs += tes_gs[0];\n"
11111                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11112                                                                          "    EmitVertex();\n"
11113                                                                          "}\n"
11114                                                                          "\n";
11115         static const GLchar* tcs = "#version 430 core\n"
11116                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11117                                                            "\n"
11118                                                            "layout(vertices = 1) out;\n"
11119                                                            "\n"
11120                                                            "in  vec4 vs_tcs[];\n"
11121                                                            "out vec4 tcs_tes[];\n"
11122                                                            "\n"
11123                                                            "void main()\n"
11124                                                            "{\n"
11125                                                            "\n"
11126                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11127                                                            "\n"
11128                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11129                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11130                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11131                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11132                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11133                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11134                                                            "}\n"
11135                                                            "\n";
11136         static const GLchar* tcs_tested = "#version 430 core\n"
11137                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11138                                                                           "\n"
11139                                                                           "layout(vertices = 1) out;\n"
11140                                                                           "\n"
11141                                                                           "layout (std140) buffer Block {\n"
11142                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11143                                                                           "} block;\n"
11144                                                                           "\n"
11145                                                                           "in  vec4 vs_tcs[];\n"
11146                                                                           "out vec4 tcs_tes[];\n"
11147                                                                           "\n"
11148                                                                           "void main()\n"
11149                                                                           "{\n"
11150                                                                           "    if (TYPE(1) == block.member)\n"
11151                                                                           "    {\n"
11152                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11153                                                                           "    }\n"
11154                                                                           "\n"
11155                                                                           "\n"
11156                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11157                                                                           "\n"
11158                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11159                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11160                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11161                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11162                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11163                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11164                                                                           "}\n"
11165                                                                           "\n";
11166         static const GLchar* tes = "#version 430 core\n"
11167                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11168                                                            "\n"
11169                                                            "layout(isolines, point_mode) in;\n"
11170                                                            "\n"
11171                                                            "in  vec4 tcs_tes[];\n"
11172                                                            "out vec4 tes_gs;\n"
11173                                                            "\n"
11174                                                            "void main()\n"
11175                                                            "{\n"
11176                                                            "    tes_gs = tcs_tes[0];\n"
11177                                                            "}\n"
11178                                                            "\n";
11179         static const GLchar* tes_tested = "#version 430 core\n"
11180                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11181                                                                           "\n"
11182                                                                           "layout(isolines, point_mode) in;\n"
11183                                                                           "\n"
11184                                                                           "layout (std140) buffer Block {\n"
11185                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11186                                                                           "} block;\n"
11187                                                                           "\n"
11188                                                                           "in  vec4 tcs_tes[];\n"
11189                                                                           "out vec4 tes_gs;\n"
11190                                                                           "\n"
11191                                                                           "void main()\n"
11192                                                                           "{\n"
11193                                                                           "    if (TYPE(1) == block.member)\n"
11194                                                                           "    {\n"
11195                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11196                                                                           "    }\n"
11197                                                                           "\n"
11198                                                                           "    tes_gs += tcs_tes[0];\n"
11199                                                                           "}\n"
11200                                                                           "\n";
11201         static const GLchar* vs = "#version 430 core\n"
11202                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11203                                                           "\n"
11204                                                           "in  vec4 in_vs;\n"
11205                                                           "out vec4 vs_tcs;\n"
11206                                                           "\n"
11207                                                           "void main()\n"
11208                                                           "{\n"
11209                                                           "    vs_tcs = in_vs;\n"
11210                                                           "}\n"
11211                                                           "\n";
11212         static const GLchar* vs_tested = "#version 430 core\n"
11213                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11214                                                                          "\n"
11215                                                                          "layout (std140) buffer Block {\n"
11216                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11217                                                                          "} block;\n"
11218                                                                          "\n"
11219                                                                          "in  vec4 in_vs;\n"
11220                                                                          "out vec4 vs_tcs;\n"
11221                                                                          "\n"
11222                                                                          "void main()\n"
11223                                                                          "{\n"
11224                                                                          "    if (TYPE(1) == block.member)\n"
11225                                                                          "    {\n"
11226                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11227                                                                          "    }\n"
11228                                                                          "\n"
11229                                                                          "    vs_tcs += in_vs;\n"
11230                                                                          "}\n"
11231                                                                          "\n";
11232
11233         std::string source;
11234         testCase&   test_case = m_test_cases[test_case_index];
11235
11236         if (test_case.m_stage == stage)
11237         {
11238                 GLchar                     buffer[16];
11239                 const GLuint       offset       = test_case.m_offset;
11240                 size_t                     position  = 0;
11241                 const Utils::Type& type          = test_case.m_type;
11242                 const GLchar*     type_name = type.GetGLSLTypeName();
11243
11244                 sprintf(buffer, "%d", offset);
11245
11246                 switch (stage)
11247                 {
11248                 case Utils::Shader::COMPUTE:
11249                         source = cs;
11250                         break;
11251                 case Utils::Shader::FRAGMENT:
11252                         source = fs_tested;
11253                         break;
11254                 case Utils::Shader::GEOMETRY:
11255                         source = gs_tested;
11256                         break;
11257                 case Utils::Shader::TESS_CTRL:
11258                         source = tcs_tested;
11259                         break;
11260                 case Utils::Shader::TESS_EVAL:
11261                         source = tes_tested;
11262                         break;
11263                 case Utils::Shader::VERTEX:
11264                         source = vs_tested;
11265                         break;
11266                 default:
11267                         TCU_FAIL("Invalid enum");
11268                 }
11269
11270                 Utils::replaceToken("OFFSET", position, buffer, source);
11271                 Utils::replaceToken("TYPE", position, type_name, source);
11272                 Utils::replaceToken("TYPE", position, type_name, source);
11273         }
11274         else
11275         {
11276                 switch (stage)
11277                 {
11278                 case Utils::Shader::FRAGMENT:
11279                         source = fs;
11280                         break;
11281                 case Utils::Shader::GEOMETRY:
11282                         source = gs;
11283                         break;
11284                 case Utils::Shader::TESS_CTRL:
11285                         source = tcs;
11286                         break;
11287                 case Utils::Shader::TESS_EVAL:
11288                         source = tes;
11289                         break;
11290                 case Utils::Shader::VERTEX:
11291                         source = vs;
11292                         break;
11293                 default:
11294                         TCU_FAIL("Invalid enum");
11295                 }
11296         }
11297
11298         return source;
11299 }
11300
11301 /** Checks if stage is supported
11302  *
11303  * @param stage Shader stage
11304  *
11305  * @return true if supported, false otherwise
11306  **/
11307 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11308 {
11309         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11310         GLint                    max_supported_buffers = 0;
11311         GLenum                   pname                             = 0;
11312
11313         switch (stage)
11314         {
11315         case Utils::Shader::COMPUTE:
11316                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11317                 break;
11318         case Utils::Shader::FRAGMENT:
11319                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11320                 break;
11321         case Utils::Shader::GEOMETRY:
11322                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11323                 break;
11324         case Utils::Shader::TESS_CTRL:
11325                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11326                 break;
11327         case Utils::Shader::TESS_EVAL:
11328                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11329                 break;
11330         case Utils::Shader::VERTEX:
11331                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11332                 break;
11333         default:
11334                 TCU_FAIL("Invalid enum");
11335         }
11336
11337         gl.getIntegerv(pname, &max_supported_buffers);
11338         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11339
11340         return 1 <= max_supported_buffers;
11341 }
11342
11343 /** Constructor
11344  *
11345  * @param context Test framework context
11346  **/
11347 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11348         : UniformBlockMemberOverlappingOffsetsTest(
11349                   context, "ssb_member_overlapping_offsets",
11350                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11351 {
11352         /* Nothing to be done here */
11353 }
11354
11355 /** Source for given test case and stage
11356  *
11357  * @param test_case_index Index of test case
11358  * @param stage           Shader stage
11359  *
11360  * @return Shader source
11361  **/
11362 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11363 {
11364         static const GLchar* cs = "#version 430 core\n"
11365                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11366                                                           "\n"
11367                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11368                                                           "\n"
11369                                                           "layout (std140) buffer Block {\n"
11370                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11371                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11372                                                           "} block;\n"
11373                                                           "\n"
11374                                                           "writeonly uniform image2D uni_image;\n"
11375                                                           "\n"
11376                                                           "void main()\n"
11377                                                           "{\n"
11378                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11379                                                           "\n"
11380                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11381                                                           "        (MAN_TYPE(0) == block.man) )\n"
11382                                                           "    {\n"
11383                                                           "        result = vec4(1, 1, 1, 1);\n"
11384                                                           "    }\n"
11385                                                           "\n"
11386                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11387                                                           "}\n"
11388                                                           "\n";
11389         static const GLchar* fs = "#version 430 core\n"
11390                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11391                                                           "\n"
11392                                                           "in  vec4 gs_fs;\n"
11393                                                           "out vec4 fs_out;\n"
11394                                                           "\n"
11395                                                           "void main()\n"
11396                                                           "{\n"
11397                                                           "    fs_out = gs_fs;\n"
11398                                                           "}\n"
11399                                                           "\n";
11400         static const GLchar* fs_tested = "#version 430 core\n"
11401                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11402                                                                          "\n"
11403                                                                          "layout (std140) buffer Block {\n"
11404                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11405                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11406                                                                          "} block;\n"
11407                                                                          "\n"
11408                                                                          "in  vec4 gs_fs;\n"
11409                                                                          "out vec4 fs_out;\n"
11410                                                                          "\n"
11411                                                                          "void main()\n"
11412                                                                          "{\n"
11413                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11414                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11415                                                                          "    {\n"
11416                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11417                                                                          "    }\n"
11418                                                                          "\n"
11419                                                                          "    fs_out += gs_fs;\n"
11420                                                                          "}\n"
11421                                                                          "\n";
11422         static const GLchar* gs = "#version 430 core\n"
11423                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11424                                                           "\n"
11425                                                           "layout(points)                           in;\n"
11426                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11427                                                           "\n"
11428                                                           "in  vec4 tes_gs[];\n"
11429                                                           "out vec4 gs_fs;\n"
11430                                                           "\n"
11431                                                           "void main()\n"
11432                                                           "{\n"
11433                                                           "    gs_fs = tes_gs[0];\n"
11434                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11435                                                           "    EmitVertex();\n"
11436                                                           "    gs_fs = tes_gs[0];\n"
11437                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11438                                                           "    EmitVertex();\n"
11439                                                           "    gs_fs = tes_gs[0];\n"
11440                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11441                                                           "    EmitVertex();\n"
11442                                                           "    gs_fs = tes_gs[0];\n"
11443                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11444                                                           "    EmitVertex();\n"
11445                                                           "}\n"
11446                                                           "\n";
11447         static const GLchar* gs_tested = "#version 430 core\n"
11448                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11449                                                                          "\n"
11450                                                                          "layout(points)                           in;\n"
11451                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11452                                                                          "\n"
11453                                                                          "layout (std140) buffer Block {\n"
11454                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11455                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11456                                                                          "} block;\n"
11457                                                                          "\n"
11458                                                                          "in  vec4 tes_gs[];\n"
11459                                                                          "out vec4 gs_fs;\n"
11460                                                                          "\n"
11461                                                                          "void main()\n"
11462                                                                          "{\n"
11463                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11464                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11465                                                                          "    {\n"
11466                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11467                                                                          "    }\n"
11468                                                                          "\n"
11469                                                                          "    gs_fs += tes_gs[0];\n"
11470                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11471                                                                          "    EmitVertex();\n"
11472                                                                          "    gs_fs += tes_gs[0];\n"
11473                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11474                                                                          "    EmitVertex();\n"
11475                                                                          "    gs_fs += tes_gs[0];\n"
11476                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11477                                                                          "    EmitVertex();\n"
11478                                                                          "    gs_fs += tes_gs[0];\n"
11479                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11480                                                                          "    EmitVertex();\n"
11481                                                                          "}\n"
11482                                                                          "\n";
11483         static const GLchar* tcs = "#version 430 core\n"
11484                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11485                                                            "\n"
11486                                                            "layout(vertices = 1) out;\n"
11487                                                            "\n"
11488                                                            "in  vec4 vs_tcs[];\n"
11489                                                            "out vec4 tcs_tes[];\n"
11490                                                            "\n"
11491                                                            "void main()\n"
11492                                                            "{\n"
11493                                                            "\n"
11494                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11495                                                            "\n"
11496                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11497                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11498                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11499                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11500                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11501                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11502                                                            "}\n"
11503                                                            "\n";
11504         static const GLchar* tcs_tested = "#version 430 core\n"
11505                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11506                                                                           "\n"
11507                                                                           "layout(vertices = 1) out;\n"
11508                                                                           "\n"
11509                                                                           "layout (std140) buffer Block {\n"
11510                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11511                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11512                                                                           "} block;\n"
11513                                                                           "\n"
11514                                                                           "in  vec4 vs_tcs[];\n"
11515                                                                           "out vec4 tcs_tes[];\n"
11516                                                                           "\n"
11517                                                                           "void main()\n"
11518                                                                           "{\n"
11519                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11520                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11521                                                                           "    {\n"
11522                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11523                                                                           "    }\n"
11524                                                                           "\n"
11525                                                                           "\n"
11526                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11527                                                                           "\n"
11528                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11529                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11530                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11531                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11532                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11533                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11534                                                                           "}\n"
11535                                                                           "\n";
11536         static const GLchar* tes = "#version 430 core\n"
11537                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11538                                                            "\n"
11539                                                            "layout(isolines, point_mode) in;\n"
11540                                                            "\n"
11541                                                            "in  vec4 tcs_tes[];\n"
11542                                                            "out vec4 tes_gs;\n"
11543                                                            "\n"
11544                                                            "void main()\n"
11545                                                            "{\n"
11546                                                            "    tes_gs = tcs_tes[0];\n"
11547                                                            "}\n"
11548                                                            "\n";
11549         static const GLchar* tes_tested = "#version 430 core\n"
11550                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11551                                                                           "\n"
11552                                                                           "layout(isolines, point_mode) in;\n"
11553                                                                           "\n"
11554                                                                           "layout (std140) buffer Block {\n"
11555                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11556                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11557                                                                           "} block;\n"
11558                                                                           "\n"
11559                                                                           "in  vec4 tcs_tes[];\n"
11560                                                                           "out vec4 tes_gs;\n"
11561                                                                           "\n"
11562                                                                           "void main()\n"
11563                                                                           "{\n"
11564                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11565                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11566                                                                           "    {\n"
11567                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11568                                                                           "    }\n"
11569                                                                           "\n"
11570                                                                           "    tes_gs += tcs_tes[0];\n"
11571                                                                           "}\n"
11572                                                                           "\n";
11573         static const GLchar* vs = "#version 430 core\n"
11574                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11575                                                           "\n"
11576                                                           "in  vec4 in_vs;\n"
11577                                                           "out vec4 vs_tcs;\n"
11578                                                           "\n"
11579                                                           "void main()\n"
11580                                                           "{\n"
11581                                                           "    vs_tcs = in_vs;\n"
11582                                                           "}\n"
11583                                                           "\n";
11584         static const GLchar* vs_tested = "#version 430 core\n"
11585                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11586                                                                          "\n"
11587                                                                          "layout (std140) buffer Block {\n"
11588                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11589                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11590                                                                          "} block;\n"
11591                                                                          "\n"
11592                                                                          "in  vec4 in_vs;\n"
11593                                                                          "out vec4 vs_tcs;\n"
11594                                                                          "\n"
11595                                                                          "void main()\n"
11596                                                                          "{\n"
11597                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11598                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11599                                                                          "    {\n"
11600                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11601                                                                          "    }\n"
11602                                                                          "\n"
11603                                                                          "    vs_tcs += in_vs;\n"
11604                                                                          "}\n"
11605                                                                          "\n";
11606
11607         std::string source;
11608         testCase&   test_case = m_test_cases[test_case_index];
11609
11610         if (test_case.m_stage == stage)
11611         {
11612                 GLchar                     buffer[16];
11613                 const GLuint       boy_offset   = test_case.m_boy_offset;
11614                 const Utils::Type& boy_type              = test_case.m_boy_type;
11615                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11616                 const GLuint       man_offset   = test_case.m_man_offset;
11617                 const Utils::Type& man_type              = test_case.m_man_type;
11618                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11619                 size_t                     position              = 0;
11620
11621                 switch (stage)
11622                 {
11623                 case Utils::Shader::COMPUTE:
11624                         source = cs;
11625                         break;
11626                 case Utils::Shader::FRAGMENT:
11627                         source = fs_tested;
11628                         break;
11629                 case Utils::Shader::GEOMETRY:
11630                         source = gs_tested;
11631                         break;
11632                 case Utils::Shader::TESS_CTRL:
11633                         source = tcs_tested;
11634                         break;
11635                 case Utils::Shader::TESS_EVAL:
11636                         source = tes_tested;
11637                         break;
11638                 case Utils::Shader::VERTEX:
11639                         source = vs_tested;
11640                         break;
11641                 default:
11642                         TCU_FAIL("Invalid enum");
11643                 }
11644
11645                 sprintf(buffer, "%d", boy_offset);
11646                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11647                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11648                 sprintf(buffer, "%d", man_offset);
11649                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11650                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11651                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11652                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11653         }
11654         else
11655         {
11656                 switch (stage)
11657                 {
11658                 case Utils::Shader::FRAGMENT:
11659                         source = fs;
11660                         break;
11661                 case Utils::Shader::GEOMETRY:
11662                         source = gs;
11663                         break;
11664                 case Utils::Shader::TESS_CTRL:
11665                         source = tcs;
11666                         break;
11667                 case Utils::Shader::TESS_EVAL:
11668                         source = tes;
11669                         break;
11670                 case Utils::Shader::VERTEX:
11671                         source = vs;
11672                         break;
11673                 default:
11674                         TCU_FAIL("Invalid enum");
11675                 }
11676         }
11677
11678         return source;
11679 }
11680
11681 /** Checks if stage is supported
11682  *
11683  * @param stage Shader stage
11684  *
11685  * @return true if supported, false otherwise
11686  **/
11687 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11688 {
11689         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11690         GLint                    max_supported_buffers = 0;
11691         GLenum                   pname                             = 0;
11692
11693         switch (stage)
11694         {
11695         case Utils::Shader::COMPUTE:
11696                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11697                 break;
11698         case Utils::Shader::FRAGMENT:
11699                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11700                 break;
11701         case Utils::Shader::GEOMETRY:
11702                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11703                 break;
11704         case Utils::Shader::TESS_CTRL:
11705                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11706                 break;
11707         case Utils::Shader::TESS_EVAL:
11708                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11709                 break;
11710         case Utils::Shader::VERTEX:
11711                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11712                 break;
11713         default:
11714                 TCU_FAIL("Invalid enum");
11715         }
11716
11717         gl.getIntegerv(pname, &max_supported_buffers);
11718         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11719
11720         return 1 <= max_supported_buffers;
11721 }
11722
11723 /** Constructor
11724  *
11725  * @param context Test framework context
11726  **/
11727 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11728         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11729                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11730 {
11731         /* Nothing to be done here */
11732 }
11733
11734 /** Source for given test case and stage
11735  *
11736  * @param test_case_index Index of test case
11737  * @param stage           Shader stage
11738  *
11739  * @return Shader source
11740  **/
11741 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11742 {
11743         static const GLchar* cs = "#version 430 core\n"
11744                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11745                                                           "\n"
11746                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11747                                                           "\n"
11748                                                           "layout (std140) buffer Block {\n"
11749                                                           "    vec4 boy;\n"
11750                                                           "    layout (align = ALIGN) TYPE man;\n"
11751                                                           "} block;\n"
11752                                                           "\n"
11753                                                           "writeonly uniform image2D uni_image;\n"
11754                                                           "\n"
11755                                                           "void main()\n"
11756                                                           "{\n"
11757                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11758                                                           "\n"
11759                                                           "    if (TYPE(0) == block.man)\n"
11760                                                           "    {\n"
11761                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11762                                                           "    }\n"
11763                                                           "\n"
11764                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11765                                                           "}\n"
11766                                                           "\n";
11767         static const GLchar* fs = "#version 430 core\n"
11768                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11769                                                           "\n"
11770                                                           "in  vec4 gs_fs;\n"
11771                                                           "out vec4 fs_out;\n"
11772                                                           "\n"
11773                                                           "void main()\n"
11774                                                           "{\n"
11775                                                           "    fs_out = gs_fs;\n"
11776                                                           "}\n"
11777                                                           "\n";
11778         static const GLchar* fs_tested = "#version 430 core\n"
11779                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11780                                                                          "\n"
11781                                                                          "layout (std140) buffer Block {\n"
11782                                                                          "    vec4 boy;\n"
11783                                                                          "    layout (align = ALIGN) TYPE man;\n"
11784                                                                          "} block;\n"
11785                                                                          "\n"
11786                                                                          "in  vec4 gs_fs;\n"
11787                                                                          "out vec4 fs_out;\n"
11788                                                                          "\n"
11789                                                                          "void main()\n"
11790                                                                          "{\n"
11791                                                                          "    if (TYPE(0) == block.man)\n"
11792                                                                          "    {\n"
11793                                                                          "        fs_out = block.boy;\n"
11794                                                                          "    }\n"
11795                                                                          "\n"
11796                                                                          "    fs_out += gs_fs;\n"
11797                                                                          "}\n"
11798                                                                          "\n";
11799         static const GLchar* gs = "#version 430 core\n"
11800                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11801                                                           "\n"
11802                                                           "layout(points)                           in;\n"
11803                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11804                                                           "\n"
11805                                                           "in  vec4 tes_gs[];\n"
11806                                                           "out vec4 gs_fs;\n"
11807                                                           "\n"
11808                                                           "void main()\n"
11809                                                           "{\n"
11810                                                           "    gs_fs = tes_gs[0];\n"
11811                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11812                                                           "    EmitVertex();\n"
11813                                                           "    gs_fs = tes_gs[0];\n"
11814                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11815                                                           "    EmitVertex();\n"
11816                                                           "    gs_fs = tes_gs[0];\n"
11817                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11818                                                           "    EmitVertex();\n"
11819                                                           "    gs_fs = tes_gs[0];\n"
11820                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11821                                                           "    EmitVertex();\n"
11822                                                           "}\n"
11823                                                           "\n";
11824         static const GLchar* gs_tested = "#version 430 core\n"
11825                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11826                                                                          "\n"
11827                                                                          "layout(points)                           in;\n"
11828                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11829                                                                          "\n"
11830                                                                          "layout (std140) buffer Block {\n"
11831                                                                          "    vec4 boy;\n"
11832                                                                          "    layout (align = ALIGN) TYPE man;\n"
11833                                                                          "} block;\n"
11834                                                                          "\n"
11835                                                                          "in  vec4 tes_gs[];\n"
11836                                                                          "out vec4 gs_fs;\n"
11837                                                                          "\n"
11838                                                                          "void main()\n"
11839                                                                          "{\n"
11840                                                                          "    if (TYPE(0) == block.man)\n"
11841                                                                          "    {\n"
11842                                                                          "        gs_fs = block.boy;\n"
11843                                                                          "    }\n"
11844                                                                          "\n"
11845                                                                          "    gs_fs += tes_gs[0];\n"
11846                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11847                                                                          "    EmitVertex();\n"
11848                                                                          "    gs_fs += tes_gs[0];\n"
11849                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11850                                                                          "    EmitVertex();\n"
11851                                                                          "    gs_fs += tes_gs[0];\n"
11852                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11853                                                                          "    EmitVertex();\n"
11854                                                                          "    gs_fs += tes_gs[0];\n"
11855                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11856                                                                          "    EmitVertex();\n"
11857                                                                          "}\n"
11858                                                                          "\n";
11859         static const GLchar* tcs = "#version 430 core\n"
11860                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11861                                                            "\n"
11862                                                            "layout(vertices = 1) out;\n"
11863                                                            "\n"
11864                                                            "in  vec4 vs_tcs[];\n"
11865                                                            "out vec4 tcs_tes[];\n"
11866                                                            "\n"
11867                                                            "void main()\n"
11868                                                            "{\n"
11869                                                            "\n"
11870                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11871                                                            "\n"
11872                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11873                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11874                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11875                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11876                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11877                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11878                                                            "}\n"
11879                                                            "\n";
11880         static const GLchar* tcs_tested = "#version 430 core\n"
11881                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11882                                                                           "\n"
11883                                                                           "layout(vertices = 1) out;\n"
11884                                                                           "\n"
11885                                                                           "layout (std140) buffer Block {\n"
11886                                                                           "    vec4 boy;\n"
11887                                                                           "    layout (align = ALIGN) TYPE man;\n"
11888                                                                           "} block;\n"
11889                                                                           "\n"
11890                                                                           "in  vec4 vs_tcs[];\n"
11891                                                                           "out vec4 tcs_tes[];\n"
11892                                                                           "\n"
11893                                                                           "void main()\n"
11894                                                                           "{\n"
11895                                                                           "    if (TYPE(0) == block.man)\n"
11896                                                                           "    {\n"
11897                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
11898                                                                           "    }\n"
11899                                                                           "\n"
11900                                                                           "\n"
11901                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11902                                                                           "\n"
11903                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11904                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11905                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11906                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11907                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11908                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11909                                                                           "}\n"
11910                                                                           "\n";
11911         static const GLchar* tes = "#version 430 core\n"
11912                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11913                                                            "\n"
11914                                                            "layout(isolines, point_mode) in;\n"
11915                                                            "\n"
11916                                                            "in  vec4 tcs_tes[];\n"
11917                                                            "out vec4 tes_gs;\n"
11918                                                            "\n"
11919                                                            "void main()\n"
11920                                                            "{\n"
11921                                                            "    tes_gs = tcs_tes[0];\n"
11922                                                            "}\n"
11923                                                            "\n";
11924         static const GLchar* tes_tested = "#version 430 core\n"
11925                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11926                                                                           "\n"
11927                                                                           "layout(isolines, point_mode) in;\n"
11928                                                                           "\n"
11929                                                                           "layout (std140) buffer Block {\n"
11930                                                                           "    vec4 boy;\n"
11931                                                                           "    layout (align = ALIGN) TYPE man;\n"
11932                                                                           "} block;\n"
11933                                                                           "\n"
11934                                                                           "in  vec4 tcs_tes[];\n"
11935                                                                           "out vec4 tes_gs;\n"
11936                                                                           "\n"
11937                                                                           "void main()\n"
11938                                                                           "{\n"
11939                                                                           "    if (TYPE(0) == block.man)\n"
11940                                                                           "    {\n"
11941                                                                           "        tes_gs = block.boy;\n"
11942                                                                           "    }\n"
11943                                                                           "\n"
11944                                                                           "    tes_gs += tcs_tes[0];\n"
11945                                                                           "}\n"
11946                                                                           "\n";
11947         static const GLchar* vs = "#version 430 core\n"
11948                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11949                                                           "\n"
11950                                                           "in  vec4 in_vs;\n"
11951                                                           "out vec4 vs_tcs;\n"
11952                                                           "\n"
11953                                                           "void main()\n"
11954                                                           "{\n"
11955                                                           "    vs_tcs = in_vs;\n"
11956                                                           "}\n"
11957                                                           "\n";
11958         static const GLchar* vs_tested = "#version 430 core\n"
11959                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11960                                                                          "\n"
11961                                                                          "layout (std140) buffer Block {\n"
11962                                                                          "    vec4 boy;\n"
11963                                                                          "    layout (align = ALIGN) TYPE man;\n"
11964                                                                          "} block;\n"
11965                                                                          "\n"
11966                                                                          "in  vec4 in_vs;\n"
11967                                                                          "out vec4 vs_tcs;\n"
11968                                                                          "\n"
11969                                                                          "void main()\n"
11970                                                                          "{\n"
11971                                                                          "    if (TYPE(0) == block.man)\n"
11972                                                                          "    {\n"
11973                                                                          "        vs_tcs = block.boy;\n"
11974                                                                          "    }\n"
11975                                                                          "\n"
11976                                                                          "    vs_tcs += in_vs;\n"
11977                                                                          "}\n"
11978                                                                          "\n";
11979
11980         std::string source;
11981         testCase&   test_case = m_test_cases[test_case_index];
11982
11983         if (test_case.m_stage == stage)
11984         {
11985                 GLchar                     buffer[16];
11986                 const GLuint       alignment = test_case.m_alignment;
11987                 const Utils::Type& type          = test_case.m_type;
11988                 const GLchar*     type_name = type.GetGLSLTypeName();
11989                 size_t                     position  = 0;
11990
11991                 switch (stage)
11992                 {
11993                 case Utils::Shader::COMPUTE:
11994                         source = cs;
11995                         break;
11996                 case Utils::Shader::FRAGMENT:
11997                         source = fs_tested;
11998                         break;
11999                 case Utils::Shader::GEOMETRY:
12000                         source = gs_tested;
12001                         break;
12002                 case Utils::Shader::TESS_CTRL:
12003                         source = tcs_tested;
12004                         break;
12005                 case Utils::Shader::TESS_EVAL:
12006                         source = tes_tested;
12007                         break;
12008                 case Utils::Shader::VERTEX:
12009                         source = vs_tested;
12010                         break;
12011                 default:
12012                         TCU_FAIL("Invalid enum");
12013                 }
12014
12015                 sprintf(buffer, "%d", alignment);
12016                 Utils::replaceToken("ALIGN", position, buffer, source);
12017                 Utils::replaceToken("TYPE", position, type_name, source);
12018                 Utils::replaceToken("TYPE", position, type_name, source);
12019         }
12020         else
12021         {
12022                 switch (stage)
12023                 {
12024                 case Utils::Shader::FRAGMENT:
12025                         source = fs;
12026                         break;
12027                 case Utils::Shader::GEOMETRY:
12028                         source = gs;
12029                         break;
12030                 case Utils::Shader::TESS_CTRL:
12031                         source = tcs;
12032                         break;
12033                 case Utils::Shader::TESS_EVAL:
12034                         source = tes;
12035                         break;
12036                 case Utils::Shader::VERTEX:
12037                         source = vs;
12038                         break;
12039                 default:
12040                         TCU_FAIL("Invalid enum");
12041                 }
12042         }
12043
12044         return source;
12045 }
12046
12047 /** Checks if stage is supported
12048  *
12049  * @param stage Shader stage
12050  *
12051  * @return true if supported, false otherwise
12052  **/
12053 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12054 {
12055         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12056         GLint                    max_supported_buffers = 0;
12057         GLenum                   pname                             = 0;
12058
12059         switch (stage)
12060         {
12061         case Utils::Shader::COMPUTE:
12062                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12063                 break;
12064         case Utils::Shader::FRAGMENT:
12065                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12066                 break;
12067         case Utils::Shader::GEOMETRY:
12068                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12069                 break;
12070         case Utils::Shader::TESS_CTRL:
12071                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12072                 break;
12073         case Utils::Shader::TESS_EVAL:
12074                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12075                 break;
12076         case Utils::Shader::VERTEX:
12077                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12078                 break;
12079         default:
12080                 TCU_FAIL("Invalid enum");
12081         }
12082
12083         gl.getIntegerv(pname, &max_supported_buffers);
12084         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12085
12086         return 1 <= max_supported_buffers;
12087 }
12088
12089 /** Constructor
12090  *
12091  * @param context Test framework context
12092  **/
12093 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12094         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12095 {
12096 }
12097
12098 /** Get interface of program
12099  *
12100  * @param ignored
12101  * @param program_interface Interface of program
12102  * @param varying_passthrough Collection of connections between in and out variables
12103  **/
12104 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12105                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12106 {
12107         static const Utils::Type vec4 = Utils::Type::vec4;
12108
12109 #if WRKARD_UNIFORMBLOCKALIGNMENT
12110
12111         static const GLuint block_align = 16;
12112
12113 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12114
12115         static const GLuint block_align = 64;
12116
12117 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12118
12119         static const GLuint fifth_align = 16;
12120         static const GLuint vec4_stride = 16;
12121         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12122
12123         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12124         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12125         const GLuint third_offset =
12126                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12127         const GLuint fourth_offset =
12128                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12129         const GLuint fifth_offset =
12130                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12131         const GLuint sixth_offset =
12132                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12133
12134         Utils::Interface* structure = program_interface.Structure("Data");
12135
12136         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12137                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12138
12139         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12140                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12141                                           Utils::Type::vec4.GetSize() /* offset */);
12142
12143         /* Prepare Block */
12144         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12145
12146         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12147                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12148
12149         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12150                                                  0 /* n_array_elements */, data_stride, second_offset);
12151
12152         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12153                                                  2 /* n_array_elements */, data_stride, third_offset);
12154
12155         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12156                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12157
12158         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12159                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12160
12161         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12162                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12163
12164         const GLuint stride = calculateStride(*vs_buf_Block);
12165         m_data.resize(stride);
12166         generateData(*vs_buf_Block, 0, m_data);
12167
12168         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12169
12170 /* Add uniform BLOCK */
12171 #if WRKARD_UNIFORMBLOCKALIGNMENT
12172         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12173                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12174 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12175         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12176                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12177 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12178
12179         program_interface.CloneVertexInterface(varying_passthrough);
12180 }
12181
12182 /** Selects if "draw" stages are relevant for test
12183  *
12184  * @param ignored
12185  *
12186  * @return true if all stages support shader storage buffers, false otherwise
12187  **/
12188 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12189 {
12190         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12191         GLint                    gs_supported_buffers  = 0;
12192         GLint                    tcs_supported_buffers = 0;
12193         GLint                    tes_supported_buffers = 0;
12194         GLint                    vs_supported_buffers  = 0;
12195
12196         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12197         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12198         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12199         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12200
12201         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12202
12203         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12204                         (1 <= vs_supported_buffers));
12205 }
12206
12207 /** Constructor
12208  *
12209  * @param context Test framework context
12210  **/
12211 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12212         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12213 {
12214 }
12215
12216 /** Constructor
12217  *
12218  * @param context          Test context
12219  * @param test_name        Name of test
12220  * @param test_description Description of test
12221  **/
12222 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12223                                                                                    const glw::GLchar* test_description)
12224         : TextureTestBase(context, test_name, test_description)
12225 {
12226 }
12227
12228 /** Get interface of program
12229  *
12230  * @param test_case_index     Test case
12231  * @param program_interface   Interface of program
12232  * @param varying_passthrough Collection of connections between in and out variables
12233  **/
12234 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12235                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12236 {
12237         const Utils::Type type = getType(test_case_index);
12238
12239         m_first_data = type.GenerateDataPacked();
12240         m_last_data  = type.GenerateDataPacked();
12241
12242         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12243         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12244         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12245         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12246         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12247 }
12248
12249 /** Get type name
12250  *
12251  * @param test_case_index Index of test case
12252  *
12253  * @return Name of type test in test_case_index
12254  **/
12255 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12256 {
12257         return getTypeName(test_case_index);
12258 }
12259
12260 /** Returns number of types to test
12261  *
12262  * @return Number of types, 34
12263  **/
12264 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12265 {
12266         return getTypesNumber();
12267 }
12268
12269 /** Selects if "compute" stage is relevant for test
12270  *
12271  * @param ignored
12272  *
12273  * @return false
12274  **/
12275 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12276 {
12277         return false;
12278 }
12279
12280 /**
12281  *
12282  *
12283  **/
12284 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12285 {
12286         GLchar          buffer[16];
12287         std::string globals = "const uint first_input_location  = 0u;\n"
12288                                                   "const uint first_output_location = 0u;\n"
12289                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12290                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12291         size_t position = 100; /* Skip first part */
12292
12293         sprintf(buffer, "%d", last_in_loc);
12294         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12295
12296         sprintf(buffer, "%d", last_out_loc);
12297         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12298
12299         return globals;
12300 }
12301
12302 /**
12303  *
12304  **/
12305 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12306                                                                                           Utils::ProgramInterface&   program_interface,
12307                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12308 {
12309         const GLuint array_length  = 1;
12310         const GLuint first_in_loc  = 0;
12311         const GLuint first_out_loc = 0;
12312         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12313         size_t           position         = 0;
12314
12315         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12316
12317         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12318
12319         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12320         const GLchar* qual_first_out = "layout (location = first_output_location)";
12321         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12322         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12323
12324         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12325         const GLuint                    type_size = type.GetSize();
12326
12327         std::string first_in_name  = "PREFIXfirst";
12328         std::string first_out_name = "PREFIXfirst";
12329         std::string last_in_name   = "PREFIXlast";
12330         std::string last_out_name  = "PREFIXlast";
12331
12332         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12333         position = 0;
12334         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12335         position = 0;
12336         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12337         position = 0;
12338         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12339
12340         if (Utils::Shader::FRAGMENT == stage)
12341         {
12342                 qual_first_in = "layout (location = first_input_location) flat";
12343                 qual_last_in  = "layout (location = last_input_location)  flat";
12344         }
12345         if (Utils::Shader::GEOMETRY == stage)
12346         {
12347                 qual_first_out = "layout (location = first_output_location) flat";
12348                 qual_last_out  = "layout (location = last_output_location)  flat";
12349         }
12350
12351         Utils::Variable* first_in = si.Input(
12352                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12353                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12354                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12355
12356         Utils::Variable* last_in =
12357                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12358                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12359                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12360                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12361
12362         if (Utils::Shader::FRAGMENT != stage)
12363         {
12364                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12365
12366                 Utils::Variable* first_out =
12367                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12368                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12369                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12370                                           m_first_data.size() /* data_size */);
12371
12372                 Utils::Variable* last_out = si.Output(
12373                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12374                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12375                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12376
12377                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12378
12379                 varying_passthrough.Add(stage, first_in, first_out);
12380                 varying_passthrough.Add(stage, last_in, last_out);
12381         }
12382         else
12383         {
12384                 /* No outputs for fragment shader, so last_output_location can be 0 */
12385                 si.m_globals = prepareGlobals(last_in_loc, 0);
12386         }
12387 }
12388
12389 /** This test should be run with separable programs
12390  *
12391  * @param ignored
12392  *
12393  * @return true
12394  **/
12395 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12396 {
12397         return false;
12398 }
12399
12400 /* Constants used by VertexAttribLocationsTest */
12401 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12402 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12403 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12404 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12405 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12406
12407 /** Constructor
12408  *
12409  * @param context Test framework context
12410  **/
12411 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12412         : TextureTestBase(context, "vertex_attrib_locations",
12413                                           "Test verifies that attribute locations are respected by drawing operations")
12414 {
12415 }
12416
12417 /** Execute proper draw command for test case
12418  *
12419  * @param test_case_index Index of test case
12420  **/
12421 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12422 {
12423         const Functions& gl = m_context.getRenderContext().getFunctions();
12424
12425         switch (test_case_index)
12426         {
12427         case DRAWARRAYS:
12428                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12429                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12430                 break;
12431         case DRAWARRAYSINSTANCED:
12432                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12433                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12434                 break;
12435         case DRAWELEMENTS:
12436                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL);
12437                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12438                 break;
12439         case DRAWELEMENTSBASEVERTEX:
12440                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_base_vertex);
12441                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12442                 break;
12443         case DRAWELEMENTSINSTANCED:
12444                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances);
12445                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12446                 break;
12447         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12448                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12449                                                                                          m_base_instance);
12450                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12451                 break;
12452         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12453                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12454                                                                                    m_base_vertex);
12455                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12456                 break;
12457         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12458                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL,
12459                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12460                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12461                 break;
12462         default:
12463                 TCU_FAIL("Invalid enum");
12464         }
12465 }
12466
12467 /** Get interface of program
12468  *
12469  * @param ignored
12470  * @param program_interface   Interface of program
12471  * @param ignored
12472  **/
12473 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12474                                                                                                         Utils::ProgramInterface& program_interface,
12475                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12476 {
12477         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12478
12479         /* Globals */
12480         si.m_globals = "const uint vertex_index_location   = 2;\n"
12481                                    "const uint instance_index_location = 5;\n";
12482
12483         /* Attributes */
12484         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12485                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12486                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12487                          (GLvoid*)0 /* data */, 0 /* data_size */);
12488         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12489                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12490                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12491                          (GLvoid*)0 /* data */, 0 /* data_size */);
12492 }
12493
12494 /** Get name of test case
12495  *
12496  * @param test_case_index Index of test case
12497  *
12498  * @return Name of test case
12499  **/
12500 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12501 {
12502         std::string result;
12503
12504         switch (test_case_index)
12505         {
12506         case DRAWARRAYS:
12507                 result = "DrawArrays";
12508                 break;
12509         case DRAWARRAYSINSTANCED:
12510                 result = "DrawArraysInstanced";
12511                 break;
12512         case DRAWELEMENTS:
12513                 result = "DrawElements";
12514                 break;
12515         case DRAWELEMENTSBASEVERTEX:
12516                 result = "DrawElementsBaseVertex";
12517                 break;
12518         case DRAWELEMENTSINSTANCED:
12519                 result = "DrawElementsInstanced";
12520                 break;
12521         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12522                 result = "DrawElementsInstancedBaseInstance";
12523                 break;
12524         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12525                 result = "DrawElementsInstancedBaseVertex";
12526                 break;
12527         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12528                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12529                 break;
12530         default:
12531                 TCU_FAIL("Invalid enum");
12532         }
12533
12534         return result;
12535 }
12536
12537 /** Get number of test cases
12538  *
12539  * @return Number of test cases
12540  **/
12541 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12542 {
12543         return TESTCASES_MAX;
12544 }
12545
12546 /** Prepare code snippet that will verify in and uniform variables
12547  *
12548  * @param ignored
12549  * @param ignored
12550  * @param stage   Shader stage
12551  *
12552  * @return Code that verify variables
12553  **/
12554 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12555                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12556                                                                                                                           Utils::Shader::STAGES stage)
12557 {
12558         std::string verification;
12559
12560         if (Utils::Shader::VERTEX == stage)
12561         {
12562
12563 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12564
12565                 verification = "if (gl_InstanceID != instance_index)\n"
12566                                            "    {\n"
12567                                            "        result = 12u;\n"
12568                                            "    }\n"
12569                                            "    else if (gl_VertexID != vertex_index)\n"
12570                                            "    {\n"
12571                                            "        result = 11u;\n"
12572                                            "    }\n";
12573
12574 #else
12575
12576                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12577                                            "        (gl_InstanceID != instance_index) )\n"
12578                                            "    {\n"
12579                                            "        result = 0u;\n"
12580                                            "    }\n";
12581
12582 #endif
12583         }
12584         else
12585         {
12586                 verification = "";
12587         }
12588
12589         return verification;
12590 }
12591
12592 /** Selects if "compute" stage is relevant for test
12593  *
12594  * @param ignored
12595  *
12596  * @return false
12597  **/
12598 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12599 {
12600         return false;
12601 }
12602
12603 /** Prepare attributes, vertex array object and array buffer
12604  *
12605  * @param ignored
12606  * @param ignored Interface of program
12607  * @param buffer  Array buffer
12608  * @param vao     Vertex array object
12609  **/
12610 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12611                                                                                                   Utils::ProgramInterface& /* program_interface */,
12612                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12613 {
12614         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12615         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12616
12617         std::vector<GLuint> buffer_data;
12618         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12619
12620         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12621
12622         /*
12623          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12624          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12625          */
12626         if (test_case_index >= 2)
12627         {
12628                 buffer.m_buffer = Utils::Buffer::Element;
12629         }
12630         vao.Bind();
12631         buffer.Bind();
12632
12633         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12634                                   0 /* stride */, 0 /* offset */);
12635
12636         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12637                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12638         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12639         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12640         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12641                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12642         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12643                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12644
12645         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12646         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12647
12648         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12649 }
12650
12651 /** This test should be run with separable programs
12652  *
12653  * @param ignored
12654  *
12655  * @return true
12656  **/
12657 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12658 {
12659         return false;
12660 }
12661
12662 /** Constructor
12663  *
12664  * @param context Test framework context
12665  **/
12666 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12667         : VaryingLocationsTest(context, "varying_array_locations",
12668                                                    "Test verifies that input and output locations are respected for arrays")
12669 {
12670 }
12671
12672 /**
12673  *
12674  **/
12675 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12676                                                                                                    Utils::ProgramInterface&   program_interface,
12677                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12678 {
12679         const GLuint array_length  = 1u;
12680         const GLuint first_in_loc  = 0;
12681         const GLuint first_out_loc = 0;
12682         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12683         size_t           position         = 0;
12684
12685         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12686
12687         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12688
12689         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12690         const GLchar* qual_first_out = "layout (location = first_output_location)";
12691         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12692         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12693
12694         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12695         const GLuint                    type_size = type.GetSize();
12696
12697         std::string first_in_name  = "PREFIXfirst";
12698         std::string first_out_name = "PREFIXfirst";
12699         std::string last_in_name   = "PREFIXlast";
12700         std::string last_out_name  = "PREFIXlast";
12701
12702         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12703         position = 0;
12704         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12705         position = 0;
12706         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12707         position = 0;
12708         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12709
12710         if (Utils::Shader::FRAGMENT == stage)
12711         {
12712                 qual_first_in = "layout (location = first_input_location) flat";
12713                 qual_last_in  = "layout (location = last_input_location)  flat";
12714         }
12715         if (Utils::Shader::GEOMETRY == stage)
12716         {
12717                 qual_first_out = "layout (location = first_output_location) flat";
12718                 qual_last_out  = "layout (location = last_output_location)  flat";
12719         }
12720
12721         Utils::Variable* first_in =
12722                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12723                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12724                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12725                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12726
12727         Utils::Variable* last_in =
12728                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12729                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12730                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12731                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12732
12733         if (Utils::Shader::FRAGMENT != stage)
12734         {
12735                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12736
12737                 Utils::Variable* first_out =
12738                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12739                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12740                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12741                                           (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12742
12743                 Utils::Variable* last_out =
12744                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12745                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12746                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12747                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12748
12749                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12750
12751                 varying_passthrough.Add(stage, first_in, first_out);
12752                 varying_passthrough.Add(stage, last_in, last_out);
12753         }
12754         else
12755         {
12756                 /* No outputs for fragment shader, so last_output_location can be 0 */
12757                 si.m_globals = prepareGlobals(last_in_loc, 0);
12758         }
12759 }
12760
12761 /** Constructor
12762  *
12763  * @param context Test framework context
12764  **/
12765 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12766         : TextureTestBase(context, "varying_structure_locations",
12767                                           "Test verifies that locations are respected when structures are used as in and out ")
12768 {
12769 }
12770
12771 /** Prepare code snippet that will pass in variables to out variables
12772  *
12773  * @param ignored
12774  * @param varying_passthrough Collection of connections between in and out variables
12775  * @param stage               Shader stage
12776  *
12777  * @return Code that pass in variables to next stage
12778  **/
12779 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12780                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12781                                                                                                                   Utils::Shader::STAGES          stage)
12782 {
12783         std::string result;
12784
12785         if (Utils::Shader::VERTEX != stage)
12786         {
12787                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12788         }
12789         else
12790         {
12791                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12792                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12793         }
12794
12795         return result;
12796 }
12797
12798 /** Get interface of program
12799  *
12800  * @param test_case_index     Test case
12801  * @param program_interface   Interface of program
12802  * @param varying_passthrough Collection of connections between in and out variables
12803  **/
12804 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12805                                                                                                                 Utils::ProgramInterface&   program_interface,
12806                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12807 {
12808         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12809         const Utils::Type               type = getType(test_case_index);
12810
12811         /* Prepare data */
12812         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12813         m_single_data = type.GenerateDataPacked();
12814         m_array_data  = type.GenerateDataPacked();
12815
12816         m_data.resize(m_single_data.size() + m_array_data.size());
12817         GLubyte* ptr = (GLubyte*)&m_data[0];
12818         memcpy(ptr, &m_single_data[0], m_single_data.size());
12819         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12820
12821         Utils::Interface* structure = program_interface.Structure("Data");
12822
12823         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12824                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12825
12826         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12827         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12828                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12829
12830         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12831                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12832                          m_single_data.size() /* data_size */);
12833
12834         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12835                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12836                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12837
12838         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12839                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12840                           m_data.size() /* data_size */);
12841
12842         program_interface.CloneVertexInterface(varying_passthrough);
12843 }
12844
12845 /** Get type name
12846  *
12847  * @param test_case_index Index of test case
12848  *
12849  * @return Name of type test in test_case_index
12850  **/
12851 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12852 {
12853         return getTypeName(test_case_index);
12854 }
12855
12856 /** Returns number of types to test
12857  *
12858  * @return Number of types, 34
12859  **/
12860 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12861 {
12862         return getTypesNumber();
12863 }
12864
12865 /** Selects if "compute" stage is relevant for test
12866  *
12867  * @param ignored
12868  *
12869  * @return false
12870  **/
12871 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12872 {
12873         return false;
12874 }
12875
12876 /** This test should be run with separable programs
12877  *
12878  * @param ignored
12879  *
12880  * @return true
12881  **/
12882 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12883 {
12884         return false;
12885 }
12886
12887 /** Constructor
12888  *
12889  * @param context          Test context
12890  * @param test_name        Name of test
12891  * @param test_description Description of test
12892  **/
12893 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
12894         : NegativeTestBase(context, "varying_structure_member_location",
12895                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
12896 {
12897 }
12898
12899 /** Source for given test case and stage
12900  *
12901  * @param test_case_index Index of test case
12902  * @param stage           Shader stage
12903  *
12904  * @return Shader source
12905  **/
12906 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
12907 {
12908         static const GLchar* struct_definition = "struct Data {\n"
12909                                                                                          "    vec4 gohan;\n"
12910                                                                                          "    layout (location = 4) vec4 goten;\n"
12911                                                                                          "};\n";
12912         static const GLchar* input_var  = "in Data data;\n";
12913         static const GLchar* output_var = "out Data data;\n";
12914         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
12915         static const GLchar* output_use = "    data.gohan = result / 2;\n"
12916                                                                           "    data.goten = result / 4 - data.gohan;\n";
12917         static const GLchar* fs = "#version 430 core\n"
12918                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12919                                                           "\n"
12920                                                           "in  vec4 gs_fs;\n"
12921                                                           "out vec4 fs_out;\n"
12922                                                           "\n"
12923                                                           "void main()\n"
12924                                                           "{\n"
12925                                                           "    fs_out = gs_fs;\n"
12926                                                           "}\n"
12927                                                           "\n";
12928         static const GLchar* fs_tested = "#version 430 core\n"
12929                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12930                                                                          "\n"
12931                                                                          "STRUCT_DEFINITION"
12932                                                                          "\n"
12933                                                                          "VARIABLE_DEFINITION"
12934                                                                          "\n"
12935                                                                          "in  vec4 gs_fs;\n"
12936                                                                          "out vec4 fs_out;\n"
12937                                                                          "\n"
12938                                                                          "void main()\n"
12939                                                                          "{\n"
12940                                                                          "    vec4 result = gs_fs;\n"
12941                                                                          "\n"
12942                                                                          "VARIABLE_USE"
12943                                                                          "\n"
12944                                                                          "    fs_out += result;\n"
12945                                                                          "}\n"
12946                                                                          "\n";
12947         static const GLchar* gs = "#version 430 core\n"
12948                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12949                                                           "\n"
12950                                                           "layout(points)                           in;\n"
12951                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
12952                                                           "\n"
12953                                                           "in  vec4 tes_gs[];\n"
12954                                                           "out vec4 gs_fs;\n"
12955                                                           "\n"
12956                                                           "void main()\n"
12957                                                           "{\n"
12958                                                           "    gs_fs = tes_gs[0];\n"
12959                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12960                                                           "    EmitVertex();\n"
12961                                                           "    gs_fs = tes_gs[0];\n"
12962                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12963                                                           "    EmitVertex();\n"
12964                                                           "    gs_fs = tes_gs[0];\n"
12965                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
12966                                                           "    EmitVertex();\n"
12967                                                           "    gs_fs = tes_gs[0];\n"
12968                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
12969                                                           "    EmitVertex();\n"
12970                                                           "}\n"
12971                                                           "\n";
12972         static const GLchar* gs_tested = "#version 430 core\n"
12973                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12974                                                                          "\n"
12975                                                                          "layout(points)                           in;\n"
12976                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
12977                                                                          "\n"
12978                                                                          "STRUCT_DEFINITION"
12979                                                                          "\n"
12980                                                                          "VARIABLE_DEFINITION"
12981                                                                          "\n"
12982                                                                          "in  vec4 tes_gs[];\n"
12983                                                                          "out vec4 gs_fs;\n"
12984                                                                          "\n"
12985                                                                          "void main()\n"
12986                                                                          "{\n"
12987                                                                          "    vec4 result = tes_gs[0];\n"
12988                                                                          "\n"
12989                                                                          "VARIABLE_USE"
12990                                                                          "\n"
12991                                                                          "    gs_fs = result;\n"
12992                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12993                                                                          "    EmitVertex();\n"
12994                                                                          "    gs_fs = result;\n"
12995                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12996                                                                          "    EmitVertex();\n"
12997                                                                          "    gs_fs = result;\n"
12998                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
12999                                                                          "    EmitVertex();\n"
13000                                                                          "    gs_fs = result;\n"
13001                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13002                                                                          "    EmitVertex();\n"
13003                                                                          "}\n"
13004                                                                          "\n";
13005         static const GLchar* tcs = "#version 430 core\n"
13006                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13007                                                            "\n"
13008                                                            "layout(vertices = 1) out;\n"
13009                                                            "\n"
13010                                                            "in  vec4 vs_tcs[];\n"
13011                                                            "out vec4 tcs_tes[];\n"
13012                                                            "\n"
13013                                                            "void main()\n"
13014                                                            "{\n"
13015                                                            "\n"
13016                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13017                                                            "\n"
13018                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13019                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13020                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13021                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13022                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13023                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13024                                                            "}\n"
13025                                                            "\n";
13026         static const GLchar* tcs_tested = "#version 430 core\n"
13027                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13028                                                                           "\n"
13029                                                                           "layout(vertices = 1) out;\n"
13030                                                                           "\n"
13031                                                                           "STRUCT_DEFINITION"
13032                                                                           "\n"
13033                                                                           "VARIABLE_DEFINITION"
13034                                                                           "\n"
13035                                                                           "in  vec4 vs_tcs[];\n"
13036                                                                           "out vec4 tcs_tes[];\n"
13037                                                                           "\n"
13038                                                                           "void main()\n"
13039                                                                           "{\n"
13040                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13041                                                                           "\n"
13042                                                                           "VARIABLE_USE"
13043                                                                           "\n"
13044                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13045                                                                           "\n"
13046                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13047                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13048                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13049                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13050                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13051                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13052                                                                           "}\n"
13053                                                                           "\n";
13054         static const GLchar* tes = "#version 430 core\n"
13055                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13056                                                            "\n"
13057                                                            "layout(isolines, point_mode) in;\n"
13058                                                            "\n"
13059                                                            "in  vec4 tcs_tes[];\n"
13060                                                            "out vec4 tes_gs;\n"
13061                                                            "\n"
13062                                                            "void main()\n"
13063                                                            "{\n"
13064                                                            "    tes_gs = tcs_tes[0];\n"
13065                                                            "}\n"
13066                                                            "\n";
13067         static const GLchar* tes_tested = "#version 430 core\n"
13068                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13069                                                                           "\n"
13070                                                                           "layout(isolines, point_mode) in;\n"
13071                                                                           "\n"
13072                                                                           "STRUCT_DEFINITION"
13073                                                                           "\n"
13074                                                                           "VARIABLE_DEFINITION"
13075                                                                           "\n"
13076                                                                           "in  vec4 tcs_tes[];\n"
13077                                                                           "out vec4 tes_gs;\n"
13078                                                                           "\n"
13079                                                                           "void main()\n"
13080                                                                           "{\n"
13081                                                                           "    vec4 result = tcs_tes[0];\n"
13082                                                                           "\n"
13083                                                                           "VARIABLE_USE"
13084                                                                           "\n"
13085                                                                           "    tes_gs += result;\n"
13086                                                                           "}\n"
13087                                                                           "\n";
13088         static const GLchar* vs = "#version 430 core\n"
13089                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13090                                                           "\n"
13091                                                           "in  vec4 in_vs;\n"
13092                                                           "out vec4 vs_tcs;\n"
13093                                                           "\n"
13094                                                           "void main()\n"
13095                                                           "{\n"
13096                                                           "    vs_tcs = in_vs;\n"
13097                                                           "}\n"
13098                                                           "\n";
13099         static const GLchar* vs_tested = "#version 430 core\n"
13100                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13101                                                                          "\n"
13102                                                                          "STRUCT_DEFINITION"
13103                                                                          "\n"
13104                                                                          "VARIABLE_DEFINITION"
13105                                                                          "\n"
13106                                                                          "in  vec4 in_vs;\n"
13107                                                                          "out vec4 vs_tcs;\n"
13108                                                                          "\n"
13109                                                                          "void main()\n"
13110                                                                          "{\n"
13111                                                                          "    vec4 result = in_vs;\n"
13112                                                                          "\n"
13113                                                                          "VARIABLE_USE"
13114                                                                          "\n"
13115                                                                          "    vs_tcs += result;\n"
13116                                                                          "}\n"
13117                                                                          "\n";
13118
13119         std::string   source;
13120         testCase&        test_case               = m_test_cases[test_case_index];
13121         const GLchar* var_definition = 0;
13122         const GLchar* var_use            = 0;
13123
13124         if (true == test_case.m_is_input)
13125         {
13126                 var_definition = input_var;
13127                 var_use            = input_use;
13128         }
13129         else
13130         {
13131                 var_definition = output_var;
13132                 var_use            = output_use;
13133         }
13134
13135         if (test_case.m_stage == stage)
13136         {
13137                 size_t position = 0;
13138
13139                 switch (stage)
13140                 {
13141                 case Utils::Shader::FRAGMENT:
13142                         source = fs_tested;
13143                         break;
13144                 case Utils::Shader::GEOMETRY:
13145                         source = gs_tested;
13146                         break;
13147                 case Utils::Shader::TESS_CTRL:
13148                         source = tcs_tested;
13149                         break;
13150                 case Utils::Shader::TESS_EVAL:
13151                         source = tes_tested;
13152                         break;
13153                 case Utils::Shader::VERTEX:
13154                         source = vs_tested;
13155                         break;
13156                 default:
13157                         TCU_FAIL("Invalid enum");
13158                 }
13159
13160                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13161                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13162                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13163         }
13164         else
13165         {
13166                 switch (stage)
13167                 {
13168                 case Utils::Shader::FRAGMENT:
13169                         source = fs;
13170                         break;
13171                 case Utils::Shader::GEOMETRY:
13172                         source = gs;
13173                         break;
13174                 case Utils::Shader::TESS_CTRL:
13175                         source = tcs;
13176                         break;
13177                 case Utils::Shader::TESS_EVAL:
13178                         source = tes;
13179                         break;
13180                 case Utils::Shader::VERTEX:
13181                         source = vs;
13182                         break;
13183                 default:
13184                         TCU_FAIL("Invalid enum");
13185                 }
13186         }
13187
13188         return source;
13189 }
13190
13191 /** Get description of test case
13192  *
13193  * @param test_case_index Index of test case
13194  *
13195  * @return Test case description
13196  **/
13197 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13198 {
13199         std::stringstream stream;
13200         testCase&                 test_case = m_test_cases[test_case_index];
13201
13202         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13203
13204         if (true == test_case.m_is_input)
13205         {
13206                 stream << "input";
13207         }
13208         else
13209         {
13210                 stream << "output";
13211         }
13212
13213         return stream.str();
13214 }
13215
13216 /** Get number of test cases
13217  *
13218  * @return Number of test cases
13219  **/
13220 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13221 {
13222         return static_cast<GLuint>(m_test_cases.size());
13223 }
13224
13225 /** Selects if "compute" stage is relevant for test
13226  *
13227  * @param ignored
13228  *
13229  * @return false
13230  **/
13231 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13232 {
13233         return false;
13234 }
13235
13236 /** Prepare all test cases
13237  *
13238  **/
13239 void VaryingStructureMemberLocationTest::testInit()
13240 {
13241         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13242         {
13243                 if (Utils::Shader::COMPUTE == stage)
13244                 {
13245                         continue;
13246                 }
13247
13248                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13249                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13250
13251                 m_test_cases.push_back(test_case_in);
13252
13253                 if (Utils::Shader::FRAGMENT != stage)
13254                 {
13255                         m_test_cases.push_back(test_case_out);
13256                 }
13257         }
13258 }
13259
13260 /** Constructor
13261  *
13262  * @param context Test framework context
13263  **/
13264 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13265         : TextureTestBase(context, "varying_block_locations",
13266                                           "Test verifies that locations are respected when blocks are used as in and out ")
13267 {
13268 }
13269
13270 /** Prepare code snippet that will pass in variables to out variables
13271  *
13272  * @param ignored
13273  * @param varying_passthrough Collection of connections between in and out variables
13274  * @param stage               Shader stage
13275  *
13276  * @return Code that pass in variables to next stage
13277  **/
13278 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13279                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13280                                                                                                           Utils::Shader::STAGES          stage)
13281 {
13282         std::string result;
13283
13284         if (Utils::Shader::VERTEX != stage)
13285         {
13286                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13287         }
13288         else
13289         {
13290                 result = "vs_tcs_block.third  = vs_in_third;\n"
13291                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13292                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13293         }
13294
13295         return result;
13296 }
13297
13298 /** Get interface of program
13299  *
13300  * @param ignored
13301  * @param program_interface   Interface of program
13302  * @param varying_passthrough Collection of connections between in and out variables
13303  **/
13304 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13305                                                                                                         Utils::ProgramInterface&   program_interface,
13306                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13307 {
13308         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13309         const Utils::Type               vec4 = Utils::Type::vec4;
13310
13311         /* Prepare data */
13312         m_third_data  = vec4.GenerateData();
13313         m_fourth_data = vec4.GenerateData();
13314         m_fifth_data  = vec4.GenerateData();
13315
13316         /* Memory layout is different from location layout */
13317         const GLuint fifth_offset  = 0u;
13318         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13319         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13320
13321         m_data.resize(fourth_offset + m_fourth_data.size());
13322         GLubyte* ptr = (GLubyte*)&m_data[0];
13323         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13324         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13325         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13326
13327         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13328
13329         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13330                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13331
13332         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13333                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13334
13335         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13336                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13337
13338         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13339                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13340                           m_data.size() /* data_size */);
13341
13342         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13343                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13344                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13345
13346         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13347                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13348                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13349
13350         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13351                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13352                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13353
13354         program_interface.CloneVertexInterface(varying_passthrough);
13355 }
13356
13357 /** Selects if "compute" stage is relevant for test
13358  *
13359  * @param ignored
13360  *
13361  * @return false
13362  **/
13363 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13364 {
13365         return false;
13366 }
13367
13368 /** This test should be run with separable programs
13369  *
13370  * @param ignored
13371  *
13372  * @return true
13373  **/
13374 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13375 {
13376         return false;
13377 }
13378
13379 /** Constructor
13380  *
13381  * @param context Test framework context
13382  **/
13383 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13384         : NegativeTestBase(
13385                   context, "varying_block_member_locations",
13386                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13387 {
13388 }
13389
13390 /** Source for given test case and stage
13391  *
13392  * @param test_case_index Index of test case
13393  * @param stage           Shader stage
13394  *
13395  * @return Shader source
13396  **/
13397 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13398 {
13399         static const GLchar* block_definition_all = "Goku {\n"
13400                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13401                                                                                                 "    layout (location = 4) vec4 goten;\n"
13402                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13403                                                                                                 "} gokuARRAY;\n";
13404         static const GLchar* block_definition_default = "Goku {\n"
13405                                                                                                         "    vec4 gohan;\n"
13406                                                                                                         "    vec4 goten;\n"
13407                                                                                                         "    vec4 chichi;\n"
13408                                                                                                         "} gokuARRAY;\n";
13409         static const GLchar* block_definition_one = "Goku {\n"
13410                                                                                                 "    vec4 gohan;\n"
13411                                                                                                 "    layout (location = 4) vec4 goten;\n"
13412                                                                                                 "    vec4 chichi;\n"
13413                                                                                                 "} gokuARRAY;\n";
13414         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13415         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13416                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13417                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13418         static const GLchar* fs = "#version 430 core\n"
13419                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13420                                                           "\n"
13421                                                           "in  vec4 gs_fs;\n"
13422                                                           "out vec4 fs_out;\n"
13423                                                           "\n"
13424                                                           "void main()\n"
13425                                                           "{\n"
13426                                                           "    fs_out = gs_fs;\n"
13427                                                           "}\n"
13428                                                           "\n";
13429         static const GLchar* fs_tested = "#version 430 core\n"
13430                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13431                                                                          "\n"
13432                                                                          "DIRECTION BLOCK_DEFINITION"
13433                                                                          "\n"
13434                                                                          "in  vec4 gs_fs;\n"
13435                                                                          "out vec4 fs_out;\n"
13436                                                                          "\n"
13437                                                                          "void main()\n"
13438                                                                          "{\n"
13439                                                                          "    vec4 result = gs_fs;\n"
13440                                                                          "\n"
13441                                                                          "VARIABLE_USE"
13442                                                                          "\n"
13443                                                                          "    fs_out = result;\n"
13444                                                                          "}\n"
13445                                                                          "\n";
13446         static const GLchar* gs = "#version 430 core\n"
13447                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13448                                                           "\n"
13449                                                           "layout(points)                           in;\n"
13450                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13451                                                           "\n"
13452                                                           "in  vec4 tes_gs[];\n"
13453                                                           "out vec4 gs_fs;\n"
13454                                                           "\n"
13455                                                           "void main()\n"
13456                                                           "{\n"
13457                                                           "    gs_fs = tes_gs[0];\n"
13458                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13459                                                           "    EmitVertex();\n"
13460                                                           "    gs_fs = tes_gs[0];\n"
13461                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13462                                                           "    EmitVertex();\n"
13463                                                           "    gs_fs = tes_gs[0];\n"
13464                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13465                                                           "    EmitVertex();\n"
13466                                                           "    gs_fs = tes_gs[0];\n"
13467                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13468                                                           "    EmitVertex();\n"
13469                                                           "}\n"
13470                                                           "\n";
13471         static const GLchar* gs_tested = "#version 430 core\n"
13472                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13473                                                                          "\n"
13474                                                                          "layout(points)                           in;\n"
13475                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13476                                                                          "\n"
13477                                                                          "DIRECTION BLOCK_DEFINITION"
13478                                                                          "\n"
13479                                                                          "in  vec4 tes_gs[];\n"
13480                                                                          "out vec4 gs_fs;\n"
13481                                                                          "\n"
13482                                                                          "void main()\n"
13483                                                                          "{\n"
13484                                                                          "    vec4 result = tes_gs[0];\n"
13485                                                                          "\n"
13486                                                                          "VARIABLE_USE"
13487                                                                          "\n"
13488                                                                          "    gs_fs = result;\n"
13489                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13490                                                                          "    EmitVertex();\n"
13491                                                                          "    gs_fs = result;\n"
13492                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13493                                                                          "    EmitVertex();\n"
13494                                                                          "    gs_fs = result;\n"
13495                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13496                                                                          "    EmitVertex();\n"
13497                                                                          "    gs_fs = result;\n"
13498                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13499                                                                          "    EmitVertex();\n"
13500                                                                          "}\n"
13501                                                                          "\n";
13502         static const GLchar* tcs = "#version 430 core\n"
13503                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13504                                                            "\n"
13505                                                            "layout(vertices = 1) out;\n"
13506                                                            "\n"
13507                                                            "in  vec4 vs_tcs[];\n"
13508                                                            "out vec4 tcs_tes[];\n"
13509                                                            "\n"
13510                                                            "void main()\n"
13511                                                            "{\n"
13512                                                            "\n"
13513                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13514                                                            "\n"
13515                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13516                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13517                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13518                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13519                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13520                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13521                                                            "}\n"
13522                                                            "\n";
13523         static const GLchar* tcs_tested = "#version 430 core\n"
13524                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13525                                                                           "\n"
13526                                                                           "layout(vertices = 1) out;\n"
13527                                                                           "\n"
13528                                                                           "DIRECTION BLOCK_DEFINITION"
13529                                                                           "\n"
13530                                                                           "in  vec4 vs_tcs[];\n"
13531                                                                           "out vec4 tcs_tes[];\n"
13532                                                                           "\n"
13533                                                                           "void main()\n"
13534                                                                           "{\n"
13535                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13536                                                                           "\n"
13537                                                                           "VARIABLE_USE"
13538                                                                           "\n"
13539                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13540                                                                           "\n"
13541                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13542                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13543                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13544                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13545                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13546                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13547                                                                           "}\n"
13548                                                                           "\n";
13549         static const GLchar* tes = "#version 430 core\n"
13550                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13551                                                            "\n"
13552                                                            "layout(isolines, point_mode) in;\n"
13553                                                            "\n"
13554                                                            "in  vec4 tcs_tes[];\n"
13555                                                            "out vec4 tes_gs;\n"
13556                                                            "\n"
13557                                                            "void main()\n"
13558                                                            "{\n"
13559                                                            "    tes_gs = tcs_tes[0];\n"
13560                                                            "}\n"
13561                                                            "\n";
13562         static const GLchar* tes_tested = "#version 430 core\n"
13563                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13564                                                                           "\n"
13565                                                                           "layout(isolines, point_mode) in;\n"
13566                                                                           "\n"
13567                                                                           "DIRECTION BLOCK_DEFINITION"
13568                                                                           "\n"
13569                                                                           "in  vec4 tcs_tes[];\n"
13570                                                                           "out vec4 tes_gs;\n"
13571                                                                           "\n"
13572                                                                           "void main()\n"
13573                                                                           "{\n"
13574                                                                           "    vec4 result = tcs_tes[0];\n"
13575                                                                           "\n"
13576                                                                           "VARIABLE_USE"
13577                                                                           "\n"
13578                                                                           "    tes_gs = result;\n"
13579                                                                           "}\n"
13580                                                                           "\n";
13581         static const GLchar* vs = "#version 430 core\n"
13582                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13583                                                           "\n"
13584                                                           "in  vec4 in_vs;\n"
13585                                                           "out vec4 vs_tcs;\n"
13586                                                           "\n"
13587                                                           "void main()\n"
13588                                                           "{\n"
13589                                                           "    vs_tcs = in_vs;\n"
13590                                                           "}\n"
13591                                                           "\n";
13592         static const GLchar* vs_tested = "#version 430 core\n"
13593                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13594                                                                          "\n"
13595                                                                          "DIRECTION BLOCK_DEFINITION"
13596                                                                          "\n"
13597                                                                          "in  vec4 in_vs;\n"
13598                                                                          "out vec4 vs_tcs;\n"
13599                                                                          "\n"
13600                                                                          "void main()\n"
13601                                                                          "{\n"
13602                                                                          "    vec4 result = in_vs;\n"
13603                                                                          "\n"
13604                                                                          "VARIABLE_USE"
13605                                                                          "\n"
13606                                                                          "    vs_tcs = result;\n"
13607                                                                          "}\n"
13608                                                                          "\n";
13609
13610         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13611                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13612                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13613                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13614                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13615                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13616
13617         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13618                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13619                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13620                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13621                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13622                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13623
13624         static const bool require_modifications_in[6][6] = {
13625                 /* cs  */ { false, false, false, false, false, false },
13626                 /* vs  */ { false, true, false, false, false, false },
13627                 /* tcs */ { false, true, true, false, false, false },
13628                 /* tes */ { false, false, true, true, false, false },
13629                 /* gs  */ { false, false, false, true, true, false },
13630                 /* fs  */ { false, false, false, false, true, true }
13631         };
13632
13633         static const bool require_modifications_out[6][6] = {
13634                 /* cs  */ { false, false, false, false, false, false },
13635                 /* vs  */ { false, true, true, false, false, false },
13636                 /* tcs */ { false, false, true, true, false, false },
13637                 /* tes */ { false, false, false, true, true, false },
13638                 /* gs  */ { false, false, false, false, true, true },
13639                 /* fs  */ { false, false, false, false, false, false }
13640         };
13641
13642         const GLchar* array                                     = "";
13643         const GLchar* definition                        = block_definition_default;
13644         const GLchar* direction                         = "out";
13645         const GLchar* index                                     = "";
13646         bool              require_modifications = false;
13647         std::string   source;
13648         testCase&        test_case = m_test_cases[test_case_index];
13649         const GLchar* var_use   = output_use;
13650
13651         if (true == test_case.m_is_input)
13652         {
13653                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13654                 source                            = shaders_in[test_case.m_stage][stage];
13655
13656                 if (test_case.m_stage == stage)
13657                 {
13658                         direction = "in";
13659                         var_use   = input_use;
13660                 }
13661         }
13662         else
13663         {
13664                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13665                 source                            = shaders_out[test_case.m_stage][stage];
13666
13667                 if (test_case.m_stage != stage)
13668                 {
13669                         direction = "in";
13670                         var_use   = input_use;
13671                 }
13672         }
13673
13674         if (test_case.m_stage == stage)
13675         {
13676                 if (true == test_case.m_qualify_all)
13677                 {
13678                         definition = block_definition_all;
13679                 }
13680                 else
13681                 {
13682                         definition = block_definition_one;
13683                 }
13684         }
13685
13686         switch (stage)
13687         {
13688         case Utils::Shader::FRAGMENT:
13689                 break;
13690         case Utils::Shader::GEOMETRY:
13691                 array = "[]";
13692                 index = "[0]";
13693                 break;
13694         case Utils::Shader::TESS_CTRL:
13695                 array = "[]";
13696                 index = "[gl_InvocationID]";
13697                 break;
13698         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13699         // the GS input block is an array, so the DS output can't be declared as an array
13700         case Utils::Shader::TESS_EVAL:
13701         {
13702                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13703                 {
13704                         array = "[]";
13705                         index = "[0]";
13706                 }
13707                 else // match DS output and GS input
13708                 {
13709                         array = "";
13710                         index = "";
13711                 }
13712         }
13713         break;
13714         case Utils::Shader::VERTEX:
13715                 break;
13716         default:
13717                 TCU_FAIL("Invalid enum");
13718         }
13719
13720         if (true == require_modifications)
13721         {
13722                 size_t position = 0;
13723                 size_t temp;
13724
13725                 Utils::replaceToken("DIRECTION", position, direction, source);
13726                 temp = position;
13727                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13728                 position = temp;
13729                 Utils::replaceToken("ARRAY", position, array, source);
13730                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13731
13732                 Utils::replaceAllTokens("INDEX", index, source);
13733         }
13734         else
13735         {
13736                 switch (stage)
13737                 {
13738                 case Utils::Shader::FRAGMENT:
13739                         source = fs;
13740                         break;
13741                 case Utils::Shader::GEOMETRY:
13742                         source = gs;
13743                         break;
13744                 case Utils::Shader::TESS_CTRL:
13745                         source = tcs;
13746                         break;
13747                 case Utils::Shader::TESS_EVAL:
13748                         source = tes;
13749                         break;
13750                 case Utils::Shader::VERTEX:
13751                         source = vs;
13752                         break;
13753                 default:
13754                         TCU_FAIL("Invalid enum");
13755                 }
13756         }
13757
13758         return source;
13759 }
13760
13761 /** Get description of test case
13762  *
13763  * @param test_case_index Index of test case
13764  *
13765  * @return Test case description
13766  **/
13767 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13768 {
13769         std::stringstream stream;
13770         testCase&                 test_case = m_test_cases[test_case_index];
13771
13772         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13773
13774         if (true == test_case.m_is_input)
13775         {
13776                 stream << "input";
13777         }
13778         else
13779         {
13780                 stream << "output";
13781         }
13782
13783         if (true == test_case.m_qualify_all)
13784         {
13785                 stream << ", all members qualified";
13786         }
13787         else
13788         {
13789                 stream << ", not all members qualified";
13790         }
13791
13792         return stream.str();
13793 }
13794
13795 /** Get number of test cases
13796  *
13797  * @return Number of test cases
13798  **/
13799 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13800 {
13801         return static_cast<GLuint>(m_test_cases.size());
13802 }
13803
13804 /** Selects if "compute" stage is relevant for test
13805  *
13806  * @param ignored
13807  *
13808  * @return false
13809  **/
13810 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13811 {
13812         return false;
13813 }
13814
13815 /** Selects if compilation failure is expected result
13816  *
13817  * @param test_case_index Index of test case
13818  *
13819  * @return false when all members are qualified, true otherwise
13820  **/
13821 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13822 {
13823         return (true != m_test_cases[test_case_index].m_qualify_all);
13824 }
13825
13826 /** Prepare all test cases
13827  *
13828  **/
13829 void VaryingBlockMemberLocationsTest::testInit()
13830 {
13831         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13832         {
13833                 if (Utils::Shader::COMPUTE == stage)
13834                 {
13835                         continue;
13836                 }
13837
13838                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13839                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13840                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13841                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13842
13843                 if (Utils::Shader::VERTEX != stage)
13844                 {
13845                         m_test_cases.push_back(test_case_in_all);
13846                         m_test_cases.push_back(test_case_in_one);
13847                 }
13848
13849                 if (Utils::Shader::FRAGMENT != stage)
13850                 {
13851                         m_test_cases.push_back(test_case_out_all);
13852                         m_test_cases.push_back(test_case_out_one);
13853                 }
13854         }
13855 }
13856
13857 /** Constructor
13858  *
13859  * @param context Test framework context
13860  **/
13861 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13862         : NegativeTestBase(
13863                   context, "varying_block_automatic_member_locations",
13864                   "Test verifies that compiler assigns subsequent locations to block members, even if this causes errors")
13865 {
13866 }
13867
13868 /** Source for given test case and stage
13869  *
13870  * @param test_case_index Index of test case
13871  * @param stage           Shader stage
13872  *
13873  * @return Shader source
13874  **/
13875 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13876                                                                                                                                           Utils::Shader::STAGES stage)
13877 {
13878         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13879                                                                                         "    vec4 goku;\n"
13880                                                                                         "    vec4 gohan[4];\n"
13881                                                                                         "    vec4 goten;\n"
13882                                                                                         "    layout (location = 1) vec4 chichi;\n"
13883                                                                                         "    vec4 pan;\n"
13884                                                                                         "} dbzARRAY;\n";
13885         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13886                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13887                                                                          "dbzINDEX.pan;\n";
13888         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
13889                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
13890                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
13891                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
13892                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
13893                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
13894                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
13895                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
13896                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
13897         static const GLchar* fs = "#version 430 core\n"
13898                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13899                                                           "\n"
13900                                                           "in  vec4 gs_fs;\n"
13901                                                           "out vec4 fs_out;\n"
13902                                                           "\n"
13903                                                           "void main()\n"
13904                                                           "{\n"
13905                                                           "    fs_out = gs_fs;\n"
13906                                                           "}\n"
13907                                                           "\n";
13908         static const GLchar* fs_tested = "#version 430 core\n"
13909                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13910                                                                          "\n"
13911                                                                          "BLOCK_DEFINITION"
13912                                                                          "\n"
13913                                                                          "in  vec4 gs_fs;\n"
13914                                                                          "out vec4 fs_out;\n"
13915                                                                          "\n"
13916                                                                          "void main()\n"
13917                                                                          "{\n"
13918                                                                          "    vec4 result = gs_fs;\n"
13919                                                                          "\n"
13920                                                                          "VARIABLE_USE"
13921                                                                          "\n"
13922                                                                          "    fs_out += result;\n"
13923                                                                          "}\n"
13924                                                                          "\n";
13925         static const GLchar* gs = "#version 430 core\n"
13926                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13927                                                           "\n"
13928                                                           "layout(points)                           in;\n"
13929                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13930                                                           "\n"
13931                                                           "in  vec4 tes_gs[];\n"
13932                                                           "out vec4 gs_fs;\n"
13933                                                           "\n"
13934                                                           "void main()\n"
13935                                                           "{\n"
13936                                                           "    gs_fs = tes_gs[0];\n"
13937                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13938                                                           "    EmitVertex();\n"
13939                                                           "    gs_fs = tes_gs[0];\n"
13940                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13941                                                           "    EmitVertex();\n"
13942                                                           "    gs_fs = tes_gs[0];\n"
13943                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13944                                                           "    EmitVertex();\n"
13945                                                           "    gs_fs = tes_gs[0];\n"
13946                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13947                                                           "    EmitVertex();\n"
13948                                                           "}\n"
13949                                                           "\n";
13950         static const GLchar* gs_tested = "#version 430 core\n"
13951                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13952                                                                          "\n"
13953                                                                          "layout(points)                           in;\n"
13954                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13955                                                                          "\n"
13956                                                                          "BLOCK_DEFINITION"
13957                                                                          "\n"
13958                                                                          "in  vec4 tes_gs[];\n"
13959                                                                          "out vec4 gs_fs;\n"
13960                                                                          "\n"
13961                                                                          "void main()\n"
13962                                                                          "{\n"
13963                                                                          "    vec4 result = tes_gs[0];\n"
13964                                                                          "\n"
13965                                                                          "VARIABLE_USE"
13966                                                                          "\n"
13967                                                                          "    gs_fs = result;\n"
13968                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13969                                                                          "    EmitVertex();\n"
13970                                                                          "    gs_fs = result;\n"
13971                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13972                                                                          "    EmitVertex();\n"
13973                                                                          "    gs_fs = result;\n"
13974                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13975                                                                          "    EmitVertex();\n"
13976                                                                          "    gs_fs = result;\n"
13977                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13978                                                                          "    EmitVertex();\n"
13979                                                                          "}\n"
13980                                                                          "\n";
13981         static const GLchar* tcs = "#version 430 core\n"
13982                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13983                                                            "\n"
13984                                                            "layout(vertices = 1) out;\n"
13985                                                            "\n"
13986                                                            "in  vec4 vs_tcs[];\n"
13987                                                            "out vec4 tcs_tes[];\n"
13988                                                            "\n"
13989                                                            "void main()\n"
13990                                                            "{\n"
13991                                                            "\n"
13992                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13993                                                            "\n"
13994                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13995                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13996                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13997                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13998                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13999                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14000                                                            "}\n"
14001                                                            "\n";
14002         static const GLchar* tcs_tested = "#version 430 core\n"
14003                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14004                                                                           "\n"
14005                                                                           "layout(vertices = 1) out;\n"
14006                                                                           "\n"
14007                                                                           "BLOCK_DEFINITION"
14008                                                                           "\n"
14009                                                                           "in  vec4 vs_tcs[];\n"
14010                                                                           "out vec4 tcs_tes[];\n"
14011                                                                           "\n"
14012                                                                           "void main()\n"
14013                                                                           "{\n"
14014                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14015                                                                           "\n"
14016                                                                           "VARIABLE_USE"
14017                                                                           "\n"
14018                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14019                                                                           "\n"
14020                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14021                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14022                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14023                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14024                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14025                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14026                                                                           "}\n"
14027                                                                           "\n";
14028         static const GLchar* tes = "#version 430 core\n"
14029                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14030                                                            "\n"
14031                                                            "layout(isolines, point_mode) in;\n"
14032                                                            "\n"
14033                                                            "in  vec4 tcs_tes[];\n"
14034                                                            "out vec4 tes_gs;\n"
14035                                                            "\n"
14036                                                            "void main()\n"
14037                                                            "{\n"
14038                                                            "    tes_gs = tcs_tes[0];\n"
14039                                                            "}\n"
14040                                                            "\n";
14041         static const GLchar* tes_tested = "#version 430 core\n"
14042                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14043                                                                           "\n"
14044                                                                           "layout(isolines, point_mode) in;\n"
14045                                                                           "\n"
14046                                                                           "BLOCK_DEFINITION"
14047                                                                           "\n"
14048                                                                           "in  vec4 tcs_tes[];\n"
14049                                                                           "out vec4 tes_gs;\n"
14050                                                                           "\n"
14051                                                                           "void main()\n"
14052                                                                           "{\n"
14053                                                                           "    vec4 result = tcs_tes[0];\n"
14054                                                                           "\n"
14055                                                                           "VARIABLE_USE"
14056                                                                           "\n"
14057                                                                           "    tes_gs += result;\n"
14058                                                                           "}\n"
14059                                                                           "\n";
14060         static const GLchar* vs = "#version 430 core\n"
14061                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14062                                                           "\n"
14063                                                           "in  vec4 in_vs;\n"
14064                                                           "out vec4 vs_tcs;\n"
14065                                                           "\n"
14066                                                           "void main()\n"
14067                                                           "{\n"
14068                                                           "    vs_tcs = in_vs;\n"
14069                                                           "}\n"
14070                                                           "\n";
14071         static const GLchar* vs_tested = "#version 430 core\n"
14072                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14073                                                                          "\n"
14074                                                                          "BLOCK_DEFINITION"
14075                                                                          "\n"
14076                                                                          "in  vec4 in_vs;\n"
14077                                                                          "out vec4 vs_tcs;\n"
14078                                                                          "\n"
14079                                                                          "void main()\n"
14080                                                                          "{\n"
14081                                                                          "    vec4 result = in_vs;\n"
14082                                                                          "\n"
14083                                                                          "VARIABLE_USE"
14084                                                                          "\n"
14085                                                                          "    vs_tcs += result;\n"
14086                                                                          "}\n"
14087                                                                          "\n";
14088
14089         const GLchar* array             = "";
14090         const GLchar* direction = "out";
14091         const GLchar* index             = "";
14092         std::string   source;
14093         testCase&        test_case = m_test_cases[test_case_index];
14094         const GLchar* var_use   = output_use;
14095
14096         if (true == test_case.m_is_input)
14097         {
14098                 direction = "in ";
14099                 var_use   = input_use;
14100         }
14101
14102         if (test_case.m_stage == stage)
14103         {
14104                 size_t position = 0;
14105                 size_t temp;
14106
14107                 switch (stage)
14108                 {
14109                 case Utils::Shader::FRAGMENT:
14110                         source = fs_tested;
14111                         break;
14112                 case Utils::Shader::GEOMETRY:
14113                         source = gs_tested;
14114                         array  = "[]";
14115                         index  = "[0]";
14116                         break;
14117                 case Utils::Shader::TESS_CTRL:
14118                         source = tcs_tested;
14119                         array  = "[]";
14120                         index  = "[gl_InvocationID]";
14121                         break;
14122                 case Utils::Shader::TESS_EVAL:
14123                         source = tes_tested;
14124                         array  = "[]";
14125                         index  = "[0]";
14126                         break;
14127                 case Utils::Shader::VERTEX:
14128                         source = vs_tested;
14129                         break;
14130                 default:
14131                         TCU_FAIL("Invalid enum");
14132                 }
14133
14134                 temp = position;
14135                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14136                 position = temp;
14137                 Utils::replaceToken("DIRECTION", position, direction, source);
14138                 Utils::replaceToken("ARRAY", position, array, source);
14139                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14140
14141                 Utils::replaceAllTokens("INDEX", index, source);
14142         }
14143         else
14144         {
14145                 switch (stage)
14146                 {
14147                 case Utils::Shader::FRAGMENT:
14148                         source = fs;
14149                         break;
14150                 case Utils::Shader::GEOMETRY:
14151                         source = gs;
14152                         break;
14153                 case Utils::Shader::TESS_CTRL:
14154                         source = tcs;
14155                         break;
14156                 case Utils::Shader::TESS_EVAL:
14157                         source = tes;
14158                         break;
14159                 case Utils::Shader::VERTEX:
14160                         source = vs;
14161                         break;
14162                 default:
14163                         TCU_FAIL("Invalid enum");
14164                 }
14165         }
14166
14167         return source;
14168 }
14169
14170 /** Get description of test case
14171  *
14172  * @param test_case_index Index of test case
14173  *
14174  * @return Test case description
14175  **/
14176 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14177 {
14178         std::stringstream stream;
14179         testCase&                 test_case = m_test_cases[test_case_index];
14180
14181         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14182
14183         if (true == test_case.m_is_input)
14184         {
14185                 stream << "input";
14186         }
14187         else
14188         {
14189                 stream << "output";
14190         }
14191
14192         return stream.str();
14193 }
14194
14195 /** Get number of test cases
14196  *
14197  * @return Number of test cases
14198  **/
14199 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14200 {
14201         return static_cast<GLuint>(m_test_cases.size());
14202 }
14203
14204 /** Selects if "compute" stage is relevant for test
14205  *
14206  * @param ignored
14207  *
14208  * @return false
14209  **/
14210 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14211 {
14212         return false;
14213 }
14214
14215 /** Prepare all test cases
14216  *
14217  **/
14218 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14219 {
14220         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14221         {
14222                 if (Utils::Shader::COMPUTE == stage)
14223                 {
14224                         continue;
14225                 }
14226
14227                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14228                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14229
14230                 if (Utils::Shader::VERTEX != stage)
14231                 {
14232                         m_test_cases.push_back(test_case_in);
14233                 }
14234
14235                 if (Utils::Shader::FRAGMENT != stage)
14236                 {
14237                         m_test_cases.push_back(test_case_out);
14238                 }
14239         }
14240 }
14241
14242 /** Constructor
14243  *
14244  * @param context Test framework context
14245  **/
14246 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14247         : NegativeTestBase(context, "varying_location_limit",
14248                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14249 {
14250 }
14251
14252 /** Source for given test case and stage
14253  *
14254  * @param test_case_index Index of test case
14255  * @param stage           Shader stage
14256  *
14257  * @return Shader source
14258  **/
14259 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14260 {
14261         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14262         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14263                                                                          "    {\n"
14264                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14265                                                                          "    }\n";
14266         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14267                                                                           "    if (vec4(0) == result)\n"
14268                                                                           "    {\n"
14269                                                                           "        gokuINDEX = TYPE(1);\n"
14270                                                                           "    }\n";
14271         static const GLchar* fs = "#version 430 core\n"
14272                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14273                                                           "\n"
14274                                                           "in  vec4 gs_fs;\n"
14275                                                           "out vec4 fs_out;\n"
14276                                                           "\n"
14277                                                           "void main()\n"
14278                                                           "{\n"
14279                                                           "    fs_out = gs_fs;\n"
14280                                                           "}\n"
14281                                                           "\n";
14282         static const GLchar* fs_tested = "#version 430 core\n"
14283                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14284                                                                          "\n"
14285                                                                          "VAR_DEFINITION"
14286                                                                          "\n"
14287                                                                          "in  vec4 gs_fs;\n"
14288                                                                          "out vec4 fs_out;\n"
14289                                                                          "\n"
14290                                                                          "void main()\n"
14291                                                                          "{\n"
14292                                                                          "    vec4 result = gs_fs;\n"
14293                                                                          "\n"
14294                                                                          "VARIABLE_USE"
14295                                                                          "\n"
14296                                                                          "    fs_out += result;\n"
14297                                                                          "}\n"
14298                                                                          "\n";
14299         static const GLchar* gs = "#version 430 core\n"
14300                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14301                                                           "\n"
14302                                                           "layout(points)                           in;\n"
14303                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14304                                                           "\n"
14305                                                           "in  vec4 tes_gs[];\n"
14306                                                           "out vec4 gs_fs;\n"
14307                                                           "\n"
14308                                                           "void main()\n"
14309                                                           "{\n"
14310                                                           "    gs_fs = tes_gs[0];\n"
14311                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14312                                                           "    EmitVertex();\n"
14313                                                           "    gs_fs = tes_gs[0];\n"
14314                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14315                                                           "    EmitVertex();\n"
14316                                                           "    gs_fs = tes_gs[0];\n"
14317                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14318                                                           "    EmitVertex();\n"
14319                                                           "    gs_fs = tes_gs[0];\n"
14320                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14321                                                           "    EmitVertex();\n"
14322                                                           "}\n"
14323                                                           "\n";
14324         static const GLchar* gs_tested = "#version 430 core\n"
14325                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14326                                                                          "\n"
14327                                                                          "layout(points)                           in;\n"
14328                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14329                                                                          "\n"
14330                                                                          "VAR_DEFINITION"
14331                                                                          "\n"
14332                                                                          "in  vec4 tes_gs[];\n"
14333                                                                          "out vec4 gs_fs;\n"
14334                                                                          "\n"
14335                                                                          "void main()\n"
14336                                                                          "{\n"
14337                                                                          "    vec4 result = tes_gs[0];\n"
14338                                                                          "\n"
14339                                                                          "VARIABLE_USE"
14340                                                                          "\n"
14341                                                                          "    gs_fs = result;\n"
14342                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14343                                                                          "    EmitVertex();\n"
14344                                                                          "    gs_fs = result;\n"
14345                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14346                                                                          "    EmitVertex();\n"
14347                                                                          "    gs_fs = result;\n"
14348                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14349                                                                          "    EmitVertex();\n"
14350                                                                          "    gs_fs = result;\n"
14351                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14352                                                                          "    EmitVertex();\n"
14353                                                                          "}\n"
14354                                                                          "\n";
14355         static const GLchar* tcs = "#version 430 core\n"
14356                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14357                                                            "\n"
14358                                                            "layout(vertices = 1) out;\n"
14359                                                            "\n"
14360                                                            "in  vec4 vs_tcs[];\n"
14361                                                            "out vec4 tcs_tes[];\n"
14362                                                            "\n"
14363                                                            "void main()\n"
14364                                                            "{\n"
14365                                                            "\n"
14366                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14367                                                            "\n"
14368                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14369                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14370                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14371                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14372                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14373                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14374                                                            "}\n"
14375                                                            "\n";
14376         static const GLchar* tcs_tested = "#version 430 core\n"
14377                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14378                                                                           "\n"
14379                                                                           "layout(vertices = 1) out;\n"
14380                                                                           "\n"
14381                                                                           "VAR_DEFINITION"
14382                                                                           "\n"
14383                                                                           "in  vec4 vs_tcs[];\n"
14384                                                                           "out vec4 tcs_tes[];\n"
14385                                                                           "\n"
14386                                                                           "void main()\n"
14387                                                                           "{\n"
14388                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14389                                                                           "\n"
14390                                                                           "VARIABLE_USE"
14391                                                                           "\n"
14392                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14393                                                                           "\n"
14394                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14395                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14396                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14397                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14398                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14399                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14400                                                                           "}\n"
14401                                                                           "\n";
14402         static const GLchar* tes = "#version 430 core\n"
14403                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14404                                                            "\n"
14405                                                            "layout(isolines, point_mode) in;\n"
14406                                                            "\n"
14407                                                            "in  vec4 tcs_tes[];\n"
14408                                                            "out vec4 tes_gs;\n"
14409                                                            "\n"
14410                                                            "void main()\n"
14411                                                            "{\n"
14412                                                            "    tes_gs = tcs_tes[0];\n"
14413                                                            "}\n"
14414                                                            "\n";
14415         static const GLchar* tes_tested = "#version 430 core\n"
14416                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14417                                                                           "\n"
14418                                                                           "layout(isolines, point_mode) in;\n"
14419                                                                           "\n"
14420                                                                           "VAR_DEFINITION"
14421                                                                           "\n"
14422                                                                           "in  vec4 tcs_tes[];\n"
14423                                                                           "out vec4 tes_gs;\n"
14424                                                                           "\n"
14425                                                                           "void main()\n"
14426                                                                           "{\n"
14427                                                                           "    vec4 result = tcs_tes[0];\n"
14428                                                                           "\n"
14429                                                                           "VARIABLE_USE"
14430                                                                           "\n"
14431                                                                           "    tes_gs += result;\n"
14432                                                                           "}\n"
14433                                                                           "\n";
14434         static const GLchar* vs = "#version 430 core\n"
14435                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14436                                                           "\n"
14437                                                           "in  vec4 in_vs;\n"
14438                                                           "out vec4 vs_tcs;\n"
14439                                                           "\n"
14440                                                           "void main()\n"
14441                                                           "{\n"
14442                                                           "    vs_tcs = in_vs;\n"
14443                                                           "}\n"
14444                                                           "\n";
14445         static const GLchar* vs_tested = "#version 430 core\n"
14446                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14447                                                                          "\n"
14448                                                                          "VAR_DEFINITION"
14449                                                                          "\n"
14450                                                                          "in  vec4 in_vs;\n"
14451                                                                          "out vec4 vs_tcs;\n"
14452                                                                          "\n"
14453                                                                          "void main()\n"
14454                                                                          "{\n"
14455                                                                          "    vec4 result = in_vs;\n"
14456                                                                          "\n"
14457                                                                          "VARIABLE_USE"
14458                                                                          "\n"
14459                                                                          "    vs_tcs += result;\n"
14460                                                                          "}\n"
14461                                                                          "\n";
14462
14463         std::string source;
14464         testCase&   test_case = m_test_cases[test_case_index];
14465
14466         if (test_case.m_stage == stage)
14467         {
14468                 const GLchar*                    array = "";
14469                 GLchar                                   buffer[16];
14470                 const GLchar*                    direction = "in ";
14471                 const GLchar*                    flat     = "";
14472                 const GLchar*                    index   = "";
14473                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14474                 size_t                                   position  = 0;
14475                 size_t                                   temp;
14476                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14477                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14478                 const GLchar*                    var_use   = input_use;
14479
14480                 if (false == test_case.m_is_input)
14481                 {
14482                         direction = "out";
14483                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14484                         storage   = Utils::Variable::VARYING_OUTPUT;
14485                         var_use   = output_use;
14486                 }
14487
14488                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14489                 {
14490                         flat = "flat";
14491                 }
14492
14493                 sprintf(buffer, "%d", last);
14494
14495                 switch (stage)
14496                 {
14497                 case Utils::Shader::FRAGMENT:
14498                         source = fs_tested;
14499                         break;
14500                 case Utils::Shader::GEOMETRY:
14501                         source = gs_tested;
14502                         array  = "[]";
14503                         index  = "[0]";
14504                         break;
14505                 case Utils::Shader::TESS_CTRL:
14506                         source = tcs_tested;
14507                         array  = "[]";
14508                         index  = "[gl_InvocationID]";
14509                         break;
14510                 case Utils::Shader::TESS_EVAL:
14511                         source = tes_tested;
14512                         array  = "[]";
14513                         index  = "[0]";
14514                         break;
14515                 case Utils::Shader::VERTEX:
14516                         source = vs_tested;
14517                         break;
14518                 default:
14519                         TCU_FAIL("Invalid enum");
14520                 }
14521
14522                 temp = position;
14523                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14524                 position = temp;
14525                 Utils::replaceToken("LAST", position, buffer, source);
14526                 Utils::replaceToken("FLAT", position, flat, source);
14527                 Utils::replaceToken("DIRECTION", position, direction, source);
14528                 Utils::replaceToken("ARRAY", position, array, source);
14529                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14530
14531                 Utils::replaceAllTokens("TYPE", type_name, source);
14532                 Utils::replaceAllTokens("INDEX", index, source);
14533         }
14534         else
14535         {
14536                 switch (stage)
14537                 {
14538                 case Utils::Shader::FRAGMENT:
14539                         source = fs;
14540                         break;
14541                 case Utils::Shader::GEOMETRY:
14542                         source = gs;
14543                         break;
14544                 case Utils::Shader::TESS_CTRL:
14545                         source = tcs;
14546                         break;
14547                 case Utils::Shader::TESS_EVAL:
14548                         source = tes;
14549                         break;
14550                 case Utils::Shader::VERTEX:
14551                         source = vs;
14552                         break;
14553                 default:
14554                         TCU_FAIL("Invalid enum");
14555                 }
14556         }
14557
14558         return source;
14559 }
14560
14561 /** Get description of test case
14562  *
14563  * @param test_case_index Index of test case
14564  *
14565  * @return Test case description
14566  **/
14567 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14568 {
14569         std::stringstream stream;
14570         testCase&                 test_case = m_test_cases[test_case_index];
14571
14572         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14573                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14574
14575         if (true == test_case.m_is_input)
14576         {
14577                 stream << "input";
14578         }
14579         else
14580         {
14581                 stream << "output";
14582         }
14583
14584         return stream.str();
14585 }
14586
14587 /** Get number of test cases
14588  *
14589  * @return Number of test cases
14590  **/
14591 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14592 {
14593         return static_cast<GLuint>(m_test_cases.size());
14594 }
14595
14596 /** Selects if "compute" stage is relevant for test
14597  *
14598  * @param ignored
14599  *
14600  * @return false
14601  **/
14602 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14603 {
14604         return false;
14605 }
14606
14607 /** Prepare all test cases
14608  *
14609  **/
14610 void VaryingLocationLimitTest::testInit()
14611 {
14612         const GLuint n_types = getTypesNumber();
14613
14614         for (GLuint i = 0; i < n_types; ++i)
14615         {
14616                 const Utils::Type& type = getType(i);
14617
14618                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14619                 {
14620                         if (Utils::Shader::COMPUTE == stage)
14621                         {
14622                                 continue;
14623                         }
14624
14625                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14626                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14627
14628                         m_test_cases.push_back(test_case_in);
14629
14630                         if (Utils::Shader::FRAGMENT != stage)
14631                         {
14632                                 m_test_cases.push_back(test_case_out);
14633                         }
14634                 }
14635         }
14636 }
14637
14638 /** Constructor
14639  *
14640  * @param context Test framework context
14641  **/
14642 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14643         : VaryingLocationsTest(context, "varying_components",
14644                                                    "Test verifies that input and output components are respected")
14645 {
14646 }
14647
14648 /** Constructor
14649  *
14650  * @param context          Test framework context
14651  * @param test_name        Name of test
14652  * @param test_description Description of test
14653  **/
14654 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14655                                                                                          const glw::GLchar* test_description)
14656         : VaryingLocationsTest(context, test_name, test_description)
14657 {
14658 }
14659
14660 /** Get interface of program
14661  *
14662  * @param test_case_index     Test case
14663  * @param program_interface   Interface of program
14664  * @param varying_passthrough Collection of connections between in and out variables
14665  **/
14666 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14667                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14668 {
14669         GLuint                             array_length = getArrayLength();
14670         const testCase&            test_case    = m_test_cases[test_case_index];
14671         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14672         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14673
14674         /* Zero means no array, however we still need at least 1 slot of data */
14675         if (0 == array_length)
14676         {
14677                 array_length += 1;
14678         }
14679
14680         /* Generate data */
14681         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14682         const size_t                            data_size = data.size();
14683
14684         /* Prepare data for variables */
14685         m_data.resize(array_length * data_size);
14686
14687         GLubyte*           dst = &m_data[0];
14688         const GLubyte* src = &data[0];
14689
14690         for (GLuint i = 0; i < array_length; ++i)
14691         {
14692                 memcpy(dst + data_size * i, src, data_size);
14693         }
14694
14695         /* Prepare interface for each stage */
14696         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14697         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14698         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14699         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14700         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14701 }
14702
14703 /** Get type name
14704  *
14705  * @param test_case_index Index of test case
14706  *
14707  * @return Name of type test in test_case_index
14708  **/
14709 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14710 {
14711         std::string name;
14712
14713         const testCase& test_case = m_test_cases[test_case_index];
14714
14715         name = "Type: ";
14716
14717         switch (test_case.m_type)
14718         {
14719         case Utils::Type::Double:
14720                 name.append(Utils::Type::_double.GetGLSLTypeName());
14721                 break;
14722         case Utils::Type::Float:
14723                 name.append(Utils::Type::_float.GetGLSLTypeName());
14724                 break;
14725         case Utils::Type::Int:
14726                 name.append(Utils::Type::_int.GetGLSLTypeName());
14727                 break;
14728         case Utils::Type::Uint:
14729                 name.append(Utils::Type::uint.GetGLSLTypeName());
14730                 break;
14731         }
14732
14733         name.append(", layout: ");
14734
14735         switch (test_case.m_layout)
14736         {
14737         case GVEC4:
14738                 name.append("GVEC4");
14739                 break;
14740         case SCALAR_GVEC3:
14741                 name.append("SCALAR_GVEC3");
14742                 break;
14743         case GVEC3_SCALAR:
14744                 name.append("GVEC3_SCALAR");
14745                 break;
14746         case GVEC2_GVEC2:
14747                 name.append("GVEC2_GVEC2");
14748                 break;
14749         case GVEC2_SCALAR_SCALAR:
14750                 name.append("GVEC2_SCALAR_SCALAR");
14751                 break;
14752         case SCALAR_GVEC2_SCALAR:
14753                 name.append("SCALAR_GVEC2_SCALAR");
14754                 break;
14755         case SCALAR_SCALAR_GVEC2:
14756                 name.append("SCALAR_SCALAR_GVEC2");
14757                 break;
14758         case SCALAR_SCALAR_SCALAR_SCALAR:
14759                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14760                 break;
14761         }
14762
14763         return name;
14764 }
14765
14766 /** Returns number of types to test
14767  *
14768  * @return Number of types, 34
14769  **/
14770 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14771 {
14772         return static_cast<GLuint>(m_test_cases.size());
14773 }
14774
14775 /* Prepare test cases */
14776 void VaryingComponentsTest::testInit()
14777 {
14778         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Double));
14779         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Double));
14780         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Double));
14781         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Double));
14782         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Double));
14783         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Double));
14784         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Double));
14785         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Double));
14786
14787         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14788         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14789         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14790         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14791         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14792         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14793         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14794         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14795
14796         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14797         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14798         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14799         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14800         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14801         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14802         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14803         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14804
14805         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14806         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14807         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14808         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14809         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14810         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14811         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14812         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14813 }
14814
14815 /** Inform that test use components
14816  *
14817  * @param ignored
14818  *
14819  * @return true
14820  **/
14821 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14822 {
14823         return true;
14824 }
14825
14826 /** Get length of arrays that should be used during test
14827  *
14828  * @return 0u - no array at all
14829  **/
14830 GLuint VaryingComponentsTest::getArrayLength()
14831 {
14832         return 0;
14833 }
14834
14835 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14836 {
14837         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14838
14839         globals.append("const uint comp_x = 0u;\n"
14840                                    "const uint comp_y = 1u;\n"
14841                                    "const uint comp_z = 2u;\n"
14842                                    "const uint comp_w = 3u;\n");
14843
14844         return globals;
14845 }
14846
14847 /**
14848  *
14849  **/
14850 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14851                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14852 {
14853         GLchar            buffer[16];
14854         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14855         size_t            position = 0;
14856         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14857
14858         Utils::replaceToken("PREFIX", position, prefix, result);
14859         Utils::replaceToken("NAME", position, name, result);
14860
14861         sprintf(buffer, "%d", location);
14862         Utils::replaceToken("LOCATION", position, buffer, result);
14863
14864         sprintf(buffer, "%d", component);
14865         Utils::replaceToken("COMPONENT", position, buffer, result);
14866
14867         return result;
14868 }
14869
14870 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14871                                                                                                          const glw::GLchar* interpolation)
14872 {
14873         size_t          position   = 0;
14874         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14875
14876         Utils::replaceToken("LOCATION", position, location, qualifiers);
14877         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14878         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14879
14880         return qualifiers;
14881 }
14882
14883 /**
14884  *
14885  **/
14886 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14887                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14888                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14889 {
14890         const GLuint                    array_length = getArrayLength();
14891         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14892         descriptor                              desc_in[8];
14893         descriptor                              desc_out[8];
14894         const GLuint                    first_in_loc  = 0;
14895         const GLuint                    first_out_loc = 0;
14896         const GLchar*                   interpolation = "";
14897         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
14898         GLuint                                  last_out_loc  = 0;
14899         GLuint                                  n_desc            = 0;
14900         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
14901
14902         /* Select interpolation */
14903         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
14904         {
14905                 interpolation = " flat";
14906         }
14907
14908         if (Utils::Shader::FRAGMENT != stage)
14909         {
14910                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
14911         }
14912
14913         switch (test_case.m_layout)
14914         {
14915         case GVEC4:
14916                 n_desc = 2;
14917                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
14918                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
14919
14920                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
14921                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
14922                 break;
14923         case SCALAR_GVEC3:
14924                 n_desc = 4;
14925                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14926                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14927                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
14928                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
14929
14930                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14931                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14932                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
14933                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
14934                 break;
14935         case GVEC3_SCALAR:
14936                 n_desc = 4;
14937                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
14938                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
14939                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14940                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14941
14942                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
14943                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
14944                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14945                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14946                 break;
14947         case GVEC2_GVEC2:
14948                 n_desc = 4;
14949                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14950                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14951                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14952                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14953
14954                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14955                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14956                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14957                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14958                 break;
14959         case GVEC2_SCALAR_SCALAR:
14960                 n_desc = 6;
14961                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14962                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14963                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
14964                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
14965                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14966                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14967
14968                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14969                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14970                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
14971                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
14972                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14973                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14974                 break;
14975         case SCALAR_GVEC2_SCALAR:
14976                 n_desc = 6;
14977                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14978                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14979                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
14980                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
14981                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14982                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14983
14984                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14985                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14986                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
14987                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
14988                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14989                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14990                 break;
14991         case SCALAR_SCALAR_GVEC2:
14992                 n_desc = 6;
14993                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14994                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14995                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
14996                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
14997                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14998                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14999
15000                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15001                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15002                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15003                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15004                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15005                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15006                 break;
15007         case SCALAR_SCALAR_SCALAR_SCALAR:
15008                 n_desc = 8;
15009                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15010                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15011                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15012                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15013                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15014                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15015                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15016                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15017
15018                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15019                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15020                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15021                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15022                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15023                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15024                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15025                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15026                 break;
15027         }
15028
15029         for (GLuint i = 0; i < n_desc; ++i)
15030         {
15031                 const descriptor& in_desc = desc_in[i];
15032
15033                 Utils::Variable* in =
15034                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15035
15036                 if (Utils::Shader::FRAGMENT != stage)
15037                 {
15038                         const descriptor& out_desc = desc_out[i];
15039
15040                         Utils::Variable* out =
15041                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15042
15043                         varying_passthrough.Add(stage, in, out);
15044                 }
15045         }
15046
15047         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15048 }
15049
15050 /**
15051  *
15052  **/
15053 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15054                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15055                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15056 {
15057         const GLuint       array_length   = getArrayLength();
15058         const GLuint       component_size = basic_type.GetSize();
15059         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15060         const GLuint       offset                 = desc.m_component * component_size;
15061         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15062         const GLuint       size                   = desc.m_n_rows * component_size;
15063         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15064         Utils::Variable*   var                    = 0;
15065
15066         if (Utils::Variable::VARYING_INPUT == storage)
15067         {
15068                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15069                                            desc.m_location /* expected_location */, type, /* built_in_type */
15070                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15071                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15072         }
15073         else
15074         {
15075                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15076                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15077                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15078                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15079         }
15080
15081         return var;
15082 }
15083
15084 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15085                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15086                                                                                            const glw::GLchar* name)
15087 {
15088         m_component             = component;
15089         m_component_str = component_str;
15090         m_location              = location;
15091         m_location_str  = location_str;
15092         m_n_rows                = n_rows;
15093         m_name                  = name;
15094 }
15095
15096 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15097         : m_layout(layout), m_type(type)
15098 {
15099 }
15100
15101 /** Constructor
15102  *
15103  * @param context Test framework context
15104  **/
15105 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15106         : VaryingComponentsTest(context, "varying_array_components",
15107                                                         "Test verifies that input and output components are respected for arrays")
15108 {
15109 }
15110
15111 /** Get length of arrays that should be used during test
15112  *
15113  * @return 4u
15114  **/
15115 GLuint VaryingArrayComponentsTest::getArrayLength()
15116 {
15117         return 4u;
15118 }
15119
15120 /** Constructor
15121  *
15122  * @param context Test framework context
15123  **/
15124 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15125         : NegativeTestBase(context, "varying_exceeding_components",
15126                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15127 {
15128 }
15129
15130 /** Source for given test case and stage
15131  *
15132  * @param test_case_index Index of test case
15133  * @param stage           Shader stage
15134  *
15135  * @return Shader source
15136  **/
15137 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15138 {
15139         static const GLchar* var_definition_arr =
15140                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15141         static const GLchar* var_definition_one =
15142                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15143         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15144                                                                                  "    {\n"
15145                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15146                                                                                  "    }\n";
15147         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15148                                                                                  "    {\n"
15149                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15150                                                                                  "    }\n";
15151         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15152                                                                                   "    if (vec4(0) == result)\n"
15153                                                                                   "    {\n"
15154                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15155                                                                                   "    }\n";
15156         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15157                                                                                   "    if (vec4(0) == result)\n"
15158                                                                                   "    {\n"
15159                                                                                   "        gokuINDEX = TYPE(1);\n"
15160                                                                                   "    }\n";
15161         static const GLchar* fs = "#version 430 core\n"
15162                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15163                                                           "\n"
15164                                                           "in  vec4 gs_fs;\n"
15165                                                           "out vec4 fs_out;\n"
15166                                                           "\n"
15167                                                           "void main()\n"
15168                                                           "{\n"
15169                                                           "    fs_out = gs_fs;\n"
15170                                                           "}\n"
15171                                                           "\n";
15172         static const GLchar* fs_tested = "#version 430 core\n"
15173                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15174                                                                          "\n"
15175                                                                          "VAR_DEFINITION"
15176                                                                          "\n"
15177                                                                          "in  vec4 gs_fs;\n"
15178                                                                          "out vec4 fs_out;\n"
15179                                                                          "\n"
15180                                                                          "void main()\n"
15181                                                                          "{\n"
15182                                                                          "    vec4 result = gs_fs;\n"
15183                                                                          "\n"
15184                                                                          "VARIABLE_USE"
15185                                                                          "\n"
15186                                                                          "    fs_out += result;\n"
15187                                                                          "}\n"
15188                                                                          "\n";
15189         static const GLchar* gs = "#version 430 core\n"
15190                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15191                                                           "\n"
15192                                                           "layout(points)                           in;\n"
15193                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15194                                                           "\n"
15195                                                           "in  vec4 tes_gs[];\n"
15196                                                           "out vec4 gs_fs;\n"
15197                                                           "\n"
15198                                                           "void main()\n"
15199                                                           "{\n"
15200                                                           "    gs_fs = tes_gs[0];\n"
15201                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15202                                                           "    EmitVertex();\n"
15203                                                           "    gs_fs = tes_gs[0];\n"
15204                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15205                                                           "    EmitVertex();\n"
15206                                                           "    gs_fs = tes_gs[0];\n"
15207                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15208                                                           "    EmitVertex();\n"
15209                                                           "    gs_fs = tes_gs[0];\n"
15210                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15211                                                           "    EmitVertex();\n"
15212                                                           "}\n"
15213                                                           "\n";
15214         static const GLchar* gs_tested = "#version 430 core\n"
15215                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15216                                                                          "\n"
15217                                                                          "layout(points)                           in;\n"
15218                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15219                                                                          "\n"
15220                                                                          "VAR_DEFINITION"
15221                                                                          "\n"
15222                                                                          "in  vec4 tes_gs[];\n"
15223                                                                          "out vec4 gs_fs;\n"
15224                                                                          "\n"
15225                                                                          "void main()\n"
15226                                                                          "{\n"
15227                                                                          "    vec4 result = tes_gs[0];\n"
15228                                                                          "\n"
15229                                                                          "VARIABLE_USE"
15230                                                                          "\n"
15231                                                                          "    gs_fs = result;\n"
15232                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15233                                                                          "    EmitVertex();\n"
15234                                                                          "    gs_fs = result;\n"
15235                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15236                                                                          "    EmitVertex();\n"
15237                                                                          "    gs_fs = result;\n"
15238                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15239                                                                          "    EmitVertex();\n"
15240                                                                          "    gs_fs = result;\n"
15241                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15242                                                                          "    EmitVertex();\n"
15243                                                                          "}\n"
15244                                                                          "\n";
15245         static const GLchar* tcs = "#version 430 core\n"
15246                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15247                                                            "\n"
15248                                                            "layout(vertices = 1) out;\n"
15249                                                            "\n"
15250                                                            "in  vec4 vs_tcs[];\n"
15251                                                            "out vec4 tcs_tes[];\n"
15252                                                            "\n"
15253                                                            "void main()\n"
15254                                                            "{\n"
15255                                                            "\n"
15256                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15257                                                            "\n"
15258                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15259                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15260                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15261                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15262                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15263                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15264                                                            "}\n"
15265                                                            "\n";
15266         static const GLchar* tcs_tested = "#version 430 core\n"
15267                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15268                                                                           "\n"
15269                                                                           "layout(vertices = 1) out;\n"
15270                                                                           "\n"
15271                                                                           "VAR_DEFINITION"
15272                                                                           "\n"
15273                                                                           "in  vec4 vs_tcs[];\n"
15274                                                                           "out vec4 tcs_tes[];\n"
15275                                                                           "\n"
15276                                                                           "void main()\n"
15277                                                                           "{\n"
15278                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15279                                                                           "\n"
15280                                                                           "VARIABLE_USE"
15281                                                                           "\n"
15282                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15283                                                                           "\n"
15284                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15285                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15286                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15287                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15288                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15289                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15290                                                                           "}\n"
15291                                                                           "\n";
15292         static const GLchar* tes = "#version 430 core\n"
15293                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15294                                                            "\n"
15295                                                            "layout(isolines, point_mode) in;\n"
15296                                                            "\n"
15297                                                            "in  vec4 tcs_tes[];\n"
15298                                                            "out vec4 tes_gs;\n"
15299                                                            "\n"
15300                                                            "void main()\n"
15301                                                            "{\n"
15302                                                            "    tes_gs = tcs_tes[0];\n"
15303                                                            "}\n"
15304                                                            "\n";
15305         static const GLchar* tes_tested = "#version 430 core\n"
15306                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15307                                                                           "\n"
15308                                                                           "layout(isolines, point_mode) in;\n"
15309                                                                           "\n"
15310                                                                           "VAR_DEFINITION"
15311                                                                           "\n"
15312                                                                           "in  vec4 tcs_tes[];\n"
15313                                                                           "out vec4 tes_gs;\n"
15314                                                                           "\n"
15315                                                                           "void main()\n"
15316                                                                           "{\n"
15317                                                                           "    vec4 result = tcs_tes[0];\n"
15318                                                                           "\n"
15319                                                                           "VARIABLE_USE"
15320                                                                           "\n"
15321                                                                           "    tes_gs += result;\n"
15322                                                                           "}\n"
15323                                                                           "\n";
15324         static const GLchar* vs = "#version 430 core\n"
15325                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15326                                                           "\n"
15327                                                           "in  vec4 in_vs;\n"
15328                                                           "out vec4 vs_tcs;\n"
15329                                                           "\n"
15330                                                           "void main()\n"
15331                                                           "{\n"
15332                                                           "    vs_tcs = in_vs;\n"
15333                                                           "}\n"
15334                                                           "\n";
15335         static const GLchar* vs_tested = "#version 430 core\n"
15336                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15337                                                                          "\n"
15338                                                                          "VAR_DEFINITION"
15339                                                                          "\n"
15340                                                                          "in  vec4 in_vs;\n"
15341                                                                          "out vec4 vs_tcs;\n"
15342                                                                          "\n"
15343                                                                          "void main()\n"
15344                                                                          "{\n"
15345                                                                          "    vec4 result = in_vs;\n"
15346                                                                          "\n"
15347                                                                          "VARIABLE_USE"
15348                                                                          "\n"
15349                                                                          "    vs_tcs += result;\n"
15350                                                                          "}\n"
15351                                                                          "\n";
15352
15353         std::string source;
15354         testCase&   test_case = m_test_cases[test_case_index];
15355
15356         if (test_case.m_stage == stage)
15357         {
15358                 const GLchar* array = "";
15359                 GLchar            buffer[16];
15360                 const GLchar* var_definition = 0;
15361                 const GLchar* direction          = "in ";
15362                 const GLchar* index                      = "";
15363                 size_t            position               = 0;
15364                 size_t            temp;
15365                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15366                 const GLchar* var_use   = 0;
15367
15368                 if (false == test_case.m_is_input)
15369                 {
15370                         direction = "out";
15371
15372                         if (false == test_case.m_is_array)
15373                         {
15374                                 var_definition = var_definition_one;
15375                                 var_use            = output_use_one;
15376                         }
15377                         else
15378                         {
15379                                 var_definition = var_definition_arr;
15380                                 var_use            = output_use_arr;
15381                         }
15382                 }
15383                 else
15384                 {
15385                         if (false == test_case.m_is_array)
15386                         {
15387                                 var_definition = var_definition_one;
15388                                 var_use            = input_use_one;
15389                         }
15390                         else
15391                         {
15392                                 var_definition = var_definition_arr;
15393                                 var_use            = input_use_arr;
15394                         }
15395                 }
15396
15397                 sprintf(buffer, "%d", test_case.m_component);
15398
15399                 switch (stage)
15400                 {
15401                 case Utils::Shader::FRAGMENT:
15402                         source = fs_tested;
15403                         break;
15404                 case Utils::Shader::GEOMETRY:
15405                         source = gs_tested;
15406                         array  = "[]";
15407                         index  = "[0]";
15408                         break;
15409                 case Utils::Shader::TESS_CTRL:
15410                         source = tcs_tested;
15411                         array  = "[]";
15412                         index  = "[gl_InvocationID]";
15413                         break;
15414                 case Utils::Shader::TESS_EVAL:
15415                         source = tes_tested;
15416                         array  = "[]";
15417                         index  = "[0]";
15418                         break;
15419                 case Utils::Shader::VERTEX:
15420                         source = vs_tested;
15421                         break;
15422                 default:
15423                         TCU_FAIL("Invalid enum");
15424                 }
15425
15426                 temp = position;
15427                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15428                 position = temp;
15429                 Utils::replaceToken("COMPONENT", position, buffer, source);
15430                 Utils::replaceToken("DIRECTION", position, direction, source);
15431                 Utils::replaceToken("ARRAY", position, array, source);
15432                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15433
15434                 Utils::replaceAllTokens("TYPE", type_name, source);
15435                 Utils::replaceAllTokens("INDEX", index, source);
15436         }
15437         else
15438         {
15439                 switch (stage)
15440                 {
15441                 case Utils::Shader::FRAGMENT:
15442                         source = fs;
15443                         break;
15444                 case Utils::Shader::GEOMETRY:
15445                         source = gs;
15446                         break;
15447                 case Utils::Shader::TESS_CTRL:
15448                         source = tcs;
15449                         break;
15450                 case Utils::Shader::TESS_EVAL:
15451                         source = tes;
15452                         break;
15453                 case Utils::Shader::VERTEX:
15454                         source = vs;
15455                         break;
15456                 default:
15457                         TCU_FAIL("Invalid enum");
15458                 }
15459         }
15460
15461         return source;
15462 }
15463
15464 /** Get description of test case
15465  *
15466  * @param test_case_index Index of test case
15467  *
15468  * @return Test case description
15469  **/
15470 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15471 {
15472         std::stringstream stream;
15473         testCase&                 test_case = m_test_cases[test_case_index];
15474
15475         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15476                    << " type: " << test_case.m_type.GetGLSLTypeName();
15477
15478         if (true == test_case.m_is_array)
15479         {
15480                 stream << "[1]";
15481         }
15482
15483         stream << ", direction: ";
15484
15485         if (true == test_case.m_is_input)
15486         {
15487                 stream << "input";
15488         }
15489         else
15490         {
15491                 stream << "output";
15492         }
15493
15494         stream << ", component: " << test_case.m_component;
15495
15496         return stream.str();
15497 }
15498
15499 /** Get number of test cases
15500  *
15501  * @return Number of test cases
15502  **/
15503 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15504 {
15505         return static_cast<GLuint>(m_test_cases.size());
15506 }
15507
15508 /** Selects if "compute" stage is relevant for test
15509  *
15510  * @param ignored
15511  *
15512  * @return false
15513  **/
15514 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15515 {
15516         return false;
15517 }
15518
15519 /** Prepare all test cases
15520  *
15521  **/
15522 void VaryingExceedingComponentsTest::testInit()
15523 {
15524         static const GLuint n_components_per_location = 4;
15525         const GLuint            n_types                                   = getTypesNumber();
15526
15527         for (GLuint i = 0; i < n_types; ++i)
15528         {
15529                 const Utils::Type& type                          = getType(i);
15530                 const GLuint       n_req_components  = type.m_n_rows;
15531                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15532                 const GLuint       invalid_component = valid_component + 1;
15533
15534                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15535                 {
15536                         if (Utils::Shader::COMPUTE == stage)
15537                         {
15538                                 continue;
15539                         }
15540
15541                         /* Component cannot be used for matrices */
15542                         if (1 != type.m_n_columns)
15543                         {
15544                                 continue;
15545                         }
15546
15547                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15548                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15549                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15550                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15551
15552                         m_test_cases.push_back(test_case_in_arr);
15553                         m_test_cases.push_back(test_case_in_one);
15554
15555                         if (Utils::Shader::FRAGMENT != stage)
15556                         {
15557                                 m_test_cases.push_back(test_case_out_arr);
15558                                 m_test_cases.push_back(test_case_out_one);
15559                         }
15560                 }
15561         }
15562 }
15563
15564 /** Constructor
15565  *
15566  * @param context Test framework context
15567  **/
15568 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15569         : NegativeTestBase(context, "varying_component_without_location",
15570                                            "Test verifies that compiler reports error when component qualifier is used without location")
15571 {
15572 }
15573
15574 /** Source for given test case and stage
15575  *
15576  * @param test_case_index Index of test case
15577  * @param stage           Shader stage
15578  *
15579  * @return Shader source
15580  **/
15581 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15582 {
15583         static const GLchar* var_definition = "layout (component = COMPONENT) FLAT DIRECTION TYPE gokuARRAY;\n";
15584         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15585                                                                          "    {\n"
15586                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15587                                                                          "    }\n";
15588         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15589                                                                           "    if (vec4(0) == result)\n"
15590                                                                           "    {\n"
15591                                                                           "        gokuINDEX = TYPE(1);\n"
15592                                                                           "    }\n";
15593         static const GLchar* fs = "#version 430 core\n"
15594                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15595                                                           "\n"
15596                                                           "in  vec4 gs_fs;\n"
15597                                                           "out vec4 fs_out;\n"
15598                                                           "\n"
15599                                                           "void main()\n"
15600                                                           "{\n"
15601                                                           "    fs_out = gs_fs;\n"
15602                                                           "}\n"
15603                                                           "\n";
15604         static const GLchar* fs_tested = "#version 430 core\n"
15605                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15606                                                                          "\n"
15607                                                                          "VAR_DEFINITION"
15608                                                                          "\n"
15609                                                                          "in  vec4 gs_fs;\n"
15610                                                                          "out vec4 fs_out;\n"
15611                                                                          "\n"
15612                                                                          "void main()\n"
15613                                                                          "{\n"
15614                                                                          "    vec4 result = gs_fs;\n"
15615                                                                          "\n"
15616                                                                          "VARIABLE_USE"
15617                                                                          "\n"
15618                                                                          "    fs_out = result;\n"
15619                                                                          "}\n"
15620                                                                          "\n";
15621         static const GLchar* gs = "#version 430 core\n"
15622                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15623                                                           "\n"
15624                                                           "layout(points)                           in;\n"
15625                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15626                                                           "\n"
15627                                                           "in  vec4 tes_gs[];\n"
15628                                                           "out vec4 gs_fs;\n"
15629                                                           "\n"
15630                                                           "void main()\n"
15631                                                           "{\n"
15632                                                           "    gs_fs = tes_gs[0];\n"
15633                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15634                                                           "    EmitVertex();\n"
15635                                                           "    gs_fs = tes_gs[0];\n"
15636                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15637                                                           "    EmitVertex();\n"
15638                                                           "    gs_fs = tes_gs[0];\n"
15639                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15640                                                           "    EmitVertex();\n"
15641                                                           "    gs_fs = tes_gs[0];\n"
15642                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15643                                                           "    EmitVertex();\n"
15644                                                           "}\n"
15645                                                           "\n";
15646         static const GLchar* gs_tested = "#version 430 core\n"
15647                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15648                                                                          "\n"
15649                                                                          "layout(points)                           in;\n"
15650                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15651                                                                          "\n"
15652                                                                          "VAR_DEFINITION"
15653                                                                          "\n"
15654                                                                          "in  vec4 tes_gs[];\n"
15655                                                                          "out vec4 gs_fs;\n"
15656                                                                          "\n"
15657                                                                          "void main()\n"
15658                                                                          "{\n"
15659                                                                          "    vec4 result = tes_gs[0];\n"
15660                                                                          "\n"
15661                                                                          "VARIABLE_USE"
15662                                                                          "\n"
15663                                                                          "    gs_fs = result;\n"
15664                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15665                                                                          "    EmitVertex();\n"
15666                                                                          "    gs_fs = result;\n"
15667                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15668                                                                          "    EmitVertex();\n"
15669                                                                          "    gs_fs = result;\n"
15670                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15671                                                                          "    EmitVertex();\n"
15672                                                                          "    gs_fs = result;\n"
15673                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15674                                                                          "    EmitVertex();\n"
15675                                                                          "}\n"
15676                                                                          "\n";
15677         static const GLchar* tcs = "#version 430 core\n"
15678                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15679                                                            "\n"
15680                                                            "layout(vertices = 1) out;\n"
15681                                                            "\n"
15682                                                            "in  vec4 vs_tcs[];\n"
15683                                                            "out vec4 tcs_tes[];\n"
15684                                                            "\n"
15685                                                            "void main()\n"
15686                                                            "{\n"
15687                                                            "\n"
15688                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15689                                                            "\n"
15690                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15691                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15692                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15693                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15694                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15695                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15696                                                            "}\n"
15697                                                            "\n";
15698         static const GLchar* tcs_tested = "#version 430 core\n"
15699                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15700                                                                           "\n"
15701                                                                           "layout(vertices = 1) out;\n"
15702                                                                           "\n"
15703                                                                           "VAR_DEFINITION"
15704                                                                           "\n"
15705                                                                           "in  vec4 vs_tcs[];\n"
15706                                                                           "out vec4 tcs_tes[];\n"
15707                                                                           "\n"
15708                                                                           "void main()\n"
15709                                                                           "{\n"
15710                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15711                                                                           "\n"
15712                                                                           "VARIABLE_USE"
15713                                                                           "\n"
15714                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15715                                                                           "\n"
15716                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15717                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15718                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15719                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15720                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15721                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15722                                                                           "}\n"
15723                                                                           "\n";
15724         static const GLchar* tes = "#version 430 core\n"
15725                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15726                                                            "\n"
15727                                                            "layout(isolines, point_mode) in;\n"
15728                                                            "\n"
15729                                                            "in  vec4 tcs_tes[];\n"
15730                                                            "out vec4 tes_gs;\n"
15731                                                            "\n"
15732                                                            "void main()\n"
15733                                                            "{\n"
15734                                                            "    tes_gs = tcs_tes[0];\n"
15735                                                            "}\n"
15736                                                            "\n";
15737         static const GLchar* tes_tested = "#version 430 core\n"
15738                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15739                                                                           "\n"
15740                                                                           "layout(isolines, point_mode) in;\n"
15741                                                                           "\n"
15742                                                                           "VAR_DEFINITION"
15743                                                                           "\n"
15744                                                                           "in  vec4 tcs_tes[];\n"
15745                                                                           "out vec4 tes_gs;\n"
15746                                                                           "\n"
15747                                                                           "void main()\n"
15748                                                                           "{\n"
15749                                                                           "    vec4 result = tcs_tes[0];\n"
15750                                                                           "\n"
15751                                                                           "VARIABLE_USE"
15752                                                                           "\n"
15753                                                                           "    tes_gs = result;\n"
15754                                                                           "}\n"
15755                                                                           "\n";
15756         static const GLchar* vs = "#version 430 core\n"
15757                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15758                                                           "\n"
15759                                                           "in  vec4 in_vs;\n"
15760                                                           "out vec4 vs_tcs;\n"
15761                                                           "\n"
15762                                                           "void main()\n"
15763                                                           "{\n"
15764                                                           "    vs_tcs = in_vs;\n"
15765                                                           "}\n"
15766                                                           "\n";
15767         static const GLchar* vs_tested = "#version 430 core\n"
15768                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15769                                                                          "\n"
15770                                                                          "VAR_DEFINITION"
15771                                                                          "\n"
15772                                                                          "in  vec4 in_vs;\n"
15773                                                                          "out vec4 vs_tcs;\n"
15774                                                                          "\n"
15775                                                                          "void main()\n"
15776                                                                          "{\n"
15777                                                                          "    vec4 result = in_vs;\n"
15778                                                                          "\n"
15779                                                                          "VARIABLE_USE"
15780                                                                          "\n"
15781                                                                          "    vs_tcs = result;\n"
15782                                                                          "}\n"
15783                                                                          "\n";
15784
15785         std::string source;
15786         testCase&   test_case = m_test_cases[test_case_index];
15787
15788         if (test_case.m_stage == stage)
15789         {
15790                 const GLchar* array = "";
15791                 GLchar            buffer[16];
15792                 const GLchar* direction = "in ";
15793                 const GLchar* index             = "";
15794                 size_t            position  = 0;
15795                 size_t            temp;
15796                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15797                 const GLchar* var_use   = input_use;
15798                 const GLchar* flat              = "flat";
15799
15800                 if (false == test_case.m_is_input)
15801                 {
15802                         direction = "out";
15803                         var_use   = output_use;
15804                 }
15805
15806                 sprintf(buffer, "%d", test_case.m_component);
15807
15808                 switch (stage)
15809                 {
15810                 case Utils::Shader::FRAGMENT:
15811                         source = fs_tested;
15812                         break;
15813                 case Utils::Shader::GEOMETRY:
15814                         source = gs_tested;
15815                         array  = "[]";
15816                         index  = "[0]";
15817                         break;
15818                 case Utils::Shader::TESS_CTRL:
15819                         source = tcs_tested;
15820                         array  = "[]";
15821                         index  = "[gl_InvocationID]";
15822                         break;
15823                 case Utils::Shader::TESS_EVAL:
15824                         source = tes_tested;
15825                         array  = "[]";
15826                         index  = "[0]";
15827                         break;
15828                 case Utils::Shader::VERTEX:
15829                         source = vs_tested;
15830                         flat   = "";
15831                         break;
15832                 default:
15833                         TCU_FAIL("Invalid enum");
15834                 }
15835
15836                 temp = position;
15837                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15838                 position = temp;
15839                 Utils::replaceToken("COMPONENT", position, buffer, source);
15840                 Utils::replaceToken("FLAT", position, flat, source);
15841                 Utils::replaceToken("DIRECTION", position, direction, source);
15842                 Utils::replaceToken("ARRAY", position, array, source);
15843                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15844
15845                 Utils::replaceAllTokens("TYPE", type_name, source);
15846                 Utils::replaceAllTokens("INDEX", index, source);
15847         }
15848         else
15849         {
15850                 switch (stage)
15851                 {
15852                 case Utils::Shader::FRAGMENT:
15853                         source = fs;
15854                         break;
15855                 case Utils::Shader::GEOMETRY:
15856                         source = gs;
15857                         break;
15858                 case Utils::Shader::TESS_CTRL:
15859                         source = tcs;
15860                         break;
15861                 case Utils::Shader::TESS_EVAL:
15862                         source = tes;
15863                         break;
15864                 case Utils::Shader::VERTEX:
15865                         source = vs;
15866                         break;
15867                 default:
15868                         TCU_FAIL("Invalid enum");
15869                 }
15870         }
15871
15872         return source;
15873 }
15874
15875 /** Get description of test case
15876  *
15877  * @param test_case_index Index of test case
15878  *
15879  * @return Test case description
15880  **/
15881 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15882 {
15883         std::stringstream stream;
15884         testCase&                 test_case = m_test_cases[test_case_index];
15885
15886         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15887                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15888
15889         if (true == test_case.m_is_input)
15890         {
15891                 stream << "input";
15892         }
15893         else
15894         {
15895                 stream << "output";
15896         }
15897
15898         stream << ", component: " << test_case.m_component;
15899
15900         return stream.str();
15901 }
15902
15903 /** Get number of test cases
15904  *
15905  * @return Number of test cases
15906  **/
15907 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
15908 {
15909         return static_cast<GLuint>(m_test_cases.size());
15910 }
15911
15912 /** Selects if "compute" stage is relevant for test
15913  *
15914  * @param ignored
15915  *
15916  * @return false
15917  **/
15918 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
15919 {
15920         return false;
15921 }
15922
15923 /** Prepare all test cases
15924  *
15925  **/
15926 void VaryingComponentWithoutLocationTest::testInit()
15927 {
15928         static const GLuint n_components_per_location = 4;
15929         const GLuint            n_types                                   = getTypesNumber();
15930
15931         for (GLuint i = 0; i < n_types; ++i)
15932         {
15933                 const Utils::Type& type                         = getType(i);
15934                 const GLuint       n_req_components = type.m_n_rows;
15935                 const GLuint       valid_component  = n_components_per_location - n_req_components;
15936
15937                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15938                 {
15939                         if (Utils::Shader::COMPUTE == stage)
15940                         {
15941                                 continue;
15942                         }
15943
15944                         /* Component cannot be used for matrices */
15945                         if (1 != type.m_n_columns)
15946                         {
15947                                 continue;
15948                         }
15949
15950                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
15951                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
15952
15953                         m_test_cases.push_back(test_case_in);
15954
15955                         if (Utils::Shader::FRAGMENT != stage)
15956                         {
15957                                 m_test_cases.push_back(test_case_out);
15958                         }
15959                 }
15960         }
15961 }
15962
15963 /** Constructor
15964  *
15965  * @param context Test framework context
15966  **/
15967 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
15968         : NegativeTestBase(context, "varying_component_of_invalid_type",
15969                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
15970 {
15971 }
15972
15973 /** Source for given test case and stage
15974  *
15975  * @param test_case_index Index of test case
15976  * @param stage           Shader stage
15977  *
15978  * @return Shader source
15979  **/
15980 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15981 {
15982         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15983                                                                                                 "    TYPE member;\n"
15984                                                                                                 "} gokuARRAY[1];\n";
15985         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15986                                                                                                 "    TYPE member;\n"
15987                                                                                                 "} gokuARRAY;\n";
15988         static const GLchar* matrix_definition_arr =
15989                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15990         static const GLchar* matrix_definition_one =
15991                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15992         static const GLchar* struct_definition_arr =
15993                 "struct Goku {\n"
15994                 "    TYPE member;\n"
15995                 "};\n"
15996                 "\n"
15997                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
15998         static const GLchar* struct_definition_one =
15999                 "struct Goku {\n"
16000                 "    TYPE member;\n"
16001                 "};\n"
16002                 "\n"
16003                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
16004         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
16005                                                                                                 "    {\n"
16006                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16007                                                                                                 "    }\n";
16008         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
16009                                                                                                 "    {\n"
16010                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16011                                                                                                 "    }\n";
16012         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
16013                                                                                                  "    if (vec4(0) == result)\n"
16014                                                                                                  "    {\n"
16015                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
16016                                                                                                  "    }\n";
16017         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
16018                                                                                                  "    if (vec4(0) == result)\n"
16019                                                                                                  "    {\n"
16020                                                                                                  "        gokuINDEX = TYPE(1);\n"
16021                                                                                                  "    }\n";
16022         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16023                                                                                                 "    {\n"
16024                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16025                                                                                                 "    }\n";
16026         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16027                                                                                                 "    {\n"
16028                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16029                                                                                                 "    }\n";
16030         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16031                                                                                                  "    if (vec4(0) == result)\n"
16032                                                                                                  "    {\n"
16033                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16034                                                                                                  "    }\n";
16035         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16036                                                                                                  "    if (vec4(0) == result)\n"
16037                                                                                                  "    {\n"
16038                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16039                                                                                                  "    }\n";
16040         static const GLchar* fs = "#version 430 core\n"
16041                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16042                                                           "\n"
16043                                                           "in  vec4 gs_fs;\n"
16044                                                           "out vec4 fs_out;\n"
16045                                                           "\n"
16046                                                           "void main()\n"
16047                                                           "{\n"
16048                                                           "    fs_out = gs_fs;\n"
16049                                                           "}\n"
16050                                                           "\n";
16051         static const GLchar* fs_tested = "#version 430 core\n"
16052                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16053                                                                          "\n"
16054                                                                          "VAR_DEFINITION"
16055                                                                          "\n"
16056                                                                          "in  vec4 gs_fs;\n"
16057                                                                          "out vec4 fs_out;\n"
16058                                                                          "\n"
16059                                                                          "void main()\n"
16060                                                                          "{\n"
16061                                                                          "    vec4 result = gs_fs;\n"
16062                                                                          "\n"
16063                                                                          "VARIABLE_USE"
16064                                                                          "\n"
16065                                                                          "    fs_out += result;\n"
16066                                                                          "}\n"
16067                                                                          "\n";
16068         static const GLchar* gs = "#version 430 core\n"
16069                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16070                                                           "\n"
16071                                                           "layout(points)                           in;\n"
16072                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16073                                                           "\n"
16074                                                           "in  vec4 tes_gs[];\n"
16075                                                           "out vec4 gs_fs;\n"
16076                                                           "\n"
16077                                                           "void main()\n"
16078                                                           "{\n"
16079                                                           "    gs_fs = tes_gs[0];\n"
16080                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16081                                                           "    EmitVertex();\n"
16082                                                           "    gs_fs = tes_gs[0];\n"
16083                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16084                                                           "    EmitVertex();\n"
16085                                                           "    gs_fs = tes_gs[0];\n"
16086                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16087                                                           "    EmitVertex();\n"
16088                                                           "    gs_fs = tes_gs[0];\n"
16089                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16090                                                           "    EmitVertex();\n"
16091                                                           "}\n"
16092                                                           "\n";
16093         static const GLchar* gs_tested = "#version 430 core\n"
16094                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16095                                                                          "\n"
16096                                                                          "layout(points)                           in;\n"
16097                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16098                                                                          "\n"
16099                                                                          "VAR_DEFINITION"
16100                                                                          "\n"
16101                                                                          "in  vec4 tes_gs[];\n"
16102                                                                          "out vec4 gs_fs;\n"
16103                                                                          "\n"
16104                                                                          "void main()\n"
16105                                                                          "{\n"
16106                                                                          "    vec4 result = tes_gs[0];\n"
16107                                                                          "\n"
16108                                                                          "VARIABLE_USE"
16109                                                                          "\n"
16110                                                                          "    gs_fs = result;\n"
16111                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16112                                                                          "    EmitVertex();\n"
16113                                                                          "    gs_fs = result;\n"
16114                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16115                                                                          "    EmitVertex();\n"
16116                                                                          "    gs_fs = result;\n"
16117                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16118                                                                          "    EmitVertex();\n"
16119                                                                          "    gs_fs = result;\n"
16120                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16121                                                                          "    EmitVertex();\n"
16122                                                                          "}\n"
16123                                                                          "\n";
16124         static const GLchar* tcs = "#version 430 core\n"
16125                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16126                                                            "\n"
16127                                                            "layout(vertices = 1) out;\n"
16128                                                            "\n"
16129                                                            "in  vec4 vs_tcs[];\n"
16130                                                            "out vec4 tcs_tes[];\n"
16131                                                            "\n"
16132                                                            "void main()\n"
16133                                                            "{\n"
16134                                                            "\n"
16135                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16136                                                            "\n"
16137                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16138                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16139                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16140                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16141                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16142                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16143                                                            "}\n"
16144                                                            "\n";
16145         static const GLchar* tcs_tested = "#version 430 core\n"
16146                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16147                                                                           "\n"
16148                                                                           "layout(vertices = 1) out;\n"
16149                                                                           "\n"
16150                                                                           "VAR_DEFINITION"
16151                                                                           "\n"
16152                                                                           "in  vec4 vs_tcs[];\n"
16153                                                                           "out vec4 tcs_tes[];\n"
16154                                                                           "\n"
16155                                                                           "void main()\n"
16156                                                                           "{\n"
16157                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16158                                                                           "\n"
16159                                                                           "VARIABLE_USE"
16160                                                                           "\n"
16161                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16162                                                                           "\n"
16163                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16164                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16165                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16166                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16167                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16168                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16169                                                                           "}\n"
16170                                                                           "\n";
16171         static const GLchar* tes = "#version 430 core\n"
16172                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16173                                                            "\n"
16174                                                            "layout(isolines, point_mode) in;\n"
16175                                                            "\n"
16176                                                            "in  vec4 tcs_tes[];\n"
16177                                                            "out vec4 tes_gs;\n"
16178                                                            "\n"
16179                                                            "void main()\n"
16180                                                            "{\n"
16181                                                            "    tes_gs = tcs_tes[0];\n"
16182                                                            "}\n"
16183                                                            "\n";
16184         static const GLchar* tes_tested = "#version 430 core\n"
16185                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16186                                                                           "\n"
16187                                                                           "layout(isolines, point_mode) in;\n"
16188                                                                           "\n"
16189                                                                           "VAR_DEFINITION"
16190                                                                           "\n"
16191                                                                           "in  vec4 tcs_tes[];\n"
16192                                                                           "out vec4 tes_gs;\n"
16193                                                                           "\n"
16194                                                                           "void main()\n"
16195                                                                           "{\n"
16196                                                                           "    vec4 result = tcs_tes[0];\n"
16197                                                                           "\n"
16198                                                                           "VARIABLE_USE"
16199                                                                           "\n"
16200                                                                           "    tes_gs += result;\n"
16201                                                                           "}\n"
16202                                                                           "\n";
16203         static const GLchar* vs = "#version 430 core\n"
16204                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16205                                                           "\n"
16206                                                           "in  vec4 in_vs;\n"
16207                                                           "out vec4 vs_tcs;\n"
16208                                                           "\n"
16209                                                           "void main()\n"
16210                                                           "{\n"
16211                                                           "    vs_tcs = in_vs;\n"
16212                                                           "}\n"
16213                                                           "\n";
16214         static const GLchar* vs_tested = "#version 430 core\n"
16215                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16216                                                                          "\n"
16217                                                                          "VAR_DEFINITION"
16218                                                                          "\n"
16219                                                                          "in  vec4 in_vs;\n"
16220                                                                          "out vec4 vs_tcs;\n"
16221                                                                          "\n"
16222                                                                          "void main()\n"
16223                                                                          "{\n"
16224                                                                          "    vec4 result = in_vs;\n"
16225                                                                          "\n"
16226                                                                          "VARIABLE_USE"
16227                                                                          "\n"
16228                                                                          "    vs_tcs += result;\n"
16229                                                                          "}\n"
16230                                                                          "\n";
16231
16232         std::string source;
16233         testCase&   test_case = m_test_cases[test_case_index];
16234
16235         if (test_case.m_stage == stage)
16236         {
16237                 const GLchar* array = "";
16238                 GLchar            buffer[16];
16239                 const GLchar* var_definition = 0;
16240                 const GLchar* direction          = "in ";
16241                 const GLchar* index                      = "";
16242                 size_t            position               = 0;
16243                 size_t            temp;
16244                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16245                 const GLchar* var_use   = 0;
16246
16247                 if (false == test_case.m_is_input)
16248                 {
16249                         direction = "out";
16250
16251                         if (false == test_case.m_is_array)
16252                         {
16253                                 switch (test_case.m_case)
16254                                 {
16255                                 case BLOCK:
16256                                         var_definition = block_definition_one;
16257                                         var_use            = member_output_use_one;
16258                                         break;
16259                                 case MATRIX:
16260                                         var_definition = matrix_definition_one;
16261                                         var_use            = matrix_output_use_one;
16262                                         break;
16263                                 case STRUCT:
16264                                         var_definition = struct_definition_one;
16265                                         var_use            = member_output_use_one;
16266                                         break;
16267                                 default:
16268                                         TCU_FAIL("Invalid enum");
16269                                 }
16270                         }
16271                         else
16272                         {
16273                                 switch (test_case.m_case)
16274                                 {
16275                                 case BLOCK:
16276                                         var_definition = block_definition_arr;
16277                                         var_use            = member_output_use_arr;
16278                                         break;
16279                                 case MATRIX:
16280                                         var_definition = matrix_definition_arr;
16281                                         var_use            = matrix_output_use_arr;
16282                                         break;
16283                                 case STRUCT:
16284                                         var_definition = struct_definition_arr;
16285                                         var_use            = member_output_use_arr;
16286                                         break;
16287                                 default:
16288                                         TCU_FAIL("Invalid enum");
16289                                 }
16290                         }
16291                 }
16292                 else
16293                 {
16294                         if (false == test_case.m_is_array)
16295                         {
16296                                 switch (test_case.m_case)
16297                                 {
16298                                 case BLOCK:
16299                                         var_definition = block_definition_one;
16300                                         var_use            = member_input_use_one;
16301                                         break;
16302                                 case MATRIX:
16303                                         var_definition = matrix_definition_one;
16304                                         var_use            = matrix_input_use_one;
16305                                         break;
16306                                 case STRUCT:
16307                                         var_definition = struct_definition_one;
16308                                         var_use            = member_input_use_one;
16309                                         break;
16310                                 default:
16311                                         TCU_FAIL("Invalid enum");
16312                                 }
16313                         }
16314                         else
16315                         {
16316                                 switch (test_case.m_case)
16317                                 {
16318                                 case BLOCK:
16319                                         var_definition = block_definition_arr;
16320                                         var_use            = member_input_use_arr;
16321                                         break;
16322                                 case MATRIX:
16323                                         var_definition = matrix_definition_arr;
16324                                         var_use            = matrix_input_use_arr;
16325                                         break;
16326                                 case STRUCT:
16327                                         var_definition = struct_definition_arr;
16328                                         var_use            = member_input_use_arr;
16329                                         break;
16330                                 default:
16331                                         TCU_FAIL("Invalid enum");
16332                                 }
16333                         }
16334                 }
16335
16336                 sprintf(buffer, "%d", test_case.m_component);
16337
16338                 switch (stage)
16339                 {
16340                 case Utils::Shader::FRAGMENT:
16341                         source = fs_tested;
16342                         break;
16343                 case Utils::Shader::GEOMETRY:
16344                         source = gs_tested;
16345                         array  = "[]";
16346                         index  = "[0]";
16347                         break;
16348                 case Utils::Shader::TESS_CTRL:
16349                         source = tcs_tested;
16350                         array  = "[]";
16351                         index  = "[gl_InvocationID]";
16352                         break;
16353                 case Utils::Shader::TESS_EVAL:
16354                         source = tes_tested;
16355                         array  = "[]";
16356                         index  = "[0]";
16357                         break;
16358                 case Utils::Shader::VERTEX:
16359                         source = vs_tested;
16360                         break;
16361                 default:
16362                         TCU_FAIL("Invalid enum");
16363                 }
16364
16365                 temp = position;
16366                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16367                 position = temp;
16368                 Utils::replaceToken("COMPONENT", position, buffer, source);
16369                 Utils::replaceToken("DIRECTION", position, direction, source);
16370                 Utils::replaceToken("ARRAY", position, array, source);
16371                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16372
16373                 Utils::replaceAllTokens("TYPE", type_name, source);
16374                 Utils::replaceAllTokens("INDEX", index, source);
16375         }
16376         else
16377         {
16378                 switch (stage)
16379                 {
16380                 case Utils::Shader::FRAGMENT:
16381                         source = fs;
16382                         break;
16383                 case Utils::Shader::GEOMETRY:
16384                         source = gs;
16385                         break;
16386                 case Utils::Shader::TESS_CTRL:
16387                         source = tcs;
16388                         break;
16389                 case Utils::Shader::TESS_EVAL:
16390                         source = tes;
16391                         break;
16392                 case Utils::Shader::VERTEX:
16393                         source = vs;
16394                         break;
16395                 default:
16396                         TCU_FAIL("Invalid enum");
16397                 }
16398         }
16399
16400         return source;
16401 }
16402
16403 /** Get description of test case
16404  *
16405  * @param test_case_index Index of test case
16406  *
16407  * @return Test case description
16408  **/
16409 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16410 {
16411         std::stringstream stream;
16412         testCase&                 test_case = m_test_cases[test_case_index];
16413
16414         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16415                    << " type: " << test_case.m_type.GetGLSLTypeName();
16416
16417         if (true == test_case.m_is_array)
16418         {
16419                 stream << "[1]";
16420         }
16421
16422         stream << ", direction: ";
16423
16424         if (true == test_case.m_is_input)
16425         {
16426                 stream << "input";
16427         }
16428         else
16429         {
16430                 stream << "output";
16431         }
16432
16433         stream << ", component: " << test_case.m_component;
16434
16435         return stream.str();
16436 }
16437
16438 /** Get number of test cases
16439  *
16440  * @return Number of test cases
16441  **/
16442 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16443 {
16444         return static_cast<GLuint>(m_test_cases.size());
16445 }
16446
16447 /** Selects if "compute" stage is relevant for test
16448  *
16449  * @param ignored
16450  *
16451  * @return false
16452  **/
16453 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16454 {
16455         return false;
16456 }
16457
16458 /** Prepare all test cases
16459  *
16460  **/
16461 void VaryingComponentOfInvalidTypeTest::testInit()
16462 {
16463         static const GLuint n_components_per_location = 4;
16464         const GLuint            n_types                                   = getTypesNumber();
16465
16466         for (GLuint i = 0; i < n_types; ++i)
16467         {
16468                 const Utils::Type& type                         = getType(i);
16469                 const GLuint       n_req_components = type.m_n_rows;
16470                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16471
16472                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16473                 {
16474                         if (Utils::Shader::COMPUTE == stage)
16475                         {
16476                                 continue;
16477                         }
16478
16479                         /* Use different CASE for matrices */
16480                         if (1 != type.m_n_columns)
16481                         {
16482                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16483                                 testCase test_case_in_one = {
16484                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16485                                 };
16486                                 testCase test_case_out_arr = {
16487                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16488                                 };
16489                                 testCase test_case_out_one = {
16490                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16491                                 };
16492
16493                                 m_test_cases.push_back(test_case_in_arr);
16494                                 m_test_cases.push_back(test_case_in_one);
16495
16496                                 if (Utils::Shader::FRAGMENT != stage)
16497                                 {
16498                                         m_test_cases.push_back(test_case_out_arr);
16499                                         m_test_cases.push_back(test_case_out_one);
16500                                 }
16501                         }
16502                         else
16503                         {
16504                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16505                                 {
16506                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16507                                                                                                   type };
16508                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16509                                                                                                   type };
16510                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16511                                                                                                    type };
16512                                         testCase test_case_out_one = {
16513                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16514                                         };
16515
16516                                         if (Utils::Shader::VERTEX != stage)
16517                                         {
16518                                                 m_test_cases.push_back(test_case_in_arr);
16519                                                 m_test_cases.push_back(test_case_in_one);
16520                                         }
16521
16522                                         if (Utils::Shader::FRAGMENT != stage)
16523                                         {
16524                                                 m_test_cases.push_back(test_case_out_arr);
16525                                                 m_test_cases.push_back(test_case_out_one);
16526                                         }
16527                                 }
16528                         }
16529                 }
16530         }
16531 }
16532
16533 /** Constructor
16534  *
16535  * @param context Test framework context
16536  **/
16537 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16538         : NegativeTestBase(context, "input_component_aliasing",
16539                                            "Test verifies that compiler reports component aliasing as error")
16540 {
16541 }
16542
16543 /** Source for given test case and stage
16544  *
16545  * @param test_case_index Index of test case
16546  * @param stage           Shader stage
16547  *
16548  * @return Shader source
16549  **/
16550 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16551 {
16552         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16553                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16554         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16555                                                                         "    {\n"
16556                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16557                                                                         "    }\n";
16558         static const GLchar* test_both = "    if (TYPE(0) == gohanINDEX)\n"
16559                                                                          "    {\n"
16560                                                                          "        result = vec4(goten.xxxx);\n"
16561                                                                          "    }\n";
16562         static const GLchar* fs = "#version 430 core\n"
16563                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16564                                                           "\n"
16565                                                           "in  vec4 gs_fs;\n"
16566                                                           "out vec4 fs_out;\n"
16567                                                           "\n"
16568                                                           "void main()\n"
16569                                                           "{\n"
16570                                                           "    fs_out = gs_fs;\n"
16571                                                           "}\n"
16572                                                           "\n";
16573         static const GLchar* fs_tested = "#version 430 core\n"
16574                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16575                                                                          "\n"
16576                                                                          "VAR_DEFINITION"
16577                                                                          "\n"
16578                                                                          "in  vec4 gs_fs;\n"
16579                                                                          "out vec4 fs_out;\n"
16580                                                                          "\n"
16581                                                                          "void main()\n"
16582                                                                          "{\n"
16583                                                                          "    vec4 result = gs_fs;\n"
16584                                                                          "\n"
16585                                                                          "VARIABLE_USE"
16586                                                                          "\n"
16587                                                                          "    fs_out += result;\n"
16588                                                                          "}\n"
16589                                                                          "\n";
16590         static const GLchar* gs = "#version 430 core\n"
16591                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16592                                                           "\n"
16593                                                           "layout(points)                           in;\n"
16594                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16595                                                           "\n"
16596                                                           "in  vec4 tes_gs[];\n"
16597                                                           "out vec4 gs_fs;\n"
16598                                                           "\n"
16599                                                           "void main()\n"
16600                                                           "{\n"
16601                                                           "    gs_fs = tes_gs[0];\n"
16602                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16603                                                           "    EmitVertex();\n"
16604                                                           "    gs_fs = tes_gs[0];\n"
16605                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16606                                                           "    EmitVertex();\n"
16607                                                           "    gs_fs = tes_gs[0];\n"
16608                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16609                                                           "    EmitVertex();\n"
16610                                                           "    gs_fs = tes_gs[0];\n"
16611                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16612                                                           "    EmitVertex();\n"
16613                                                           "}\n"
16614                                                           "\n";
16615         static const GLchar* gs_tested = "#version 430 core\n"
16616                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16617                                                                          "\n"
16618                                                                          "layout(points)                           in;\n"
16619                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16620                                                                          "\n"
16621                                                                          "VAR_DEFINITION"
16622                                                                          "\n"
16623                                                                          "in  vec4 tes_gs[];\n"
16624                                                                          "out vec4 gs_fs;\n"
16625                                                                          "\n"
16626                                                                          "void main()\n"
16627                                                                          "{\n"
16628                                                                          "    vec4 result = tes_gs[0];\n"
16629                                                                          "\n"
16630                                                                          "VARIABLE_USE"
16631                                                                          "\n"
16632                                                                          "    gs_fs = result;\n"
16633                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16634                                                                          "    EmitVertex();\n"
16635                                                                          "    gs_fs = result;\n"
16636                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16637                                                                          "    EmitVertex();\n"
16638                                                                          "    gs_fs = result;\n"
16639                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16640                                                                          "    EmitVertex();\n"
16641                                                                          "    gs_fs = result;\n"
16642                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16643                                                                          "    EmitVertex();\n"
16644                                                                          "}\n"
16645                                                                          "\n";
16646         static const GLchar* tcs = "#version 430 core\n"
16647                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16648                                                            "\n"
16649                                                            "layout(vertices = 1) out;\n"
16650                                                            "\n"
16651                                                            "in  vec4 vs_tcs[];\n"
16652                                                            "out vec4 tcs_tes[];\n"
16653                                                            "\n"
16654                                                            "void main()\n"
16655                                                            "{\n"
16656                                                            "\n"
16657                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16658                                                            "\n"
16659                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16660                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16661                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16662                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16663                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16664                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16665                                                            "}\n"
16666                                                            "\n";
16667         static const GLchar* tcs_tested = "#version 430 core\n"
16668                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16669                                                                           "\n"
16670                                                                           "layout(vertices = 1) out;\n"
16671                                                                           "\n"
16672                                                                           "VAR_DEFINITION"
16673                                                                           "\n"
16674                                                                           "in  vec4 vs_tcs[];\n"
16675                                                                           "out vec4 tcs_tes[];\n"
16676                                                                           "\n"
16677                                                                           "void main()\n"
16678                                                                           "{\n"
16679                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16680                                                                           "\n"
16681                                                                           "VARIABLE_USE"
16682                                                                           "\n"
16683                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16684                                                                           "\n"
16685                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16686                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16687                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16688                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16689                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16690                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16691                                                                           "}\n"
16692                                                                           "\n";
16693         static const GLchar* tes = "#version 430 core\n"
16694                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16695                                                            "\n"
16696                                                            "layout(isolines, point_mode) in;\n"
16697                                                            "\n"
16698                                                            "in  vec4 tcs_tes[];\n"
16699                                                            "out vec4 tes_gs;\n"
16700                                                            "\n"
16701                                                            "void main()\n"
16702                                                            "{\n"
16703                                                            "    tes_gs = tcs_tes[0];\n"
16704                                                            "}\n"
16705                                                            "\n";
16706         static const GLchar* tes_tested = "#version 430 core\n"
16707                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16708                                                                           "\n"
16709                                                                           "layout(isolines, point_mode) in;\n"
16710                                                                           "\n"
16711                                                                           "VAR_DEFINITION"
16712                                                                           "\n"
16713                                                                           "in  vec4 tcs_tes[];\n"
16714                                                                           "out vec4 tes_gs;\n"
16715                                                                           "\n"
16716                                                                           "void main()\n"
16717                                                                           "{\n"
16718                                                                           "    vec4 result = tcs_tes[0];\n"
16719                                                                           "\n"
16720                                                                           "VARIABLE_USE"
16721                                                                           "\n"
16722                                                                           "    tes_gs += result;\n"
16723                                                                           "}\n"
16724                                                                           "\n";
16725         static const GLchar* vs = "#version 430 core\n"
16726                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16727                                                           "\n"
16728                                                           "in  vec4 in_vs;\n"
16729                                                           "out vec4 vs_tcs;\n"
16730                                                           "\n"
16731                                                           "void main()\n"
16732                                                           "{\n"
16733                                                           "    vs_tcs = in_vs;\n"
16734                                                           "}\n"
16735                                                           "\n";
16736         static const GLchar* vs_tested = "#version 430 core\n"
16737                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16738                                                                          "\n"
16739                                                                          "VAR_DEFINITION"
16740                                                                          "\n"
16741                                                                          "in  vec4 in_vs;\n"
16742                                                                          "out vec4 vs_tcs;\n"
16743                                                                          "\n"
16744                                                                          "void main()\n"
16745                                                                          "{\n"
16746                                                                          "    vec4 result = in_vs;\n"
16747                                                                          "\n"
16748                                                                          "VARIABLE_USE"
16749                                                                          "\n"
16750                                                                          "    vs_tcs += result;\n"
16751                                                                          "}\n"
16752                                                                          "\n";
16753
16754         std::string source;
16755         testCase&   test_case = m_test_cases[test_case_index];
16756
16757         if (test_case.m_stage == stage)
16758         {
16759                 const GLchar* array = "";
16760                 GLchar            buffer_gohan[16];
16761                 GLchar            buffer_goten[16];
16762                 const GLchar* flat                = "";
16763                 const GLchar* index               = "";
16764                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16765                 size_t            position      = 0;
16766                 size_t            temp;
16767                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16768                 const GLchar* var_use   = test_one;
16769
16770                 if (true == test_case.m_use_both)
16771                 {
16772                         var_use = test_both;
16773                 }
16774
16775                 if (true == is_flat_req)
16776                 {
16777                         flat = "flat";
16778                 }
16779
16780                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16781                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16782
16783                 switch (stage)
16784                 {
16785                 case Utils::Shader::FRAGMENT:
16786                         source = fs_tested;
16787                         break;
16788                 case Utils::Shader::GEOMETRY:
16789                         source = gs_tested;
16790                         array  = "[]";
16791                         index  = "[0]";
16792                         break;
16793                 case Utils::Shader::TESS_CTRL:
16794                         source = tcs_tested;
16795                         array  = "[]";
16796                         index  = "[gl_InvocationID]";
16797                         break;
16798                 case Utils::Shader::TESS_EVAL:
16799                         source = tes_tested;
16800                         array  = "[]";
16801                         index  = "[0]";
16802                         break;
16803                 case Utils::Shader::VERTEX:
16804                         source = vs_tested;
16805                         break;
16806                 default:
16807                         TCU_FAIL("Invalid enum");
16808                 }
16809
16810                 temp = position;
16811                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16812                 position = temp;
16813                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16814                 Utils::replaceToken("ARRAY", position, array, source);
16815                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16816                 Utils::replaceToken("ARRAY", position, array, source);
16817                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16818
16819                 Utils::replaceAllTokens("FLAT", flat, source);
16820                 Utils::replaceAllTokens("TYPE", type_name, source);
16821                 Utils::replaceAllTokens("INDEX", index, source);
16822         }
16823         else
16824         {
16825                 switch (stage)
16826                 {
16827                 case Utils::Shader::FRAGMENT:
16828                         source = fs;
16829                         break;
16830                 case Utils::Shader::GEOMETRY:
16831                         source = gs;
16832                         break;
16833                 case Utils::Shader::TESS_CTRL:
16834                         source = tcs;
16835                         break;
16836                 case Utils::Shader::TESS_EVAL:
16837                         source = tes;
16838                         break;
16839                 case Utils::Shader::VERTEX:
16840                         source = vs;
16841                         break;
16842                 default:
16843                         TCU_FAIL("Invalid enum");
16844                 }
16845         }
16846
16847         return source;
16848 }
16849
16850 /** Get description of test case
16851  *
16852  * @param test_case_index Index of test case
16853  *
16854  * @return Test case description
16855  **/
16856 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16857 {
16858         std::stringstream stream;
16859         testCase&                 test_case = m_test_cases[test_case_index];
16860
16861         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16862                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16863                    << " & " << test_case.m_component_goten;
16864
16865         return stream.str();
16866 }
16867
16868 /** Get number of test cases
16869  *
16870  * @return Number of test cases
16871  **/
16872 GLuint InputComponentAliasingTest::getTestCaseNumber()
16873 {
16874         return static_cast<GLuint>(m_test_cases.size());
16875 }
16876
16877 /** Selects if "compute" stage is relevant for test
16878  *
16879  * @param ignored
16880  *
16881  * @return false
16882  **/
16883 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16884 {
16885         return false;
16886 }
16887
16888 /** Selects if compilation failure is expected result
16889  *
16890  * @param test_case_index Index of test case
16891  *
16892  * @return false for VS that use only single variable, true otherwise
16893  **/
16894 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16895 {
16896         testCase& test_case = m_test_cases[test_case_index];
16897
16898         return !((Utils::Shader::VERTEX == test_case.m_stage) && (false == test_case.m_use_both));
16899 }
16900
16901 /** Prepare all test cases
16902  *
16903  **/
16904 void InputComponentAliasingTest::testInit()
16905 {
16906         static const GLuint n_components_per_location = 4;
16907         const GLuint            n_types                                   = getTypesNumber();
16908
16909         for (GLuint i = 0; i < n_types; ++i)
16910         {
16911                 const Utils::Type& type                         = getType(i);
16912                 const GLuint       n_req_components = type.m_n_rows;
16913                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16914
16915                 /* Skip matrices */
16916                 if (1 != type.m_n_columns)
16917                 {
16918                         continue;
16919                 }
16920
16921                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16922                 {
16923                         if (Utils::Shader::COMPUTE == stage)
16924                         {
16925                                 continue;
16926                         }
16927
16928                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
16929                         {
16930                                 const GLint first_aliasing = gohan - n_req_components + 1;
16931                                 const GLint last_aliasing  = gohan + n_req_components - 1;
16932
16933                                 const GLuint goten_start = std::max(0, first_aliasing);
16934                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
16935
16936                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
16937                                 {
16938                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type, false };
16939
16940                                         m_test_cases.push_back(test_case);
16941
16942                                         if (Utils::Shader::VERTEX == test_case.m_stage)
16943                                         {
16944                                                 test_case.m_use_both = true;
16945
16946                                                 m_test_cases.push_back(test_case);
16947                                         }
16948                                 }
16949                         }
16950                 }
16951         }
16952 }
16953
16954 /** Constructor
16955  *
16956  * @param context Test framework context
16957  **/
16958 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
16959         : NegativeTestBase(context, "output_component_aliasing",
16960                                            "Test verifies that compiler reports component aliasing as error")
16961 {
16962 }
16963
16964 /** Source for given test case and stage
16965  *
16966  * @param test_case_index Index of test case
16967  * @param stage           Shader stage
16968  *
16969  * @return Shader source
16970  **/
16971 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16972 {
16973         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
16974                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
16975         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
16976                                                                   "    gotenINDEX = TYPE(0);\n";
16977         static const GLchar* fs = "#version 430 core\n"
16978                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16979                                                           "\n"
16980                                                           "in  vec4 gs_fs;\n"
16981                                                           "out vec4 fs_out;\n"
16982                                                           "\n"
16983                                                           "void main()\n"
16984                                                           "{\n"
16985                                                           "    fs_out = gs_fs;\n"
16986                                                           "}\n"
16987                                                           "\n";
16988         static const GLchar* fs_tested = "#version 430 core\n"
16989                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16990                                                                          "\n"
16991                                                                          "VAR_DEFINITION"
16992                                                                          "\n"
16993                                                                          "in  vec4 gs_fs;\n"
16994                                                                          "out vec4 fs_out;\n"
16995                                                                          "\n"
16996                                                                          "void main()\n"
16997                                                                          "{\n"
16998                                                                          "    vec4 result = gs_fs;\n"
16999                                                                          "\n"
17000                                                                          "VARIABLE_USE"
17001                                                                          "\n"
17002                                                                          "    fs_out += result;\n"
17003                                                                          "}\n"
17004                                                                          "\n";
17005         static const GLchar* gs = "#version 430 core\n"
17006                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17007                                                           "\n"
17008                                                           "layout(points)                           in;\n"
17009                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17010                                                           "\n"
17011                                                           "in  vec4 tes_gs[];\n"
17012                                                           "out vec4 gs_fs;\n"
17013                                                           "\n"
17014                                                           "void main()\n"
17015                                                           "{\n"
17016                                                           "    gs_fs = tes_gs[0];\n"
17017                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17018                                                           "    EmitVertex();\n"
17019                                                           "    gs_fs = tes_gs[0];\n"
17020                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17021                                                           "    EmitVertex();\n"
17022                                                           "    gs_fs = tes_gs[0];\n"
17023                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17024                                                           "    EmitVertex();\n"
17025                                                           "    gs_fs = tes_gs[0];\n"
17026                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17027                                                           "    EmitVertex();\n"
17028                                                           "}\n"
17029                                                           "\n";
17030         static const GLchar* gs_tested = "#version 430 core\n"
17031                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17032                                                                          "\n"
17033                                                                          "layout(points)                           in;\n"
17034                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17035                                                                          "\n"
17036                                                                          "VAR_DEFINITION"
17037                                                                          "\n"
17038                                                                          "in  vec4 tes_gs[];\n"
17039                                                                          "out vec4 gs_fs;\n"
17040                                                                          "\n"
17041                                                                          "void main()\n"
17042                                                                          "{\n"
17043                                                                          "    vec4 result = tes_gs[0];\n"
17044                                                                          "\n"
17045                                                                          "VARIABLE_USE"
17046                                                                          "\n"
17047                                                                          "    gs_fs = result;\n"
17048                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17049                                                                          "    EmitVertex();\n"
17050                                                                          "    gs_fs = result;\n"
17051                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17052                                                                          "    EmitVertex();\n"
17053                                                                          "    gs_fs = result;\n"
17054                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17055                                                                          "    EmitVertex();\n"
17056                                                                          "    gs_fs = result;\n"
17057                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17058                                                                          "    EmitVertex();\n"
17059                                                                          "}\n"
17060                                                                          "\n";
17061         static const GLchar* tcs = "#version 430 core\n"
17062                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17063                                                            "\n"
17064                                                            "layout(vertices = 1) out;\n"
17065                                                            "\n"
17066                                                            "in  vec4 vs_tcs[];\n"
17067                                                            "out vec4 tcs_tes[];\n"
17068                                                            "\n"
17069                                                            "void main()\n"
17070                                                            "{\n"
17071                                                            "\n"
17072                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17073                                                            "\n"
17074                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17075                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17076                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17077                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17078                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17079                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17080                                                            "}\n"
17081                                                            "\n";
17082         static const GLchar* tcs_tested = "#version 430 core\n"
17083                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17084                                                                           "\n"
17085                                                                           "layout(vertices = 1) out;\n"
17086                                                                           "\n"
17087                                                                           "VAR_DEFINITION"
17088                                                                           "\n"
17089                                                                           "in  vec4 vs_tcs[];\n"
17090                                                                           "out vec4 tcs_tes[];\n"
17091                                                                           "\n"
17092                                                                           "void main()\n"
17093                                                                           "{\n"
17094                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17095                                                                           "\n"
17096                                                                           "VARIABLE_USE"
17097                                                                           "\n"
17098                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17099                                                                           "\n"
17100                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17101                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17102                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17103                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17104                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17105                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17106                                                                           "}\n"
17107                                                                           "\n";
17108         static const GLchar* tes = "#version 430 core\n"
17109                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17110                                                            "\n"
17111                                                            "layout(isolines, point_mode) in;\n"
17112                                                            "\n"
17113                                                            "in  vec4 tcs_tes[];\n"
17114                                                            "out vec4 tes_gs;\n"
17115                                                            "\n"
17116                                                            "void main()\n"
17117                                                            "{\n"
17118                                                            "    tes_gs = tcs_tes[0];\n"
17119                                                            "}\n"
17120                                                            "\n";
17121         static const GLchar* tes_tested = "#version 430 core\n"
17122                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17123                                                                           "\n"
17124                                                                           "layout(isolines, point_mode) in;\n"
17125                                                                           "\n"
17126                                                                           "VAR_DEFINITION"
17127                                                                           "\n"
17128                                                                           "in  vec4 tcs_tes[];\n"
17129                                                                           "out vec4 tes_gs;\n"
17130                                                                           "\n"
17131                                                                           "void main()\n"
17132                                                                           "{\n"
17133                                                                           "    vec4 result = tcs_tes[0];\n"
17134                                                                           "\n"
17135                                                                           "VARIABLE_USE"
17136                                                                           "\n"
17137                                                                           "    tes_gs += result;\n"
17138                                                                           "}\n"
17139                                                                           "\n";
17140         static const GLchar* vs = "#version 430 core\n"
17141                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17142                                                           "\n"
17143                                                           "in  vec4 in_vs;\n"
17144                                                           "out vec4 vs_tcs;\n"
17145                                                           "\n"
17146                                                           "void main()\n"
17147                                                           "{\n"
17148                                                           "    vs_tcs = in_vs;\n"
17149                                                           "}\n"
17150                                                           "\n";
17151         static const GLchar* vs_tested = "#version 430 core\n"
17152                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17153                                                                          "\n"
17154                                                                          "VAR_DEFINITION"
17155                                                                          "\n"
17156                                                                          "in  vec4 in_vs;\n"
17157                                                                          "out vec4 vs_tcs;\n"
17158                                                                          "\n"
17159                                                                          "void main()\n"
17160                                                                          "{\n"
17161                                                                          "    vec4 result = in_vs;\n"
17162                                                                          "\n"
17163                                                                          "VARIABLE_USE"
17164                                                                          "\n"
17165                                                                          "    vs_tcs += result;\n"
17166                                                                          "}\n"
17167                                                                          "\n";
17168
17169         std::string source;
17170         testCase&   test_case = m_test_cases[test_case_index];
17171
17172         if (test_case.m_stage == stage)
17173         {
17174                 const GLchar* array = "";
17175                 GLchar            buffer_gohan[16];
17176                 GLchar            buffer_goten[16];
17177                 const GLchar* index     = "";
17178                 size_t            position = 0;
17179                 size_t            temp;
17180                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17181
17182                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17183                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17184
17185                 switch (stage)
17186                 {
17187                 case Utils::Shader::FRAGMENT:
17188                         source = fs_tested;
17189                         break;
17190                 case Utils::Shader::GEOMETRY:
17191                         source = gs_tested;
17192                         array  = "[]";
17193                         index  = "[0]";
17194                         break;
17195                 case Utils::Shader::TESS_CTRL:
17196                         source = tcs_tested;
17197                         array  = "[]";
17198                         index  = "[gl_InvocationID]";
17199                         break;
17200                 case Utils::Shader::TESS_EVAL:
17201                         source = tes_tested;
17202                         array  = "[]";
17203                         index  = "[0]";
17204                         break;
17205                 case Utils::Shader::VERTEX:
17206                         source = vs_tested;
17207                         break;
17208                 default:
17209                         TCU_FAIL("Invalid enum");
17210                 }
17211
17212                 temp = position;
17213                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17214                 position = temp;
17215                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17216                 Utils::replaceToken("ARRAY", position, array, source);
17217                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17218                 Utils::replaceToken("ARRAY", position, array, source);
17219                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17220
17221                 Utils::replaceAllTokens("TYPE", type_name, source);
17222                 Utils::replaceAllTokens("INDEX", index, source);
17223         }
17224         else
17225         {
17226                 switch (stage)
17227                 {
17228                 case Utils::Shader::FRAGMENT:
17229                         source = fs;
17230                         break;
17231                 case Utils::Shader::GEOMETRY:
17232                         source = gs;
17233                         break;
17234                 case Utils::Shader::TESS_CTRL:
17235                         source = tcs;
17236                         break;
17237                 case Utils::Shader::TESS_EVAL:
17238                         source = tes;
17239                         break;
17240                 case Utils::Shader::VERTEX:
17241                         source = vs;
17242                         break;
17243                 default:
17244                         TCU_FAIL("Invalid enum");
17245                 }
17246         }
17247
17248         return source;
17249 }
17250
17251 /** Get description of test case
17252  *
17253  * @param test_case_index Index of test case
17254  *
17255  * @return Test case description
17256  **/
17257 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17258 {
17259         std::stringstream stream;
17260         testCase&                 test_case = m_test_cases[test_case_index];
17261
17262         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17263                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17264                    << " & " << test_case.m_component_goten;
17265
17266         return stream.str();
17267 }
17268
17269 /** Get number of test cases
17270  *
17271  * @return Number of test cases
17272  **/
17273 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17274 {
17275         return static_cast<GLuint>(m_test_cases.size());
17276 }
17277
17278 /** Selects if "compute" stage is relevant for test
17279  *
17280  * @param ignored
17281  *
17282  * @return false
17283  **/
17284 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17285 {
17286         return false;
17287 }
17288
17289 /** Prepare all test cases
17290  *
17291  **/
17292 void OutputComponentAliasingTest::testInit()
17293 {
17294         static const GLuint n_components_per_location = 4;
17295         const GLuint            n_types                                   = getTypesNumber();
17296
17297         for (GLuint i = 0; i < n_types; ++i)
17298         {
17299                 const Utils::Type& type                         = getType(i);
17300                 const GLuint       n_req_components = type.m_n_rows;
17301                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17302
17303                 /* Skip matrices */
17304                 if (1 != type.m_n_columns)
17305                 {
17306                         continue;
17307                 }
17308
17309                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17310                 {
17311                         if (Utils::Shader::COMPUTE == stage)
17312                         {
17313                                 continue;
17314                         }
17315
17316                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17317                         {
17318                                 continue;
17319                         }
17320
17321                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17322                         {
17323                                 const GLint first_aliasing = gohan - n_req_components + 1;
17324                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17325
17326                                 const GLuint goten_start = std::max(0, first_aliasing);
17327                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17328
17329                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17330                                 {
17331                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17332
17333                                         m_test_cases.push_back(test_case);
17334                                 }
17335                         }
17336                 }
17337         }
17338 }
17339
17340 /** Constructor
17341  *
17342  * @param context Test framework context
17343  **/
17344 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17345         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17346                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17347 {
17348 }
17349
17350 /** Source for given test case and stage
17351  *
17352  * @param test_case_index Index of test case
17353  * @param stage           Shader stage
17354  *
17355  * @return Shader source
17356  **/
17357 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17358                                                                                                                                            Utils::Shader::STAGES stage)
17359 {
17360         static const GLchar* var_definition =
17361                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17362                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17363         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17364                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17365                                                                          "    {\n"
17366                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17367                                                                          "    }\n";
17368         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17369                                                                           "    gotenINDEX = TYPE(1);\n"
17370                                                                           "    if (vec4(0) == result)\n"
17371                                                                           "    {\n"
17372                                                                           "        gohanINDEX = TYPE(1);\n"
17373                                                                           "        gotenINDEX = TYPE(0);\n"
17374                                                                           "    }\n";
17375         static const GLchar* fs = "#version 430 core\n"
17376                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17377                                                           "\n"
17378                                                           "in  vec4 gs_fs;\n"
17379                                                           "out vec4 fs_out;\n"
17380                                                           "\n"
17381                                                           "void main()\n"
17382                                                           "{\n"
17383                                                           "    fs_out = gs_fs;\n"
17384                                                           "}\n"
17385                                                           "\n";
17386         static const GLchar* fs_tested = "#version 430 core\n"
17387                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17388                                                                          "\n"
17389                                                                          "VAR_DEFINITION"
17390                                                                          "\n"
17391                                                                          "in  vec4 gs_fs;\n"
17392                                                                          "out vec4 fs_out;\n"
17393                                                                          "\n"
17394                                                                          "void main()\n"
17395                                                                          "{\n"
17396                                                                          "    vec4 result = gs_fs;\n"
17397                                                                          "\n"
17398                                                                          "VARIABLE_USE"
17399                                                                          "\n"
17400                                                                          "    fs_out += result;\n"
17401                                                                          "}\n"
17402                                                                          "\n";
17403         static const GLchar* gs = "#version 430 core\n"
17404                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17405                                                           "\n"
17406                                                           "layout(points)                           in;\n"
17407                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17408                                                           "\n"
17409                                                           "in  vec4 tes_gs[];\n"
17410                                                           "out vec4 gs_fs;\n"
17411                                                           "\n"
17412                                                           "void main()\n"
17413                                                           "{\n"
17414                                                           "    gs_fs = tes_gs[0];\n"
17415                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17416                                                           "    EmitVertex();\n"
17417                                                           "    gs_fs = tes_gs[0];\n"
17418                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17419                                                           "    EmitVertex();\n"
17420                                                           "    gs_fs = tes_gs[0];\n"
17421                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17422                                                           "    EmitVertex();\n"
17423                                                           "    gs_fs = tes_gs[0];\n"
17424                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17425                                                           "    EmitVertex();\n"
17426                                                           "}\n"
17427                                                           "\n";
17428         static const GLchar* gs_tested = "#version 430 core\n"
17429                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17430                                                                          "\n"
17431                                                                          "layout(points)                           in;\n"
17432                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17433                                                                          "\n"
17434                                                                          "VAR_DEFINITION"
17435                                                                          "\n"
17436                                                                          "in  vec4 tes_gs[];\n"
17437                                                                          "out vec4 gs_fs;\n"
17438                                                                          "\n"
17439                                                                          "void main()\n"
17440                                                                          "{\n"
17441                                                                          "    vec4 result = tes_gs[0];\n"
17442                                                                          "\n"
17443                                                                          "VARIABLE_USE"
17444                                                                          "\n"
17445                                                                          "    gs_fs = result;\n"
17446                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17447                                                                          "    EmitVertex();\n"
17448                                                                          "    gs_fs = result;\n"
17449                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17450                                                                          "    EmitVertex();\n"
17451                                                                          "    gs_fs = result;\n"
17452                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17453                                                                          "    EmitVertex();\n"
17454                                                                          "    gs_fs = result;\n"
17455                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17456                                                                          "    EmitVertex();\n"
17457                                                                          "}\n"
17458                                                                          "\n";
17459         static const GLchar* tcs = "#version 430 core\n"
17460                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17461                                                            "\n"
17462                                                            "layout(vertices = 1) out;\n"
17463                                                            "\n"
17464                                                            "in  vec4 vs_tcs[];\n"
17465                                                            "out vec4 tcs_tes[];\n"
17466                                                            "\n"
17467                                                            "void main()\n"
17468                                                            "{\n"
17469                                                            "\n"
17470                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17471                                                            "\n"
17472                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17473                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17474                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17475                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17476                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17477                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17478                                                            "}\n"
17479                                                            "\n";
17480         static const GLchar* tcs_tested = "#version 430 core\n"
17481                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17482                                                                           "\n"
17483                                                                           "layout(vertices = 1) out;\n"
17484                                                                           "\n"
17485                                                                           "VAR_DEFINITION"
17486                                                                           "\n"
17487                                                                           "in  vec4 vs_tcs[];\n"
17488                                                                           "out vec4 tcs_tes[];\n"
17489                                                                           "\n"
17490                                                                           "void main()\n"
17491                                                                           "{\n"
17492                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17493                                                                           "\n"
17494                                                                           "VARIABLE_USE"
17495                                                                           "\n"
17496                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17497                                                                           "\n"
17498                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17499                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17500                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17501                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17502                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17503                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17504                                                                           "}\n"
17505                                                                           "\n";
17506         static const GLchar* tes = "#version 430 core\n"
17507                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17508                                                            "\n"
17509                                                            "layout(isolines, point_mode) in;\n"
17510                                                            "\n"
17511                                                            "in  vec4 tcs_tes[];\n"
17512                                                            "out vec4 tes_gs;\n"
17513                                                            "\n"
17514                                                            "void main()\n"
17515                                                            "{\n"
17516                                                            "    tes_gs = tcs_tes[0];\n"
17517                                                            "}\n"
17518                                                            "\n";
17519         static const GLchar* tes_tested = "#version 430 core\n"
17520                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17521                                                                           "\n"
17522                                                                           "layout(isolines, point_mode) in;\n"
17523                                                                           "\n"
17524                                                                           "VAR_DEFINITION"
17525                                                                           "\n"
17526                                                                           "in  vec4 tcs_tes[];\n"
17527                                                                           "out vec4 tes_gs;\n"
17528                                                                           "\n"
17529                                                                           "void main()\n"
17530                                                                           "{\n"
17531                                                                           "    vec4 result = tcs_tes[0];\n"
17532                                                                           "\n"
17533                                                                           "VARIABLE_USE"
17534                                                                           "\n"
17535                                                                           "    tes_gs += result;\n"
17536                                                                           "}\n"
17537                                                                           "\n";
17538         static const GLchar* vs = "#version 430 core\n"
17539                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17540                                                           "\n"
17541                                                           "in  vec4 in_vs;\n"
17542                                                           "out vec4 vs_tcs;\n"
17543                                                           "\n"
17544                                                           "void main()\n"
17545                                                           "{\n"
17546                                                           "    vs_tcs = in_vs;\n"
17547                                                           "}\n"
17548                                                           "\n";
17549         static const GLchar* vs_tested = "#version 430 core\n"
17550                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17551                                                                          "\n"
17552                                                                          "VAR_DEFINITION"
17553                                                                          "\n"
17554                                                                          "in  vec4 in_vs;\n"
17555                                                                          "out vec4 vs_tcs;\n"
17556                                                                          "\n"
17557                                                                          "void main()\n"
17558                                                                          "{\n"
17559                                                                          "    vec4 result = in_vs;\n"
17560                                                                          "\n"
17561                                                                          "VARIABLE_USE"
17562                                                                          "\n"
17563                                                                          "    vs_tcs += result;\n"
17564                                                                          "}\n"
17565                                                                          "\n";
17566
17567         std::string source;
17568         testCase&   test_case = m_test_cases[test_case_index];
17569
17570         if (test_case.m_stage == stage)
17571         {
17572                 const GLchar*                    array = "";
17573                 GLchar                                   buffer_gohan[16];
17574                 GLchar                                   buffer_goten[16];
17575                 const GLchar*                    direction  = "in ";
17576                 const GLchar*                    flat_gohan = "";
17577                 const GLchar*                    flat_goten = "";
17578                 const GLchar*                    index          = "";
17579                 size_t                                   position   = 0;
17580                 size_t                                   temp;
17581                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17582                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17583                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17584                 const GLchar*                    var_use                 = input_use;
17585
17586                 if (false == test_case.m_is_input)
17587                 {
17588                         direction = "out";
17589                         storage   = Utils::Variable::VARYING_OUTPUT;
17590                         var_use   = output_use;
17591                 }
17592
17593                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17594                 {
17595                         flat_gohan = "flat";
17596                 }
17597
17598                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17599                 {
17600                         flat_goten = "flat";
17601                 }
17602
17603                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17604                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17605
17606                 switch (stage)
17607                 {
17608                 case Utils::Shader::FRAGMENT:
17609                         source = fs_tested;
17610                         break;
17611                 case Utils::Shader::GEOMETRY:
17612                         source = gs_tested;
17613                         array  = "[]";
17614                         index  = "[0]";
17615                         break;
17616                 case Utils::Shader::TESS_CTRL:
17617                         source = tcs_tested;
17618                         array  = "[]";
17619                         index  = "[gl_InvocationID]";
17620                         break;
17621                 case Utils::Shader::TESS_EVAL:
17622                         source = tes_tested;
17623                         array  = "[]";
17624                         index  = "[0]";
17625                         break;
17626                 case Utils::Shader::VERTEX:
17627                         source = vs_tested;
17628                         break;
17629                 default:
17630                         TCU_FAIL("Invalid enum");
17631                 }
17632
17633                 temp = position;
17634                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17635                 position = temp;
17636                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17637                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17638                 Utils::replaceToken("DIRECTION", position, direction, source);
17639                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17640                 Utils::replaceToken("ARRAY", position, array, source);
17641                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17642                 Utils::replaceToken("FLAT", position, flat_goten, source);
17643                 Utils::replaceToken("DIRECTION", position, direction, source);
17644                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17645                 Utils::replaceToken("ARRAY", position, array, source);
17646
17647                 temp = position;
17648                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17649                 position = temp;
17650                 if (true == test_case.m_is_input)
17651                 {
17652                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17653                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17654                 }
17655                 else
17656                 {
17657                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17658                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17659                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17660                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17661                 }
17662
17663                 Utils::replaceAllTokens("INDEX", index, source);
17664         }
17665         else
17666         {
17667                 switch (stage)
17668                 {
17669                 case Utils::Shader::FRAGMENT:
17670                         source = fs;
17671                         break;
17672                 case Utils::Shader::GEOMETRY:
17673                         source = gs;
17674                         break;
17675                 case Utils::Shader::TESS_CTRL:
17676                         source = tcs;
17677                         break;
17678                 case Utils::Shader::TESS_EVAL:
17679                         source = tes;
17680                         break;
17681                 case Utils::Shader::VERTEX:
17682                         source = vs;
17683                         break;
17684                 default:
17685                         TCU_FAIL("Invalid enum");
17686                 }
17687         }
17688
17689         return source;
17690 }
17691
17692 /** Get description of test case
17693  *
17694  * @param test_case_index Index of test case
17695  *
17696  * @return Test case description
17697  **/
17698 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17699 {
17700         std::stringstream stream;
17701         testCase&                 test_case = m_test_cases[test_case_index];
17702
17703         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17704                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17705                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17706
17707         if (true == test_case.m_is_input)
17708         {
17709                 stream << "input";
17710         }
17711         else
17712         {
17713                 stream << "output";
17714         }
17715
17716         return stream.str();
17717 }
17718
17719 /** Get number of test cases
17720  *
17721  * @return Number of test cases
17722  **/
17723 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17724 {
17725         return static_cast<GLuint>(m_test_cases.size());
17726 }
17727
17728 /** Selects if "compute" stage is relevant for test
17729  *
17730  * @param ignored
17731  *
17732  * @return false
17733  **/
17734 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17735 {
17736         return false;
17737 }
17738
17739 /** Prepare all test cases
17740  *
17741  **/
17742 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17743 {
17744         static const GLuint n_components_per_location = 4;
17745         const GLuint            n_types                                   = getTypesNumber();
17746
17747         for (GLuint i = 0; i < n_types; ++i)
17748         {
17749                 const Utils::Type& type_gohan              = getType(i);
17750                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17751
17752                 /* Skip matrices */
17753                 if (1 != type_gohan.m_n_columns)
17754                 {
17755                         continue;
17756                 }
17757
17758                 for (GLuint j = 0; j < n_types; ++j)
17759                 {
17760                         const Utils::Type& type_goten              = getType(j);
17761                         const bool                 is_float_type_goten = isFloatType(type_goten);
17762
17763                         /* Skip matrices */
17764                         if (1 != type_goten.m_n_columns)
17765                         {
17766                                 continue;
17767                         }
17768
17769                         /* Skip valid combinations */
17770                         if (is_float_type_gohan == is_float_type_goten)
17771                         {
17772                                 continue;
17773                         }
17774
17775                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17776                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17777                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17778                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17779
17780                         /* Skip pairs that cannot fit into one location */
17781                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17782                         {
17783                                 continue;
17784                         }
17785
17786                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17787                         {
17788                                 /* Skip compute shader */
17789                                 if (Utils::Shader::COMPUTE == stage)
17790                                 {
17791                                         continue;
17792                                 }
17793
17794                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17795                                 {
17796                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17797                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17798
17799                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17800                                         const GLuint goten_upper_limit = last_aliasing + 1;
17801
17802                                         /* Compoennets before gohan */
17803                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17804                                         {
17805                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17806                                                                                                   type_gohan, type_goten };
17807                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17808                                                                                                    type_gohan, type_goten };
17809
17810                                                 m_test_cases.push_back(test_case_in);
17811
17812                                                 /* Skip double outputs in fragment shader */
17813                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17814                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17815                                                 {
17816                                                         m_test_cases.push_back(test_case_out);
17817                                                 }
17818                                         }
17819
17820                                         /* Components after gohan */
17821                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17822                                         {
17823                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17824                                                                                                   type_gohan, type_goten };
17825                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17826                                                                                                    type_gohan, type_goten };
17827
17828                                                 m_test_cases.push_back(test_case_in);
17829
17830                                                 /* Skip double outputs in fragment shader */
17831                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17832                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17833                                                 {
17834                                                         m_test_cases.push_back(test_case_out);
17835                                                 }
17836                                         }
17837                                 }
17838                         }
17839                 }
17840         }
17841 }
17842
17843 /** Check if given type is float
17844  *
17845  * @param type Type in question
17846  *
17847  * @return true if tpye is float, false otherwise
17848  **/
17849 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17850 {
17851         bool is_float = false;
17852
17853         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17854         {
17855                 is_float = true;
17856         }
17857
17858         return is_float;
17859 }
17860
17861 /** Constructor
17862  *
17863  * @param context Test framework context
17864  **/
17865 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17866         deqp::Context& context)
17867         : NegativeTestBase(
17868                   context, "varying_location_aliasing_with_mixed_interpolation",
17869                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17870 {
17871 }
17872
17873 /** Source for given test case and stage
17874  *
17875  * @param test_case_index Index of test case
17876  * @param stage           Shader stage
17877  *
17878  * @return Shader source
17879  **/
17880 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17881                                                                                                                                                            Utils::Shader::STAGES stage)
17882 {
17883         static const GLchar* var_definition =
17884                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17885                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17886         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17887                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17888                                                                          "    {\n"
17889                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17890                                                                          "    }\n";
17891         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17892                                                                           "    gotenINDEX = TYPE(1);\n"
17893                                                                           "    if (vec4(0) == result)\n"
17894                                                                           "    {\n"
17895                                                                           "        gohanINDEX = TYPE(1);\n"
17896                                                                           "        gotenINDEX = TYPE(0);\n"
17897                                                                           "    }\n";
17898         static const GLchar* fs = "#version 430 core\n"
17899                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17900                                                           "\n"
17901                                                           "in  vec4 gs_fs;\n"
17902                                                           "out vec4 fs_out;\n"
17903                                                           "\n"
17904                                                           "void main()\n"
17905                                                           "{\n"
17906                                                           "    fs_out = gs_fs;\n"
17907                                                           "}\n"
17908                                                           "\n";
17909         static const GLchar* fs_tested = "#version 430 core\n"
17910                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17911                                                                          "\n"
17912                                                                          "VAR_DEFINITION"
17913                                                                          "\n"
17914                                                                          "in  vec4 gs_fs;\n"
17915                                                                          "out vec4 fs_out;\n"
17916                                                                          "\n"
17917                                                                          "void main()\n"
17918                                                                          "{\n"
17919                                                                          "    vec4 result = gs_fs;\n"
17920                                                                          "\n"
17921                                                                          "VARIABLE_USE"
17922                                                                          "\n"
17923                                                                          "    fs_out = result;\n"
17924                                                                          "}\n"
17925                                                                          "\n";
17926         static const GLchar* gs = "#version 430 core\n"
17927                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17928                                                           "\n"
17929                                                           "layout(points)                           in;\n"
17930                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17931                                                           "\n"
17932                                                           "in  vec4 tes_gs[];\n"
17933                                                           "out vec4 gs_fs;\n"
17934                                                           "\n"
17935                                                           "void main()\n"
17936                                                           "{\n"
17937                                                           "    gs_fs = tes_gs[0];\n"
17938                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17939                                                           "    EmitVertex();\n"
17940                                                           "    gs_fs = tes_gs[0];\n"
17941                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17942                                                           "    EmitVertex();\n"
17943                                                           "    gs_fs = tes_gs[0];\n"
17944                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17945                                                           "    EmitVertex();\n"
17946                                                           "    gs_fs = tes_gs[0];\n"
17947                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17948                                                           "    EmitVertex();\n"
17949                                                           "}\n"
17950                                                           "\n";
17951         static const GLchar* gs_tested = "#version 430 core\n"
17952                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17953                                                                          "\n"
17954                                                                          "layout(points)                           in;\n"
17955                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17956                                                                          "\n"
17957                                                                          "VAR_DEFINITION"
17958                                                                          "\n"
17959                                                                          "in  vec4 tes_gs[];\n"
17960                                                                          "out vec4 gs_fs;\n"
17961                                                                          "\n"
17962                                                                          "void main()\n"
17963                                                                          "{\n"
17964                                                                          "    vec4 result = tes_gs[0];\n"
17965                                                                          "\n"
17966                                                                          "VARIABLE_USE"
17967                                                                          "\n"
17968                                                                          "    gs_fs = result;\n"
17969                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17970                                                                          "    EmitVertex();\n"
17971                                                                          "    gs_fs = result;\n"
17972                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17973                                                                          "    EmitVertex();\n"
17974                                                                          "    gs_fs = result;\n"
17975                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17976                                                                          "    EmitVertex();\n"
17977                                                                          "    gs_fs = result;\n"
17978                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17979                                                                          "    EmitVertex();\n"
17980                                                                          "}\n"
17981                                                                          "\n";
17982         static const GLchar* tcs = "#version 430 core\n"
17983                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17984                                                            "\n"
17985                                                            "layout(vertices = 1) out;\n"
17986                                                            "\n"
17987                                                            "in  vec4 vs_tcs[];\n"
17988                                                            "out vec4 tcs_tes[];\n"
17989                                                            "\n"
17990                                                            "void main()\n"
17991                                                            "{\n"
17992                                                            "\n"
17993                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17994                                                            "\n"
17995                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17996                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17997                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17998                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17999                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18000                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18001                                                            "}\n"
18002                                                            "\n";
18003         static const GLchar* tcs_tested = "#version 430 core\n"
18004                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18005                                                                           "\n"
18006                                                                           "layout(vertices = 1) out;\n"
18007                                                                           "\n"
18008                                                                           "VAR_DEFINITION"
18009                                                                           "\n"
18010                                                                           "in  vec4 vs_tcs[];\n"
18011                                                                           "out vec4 tcs_tes[];\n"
18012                                                                           "\n"
18013                                                                           "void main()\n"
18014                                                                           "{\n"
18015                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18016                                                                           "\n"
18017                                                                           "VARIABLE_USE"
18018                                                                           "\n"
18019                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18020                                                                           "\n"
18021                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18022                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18023                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18024                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18025                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18026                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18027                                                                           "}\n"
18028                                                                           "\n";
18029         static const GLchar* tes = "#version 430 core\n"
18030                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18031                                                            "\n"
18032                                                            "layout(isolines, point_mode) in;\n"
18033                                                            "\n"
18034                                                            "in  vec4 tcs_tes[];\n"
18035                                                            "out vec4 tes_gs;\n"
18036                                                            "\n"
18037                                                            "void main()\n"
18038                                                            "{\n"
18039                                                            "    tes_gs = tcs_tes[0];\n"
18040                                                            "}\n"
18041                                                            "\n";
18042         static const GLchar* tes_tested = "#version 430 core\n"
18043                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18044                                                                           "\n"
18045                                                                           "layout(isolines, point_mode) in;\n"
18046                                                                           "\n"
18047                                                                           "VAR_DEFINITION"
18048                                                                           "\n"
18049                                                                           "in  vec4 tcs_tes[];\n"
18050                                                                           "out vec4 tes_gs;\n"
18051                                                                           "\n"
18052                                                                           "void main()\n"
18053                                                                           "{\n"
18054                                                                           "    vec4 result = tcs_tes[0];\n"
18055                                                                           "\n"
18056                                                                           "VARIABLE_USE"
18057                                                                           "\n"
18058                                                                           "    tes_gs += result;\n"
18059                                                                           "}\n"
18060                                                                           "\n";
18061         static const GLchar* vs = "#version 430 core\n"
18062                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18063                                                           "\n"
18064                                                           "in  vec4 in_vs;\n"
18065                                                           "out vec4 vs_tcs;\n"
18066                                                           "\n"
18067                                                           "void main()\n"
18068                                                           "{\n"
18069                                                           "    vs_tcs = in_vs;\n"
18070                                                           "}\n"
18071                                                           "\n";
18072         static const GLchar* vs_tested = "#version 430 core\n"
18073                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18074                                                                          "\n"
18075                                                                          "VAR_DEFINITION"
18076                                                                          "\n"
18077                                                                          "in  vec4 in_vs;\n"
18078                                                                          "out vec4 vs_tcs;\n"
18079                                                                          "\n"
18080                                                                          "void main()\n"
18081                                                                          "{\n"
18082                                                                          "    vec4 result = in_vs;\n"
18083                                                                          "\n"
18084                                                                          "VARIABLE_USE"
18085                                                                          "\n"
18086                                                                          "    vs_tcs += result;\n"
18087                                                                          "}\n"
18088                                                                          "\n";
18089
18090         std::string source;
18091         testCase&   test_case = m_test_cases[test_case_index];
18092
18093         if (test_case.m_stage == stage)
18094         {
18095                 const GLchar* array = "";
18096                 GLchar            buffer_gohan[16];
18097                 GLchar            buffer_goten[16];
18098                 const GLchar* direction = "in ";
18099                 const GLchar* index             = "";
18100                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18101                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18102                 size_t            position  = 0;
18103                 size_t            temp;
18104                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18105                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18106                 const GLchar* var_use             = input_use;
18107
18108                 if (false == test_case.m_is_input)
18109                 {
18110                         direction = "out";
18111
18112                         var_use = output_use;
18113                 }
18114
18115                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18116                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18117
18118                 switch (stage)
18119                 {
18120                 case Utils::Shader::FRAGMENT:
18121                         source = fs_tested;
18122                         break;
18123                 case Utils::Shader::GEOMETRY:
18124                         source = gs_tested;
18125                         array  = "[]";
18126                         index  = "[0]";
18127                         break;
18128                 case Utils::Shader::TESS_CTRL:
18129                         source = tcs_tested;
18130                         array  = "[]";
18131                         index  = "[gl_InvocationID]";
18132                         break;
18133                 case Utils::Shader::TESS_EVAL:
18134                         source = tes_tested;
18135                         array  = "[]";
18136                         index  = "[0]";
18137                         break;
18138                 case Utils::Shader::VERTEX:
18139                         source = vs_tested;
18140                         break;
18141                 default:
18142                         TCU_FAIL("Invalid enum");
18143                 }
18144
18145                 temp = position;
18146                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18147                 position = temp;
18148                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18149                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18150                 Utils::replaceToken("DIRECTION", position, direction, source);
18151                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18152                 Utils::replaceToken("ARRAY", position, array, source);
18153                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18154                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18155                 Utils::replaceToken("DIRECTION", position, direction, source);
18156                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18157                 Utils::replaceToken("ARRAY", position, array, source);
18158
18159                 temp = position;
18160                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18161                 position = temp;
18162                 if (true == test_case.m_is_input)
18163                 {
18164                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18165                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18166                 }
18167                 else
18168                 {
18169                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18170                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18171                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18172                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18173                 }
18174
18175                 Utils::replaceAllTokens("INDEX", index, source);
18176         }
18177         else
18178         {
18179                 switch (stage)
18180                 {
18181                 case Utils::Shader::FRAGMENT:
18182                         source = fs;
18183                         break;
18184                 case Utils::Shader::GEOMETRY:
18185                         source = gs;
18186                         break;
18187                 case Utils::Shader::TESS_CTRL:
18188                         source = tcs;
18189                         break;
18190                 case Utils::Shader::TESS_EVAL:
18191                         source = tes;
18192                         break;
18193                 case Utils::Shader::VERTEX:
18194                         source = vs;
18195                         break;
18196                 default:
18197                         TCU_FAIL("Invalid enum");
18198                 }
18199         }
18200
18201         return source;
18202 }
18203
18204 /** Get description of test case
18205  *
18206  * @param test_case_index Index of test case
18207  *
18208  * @return Test case description
18209  **/
18210 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18211 {
18212         std::stringstream stream;
18213         testCase&                 test_case = m_test_cases[test_case_index];
18214
18215         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18216                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18217                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18218                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18219                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18220
18221         if (true == test_case.m_is_input)
18222         {
18223                 stream << "input";
18224         }
18225         else
18226         {
18227                 stream << "output";
18228         }
18229
18230         return stream.str();
18231 }
18232
18233 /** Get number of test cases
18234  *
18235  * @return Number of test cases
18236  **/
18237 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18238 {
18239         return static_cast<GLuint>(m_test_cases.size());
18240 }
18241
18242 /** Selects if "compute" stage is relevant for test
18243  *
18244  * @param ignored
18245  *
18246  * @return false
18247  **/
18248 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18249 {
18250         return false;
18251 }
18252
18253 /** Prepare all test cases
18254  *
18255  **/
18256 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18257 {
18258         static const GLuint n_components_per_location = 4;
18259         const GLuint            n_types                                   = getTypesNumber();
18260
18261         for (GLuint i = 0; i < n_types; ++i)
18262         {
18263                 const Utils::Type& type_gohan              = getType(i);
18264                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18265
18266                 /* Skip matrices */
18267                 if (1 != type_gohan.m_n_columns)
18268                 {
18269                         continue;
18270                 }
18271
18272                 for (GLuint j = 0; j < n_types; ++j)
18273                 {
18274                         const Utils::Type& type_goten              = getType(j);
18275                         const bool                 is_float_type_goten = isFloatType(type_goten);
18276
18277                         /* Skip matrices */
18278                         if (1 != type_goten.m_n_columns)
18279                         {
18280                                 continue;
18281                         }
18282
18283                         /* Skip invalid combinations */
18284                         if (is_float_type_gohan != is_float_type_goten)
18285                         {
18286                                 continue;
18287                         }
18288
18289                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18290                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18291
18292                         /* Skip pairs that cannot fit into one location */
18293                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18294                         {
18295                                 continue;
18296                         }
18297
18298                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18299                         {
18300                                 /* Skip compute shader */
18301                                 if (Utils::Shader::COMPUTE == stage)
18302                                 {
18303                                         continue;
18304                                 }
18305
18306                                 const GLuint gohan = 0;
18307                                 const GLuint goten = gohan + n_req_components_gohan;
18308
18309                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18310                                 {
18311                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18312                                         {
18313                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18314                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18315                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18316                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18317                                                 const bool is_gohan_accepted_as_fs_in =
18318                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18319                                                 const bool is_goten_accepted_as_fs_in =
18320                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18321                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18322
18323                                                 /* Skip when both are the same */
18324                                                 if (int_gohan == int_goten)
18325                                                 {
18326                                                         continue;
18327                                                 }
18328
18329                                                 testCase test_case_in = { gohan,
18330                                                                                                   goten,
18331                                                                                                   (INTERPOLATIONS)int_gohan,
18332                                                                                                   (INTERPOLATIONS)int_goten,
18333                                                                                                   true,
18334                                                                                                   (Utils::Shader::STAGES)stage,
18335                                                                                                   type_gohan,
18336                                                                                                   type_goten };
18337
18338                                                 testCase test_case_out = { gohan,
18339                                                                                                    goten,
18340                                                                                                    (INTERPOLATIONS)int_gohan,
18341                                                                                                    (INTERPOLATIONS)int_goten,
18342                                                                                                    false,
18343                                                                                                    (Utils::Shader::STAGES)stage,
18344                                                                                                    type_gohan,
18345                                                                                                    type_goten };
18346
18347                                                 /* Skip inputs in:
18348                                                  * vertex shader,
18349                                                  * fragment shader when not flat double is used
18350                                                  */
18351                                                 if ((Utils::Shader::VERTEX != stage) &&
18352                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18353                                                 {
18354                                                         m_test_cases.push_back(test_case_in);
18355                                                 }
18356
18357                                                 /* Skip outputs in fragment shader */
18358                                                 if (Utils::Shader::FRAGMENT != stage)
18359                                                 {
18360                                                         m_test_cases.push_back(test_case_out);
18361                                                 }
18362                                         }
18363                                 }
18364                         }
18365                 }
18366         }
18367 }
18368
18369 /** Get interpolation qualifier
18370  *
18371  * @param interpolation Enumeration
18372  *
18373  * @return GLSL qualifier
18374  **/
18375 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18376 {
18377         const GLchar* result = 0;
18378
18379         switch (interpolation)
18380         {
18381         case SMOOTH:
18382                 result = "smooth";
18383                 break;
18384         case FLAT:
18385                 result = "flat";
18386                 break;
18387         case NO_PERSPECTIVE:
18388                 result = "noperspective";
18389                 break;
18390         default:
18391                 TCU_FAIL("Invalid enum");
18392         }
18393
18394         return result;
18395 }
18396
18397 /** Check if given type is float
18398  *
18399  * @param type Type in question
18400  *
18401  * @return true if tpye is float, false otherwise
18402  **/
18403 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18404 {
18405         bool is_float = false;
18406
18407         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18408         {
18409                 is_float = true;
18410         }
18411
18412         return is_float;
18413 }
18414
18415 /** Constructor
18416  *
18417  * @param context Test framework context
18418  **/
18419 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18420         deqp::Context& context)
18421         : NegativeTestBase(
18422                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18423                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18424 {
18425 }
18426
18427 /** Source for given test case and stage
18428  *
18429  * @param test_case_index Index of test case
18430  * @param stage           Shader stage
18431  *
18432  * @return Shader source
18433  **/
18434 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18435                                                                                                                                                                   Utils::Shader::STAGES stage)
18436 {
18437         static const GLchar* var_definition =
18438                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18439                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18440         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18441                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18442                                                                          "    {\n"
18443                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18444                                                                          "    }\n";
18445         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18446                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18447                                                                           "    if (vec4(0) == result)\n"
18448                                                                           "    {\n"
18449                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18450                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18451                                                                           "    }\n";
18452         static const GLchar* fs = "#version 430 core\n"
18453                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18454                                                           "\n"
18455                                                           "in  vec4 gs_fs;\n"
18456                                                           "out vec4 fs_out;\n"
18457                                                           "\n"
18458                                                           "void main()\n"
18459                                                           "{\n"
18460                                                           "    fs_out = gs_fs;\n"
18461                                                           "}\n"
18462                                                           "\n";
18463         static const GLchar* fs_tested = "#version 430 core\n"
18464                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18465                                                                          "\n"
18466                                                                          "VAR_DEFINITION"
18467                                                                          "\n"
18468                                                                          "in  vec4 gs_fs;\n"
18469                                                                          "out vec4 fs_out;\n"
18470                                                                          "\n"
18471                                                                          "void main()\n"
18472                                                                          "{\n"
18473                                                                          "    vec4 result = gs_fs;\n"
18474                                                                          "\n"
18475                                                                          "VARIABLE_USE"
18476                                                                          "\n"
18477                                                                          "    fs_out = result;\n"
18478                                                                          "}\n"
18479                                                                          "\n";
18480         static const GLchar* gs = "#version 430 core\n"
18481                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18482                                                           "\n"
18483                                                           "layout(points)                           in;\n"
18484                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18485                                                           "\n"
18486                                                           "in  vec4 tes_gs[];\n"
18487                                                           "out vec4 gs_fs;\n"
18488                                                           "\n"
18489                                                           "void main()\n"
18490                                                           "{\n"
18491                                                           "    gs_fs = tes_gs[0];\n"
18492                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18493                                                           "    EmitVertex();\n"
18494                                                           "    gs_fs = tes_gs[0];\n"
18495                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18496                                                           "    EmitVertex();\n"
18497                                                           "    gs_fs = tes_gs[0];\n"
18498                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18499                                                           "    EmitVertex();\n"
18500                                                           "    gs_fs = tes_gs[0];\n"
18501                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18502                                                           "    EmitVertex();\n"
18503                                                           "}\n"
18504                                                           "\n";
18505         static const GLchar* gs_tested = "#version 430 core\n"
18506                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18507                                                                          "\n"
18508                                                                          "layout(points)                           in;\n"
18509                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18510                                                                          "\n"
18511                                                                          "VAR_DEFINITION"
18512                                                                          "\n"
18513                                                                          "in  vec4 tes_gs[];\n"
18514                                                                          "out vec4 gs_fs;\n"
18515                                                                          "\n"
18516                                                                          "void main()\n"
18517                                                                          "{\n"
18518                                                                          "    vec4 result = tes_gs[0];\n"
18519                                                                          "\n"
18520                                                                          "VARIABLE_USE"
18521                                                                          "\n"
18522                                                                          "    gs_fs = result;\n"
18523                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18524                                                                          "    EmitVertex();\n"
18525                                                                          "    gs_fs = result;\n"
18526                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18527                                                                          "    EmitVertex();\n"
18528                                                                          "    gs_fs = result;\n"
18529                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18530                                                                          "    EmitVertex();\n"
18531                                                                          "    gs_fs = result;\n"
18532                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18533                                                                          "    EmitVertex();\n"
18534                                                                          "}\n"
18535                                                                          "\n";
18536         static const GLchar* tcs = "#version 430 core\n"
18537                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18538                                                            "\n"
18539                                                            "layout(vertices = 1) out;\n"
18540                                                            "\n"
18541                                                            "in  vec4 vs_tcs[];\n"
18542                                                            "out vec4 tcs_tes[];\n"
18543                                                            "\n"
18544                                                            "void main()\n"
18545                                                            "{\n"
18546                                                            "\n"
18547                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18548                                                            "\n"
18549                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18550                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18551                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18552                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18553                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18554                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18555                                                            "}\n"
18556                                                            "\n";
18557         static const GLchar* tcs_tested = "#version 430 core\n"
18558                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18559                                                                           "\n"
18560                                                                           "layout(vertices = 1) out;\n"
18561                                                                           "\n"
18562                                                                           "VAR_DEFINITION"
18563                                                                           "\n"
18564                                                                           "in  vec4 vs_tcs[];\n"
18565                                                                           "out vec4 tcs_tes[];\n"
18566                                                                           "\n"
18567                                                                           "void main()\n"
18568                                                                           "{\n"
18569                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18570                                                                           "\n"
18571                                                                           "VARIABLE_USE"
18572                                                                           "\n"
18573                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18574                                                                           "\n"
18575                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18576                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18577                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18578                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18579                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18580                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18581                                                                           "}\n"
18582                                                                           "\n";
18583         static const GLchar* tes = "#version 430 core\n"
18584                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18585                                                            "\n"
18586                                                            "layout(isolines, point_mode) in;\n"
18587                                                            "\n"
18588                                                            "in  vec4 tcs_tes[];\n"
18589                                                            "out vec4 tes_gs;\n"
18590                                                            "\n"
18591                                                            "void main()\n"
18592                                                            "{\n"
18593                                                            "    tes_gs = tcs_tes[0];\n"
18594                                                            "}\n"
18595                                                            "\n";
18596         static const GLchar* tes_tested = "#version 430 core\n"
18597                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18598                                                                           "\n"
18599                                                                           "layout(isolines, point_mode) in;\n"
18600                                                                           "\n"
18601                                                                           "VAR_DEFINITION"
18602                                                                           "\n"
18603                                                                           "in  vec4 tcs_tes[];\n"
18604                                                                           "out vec4 tes_gs;\n"
18605                                                                           "\n"
18606                                                                           "void main()\n"
18607                                                                           "{\n"
18608                                                                           "    vec4 result = tcs_tes[0];\n"
18609                                                                           "\n"
18610                                                                           "VARIABLE_USE"
18611                                                                           "\n"
18612                                                                           "    tes_gs += result;\n"
18613                                                                           "}\n"
18614                                                                           "\n";
18615         static const GLchar* vs = "#version 430 core\n"
18616                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18617                                                           "\n"
18618                                                           "in  vec4 in_vs;\n"
18619                                                           "out vec4 vs_tcs;\n"
18620                                                           "\n"
18621                                                           "void main()\n"
18622                                                           "{\n"
18623                                                           "    vs_tcs = in_vs;\n"
18624                                                           "}\n"
18625                                                           "\n";
18626         static const GLchar* vs_tested = "#version 430 core\n"
18627                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18628                                                                          "\n"
18629                                                                          "VAR_DEFINITION"
18630                                                                          "\n"
18631                                                                          "in  vec4 in_vs;\n"
18632                                                                          "out vec4 vs_tcs;\n"
18633                                                                          "\n"
18634                                                                          "void main()\n"
18635                                                                          "{\n"
18636                                                                          "    vec4 result = in_vs;\n"
18637                                                                          "\n"
18638                                                                          "VARIABLE_USE"
18639                                                                          "\n"
18640                                                                          "    vs_tcs += result;\n"
18641                                                                          "}\n"
18642                                                                          "\n";
18643
18644         std::string source;
18645         testCase&   test_case = m_test_cases[test_case_index];
18646
18647         if (test_case.m_stage == stage)
18648         {
18649                 const GLchar* array_gohan = "";
18650                 const GLchar* array_goten = "";
18651                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18652                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18653                 GLchar            buffer_gohan[16];
18654                 GLchar            buffer_goten[16];
18655                 const GLchar* direction   = "in ";
18656                 const GLchar* index_gohan = "";
18657                 const GLchar* index_goten = "";
18658                 const GLchar* int_gohan   = test_case.m_int_gohan;
18659                 const GLchar* int_goten   = test_case.m_int_goten;
18660                 size_t            position      = 0;
18661                 size_t            temp;
18662                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18663                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18664                 const GLchar* var_use             = input_use;
18665
18666                 if (false == test_case.m_is_input)
18667                 {
18668                         direction = "out";
18669
18670                         var_use = output_use;
18671                 }
18672
18673                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18674                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18675
18676                 switch (stage)
18677                 {
18678                 case Utils::Shader::FRAGMENT:
18679                         source = fs_tested;
18680                         break;
18681                 case Utils::Shader::GEOMETRY:
18682                         source          = gs_tested;
18683                         array_gohan = "[]";
18684                         index_gohan = "[0]";
18685                         array_goten = "[]";
18686                         index_goten = "[0]";
18687                         break;
18688                 case Utils::Shader::TESS_CTRL:
18689                         source = tcs_tested;
18690                         if (PATCH != test_case.m_aux_gohan)
18691                         {
18692                                 array_gohan = "[]";
18693                                 index_gohan = "[gl_InvocationID]";
18694                         }
18695                         if (PATCH != test_case.m_aux_goten)
18696                         {
18697                                 array_goten = "[]";
18698                                 index_goten = "[gl_InvocationID]";
18699                         }
18700                         break;
18701                 case Utils::Shader::TESS_EVAL:
18702                         source          = tes_tested;
18703                         array_gohan = "[]";
18704                         index_gohan = "[0]";
18705                         array_goten = "[]";
18706                         index_goten = "[0]";
18707                         break;
18708                 case Utils::Shader::VERTEX:
18709                         source = vs_tested;
18710                         break;
18711                 default:
18712                         TCU_FAIL("Invalid enum");
18713                 }
18714
18715                 temp = position;
18716                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18717                 position = temp;
18718                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18719                 Utils::replaceToken("AUX", position, aux_gohan, source);
18720                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18721                 Utils::replaceToken("DIRECTION", position, direction, source);
18722                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18723                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18724                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18725                 Utils::replaceToken("AUX", position, aux_goten, source);
18726                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18727                 Utils::replaceToken("DIRECTION", position, direction, source);
18728                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18729                 Utils::replaceToken("ARRAY", position, array_goten, source);
18730
18731                 temp = position;
18732                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18733                 position = temp;
18734                 if (true == test_case.m_is_input)
18735                 {
18736                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18737                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18738                 }
18739                 else
18740                 {
18741                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18742                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18743                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18744                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18745                 }
18746
18747                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18748                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18749         }
18750         else
18751         {
18752                 switch (stage)
18753                 {
18754                 case Utils::Shader::FRAGMENT:
18755                         source = fs;
18756                         break;
18757                 case Utils::Shader::GEOMETRY:
18758                         source = gs;
18759                         break;
18760                 case Utils::Shader::TESS_CTRL:
18761                         source = tcs;
18762                         break;
18763                 case Utils::Shader::TESS_EVAL:
18764                         source = tes;
18765                         break;
18766                 case Utils::Shader::VERTEX:
18767                         source = vs;
18768                         break;
18769                 default:
18770                         TCU_FAIL("Invalid enum");
18771                 }
18772         }
18773
18774         return source;
18775 }
18776
18777 /** Get description of test case
18778  *
18779  * @param test_case_index Index of test case
18780  *
18781  * @return Test case description
18782  **/
18783 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18784 {
18785         std::stringstream stream;
18786         testCase&                 test_case = m_test_cases[test_case_index];
18787
18788         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18789                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18790                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18791                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18792
18793         if (true == test_case.m_is_input)
18794         {
18795                 stream << "input";
18796         }
18797         else
18798         {
18799                 stream << "output";
18800         }
18801
18802         return stream.str();
18803 }
18804
18805 /** Get number of test cases
18806  *
18807  * @return Number of test cases
18808  **/
18809 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18810 {
18811         return static_cast<GLuint>(m_test_cases.size());
18812 }
18813
18814 /** Selects if "compute" stage is relevant for test
18815  *
18816  * @param ignored
18817  *
18818  * @return false
18819  **/
18820 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18821 {
18822         return false;
18823 }
18824
18825 /** Prepare all test cases
18826  *
18827  **/
18828 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18829 {
18830         static const GLuint n_components_per_location = 4;
18831         const GLuint            n_types                                   = getTypesNumber();
18832
18833         for (GLuint i = 0; i < n_types; ++i)
18834         {
18835                 const Utils::Type& type_gohan              = getType(i);
18836                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18837
18838                 /* Skip matrices */
18839                 if (1 != type_gohan.m_n_columns)
18840                 {
18841                         continue;
18842                 }
18843
18844                 for (GLuint j = 0; j < n_types; ++j)
18845                 {
18846                         const Utils::Type& type_goten              = getType(j);
18847                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18848                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18849                         const bool                 is_float_type_goten = isFloatType(type_goten);
18850
18851                         /* Skip matrices */
18852                         if (1 != type_goten.m_n_columns)
18853                         {
18854                                 continue;
18855                         }
18856
18857                         /* Skip invalid combinations */
18858                         if (is_float_type_gohan != is_float_type_goten)
18859                         {
18860                                 continue;
18861                         }
18862
18863                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18864                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18865
18866                         /* Skip pairs that cannot fit into one location */
18867                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18868                         {
18869                                 continue;
18870                         }
18871
18872                         const GLuint gohan = 0;
18873                         const GLuint goten = gohan + n_req_components_gohan;
18874
18875                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18876                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18877
18878                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18879                                                                                   type_gohan, type_goten };
18880
18881                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18882                                                                                   type_gohan, type_goten };
18883
18884                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18885                                                                                   type_gohan, type_goten };
18886
18887                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18888                                                                                   type_gohan, type_goten };
18889
18890                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18891                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18892                                                                                  type_gohan,   type_goten };
18893
18894                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18895                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18896                                                                                  type_gohan,   type_goten };
18897
18898                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18899                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18900                                                                                  type_gohan,   type_goten };
18901
18902                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
18903                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18904                                                                                  type_gohan,   type_goten };
18905
18906                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
18907                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18908                                                                                  type_gohan,   type_goten };
18909
18910                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
18911                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18912                                                                                  type_gohan,   type_goten };
18913
18914                         m_test_cases.push_back(test_case_tcs_np);
18915                         m_test_cases.push_back(test_case_tcs_pn);
18916                         m_test_cases.push_back(test_case_tes_np);
18917                         m_test_cases.push_back(test_case_tes_pn);
18918                         m_test_cases.push_back(test_case_fs_nc);
18919                         m_test_cases.push_back(test_case_fs_cn);
18920                         m_test_cases.push_back(test_case_fs_ns);
18921                         m_test_cases.push_back(test_case_fs_sn);
18922                         m_test_cases.push_back(test_case_fs_cs);
18923                         m_test_cases.push_back(test_case_fs_sc);
18924                 }
18925         }
18926 }
18927
18928 /** Get auxiliary storage qualifier
18929  *
18930  * @param aux Enumeration
18931  *
18932  * @return GLSL qualifier
18933  **/
18934 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
18935 {
18936         const GLchar* result = 0;
18937
18938         switch (aux)
18939         {
18940         case NONE:
18941                 result = "";
18942                 break;
18943         case PATCH:
18944                 result = "patch";
18945                 break;
18946         case CENTROID:
18947                 result = "centroid";
18948                 break;
18949         case SAMPLE:
18950                 result = "sample";
18951                 break;
18952         default:
18953                 TCU_FAIL("Invalid enum");
18954         }
18955
18956         return result;
18957 }
18958
18959 /** Check if given type is float
18960  *
18961  * @param type Type in question
18962  *
18963  * @return true if tpye is float, false otherwise
18964  **/
18965 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
18966 {
18967         bool is_float = false;
18968
18969         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18970         {
18971                 is_float = true;
18972         }
18973
18974         return is_float;
18975 }
18976
18977 /* Constants used by VertexAttribLocationAPITest */
18978 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
18979
18980 /** Constructor
18981  *
18982  * @param context Test framework context
18983  **/
18984 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
18985         : TextureTestBase(context, "vertex_attrib_location_api",
18986                                           "Test verifies that attribute locations API works as expected")
18987 {
18988 }
18989
18990 /** Does BindAttribLocation for "goten" and relink program
18991  *
18992  * @param program           Program object
18993  * @param program_interface Interface of program
18994  **/
18995 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
18996                                                                                                                 Utils::ProgramInterface& program_interface)
18997 {
18998         const Functions& gl = m_context.getRenderContext().getFunctions();
18999
19000         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
19001         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
19002
19003         program.Link(gl, program.m_id);
19004
19005         /* We still need to get locations for gohan and chichi */
19006         TextureTestBase::prepareAttribLocation(program, program_interface);
19007 }
19008
19009 /** Get interface of program
19010  *
19011  * @param ignored
19012  * @param program_interface   Interface of program
19013  * @param ignored
19014  **/
19015 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19016                                                                                                           Utils::ProgramInterface& program_interface,
19017                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19018 {
19019         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19020         const Utils::Type&              type      = Utils::Type::vec4;
19021         const GLuint                    type_size = type.GetSize();
19022
19023         /* Offsets */
19024         const GLuint chichi_offset = 0;
19025         const GLuint goten_offset  = chichi_offset + type_size;
19026         const GLuint gohan_offset  = goten_offset + type_size;
19027         const GLuint goku_offset   = gohan_offset + type_size;
19028
19029         /* Locations */
19030         const GLuint goku_location  = 2;
19031         const GLuint goten_location = m_goten_location;
19032
19033         /* Generate data */
19034         m_goku_data   = type.GenerateDataPacked();
19035         m_gohan_data  = type.GenerateDataPacked();
19036         m_goten_data  = type.GenerateDataPacked();
19037         m_chichi_data = type.GenerateDataPacked();
19038
19039         /* Globals */
19040         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19041
19042         /* Attributes */
19043         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19044                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19045                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19046                          m_goku_data.size() /* data_size */);
19047
19048         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19049                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19050                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19051                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19052
19053         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19054                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19055                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19056                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19057
19058         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19059                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19060                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19061                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19062 }
19063
19064 /** Selects if "compute" stage is relevant for test
19065  *
19066  * @param ignored
19067  *
19068  * @return false
19069  **/
19070 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19071 {
19072         return false;
19073 }
19074
19075 /* Constants used by FragmentDataLocationAPITest */
19076 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19077
19078 /** Constructor
19079  *
19080  * @param context Test framework context
19081  **/
19082 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19083         : TextureTestBase(context, "fragment_data_location_api",
19084                                           "Test verifies that fragment data locations API works as expected")
19085         , m_goku(context)
19086         , m_gohan(context)
19087         , m_goten(context)
19088         , m_chichi(context)
19089 {
19090 }
19091
19092 /** Verifies contents of drawn images
19093  *
19094  * @param ignored
19095  * @param ignored
19096  *
19097  * @return true if images are filled with expected values, false otherwise
19098  **/
19099 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19100 {
19101         static const GLuint size                        = m_width * m_height;
19102         static const GLuint expected_goku   = 0xff000000;
19103         static const GLuint expected_gohan  = 0xff0000ff;
19104         static const GLuint expected_goten  = 0xff00ff00;
19105         static const GLuint expected_chichi = 0xffff0000;
19106
19107         std::vector<GLuint> data;
19108         data.resize(size);
19109
19110         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19111
19112         for (GLuint i = 0; i < size; ++i)
19113         {
19114                 const GLuint color = data[i];
19115
19116                 if (expected_goku != color)
19117                 {
19118                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19119                                                                                                 << tcu::TestLog::EndMessage;
19120                         return false;
19121                 }
19122         }
19123
19124         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19125
19126         for (GLuint i = 0; i < size; ++i)
19127         {
19128                 const GLuint color = data[i];
19129
19130                 if (expected_gohan != color)
19131                 {
19132                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19133                                                                                                 << tcu::TestLog::EndMessage;
19134                         return false;
19135                 }
19136         }
19137
19138         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19139
19140         for (GLuint i = 0; i < size; ++i)
19141         {
19142                 const GLuint color = data[i];
19143
19144                 if (expected_goten != color)
19145                 {
19146                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19147                                                                                                 << tcu::TestLog::EndMessage;
19148                         return false;
19149                 }
19150         }
19151
19152         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19153
19154         for (GLuint i = 0; i < size; ++i)
19155         {
19156                 const GLuint color = data[i];
19157
19158                 if (expected_chichi != color)
19159                 {
19160                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19161                                                                                                 << tcu::TestLog::EndMessage;
19162                         return false;
19163                 }
19164         }
19165
19166         return true;
19167 }
19168
19169 /** Prepare code snippet that will set out variables
19170  *
19171  * @param ignored
19172  * @param ignored
19173  * @param stage               Shader stage
19174  *
19175  * @return Code that pass in variables to next stage
19176  **/
19177 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19178                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19179                                                                                                                 Utils::Shader::STAGES stage)
19180 {
19181         std::string result;
19182
19183         /* Skip for compute shader */
19184         if (Utils::Shader::FRAGMENT != stage)
19185         {
19186                 result = "";
19187         }
19188         else
19189         {
19190                 result = "chichi = vec4(0, 0, 1, 1);\n"
19191                                  "    goku   = vec4(0, 0, 0, 1);\n"
19192                                  "    goten  = vec4(0, 1, 0, 1);\n"
19193                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19194         }
19195
19196         return result;
19197 }
19198
19199 /** Get interface of program
19200  *
19201  * @param ignored
19202  * @param program_interface Interface of program
19203  * @param ignored
19204  **/
19205 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19206                                                                                                           Utils::ProgramInterface& program_interface,
19207                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19208 {
19209         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19210         const Utils::Type&              type = Utils::Type::vec4;
19211
19212         /* Locations */
19213         m_goku_location = 2;
19214
19215         /* Globals */
19216         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19217
19218         /* Attributes */
19219         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19220                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19221                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19222
19223         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19224                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19225                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19226
19227         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19228                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19229                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19230
19231         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19232                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19233                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19234 }
19235
19236 /** Selects if "compute" stage is relevant for test
19237  *
19238  * @param ignored
19239  *
19240  * @return false
19241  **/
19242 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19243 {
19244         return false;
19245 }
19246
19247 /** Get locations for all outputs with automatic_location
19248  *
19249  * @param program           Program object
19250  * @param program_interface Interface of program
19251  **/
19252 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19253                                                                                                                  Utils::ProgramInterface& program_interface)
19254 {
19255         /* Bind location of goten */
19256         const Functions& gl = m_context.getRenderContext().getFunctions();
19257
19258         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19259         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19260
19261         program.Link(gl, program.m_id);
19262
19263         /* Prepare locations for gohan and chichi */
19264         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19265
19266         /* Get all locations */
19267         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19268
19269         Utils::Variable::PtrVector& outputs = si.m_outputs;
19270
19271         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19272         {
19273                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19274
19275                 if (0 == desc.m_name.compare("gohan"))
19276                 {
19277                         m_gohan_location = desc.m_expected_location;
19278                 }
19279                 else if (0 == desc.m_name.compare("chichi"))
19280                 {
19281                         m_chichi_location = desc.m_expected_location;
19282                 }
19283
19284                 /* Locations of goku and goten are fixed */
19285         }
19286 }
19287
19288 /** Prepare framebuffer with single texture as color attachment
19289  *
19290  * @param framebuffer     Framebuffer
19291  * @param color_0_texture Texture that will used as color attachment
19292  **/
19293 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19294 {
19295         /* Let parent prepare its stuff */
19296         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19297
19298         /* Prepare data */
19299         std::vector<GLuint> texture_data;
19300         texture_data.resize(m_width * m_height);
19301
19302         for (GLuint i = 0; i < texture_data.size(); ++i)
19303         {
19304                 texture_data[i] = 0x20406080;
19305         }
19306
19307         /* Prepare textures */
19308         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19309
19310         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19311
19312         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19313
19314         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19315
19316         /* Attach textures to framebuffer */
19317         framebuffer.Bind();
19318         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19319         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19320         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19321         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19322
19323         /* Set up drawbuffers */
19324         const Functions& gl = m_context.getRenderContext().getFunctions();
19325         //  1. There are only 4 outputs in fragment shader, so only need to do buffer mapping for 4 attachments,
19326         //  2. another issue is each output variable has a location, it is the fragment color index, so the index of
19327         //  GL_COLOR_ATTACHMENT in glDrawBuffers() should keep the same with the location, to make test correct,
19328         //  we needt to change the above code of glDrawBuffers() as :
19329         GLint  buffers_size = 4;
19330         GLenum buffers[]        = { GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location),
19331                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location),
19332                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location),
19333                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location) };
19334         gl.drawBuffers(buffers_size, buffers);
19335         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19336 }
19337
19338 /** Constructor
19339  *
19340  * @param context Test framework context
19341  **/
19342 XFBInputTest::XFBInputTest(deqp::Context& context)
19343         : NegativeTestBase(context, "xfb_input",
19344                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19345 {
19346 }
19347
19348 /** Source for given test case and stage
19349  *
19350  * @param test_case_index Index of test case
19351  * @param stage           Shader stage
19352  *
19353  * @return Shader source
19354  **/
19355 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19356 {
19357         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19358         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19359         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19360         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19361         static const GLchar* fs                                    = "#version 430 core\n"
19362                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19363                                                           "\n"
19364                                                           "in  vec4 gs_fs;\n"
19365                                                           "out vec4 fs_out;\n"
19366                                                           "\n"
19367                                                           "void main()\n"
19368                                                           "{\n"
19369                                                           "    fs_out = gs_fs;\n"
19370                                                           "}\n"
19371                                                           "\n";
19372         static const GLchar* fs_tested = "#version 430 core\n"
19373                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19374                                                                          "\n"
19375                                                                          "VAR_DEFINITION"
19376                                                                          "\n"
19377                                                                          "in  vec4 gs_fs;\n"
19378                                                                          "out vec4 fs_out;\n"
19379                                                                          "\n"
19380                                                                          "void main()\n"
19381                                                                          "{\n"
19382                                                                          "    vec4 result = gs_fs;\n"
19383                                                                          "\n"
19384                                                                          "VARIABLE_USE"
19385                                                                          "\n"
19386                                                                          "    fs_out = result;\n"
19387                                                                          "}\n"
19388                                                                          "\n";
19389         static const GLchar* gs = "#version 430 core\n"
19390                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19391                                                           "\n"
19392                                                           "layout(points)                           in;\n"
19393                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19394                                                           "\n"
19395                                                           "in  vec4 tes_gs[];\n"
19396                                                           "out vec4 gs_fs;\n"
19397                                                           "\n"
19398                                                           "void main()\n"
19399                                                           "{\n"
19400                                                           "    gs_fs = tes_gs[0];\n"
19401                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19402                                                           "    EmitVertex();\n"
19403                                                           "    gs_fs = tes_gs[0];\n"
19404                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19405                                                           "    EmitVertex();\n"
19406                                                           "    gs_fs = tes_gs[0];\n"
19407                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19408                                                           "    EmitVertex();\n"
19409                                                           "    gs_fs = tes_gs[0];\n"
19410                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19411                                                           "    EmitVertex();\n"
19412                                                           "}\n"
19413                                                           "\n";
19414         static const GLchar* gs_tested = "#version 430 core\n"
19415                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19416                                                                          "\n"
19417                                                                          "layout(points)                           in;\n"
19418                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19419                                                                          "\n"
19420                                                                          "VAR_DEFINITION"
19421                                                                          "\n"
19422                                                                          "in  vec4 tes_gs[];\n"
19423                                                                          "out vec4 gs_fs;\n"
19424                                                                          "\n"
19425                                                                          "void main()\n"
19426                                                                          "{\n"
19427                                                                          "    vec4 result = tes_gs[0];\n"
19428                                                                          "\n"
19429                                                                          "VARIABLE_USE"
19430                                                                          "\n"
19431                                                                          "    gs_fs = result;\n"
19432                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19433                                                                          "    EmitVertex();\n"
19434                                                                          "    gs_fs = result;\n"
19435                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19436                                                                          "    EmitVertex();\n"
19437                                                                          "    gs_fs = result;\n"
19438                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19439                                                                          "    EmitVertex();\n"
19440                                                                          "    gs_fs = result;\n"
19441                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19442                                                                          "    EmitVertex();\n"
19443                                                                          "}\n"
19444                                                                          "\n";
19445         static const GLchar* tcs = "#version 430 core\n"
19446                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19447                                                            "\n"
19448                                                            "layout(vertices = 1) out;\n"
19449                                                            "\n"
19450                                                            "in  vec4 vs_tcs[];\n"
19451                                                            "out vec4 tcs_tes[];\n"
19452                                                            "\n"
19453                                                            "void main()\n"
19454                                                            "{\n"
19455                                                            "\n"
19456                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19457                                                            "\n"
19458                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19459                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19460                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19461                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19462                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19463                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19464                                                            "}\n"
19465                                                            "\n";
19466         static const GLchar* tcs_tested = "#version 430 core\n"
19467                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19468                                                                           "\n"
19469                                                                           "layout(vertices = 1) out;\n"
19470                                                                           "\n"
19471                                                                           "VAR_DEFINITION"
19472                                                                           "\n"
19473                                                                           "in  vec4 vs_tcs[];\n"
19474                                                                           "out vec4 tcs_tes[];\n"
19475                                                                           "\n"
19476                                                                           "void main()\n"
19477                                                                           "{\n"
19478                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19479                                                                           "\n"
19480                                                                           "VARIABLE_USE"
19481                                                                           "\n"
19482                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19483                                                                           "\n"
19484                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19485                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19486                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19487                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19488                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19489                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19490                                                                           "}\n"
19491                                                                           "\n";
19492         static const GLchar* tes = "#version 430 core\n"
19493                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19494                                                            "\n"
19495                                                            "layout(isolines, point_mode) in;\n"
19496                                                            "\n"
19497                                                            "in  vec4 tcs_tes[];\n"
19498                                                            "out vec4 tes_gs;\n"
19499                                                            "\n"
19500                                                            "void main()\n"
19501                                                            "{\n"
19502                                                            "    tes_gs = tcs_tes[0];\n"
19503                                                            "}\n"
19504                                                            "\n";
19505         static const GLchar* tes_tested = "#version 430 core\n"
19506                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19507                                                                           "\n"
19508                                                                           "layout(isolines, point_mode) in;\n"
19509                                                                           "\n"
19510                                                                           "VAR_DEFINITION"
19511                                                                           "\n"
19512                                                                           "in  vec4 tcs_tes[];\n"
19513                                                                           "out vec4 tes_gs;\n"
19514                                                                           "\n"
19515                                                                           "void main()\n"
19516                                                                           "{\n"
19517                                                                           "    vec4 result = tcs_tes[0];\n"
19518                                                                           "\n"
19519                                                                           "VARIABLE_USE"
19520                                                                           "\n"
19521                                                                           "    tes_gs += result;\n"
19522                                                                           "}\n"
19523                                                                           "\n";
19524         static const GLchar* vs = "#version 430 core\n"
19525                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19526                                                           "\n"
19527                                                           "in  vec4 in_vs;\n"
19528                                                           "out vec4 vs_tcs;\n"
19529                                                           "\n"
19530                                                           "void main()\n"
19531                                                           "{\n"
19532                                                           "    vs_tcs = in_vs;\n"
19533                                                           "}\n"
19534                                                           "\n";
19535         static const GLchar* vs_tested = "#version 430 core\n"
19536                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19537                                                                          "\n"
19538                                                                          "VAR_DEFINITION"
19539                                                                          "\n"
19540                                                                          "in  vec4 in_vs;\n"
19541                                                                          "out vec4 vs_tcs;\n"
19542                                                                          "\n"
19543                                                                          "void main()\n"
19544                                                                          "{\n"
19545                                                                          "    vec4 result = in_vs;\n"
19546                                                                          "\n"
19547                                                                          "VARIABLE_USE"
19548                                                                          "\n"
19549                                                                          "    vs_tcs += result;\n"
19550                                                                          "}\n"
19551                                                                          "\n";
19552
19553         std::string source;
19554         testCase&   test_case = m_test_cases[test_case_index];
19555
19556         if (test_case.m_stage == stage)
19557         {
19558                 const GLchar* array     = "";
19559                 const GLchar* index     = "";
19560                 size_t            position = 0;
19561                 size_t            temp;
19562                 const GLchar* var_definition = 0;
19563                 const GLchar* var_use            = input_use;
19564
19565                 switch (test_case.m_qualifier)
19566                 {
19567                 case BUFFER:
19568                         var_definition = buffer_var_definition;
19569                         break;
19570                 case OFFSET:
19571                         var_definition = offset_var_definition;
19572                         break;
19573                 case STRIDE:
19574                         var_definition = stride_var_definition;
19575                         break;
19576                 default:
19577                         TCU_FAIL("Invalid enum");
19578                 }
19579
19580                 switch (stage)
19581                 {
19582                 case Utils::Shader::FRAGMENT:
19583                         source = fs_tested;
19584                         break;
19585                 case Utils::Shader::GEOMETRY:
19586                         source = gs_tested;
19587                         array  = "[]";
19588                         index  = "[0]";
19589                         break;
19590                 case Utils::Shader::TESS_CTRL:
19591                         source = tcs_tested;
19592                         array  = "[]";
19593                         index  = "[gl_InvocationID]";
19594                         break;
19595                 case Utils::Shader::TESS_EVAL:
19596                         source = tes_tested;
19597                         array  = "[]";
19598                         index  = "[0]";
19599                         break;
19600                 case Utils::Shader::VERTEX:
19601                         source = vs_tested;
19602                         break;
19603                 default:
19604                         TCU_FAIL("Invalid enum");
19605                 }
19606
19607                 temp = position;
19608                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19609                 position = temp;
19610                 Utils::replaceToken("ARRAY", position, array, source);
19611                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19612
19613                 Utils::replaceAllTokens("INDEX", index, source);
19614         }
19615         else
19616         {
19617                 switch (stage)
19618                 {
19619                 case Utils::Shader::FRAGMENT:
19620                         source = fs;
19621                         break;
19622                 case Utils::Shader::GEOMETRY:
19623                         source = gs;
19624                         break;
19625                 case Utils::Shader::TESS_CTRL:
19626                         source = tcs;
19627                         break;
19628                 case Utils::Shader::TESS_EVAL:
19629                         source = tes;
19630                         break;
19631                 case Utils::Shader::VERTEX:
19632                         source = vs;
19633                         break;
19634                 default:
19635                         TCU_FAIL("Invalid enum");
19636                 }
19637         }
19638
19639         return source;
19640 }
19641
19642 /** Get description of test case
19643  *
19644  * @param test_case_index Index of test case
19645  *
19646  * @return Test case description
19647  **/
19648 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19649 {
19650         std::stringstream stream;
19651         testCase&                 test_case = m_test_cases[test_case_index];
19652
19653         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19654
19655         switch (test_case.m_qualifier)
19656         {
19657         case BUFFER:
19658                 stream << "xfb_buffer";
19659                 break;
19660         case OFFSET:
19661                 stream << "xfb_offset";
19662                 break;
19663         case STRIDE:
19664                 stream << "xfb_stride";
19665                 break;
19666         default:
19667                 TCU_FAIL("Invalid enum");
19668         }
19669
19670         return stream.str();
19671 }
19672
19673 /** Get number of test cases
19674  *
19675  * @return Number of test cases
19676  **/
19677 GLuint XFBInputTest::getTestCaseNumber()
19678 {
19679         return static_cast<GLuint>(m_test_cases.size());
19680 }
19681
19682 /** Selects if "compute" stage is relevant for test
19683  *
19684  * @param ignored
19685  *
19686  * @return false
19687  **/
19688 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19689 {
19690         return false;
19691 }
19692
19693 /** Prepare all test cases
19694  *
19695  **/
19696 void XFBInputTest::testInit()
19697 {
19698         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19699         {
19700                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19701                 {
19702                         if (Utils::Shader::COMPUTE == stage)
19703                         {
19704                                 continue;
19705                         }
19706
19707                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19708
19709                         m_test_cases.push_back(test_case);
19710                 }
19711         }
19712 }
19713
19714 /* Constants used by XFBAllStagesTest */
19715 const GLuint XFBAllStagesTest::m_gs_index = 3;
19716
19717 /** Constructor
19718  *
19719  * @param context Test context
19720  **/
19721 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19722         : BufferTestBase(context, "xfb_all_stages",
19723                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19724 {
19725         /* Nothing to be done here */
19726 }
19727
19728 /** Get descriptors of buffers necessary for test
19729  *
19730  * @param ignored
19731  * @param out_descriptors Descriptors of buffers used by test
19732  **/
19733 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19734                                                                                         bufferDescriptor::Vector& out_descriptors)
19735 {
19736         static const GLuint n_stages = 4;
19737         const Utils::Type&  vec4         = Utils::Type::vec4;
19738
19739         /* Data */
19740         tcu::Vec4 sum;
19741
19742         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19743         out_descriptors.resize(n_stages * 2 + 1);
19744
19745         /* */
19746         for (GLuint i = 0; i < n_stages; ++i)
19747         {
19748                 /* Get references */
19749                 bufferDescriptor& uniform = out_descriptors[i + 0];
19750                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19751
19752                 /* Index */
19753                 uniform.m_index = i;
19754                 xfb.m_index             = i;
19755
19756                 /* Target */
19757                 uniform.m_target = Utils::Buffer::Uniform;
19758                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19759
19760                 /* Data */
19761                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19762
19763                 sum += var;
19764
19765                 uniform.m_initial_data.resize(vec4.GetSize());
19766                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19767
19768                 xfb.m_initial_data = vec4.GenerateDataPacked();
19769
19770                 if (m_gs_index != i)
19771                 {
19772                         xfb.m_expected_data = xfb.m_initial_data;
19773                 }
19774                 else
19775                 {
19776                         xfb.m_expected_data.resize(vec4.GetSize());
19777                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19778                 }
19779         }
19780
19781         /* FS */
19782         {
19783                 /* Get reference */
19784                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19785
19786                 /* Index */
19787                 uniform.m_index = n_stages;
19788
19789                 /* Target */
19790                 uniform.m_target = Utils::Buffer::Uniform;
19791
19792                 /* Data */
19793                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19794
19795                 uniform.m_initial_data.resize(vec4.GetSize());
19796                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19797         }
19798 }
19799
19800 /** Get body of main function for given shader stage
19801  *
19802  * @param ignored
19803  * @param stage            Shader stage
19804  * @param out_assignments  Set to empty
19805  * @param out_calculations Set to empty
19806  **/
19807 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19808                                                                          std::string& out_assignments, std::string& out_calculations)
19809 {
19810         out_calculations = "";
19811
19812         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19813         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19814         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19815         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19816         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19817
19818         const GLchar* assignments = 0;
19819         switch (stage)
19820         {
19821         case Utils::Shader::FRAGMENT:
19822                 assignments = fs;
19823                 break;
19824         case Utils::Shader::GEOMETRY:
19825                 assignments = gs;
19826                 break;
19827         case Utils::Shader::TESS_CTRL:
19828                 assignments = tcs;
19829                 break;
19830         case Utils::Shader::TESS_EVAL:
19831                 assignments = tes;
19832                 break;
19833         case Utils::Shader::VERTEX:
19834                 assignments = vs;
19835                 break;
19836         default:
19837                 TCU_FAIL("Invalid enum");
19838         }
19839
19840         out_assignments = assignments;
19841 }
19842
19843 /** Get interface of shader
19844  *
19845  * @param ignored
19846  * @param stage         Shader stage
19847  * @param out_interface Set to ""
19848  **/
19849 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19850                                                                                   std::string& out_interface)
19851 {
19852         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19853                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19854                                                           "    vec4 uni_vs;\n"
19855                                                           "};\n";
19856         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19857                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19858                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19859                                                            "    vec4 uni_tcs;\n"
19860                                                            "};\n";
19861         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19862                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19863                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19864                                                            "    vec4 uni_tes;\n"
19865                                                            "};\n";
19866         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19867                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19868                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19869                                                           "    vec4 uni_gs;\n"
19870                                                           "};\n";
19871         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19872                                                           "                       out     vec4 fs_out;\n"
19873                                                           "layout(binding    = 4) uniform fs_block {\n"
19874                                                           "    vec4 uni_fs;\n"
19875                                                           "};\n";
19876
19877         const GLchar* interface = 0;
19878         switch (stage)
19879         {
19880         case Utils::Shader::FRAGMENT:
19881                 interface = fs;
19882                 break;
19883         case Utils::Shader::GEOMETRY:
19884                 interface = gs;
19885                 break;
19886         case Utils::Shader::TESS_CTRL:
19887                 interface = tcs;
19888                 break;
19889         case Utils::Shader::TESS_EVAL:
19890                 interface = tes;
19891                 break;
19892         case Utils::Shader::VERTEX:
19893                 interface = vs;
19894                 break;
19895         default:
19896                 TCU_FAIL("Invalid enum");
19897         }
19898
19899         out_interface = interface;
19900 }
19901
19902 /* Constants used by XFBStrideOfEmptyListTest */
19903 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
19904
19905 /** Constructor
19906  *
19907  * @param context Test context
19908  **/
19909 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
19910         : BufferTestBase(context, "xfb_stride_of_empty_list",
19911                                          "Test verifies that xfb_stride qualifier is respected when no xfb_offset is specified")
19912 {
19913         /* Nothing to be done here */
19914 }
19915
19916 /** Execute drawArrays for single vertex
19917  *
19918  * @param test_case_index Index of test case
19919  *
19920  * @return true if proper error is reported
19921  **/
19922 bool XFBStrideOfEmptyListTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
19923 {
19924         const Functions& gl             = m_context.getRenderContext().getFunctions();
19925         bool                     result = true;
19926
19927         /* Draw */
19928         gl.disable(GL_RASTERIZER_DISCARD);
19929         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
19930
19931         gl.beginTransformFeedback(GL_POINTS);
19932         GLenum error = gl.getError();
19933         switch (test_case_index)
19934         {
19935         case VALID:
19936                 if (GL_NO_ERROR != error)
19937                 {
19938                         gl.endTransformFeedback();
19939                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
19940                 }
19941
19942                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
19943                 error = gl.getError();
19944
19945                 gl.endTransformFeedback();
19946                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
19947                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
19948
19949                 break;
19950
19951         case FIRST_MISSING:
19952                 if (GL_NO_ERROR == error)
19953                 {
19954                         gl.endTransformFeedback();
19955                 }
19956
19957                 if (GL_INVALID_OPERATION != error)
19958                 {
19959                         m_context.getTestContext().getLog()
19960                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
19961                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19962                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19963
19964                         result = false;
19965                 }
19966
19967                 break;
19968
19969         case SECOND_MISSING:
19970                 if (GL_NO_ERROR == error)
19971                 {
19972                         gl.endTransformFeedback();
19973                 }
19974
19975                 if (GL_INVALID_OPERATION != error)
19976                 {
19977                         m_context.getTestContext().getLog()
19978                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
19979                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19980                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19981
19982                         result = false;
19983                 }
19984
19985                 break;
19986         }
19987
19988         /* Done */
19989         return result;
19990 }
19991
19992 /** Get descriptors of buffers necessary for test
19993  *
19994  * @param test_case_index Index of test case
19995  * @param out_descriptors Descriptors of buffers used by test
19996  **/
19997 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
19998                                                                                                         bufferDescriptor::Vector& out_descriptors)
19999 {
20000         switch (test_case_index)
20001         {
20002         case VALID:
20003         {
20004                 /* Test needs single uniform and two xfbs */
20005                 out_descriptors.resize(3);
20006
20007                 /* Get references */
20008                 bufferDescriptor& uniform = out_descriptors[0];
20009                 bufferDescriptor& xfb_0   = out_descriptors[1];
20010                 bufferDescriptor& xfb_1   = out_descriptors[2];
20011
20012                 /* Index */
20013                 uniform.m_index = 0;
20014                 xfb_0.m_index   = 0;
20015                 xfb_1.m_index   = 1;
20016
20017                 /* Target */
20018                 uniform.m_target = Utils::Buffer::Uniform;
20019                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20020                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20021
20022                 /* Data */
20023                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20024
20025                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20026                 xfb_0.m_expected_data = uniform.m_initial_data;
20027
20028                 /* Data, contents are the same as no modification is expected */
20029                 xfb_1.m_initial_data.resize(m_stride);
20030                 xfb_1.m_expected_data.resize(m_stride);
20031
20032                 for (GLuint i = 0; i < m_stride; ++i)
20033                 {
20034                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20035                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20036                 }
20037         }
20038
20039         break;
20040
20041         case FIRST_MISSING:
20042         {
20043                 /* Test needs single uniform and two xfbs */
20044                 out_descriptors.resize(2);
20045
20046                 /* Get references */
20047                 bufferDescriptor& uniform = out_descriptors[0];
20048                 bufferDescriptor& xfb_1   = out_descriptors[1];
20049
20050                 /* Index */
20051                 uniform.m_index = 0;
20052                 xfb_1.m_index   = 1;
20053
20054                 /* Target */
20055                 uniform.m_target = Utils::Buffer::Uniform;
20056                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20057
20058                 /* Data */
20059                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20060
20061                 /* Draw call will not be executed, contents does not matter */
20062                 xfb_1.m_initial_data.resize(m_stride);
20063         }
20064
20065         break;
20066
20067         case SECOND_MISSING:
20068         {
20069                 /* Test needs single uniform and two xfbs */
20070                 out_descriptors.resize(2);
20071
20072                 /* Get references */
20073                 bufferDescriptor& uniform = out_descriptors[0];
20074                 bufferDescriptor& xfb_0   = out_descriptors[1];
20075
20076                 /* Index */
20077                 uniform.m_index = 0;
20078                 xfb_0.m_index   = 0;
20079
20080                 /* Target */
20081                 uniform.m_target = Utils::Buffer::Uniform;
20082                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20083
20084                 /* Data */
20085                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20086
20087                 /* Draw call will not be executed, contents does not matter */
20088                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20089         }
20090
20091         break;
20092         }
20093 }
20094
20095 /** Get body of main function for given shader stage
20096  *
20097  * @param ignored
20098  * @param stage            Shader stage
20099  * @param out_assignments  Set to empty
20100  * @param out_calculations Set to empty
20101  **/
20102 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20103                                                                                          std::string& out_assignments, std::string& out_calculations)
20104 {
20105         out_calculations = "";
20106
20107         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20108         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20109
20110         const GLchar* assignments = "";
20111         switch (stage)
20112         {
20113         case Utils::Shader::FRAGMENT:
20114                 assignments = fs;
20115                 break;
20116         case Utils::Shader::GEOMETRY:
20117                 assignments = gs;
20118                 break;
20119         default:
20120                 break;
20121         }
20122
20123         out_assignments = assignments;
20124 }
20125
20126 /** Get interface of shader
20127  *
20128  * @param ignored
20129  * @param stage            Shader stage
20130  * @param out_interface    Set to ""
20131  **/
20132 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20133                                                                                                   std::string& out_interface)
20134 {
20135         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20136                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20137                                                           "\n"
20138                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20139                                                           "    vec4 uni_gs;\n"
20140                                                           "};\n";
20141         static const GLchar* fs = "in  vec4 gs_fs;\n"
20142                                                           "out vec4 fs_out;\n";
20143
20144         switch (stage)
20145         {
20146         case Utils::Shader::FRAGMENT:
20147                 out_interface = fs;
20148                 break;
20149         case Utils::Shader::GEOMETRY:
20150                 out_interface = gs;
20151                 break;
20152         default:
20153                 out_interface = "";
20154                 return;
20155         }
20156 }
20157
20158 /** Returns buffer details in human readable form.
20159  *
20160  * @param test_case_index Index of test case
20161  *
20162  * @return Case description
20163  **/
20164 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20165 {
20166         std::string result;
20167
20168         switch (test_case_index)
20169         {
20170         case VALID:
20171                 result = "Valid case";
20172                 break;
20173         case FIRST_MISSING:
20174                 result = "Missing xfb at index 0";
20175                 break;
20176         case SECOND_MISSING:
20177                 result = "Missing xfb at index 1";
20178                 break;
20179         default:
20180                 TCU_FAIL("Invalid enum");
20181         }
20182
20183         return result;
20184 }
20185
20186 /** Get number of test cases
20187  *
20188  * @return 3
20189  **/
20190 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20191 {
20192         return 3;
20193 }
20194
20195 /* Constants used by XFBStrideOfEmptyListTest */
20196 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20197
20198 /** Constructor
20199  *
20200  * @param context Test context
20201  **/
20202 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20203         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20204                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20205 {
20206         /* Nothing to be done here */
20207 }
20208
20209 /** Execute drawArrays for single vertex
20210  *
20211  * @param test_case_index Index of test case
20212  *
20213  * @return true if proper error is reported
20214  **/
20215 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
20216 {
20217         const Functions& gl             = m_context.getRenderContext().getFunctions();
20218         bool                     result = true;
20219
20220         /* Draw */
20221         gl.disable(GL_RASTERIZER_DISCARD);
20222         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20223
20224         gl.beginTransformFeedback(GL_POINTS);
20225         GLenum error = gl.getError();
20226         switch (test_case_index)
20227         {
20228         case VALID:
20229                 if (GL_NO_ERROR != error)
20230                 {
20231                         gl.endTransformFeedback();
20232                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20233                 }
20234
20235                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20236                 error = gl.getError();
20237
20238                 gl.endTransformFeedback();
20239                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20240                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20241
20242                 break;
20243
20244         case FIRST_MISSING:
20245                 if (GL_NO_ERROR == error)
20246                 {
20247                         gl.endTransformFeedback();
20248                 }
20249
20250                 if (GL_INVALID_OPERATION != error)
20251                 {
20252                         m_context.getTestContext().getLog()
20253                                 << tcu::TestLog::Message << "XFB at index 0, that is declared as empty, is missing. It was expected "
20254                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20255                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20256
20257                         result = false;
20258                 }
20259
20260                 break;
20261
20262         case SECOND_MISSING:
20263                 if (GL_NO_ERROR == error)
20264                 {
20265                         gl.endTransformFeedback();
20266                 }
20267
20268                 if (GL_INVALID_OPERATION != error)
20269                 {
20270                         m_context.getTestContext().getLog()
20271                                 << tcu::TestLog::Message << "XFB at index 1, that is written by GS, is missing. It was expected that "
20272                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20273                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20274
20275                         result = false;
20276                 }
20277
20278                 break;
20279         }
20280
20281         /* Done */
20282         return result;
20283 }
20284
20285 /** Get descriptors of buffers necessary for test
20286  *
20287  * @param test_case_index Index of test case
20288  * @param out_descriptors Descriptors of buffers used by test
20289  **/
20290 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20291                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20292 {
20293         switch (test_case_index)
20294         {
20295         case VALID:
20296         {
20297                 /* Test needs single uniform and two xfbs */
20298                 out_descriptors.resize(3);
20299
20300                 /* Get references */
20301                 bufferDescriptor& uniform = out_descriptors[0];
20302                 bufferDescriptor& xfb_0   = out_descriptors[1];
20303                 bufferDescriptor& xfb_1   = out_descriptors[2];
20304
20305                 /* Index */
20306                 uniform.m_index = 0;
20307                 xfb_0.m_index   = 0;
20308                 xfb_1.m_index   = 1;
20309
20310                 /* Target */
20311                 uniform.m_target = Utils::Buffer::Uniform;
20312                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20313                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20314
20315                 /* Data */
20316                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20317
20318                 /* Data, contents are the same as no modification is expected */
20319                 xfb_0.m_initial_data.resize(m_stride);
20320                 xfb_0.m_expected_data.resize(m_stride);
20321
20322                 for (GLuint i = 0; i < m_stride; ++i)
20323                 {
20324                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20325                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20326                 }
20327
20328                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20329                 xfb_1.m_expected_data = uniform.m_initial_data;
20330         }
20331
20332         break;
20333
20334         case FIRST_MISSING:
20335         {
20336                 /* Test needs single uniform and two xfbs */
20337                 out_descriptors.resize(2);
20338
20339                 /* Get references */
20340                 bufferDescriptor& uniform = out_descriptors[0];
20341                 bufferDescriptor& xfb_1   = out_descriptors[1];
20342
20343                 /* Index */
20344                 uniform.m_index = 0;
20345                 xfb_1.m_index   = 1;
20346
20347                 /* Target */
20348                 uniform.m_target = Utils::Buffer::Uniform;
20349                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20350
20351                 /* Data */
20352                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20353
20354                 /* Draw call will not be executed, contents does not matter */
20355                 xfb_1.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20356         }
20357
20358         break;
20359
20360         case SECOND_MISSING:
20361         {
20362                 /* Test needs single uniform and two xfbs */
20363                 out_descriptors.resize(2);
20364
20365                 /* Get references */
20366                 bufferDescriptor& uniform = out_descriptors[0];
20367                 bufferDescriptor& xfb_0   = out_descriptors[1];
20368
20369                 /* Index */
20370                 uniform.m_index = 0;
20371                 xfb_0.m_index   = 0;
20372
20373                 /* Target */
20374                 uniform.m_target = Utils::Buffer::Uniform;
20375                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20376
20377                 /* Data */
20378                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20379
20380                 /* Draw call will not be executed, contents does not matter */
20381                 xfb_0.m_initial_data.resize(m_stride);
20382         }
20383
20384         break;
20385         }
20386 }
20387
20388 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20389  *
20390  * @param ignored
20391  * @param captured_varyings Vector of varying names to be captured
20392  **/
20393 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20394                                                                                                                  Utils::Program::NameVector& captured_varyings)
20395 {
20396         captured_varyings.push_back("gs_fs");
20397 }
20398
20399 /** Get body of main function for given shader stage
20400  *
20401  * @param ignored
20402  * @param stage            Shader stage
20403  * @param out_assignments  Set to empty
20404  * @param out_calculations Set to empty
20405  **/
20406 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20407                                                                                                    std::string& out_assignments, std::string& out_calculations)
20408 {
20409         out_calculations = "";
20410
20411         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20412         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20413
20414         const GLchar* assignments = "";
20415         switch (stage)
20416         {
20417         case Utils::Shader::FRAGMENT:
20418                 assignments = fs;
20419                 break;
20420         case Utils::Shader::GEOMETRY:
20421                 assignments = gs;
20422                 break;
20423         default:
20424                 break;
20425         }
20426
20427         out_assignments = assignments;
20428 }
20429
20430 /** Get interface of shader
20431  *
20432  * @param ignored
20433  * @param stage            Shader stage
20434  * @param out_interface    Set to ""
20435  **/
20436 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20437                                                                                                                 std::string& out_interface)
20438 {
20439         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out;\n"
20440                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs;\n"
20441                                                           "\n"
20442                                                           "layout(binding    = 0) uniform gs_block {\n"
20443                                                           "    vec4 uni_gs;\n"
20444                                                           "};\n";
20445         static const GLchar* fs = "in  vec4 gs_fs;\n"
20446                                                           "out vec4 fs_out;\n";
20447
20448         switch (stage)
20449         {
20450         case Utils::Shader::FRAGMENT:
20451                 out_interface = fs;
20452                 break;
20453         case Utils::Shader::GEOMETRY:
20454                 out_interface = gs;
20455                 break;
20456         default:
20457                 out_interface = "";
20458                 return;
20459         }
20460 }
20461
20462 /** Returns buffer details in human readable form.
20463  *
20464  * @param test_case_index Index of test case
20465  *
20466  * @return Case description
20467  **/
20468 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20469 {
20470         std::string result;
20471
20472         switch (test_case_index)
20473         {
20474         case VALID:
20475                 result = "Valid case";
20476                 break;
20477         case FIRST_MISSING:
20478                 result = "Missing xfb at index 0";
20479                 break;
20480         case SECOND_MISSING:
20481                 result = "Missing xfb at index 1";
20482                 break;
20483         default:
20484                 TCU_FAIL("Invalid enum");
20485         }
20486
20487         return result;
20488 }
20489
20490 /** Get number of test cases
20491  *
20492  * @return 2
20493  **/
20494 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20495 {
20496         return 3;
20497 }
20498
20499 /** Constructor
20500  *
20501  * @param context Test framework context
20502  **/
20503 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20504         : NegativeTestBase(context, "xfb_too_small_stride",
20505                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20506 {
20507 }
20508
20509 /** Source for given test case and stage
20510  *
20511  * @param test_case_index Index of test case
20512  * @param stage           Shader stage
20513  *
20514  * @return Shader source
20515  **/
20516 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20517 {
20518         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20519                                                                                                 "\n"
20520                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20521         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20522                                                                                                 "\n"
20523                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20524                                                                                                 "    vec4 gohan;\n"
20525                                                                                                 "    vec4 goten;\n"
20526                                                                                                 "    vec4 chichi;\n"
20527                                                                                                 "} gokuARRAY;\n";
20528         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20529                                                                                                  "\n"
20530                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20531         // 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;"
20532         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20533         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20534                                                                                                  "\n"
20535                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20536         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20537                                                                          "    gohanINDEX[1] = result / 4;\n"
20538                                                                          "    gohanINDEX[2] = result / 6;\n"
20539                                                                          "    gohanINDEX[3] = result / 8;\n";
20540         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20541                                                                          "    gokuINDEX.goten  = result / 4;\n"
20542                                                                          "    gokuINDEX.chichi = result / 6;\n";
20543         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20544         static const GLchar* fs                 = "#version 430 core\n"
20545                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20546                                                           "\n"
20547                                                           "in  vec4 gs_fs;\n"
20548                                                           "out vec4 fs_out;\n"
20549                                                           "\n"
20550                                                           "void main()\n"
20551                                                           "{\n"
20552                                                           "    fs_out = gs_fs;\n"
20553                                                           "}\n"
20554                                                           "\n";
20555         static const GLchar* gs_tested = "#version 430 core\n"
20556                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20557                                                                          "\n"
20558                                                                          "layout(points)                           in;\n"
20559                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20560                                                                          "\n"
20561                                                                          "VAR_DEFINITION"
20562                                                                          "\n"
20563                                                                          "in  vec4 tes_gs[];\n"
20564                                                                          "out vec4 gs_fs;\n"
20565                                                                          "\n"
20566                                                                          "void main()\n"
20567                                                                          "{\n"
20568                                                                          "    vec4 result = tes_gs[0];\n"
20569                                                                          "\n"
20570                                                                          "VARIABLE_USE"
20571                                                                          "\n"
20572                                                                          "    gs_fs = result;\n"
20573                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20574                                                                          "    EmitVertex();\n"
20575                                                                          "    gs_fs = result;\n"
20576                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20577                                                                          "    EmitVertex();\n"
20578                                                                          "    gs_fs = result;\n"
20579                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20580                                                                          "    EmitVertex();\n"
20581                                                                          "    gs_fs = result;\n"
20582                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20583                                                                          "    EmitVertex();\n"
20584                                                                          "}\n"
20585                                                                          "\n";
20586         static const GLchar* tcs = "#version 430 core\n"
20587                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20588                                                            "\n"
20589                                                            "layout(vertices = 1) out;\n"
20590                                                            "\n"
20591                                                            "in  vec4 vs_tcs[];\n"
20592                                                            "out vec4 tcs_tes[];\n"
20593                                                            "\n"
20594                                                            "void main()\n"
20595                                                            "{\n"
20596                                                            "\n"
20597                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20598                                                            "\n"
20599                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20600                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20601                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20602                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20603                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20604                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20605                                                            "}\n"
20606                                                            "\n";
20607         static const GLchar* tcs_tested = "#version 430 core\n"
20608                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20609                                                                           "\n"
20610                                                                           "layout(vertices = 1) out;\n"
20611                                                                           "\n"
20612                                                                           "VAR_DEFINITION"
20613                                                                           "\n"
20614                                                                           "in  vec4 vs_tcs[];\n"
20615                                                                           "out vec4 tcs_tes[];\n"
20616                                                                           "\n"
20617                                                                           "void main()\n"
20618                                                                           "{\n"
20619                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20620                                                                           "\n"
20621                                                                           "VARIABLE_USE"
20622                                                                           "\n"
20623                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20624                                                                           "\n"
20625                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20626                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20627                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20628                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20629                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20630                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20631                                                                           "}\n"
20632                                                                           "\n";
20633         static const GLchar* tes_tested = "#version 430 core\n"
20634                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20635                                                                           "\n"
20636                                                                           "layout(isolines, point_mode) in;\n"
20637                                                                           "\n"
20638                                                                           "VAR_DEFINITION"
20639                                                                           "\n"
20640                                                                           "in  vec4 tcs_tes[];\n"
20641                                                                           "out vec4 tes_gs;\n"
20642                                                                           "\n"
20643                                                                           "void main()\n"
20644                                                                           "{\n"
20645                                                                           "    vec4 result = tcs_tes[0];\n"
20646                                                                           "\n"
20647                                                                           "VARIABLE_USE"
20648                                                                           "\n"
20649                                                                           "    tes_gs += result;\n"
20650                                                                           "}\n"
20651                                                                           "\n";
20652         static const GLchar* vs = "#version 430 core\n"
20653                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20654                                                           "\n"
20655                                                           "in  vec4 in_vs;\n"
20656                                                           "out vec4 vs_tcs;\n"
20657                                                           "\n"
20658                                                           "void main()\n"
20659                                                           "{\n"
20660                                                           "    vs_tcs = in_vs;\n"
20661                                                           "}\n"
20662                                                           "\n";
20663         static const GLchar* vs_tested = "#version 430 core\n"
20664                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20665                                                                          "\n"
20666                                                                          "VAR_DEFINITION"
20667                                                                          "\n"
20668                                                                          "in  vec4 in_vs;\n"
20669                                                                          "out vec4 vs_tcs;\n"
20670                                                                          "\n"
20671                                                                          "void main()\n"
20672                                                                          "{\n"
20673                                                                          "    vec4 result = in_vs;\n"
20674                                                                          "\n"
20675                                                                          "VARIABLE_USE"
20676                                                                          "\n"
20677                                                                          "    vs_tcs += result;\n"
20678                                                                          "}\n"
20679                                                                          "\n";
20680
20681         std::string source;
20682         testCase&   test_case = m_test_cases[test_case_index];
20683
20684         if (test_case.m_stage == stage)
20685         {
20686                 const GLchar* array     = "";
20687                 const GLchar* index     = "";
20688                 size_t            position = 0;
20689                 size_t            temp;
20690                 const GLchar* var_definition = 0;
20691                 const GLchar* var_use            = 0;
20692
20693                 switch (test_case.m_case)
20694                 {
20695                 case OFFSET:
20696                         var_definition = offset_var_definition;
20697                         var_use            = output_use;
20698                         break;
20699                 case STRIDE:
20700                         var_definition = stride_var_definition;
20701                         var_use            = output_use;
20702                         break;
20703                 case BLOCK:
20704                         var_definition = block_var_definition;
20705                         var_use            = block_use;
20706                         break;
20707                 case ARRAY:
20708                         var_definition = array_var_definition;
20709                         var_use            = array_use;
20710                         break;
20711                 default:
20712                         TCU_FAIL("Invalid enum");
20713                 }
20714
20715                 switch (stage)
20716                 {
20717                 case Utils::Shader::GEOMETRY:
20718                         source = gs_tested;
20719                         array  = "[]";
20720                         index  = "[0]";
20721                         break;
20722                 case Utils::Shader::TESS_CTRL:
20723                         source = tcs_tested;
20724                         array  = "[]";
20725                         index  = "[gl_InvocationID]";
20726                         break;
20727                 case Utils::Shader::TESS_EVAL:
20728                         source = tes_tested;
20729                         array  = "[]";
20730                         index  = "[0]";
20731                         break;
20732                 case Utils::Shader::VERTEX:
20733                         source = vs_tested;
20734                         break;
20735                 default:
20736                         TCU_FAIL("Invalid enum");
20737                 }
20738
20739                 temp = position;
20740                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20741                 position = temp;
20742                 Utils::replaceToken("ARRAY", position, array, source);
20743                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20744
20745                 Utils::replaceAllTokens("INDEX", index, source);
20746         }
20747         else
20748         {
20749                 switch (test_case.m_stage)
20750                 {
20751                 case Utils::Shader::GEOMETRY:
20752                         switch (stage)
20753                         {
20754                         case Utils::Shader::FRAGMENT:
20755                                 source = fs;
20756                                 break;
20757                         case Utils::Shader::VERTEX:
20758                                 source = vs;
20759                                 break;
20760                         default:
20761                                 source = "";
20762                         }
20763                         break;
20764                 case Utils::Shader::TESS_CTRL:
20765                         switch (stage)
20766                         {
20767                         case Utils::Shader::FRAGMENT:
20768                                 source = fs;
20769                                 break;
20770                         case Utils::Shader::VERTEX:
20771                                 source = vs;
20772                                 break;
20773                         default:
20774                                 source = "";
20775                         }
20776                         break;
20777                 case Utils::Shader::TESS_EVAL:
20778                         switch (stage)
20779                         {
20780                         case Utils::Shader::FRAGMENT:
20781                                 source = fs;
20782                                 break;
20783                         case Utils::Shader::TESS_CTRL:
20784                                 source = tcs;
20785                                 break;
20786                         case Utils::Shader::VERTEX:
20787                                 source = vs;
20788                                 break;
20789                         default:
20790                                 source = "";
20791                         }
20792                         break;
20793                 case Utils::Shader::VERTEX:
20794                         switch (stage)
20795                         {
20796                         case Utils::Shader::FRAGMENT:
20797                                 source = fs;
20798                                 break;
20799                         default:
20800                                 source = "";
20801                         }
20802                         break;
20803                 default:
20804                         TCU_FAIL("Invalid enum");
20805                         break;
20806                 }
20807         }
20808
20809         return source;
20810 }
20811
20812 /** Get description of test case
20813  *
20814  * @param test_case_index Index of test case
20815  *
20816  * @return Test case description
20817  **/
20818 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20819 {
20820         std::stringstream stream;
20821         testCase&                 test_case = m_test_cases[test_case_index];
20822
20823         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20824
20825         switch (test_case.m_case)
20826         {
20827         case OFFSET:
20828                 stream << "buffer stride: 40, vec4 offset: 32";
20829                 break;
20830         case STRIDE:
20831                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20832                 break;
20833         case BLOCK:
20834                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20835                 break;
20836         case ARRAY:
20837                 stream << "buffer stride: 32, vec4[4] offset 16";
20838                 break;
20839         default:
20840                 TCU_FAIL("Invalid enum");
20841         }
20842
20843         return stream.str();
20844 }
20845
20846 /** Get number of test cases
20847  *
20848  * @return Number of test cases
20849  **/
20850 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20851 {
20852         return static_cast<GLuint>(m_test_cases.size());
20853 }
20854
20855 /** Selects if "compute" stage is relevant for test
20856  *
20857  * @param ignored
20858  *
20859  * @return false
20860  **/
20861 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20862 {
20863         return false;
20864 }
20865
20866 /** Prepare all test cases
20867  *
20868  **/
20869 void XFBTooSmallStrideTest::testInit()
20870 {
20871         for (GLuint c = 0; c < CASE_MAX; ++c)
20872         {
20873                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20874                 {
20875                         /*
20876                          It is invalid to define transform feedback output in TCS, according to spec:
20877                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20878                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20879                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20880                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20881                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20882                          each primitive processed by the vertex shader.
20883                          */
20884                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20885                                 (Utils::Shader::FRAGMENT == stage))
20886                         {
20887                                 continue;
20888                         }
20889
20890                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20891
20892                         m_test_cases.push_back(test_case);
20893                 }
20894         }
20895 }
20896
20897 /** Constructor
20898  *
20899  * @param context Test framework context
20900  **/
20901 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
20902         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
20903 {
20904 }
20905
20906 /** Source for given test case and stage
20907  *
20908  * @param test_case_index Index of test case
20909  * @param stage           Shader stage
20910  *
20911  * @return Shader source
20912  **/
20913 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20914 {
20915         static const GLchar* invalid_var_definition =
20916                 "const uint type_size = SIZE;\n"
20917                 "\n"
20918                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
20919                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
20920         static const GLchar* valid_var_definition =
20921                 "const uint type_size = SIZE;\n"
20922                 "\n"
20923                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
20924         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
20925                                                                            "    vegetaINDEX = TYPE(0);\n"
20926                                                                            "    if (vec4(0) == result)\n"
20927                                                                            "    {\n"
20928                                                                            "        gokuINDEX   = TYPE(0);\n"
20929                                                                            "        vegetaINDEX = TYPE(1);\n"
20930                                                                            "    }\n";
20931         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
20932                                                                          "    if (vec4(0) == result)\n"
20933                                                                          "    {\n"
20934                                                                          "        gokuINDEX   = TYPE(0);\n"
20935                                                                          "    }\n";
20936         static const GLchar* fs = "#version 430 core\n"
20937                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20938                                                           "\n"
20939                                                           "in  vec4 any_fs;\n"
20940                                                           "out vec4 fs_out;\n"
20941                                                           "\n"
20942                                                           "void main()\n"
20943                                                           "{\n"
20944                                                           "    fs_out = any_fs;\n"
20945                                                           "}\n"
20946                                                           "\n";
20947         static const GLchar* gs_tested = "#version 430 core\n"
20948                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20949                                                                          "\n"
20950                                                                          "layout(points)                           in;\n"
20951                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20952                                                                          "\n"
20953                                                                          "VAR_DEFINITION"
20954                                                                          "\n"
20955                                                                          "in  vec4 vs_any[];\n"
20956                                                                          "out vec4 any_fs;\n"
20957                                                                          "\n"
20958                                                                          "void main()\n"
20959                                                                          "{\n"
20960                                                                          "    vec4 result = vs_any[0];\n"
20961                                                                          "\n"
20962                                                                          "VARIABLE_USE"
20963                                                                          "\n"
20964                                                                          "    any_fs = result;\n"
20965                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20966                                                                          "    EmitVertex();\n"
20967                                                                          "    any_fs = result;\n"
20968                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20969                                                                          "    EmitVertex();\n"
20970                                                                          "    any_fs = result;\n"
20971                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20972                                                                          "    EmitVertex();\n"
20973                                                                          "    any_fs = result;\n"
20974                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20975                                                                          "    EmitVertex();\n"
20976                                                                          "}\n"
20977                                                                          "\n";
20978         static const GLchar* tcs = "#version 430 core\n"
20979                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20980                                                            "\n"
20981                                                            "layout(vertices = 1) out;\n"
20982                                                            "\n"
20983                                                            "in  vec4 vs_any[];\n"
20984                                                            "out vec4 tcs_tes[];\n"
20985                                                            "\n"
20986                                                            "void main()\n"
20987                                                            "{\n"
20988                                                            "\n"
20989                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
20990                                                            "\n"
20991                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20992                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20993                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20994                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20995                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20996                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20997                                                            "}\n"
20998                                                            "\n";
20999         static const GLchar* tcs_tested = "#version 430 core\n"
21000                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21001                                                                           "\n"
21002                                                                           "layout(vertices = 1) out;\n"
21003                                                                           "\n"
21004                                                                           "VAR_DEFINITION"
21005                                                                           "\n"
21006                                                                           "in  vec4 vs_any[];\n"
21007                                                                           "out vec4 any_fs[];\n"
21008                                                                           "\n"
21009                                                                           "void main()\n"
21010                                                                           "{\n"
21011                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21012                                                                           "\n"
21013                                                                           "VARIABLE_USE"
21014                                                                           "\n"
21015                                                                           "    any_fs[gl_InvocationID] = result;\n"
21016                                                                           "\n"
21017                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21018                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21019                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21020                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21021                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21022                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21023                                                                           "}\n"
21024                                                                           "\n";
21025         static const GLchar* tes_tested = "#version 430 core\n"
21026                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21027                                                                           "\n"
21028                                                                           "layout(isolines, point_mode) in;\n"
21029                                                                           "\n"
21030                                                                           "VAR_DEFINITION"
21031                                                                           "\n"
21032                                                                           "in  vec4 tcs_tes[];\n"
21033                                                                           "out vec4 any_fs;\n"
21034                                                                           "\n"
21035                                                                           "void main()\n"
21036                                                                           "{\n"
21037                                                                           "    vec4 result = tcs_tes[0];\n"
21038                                                                           "\n"
21039                                                                           "VARIABLE_USE"
21040                                                                           "\n"
21041                                                                           "    any_fs = result;\n"
21042                                                                           "}\n"
21043                                                                           "\n";
21044         static const GLchar* vs = "#version 430 core\n"
21045                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21046                                                           "\n"
21047                                                           "in  vec4 in_vs;\n"
21048                                                           "out vec4 vs_any;\n"
21049                                                           "\n"
21050                                                           "void main()\n"
21051                                                           "{\n"
21052                                                           "    vs_any = in_vs;\n"
21053                                                           "}\n"
21054                                                           "\n";
21055         static const GLchar* vs_tested = "#version 430 core\n"
21056                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21057                                                                          "\n"
21058                                                                          "VAR_DEFINITION"
21059                                                                          "\n"
21060                                                                          "in  vec4 in_vs;\n"
21061                                                                          "out vec4 any_fs;\n"
21062                                                                          "\n"
21063                                                                          "void main()\n"
21064                                                                          "{\n"
21065                                                                          "    vec4 result = in_vs;\n"
21066                                                                          "\n"
21067                                                                          "VARIABLE_USE"
21068                                                                          "\n"
21069                                                                          "    any_fs = result;\n"
21070                                                                          "}\n"
21071                                                                          "\n";
21072
21073         std::string source;
21074         testCase&   test_case = m_test_cases[test_case_index];
21075
21076         if (test_case.m_stage == stage)
21077         {
21078                 const GLchar* array = "";
21079                 GLchar            buffer[16];
21080                 const GLchar* index     = "";
21081                 size_t            position = 0;
21082                 size_t            temp;
21083                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21084                 const GLchar* var_definition = 0;
21085                 const GLchar* var_use            = 0;
21086
21087                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21088
21089                 switch (test_case.m_case)
21090                 {
21091                 case VALID:
21092                         var_definition = valid_var_definition;
21093                         var_use            = valid_use;
21094                         break;
21095                 case INVALID:
21096                         var_definition = invalid_var_definition;
21097                         var_use            = invalid_use;
21098                         break;
21099                 default:
21100                         TCU_FAIL("Invalid enum");
21101                 }
21102
21103                 switch (stage)
21104                 {
21105                 case Utils::Shader::GEOMETRY:
21106                         source = gs_tested;
21107                         array  = "[1]";
21108                         index  = "[0]";
21109                         break;
21110                 case Utils::Shader::TESS_CTRL:
21111                         source = tcs_tested;
21112                         array  = "[1]";
21113                         index  = "[gl_InvocationID]";
21114                         break;
21115                 case Utils::Shader::TESS_EVAL:
21116                         source = tes_tested;
21117                         array  = "[1]";
21118                         index  = "[0]";
21119                         break;
21120                 case Utils::Shader::VERTEX:
21121                         source = vs_tested;
21122                         break;
21123                 default:
21124                         TCU_FAIL("Invalid enum");
21125                 }
21126
21127                 temp = position;
21128                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21129                 position = temp;
21130                 Utils::replaceToken("SIZE", position, buffer, source);
21131                 Utils::replaceToken("ARRAY", position, array, source);
21132                 if (INVALID == test_case.m_case)
21133                 {
21134                         Utils::replaceToken("ARRAY", position, array, source);
21135                 }
21136                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21137
21138                 Utils::replaceAllTokens("TYPE", type_name, source);
21139                 Utils::replaceAllTokens("INDEX", index, source);
21140         }
21141         else
21142         {
21143                 switch (test_case.m_stage)
21144                 {
21145                 case Utils::Shader::GEOMETRY:
21146                         switch (stage)
21147                         {
21148                         case Utils::Shader::FRAGMENT:
21149                                 source = fs;
21150                                 break;
21151                         case Utils::Shader::VERTEX:
21152                                 source = vs;
21153                                 break;
21154                         default:
21155                                 source = "";
21156                         }
21157                         break;
21158                 case Utils::Shader::TESS_CTRL:
21159                         switch (stage)
21160                         {
21161                         case Utils::Shader::FRAGMENT:
21162                                 source = fs;
21163                                 break;
21164                         case Utils::Shader::VERTEX:
21165                                 source = vs;
21166                                 break;
21167                         default:
21168                                 source = "";
21169                         }
21170                         break;
21171                 case Utils::Shader::TESS_EVAL:
21172                         switch (stage)
21173                         {
21174                         case Utils::Shader::FRAGMENT:
21175                                 source = fs;
21176                                 break;
21177                         case Utils::Shader::TESS_CTRL:
21178                                 source = tcs;
21179                                 break;
21180                         case Utils::Shader::VERTEX:
21181                                 source = vs;
21182                                 break;
21183                         default:
21184                                 source = "";
21185                         }
21186                         break;
21187                 case Utils::Shader::VERTEX:
21188                         switch (stage)
21189                         {
21190                         case Utils::Shader::FRAGMENT:
21191                                 source = fs;
21192                                 break;
21193                         default:
21194                                 source = "";
21195                         }
21196                         break;
21197                 default:
21198                         TCU_FAIL("Invalid enum");
21199                         break;
21200                 }
21201         }
21202
21203         return source;
21204 }
21205
21206 /** Get description of test case
21207  *
21208  * @param test_case_index Index of test case
21209  *
21210  * @return Test case description
21211  **/
21212 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21213 {
21214         std::stringstream stream;
21215         testCase&                 test_case = m_test_cases[test_case_index];
21216
21217         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21218                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21219
21220         switch (test_case.m_case)
21221         {
21222         case VALID:
21223                 stream << "valid";
21224                 break;
21225         case INVALID:
21226                 stream << "invalid";
21227                 break;
21228         default:
21229                 TCU_FAIL("Invalid enum");
21230         }
21231
21232         return stream.str();
21233 }
21234
21235 /** Get number of test cases
21236  *
21237  * @return Number of test cases
21238  **/
21239 GLuint XFBVariableStrideTest::getTestCaseNumber()
21240 {
21241         return static_cast<GLuint>(m_test_cases.size());
21242 }
21243
21244 /** Selects if "compute" stage is relevant for test
21245  *
21246  * @param ignored
21247  *
21248  * @return false
21249  **/
21250 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21251 {
21252         return false;
21253 }
21254
21255 /** Selects if compilation failure is expected result
21256  *
21257  * @param test_case_index Index of test case
21258  *
21259  * @return true
21260  **/
21261 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21262 {
21263         testCase& test_case = m_test_cases[test_case_index];
21264
21265         return (INVALID == test_case.m_case);
21266 }
21267
21268 /** Prepare all test cases
21269  *
21270  **/
21271 void XFBVariableStrideTest::testInit()
21272 {
21273         const GLuint n_types = getTypesNumber();
21274
21275         for (GLuint i = 0; i < n_types; ++i)
21276         {
21277                 const Utils::Type& type = getType(i);
21278
21279                 /*
21280                  Some of the cases are declared as following are considered as invalid,
21281                  but accoring to spec, the following declaration is valid: shaders in the
21282                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21283                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21284                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21285                  the stride.
21286
21287                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21288                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21289                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21290                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21291
21292                  int type_size = 8;
21293                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21294                  layout (xfb_offset = type_size)                     out double vegeta;
21295                  */
21296                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21297                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21298                 {
21299                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21300                         {
21301                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21302                                         (Utils::Shader::FRAGMENT == stage))
21303                                 {
21304                                         continue;
21305                                 }
21306
21307                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21308
21309                                 m_test_cases.push_back(test_case);
21310                         }
21311                 }
21312         }
21313 }
21314
21315 /** Constructor
21316  *
21317  * @param context Test framework context
21318  **/
21319 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21320         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21321 {
21322 }
21323
21324 /** Source for given test case and stage
21325  *
21326  * @param test_case_index Index of test case
21327  * @param stage           Shader stage
21328  *
21329  * @return Shader source
21330  **/
21331 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21332 {
21333         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21334                                                                                   "    vec4 gohan;\n"
21335                                                                                   "    vec4 goten;\n"
21336                                                                                   "    vec4 chichi;\n"
21337                                                                                   "} gokuARRAY;\n";
21338         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21339                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21340                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21341                                                                    "    if (vec4(0) == result)\n"
21342                                                                    "    {\n"
21343                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21344                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21345                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21346                                                                    "    }\n";
21347         static const GLchar* gs_tested =
21348                 "#version 430 core\n"
21349                 "#extension GL_ARB_enhanced_layouts : require\n"
21350                 "\n"
21351                 "layout(points)                           in;\n"
21352                 "layout(triangle_strip, max_vertices = 4) out;\n"
21353                 "\n"
21354                 "VAR_DEFINITION"
21355                 "\n"
21356                 "out gl_PerVertex \n"
21357                 "{ \n"
21358                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21359                 "}; \n"
21360                 "in  vec4 tes_gs[];\n"
21361                 "out vec4 gs_fs;\n"
21362                 "\n"
21363                 "void main()\n"
21364                 "{\n"
21365                 "    vec4 result = tes_gs[0];\n"
21366                 "\n"
21367                 "VARIABLE_USE"
21368                 "\n"
21369                 "    gs_fs = result;\n"
21370                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21371                 "    EmitVertex();\n"
21372                 "    gs_fs = result;\n"
21373                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21374                 "    EmitVertex();\n"
21375                 "    gs_fs = result;\n"
21376                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21377                 "    EmitVertex();\n"
21378                 "    gs_fs = result;\n"
21379                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21380                 "    EmitVertex();\n"
21381                 "}\n"
21382                 "\n";
21383         static const GLchar* tcs = "#version 430 core\n"
21384                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21385                                                            "\n"
21386                                                            "layout(vertices = 1) out;\n"
21387                                                            "\n"
21388                                                            "in  vec4 vs_tcs[];\n"
21389                                                            "out vec4 tcs_tes[];\n"
21390                                                            "\n"
21391                                                            "void main()\n"
21392                                                            "{\n"
21393                                                            "\n"
21394                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21395                                                            "\n"
21396                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21397                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21398                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21399                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21400                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21401                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21402                                                            "}\n"
21403                                                            "\n";
21404 #if 0
21405         static const GLchar* tcs_tested =
21406                 "#version 430 core\n"
21407                 "#extension GL_ARB_enhanced_layouts : require\n"
21408                 "\n"
21409                 "layout(vertices = 1) out;\n"
21410                 "\n"
21411                 "VAR_DEFINITION"
21412                 "\n"
21413                 "in  vec4 vs_tcs[];\n"
21414                 "out vec4 tcs_tes[];\n"
21415                 "\n"
21416                 "void main()\n"
21417                 "{\n"
21418                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21419                 "\n"
21420                 "VARIABLE_USE"
21421                 "\n"
21422                 "    tcs_tes[gl_InvocationID] = result;\n"
21423                 "\n"
21424                 "    gl_TessLevelOuter[0] = 1.0;\n"
21425                 "    gl_TessLevelOuter[1] = 1.0;\n"
21426                 "    gl_TessLevelOuter[2] = 1.0;\n"
21427                 "    gl_TessLevelOuter[3] = 1.0;\n"
21428                 "    gl_TessLevelInner[0] = 1.0;\n"
21429                 "    gl_TessLevelInner[1] = 1.0;\n"
21430                 "}\n"
21431                 "\n";
21432 #endif
21433         static const GLchar* tes_tested = "#version 430 core\n"
21434                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21435                                                                           "\n"
21436                                                                           "layout(isolines, point_mode) in;\n"
21437                                                                           "\n"
21438                                                                           "VAR_DEFINITION"
21439                                                                           "\n"
21440                                                                           "in  vec4 tcs_tes[];\n"
21441                                                                           "out vec4 tes_gs;\n"
21442                                                                           "\n"
21443                                                                           "void main()\n"
21444                                                                           "{\n"
21445                                                                           "    vec4 result = tcs_tes[0];\n"
21446                                                                           "\n"
21447                                                                           "VARIABLE_USE"
21448                                                                           "\n"
21449                                                                           "    tes_gs += result;\n"
21450                                                                           "}\n"
21451                                                                           "\n";
21452         static const GLchar* vs = "#version 430 core\n"
21453                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21454                                                           "\n"
21455                                                           "in  vec4 in_vs;\n"
21456                                                           "out vec4 vs_tcs;\n"
21457                                                           "\n"
21458                                                           "void main()\n"
21459                                                           "{\n"
21460                                                           "    vs_tcs = in_vs;\n"
21461                                                           "}\n"
21462                                                           "\n";
21463         static const GLchar* vs_tested = "#version 430 core\n"
21464                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21465                                                                          "\n"
21466                                                                          "VAR_DEFINITION"
21467                                                                          "\n"
21468                                                                          "in  vec4 in_vs;\n"
21469                                                                          "out vec4 vs_tcs;\n"
21470                                                                          "\n"
21471                                                                          "void main()\n"
21472                                                                          "{\n"
21473                                                                          "    vec4 result = in_vs;\n"
21474                                                                          "\n"
21475                                                                          "VARIABLE_USE"
21476                                                                          "\n"
21477                                                                          "    vs_tcs += result;\n"
21478                                                                          "}\n"
21479                                                                          "\n";
21480
21481         std::string                       source;
21482         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21483
21484         if (test_case == stage)
21485         {
21486                 const GLchar* array     = "";
21487                 const GLchar* index     = "";
21488                 size_t            position = 0;
21489                 size_t            temp;
21490                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21491                 // change array = "[]" to "[1]"
21492                 switch (stage)
21493                 {
21494                 case Utils::Shader::GEOMETRY:
21495                         source = gs_tested;
21496                         array  = "[1]";
21497                         index  = "[0]";
21498                         break;
21499 /*
21500                          It is invalid to define transform feedback output in HS
21501                          */
21502 #if 0
21503                         case Utils::Shader::TESS_CTRL:
21504                         source = tcs_tested;
21505                         array = "[]";
21506                         index = "[gl_InvocationID]";
21507                         break;
21508 #endif
21509                 case Utils::Shader::TESS_EVAL:
21510                         source = tes_tested;
21511                         array  = "[1]";
21512                         index  = "[0]";
21513                         break;
21514                 case Utils::Shader::VERTEX:
21515                         source = vs_tested;
21516                         break;
21517                 default:
21518                         TCU_FAIL("Invalid enum");
21519                 }
21520
21521                 temp = position;
21522                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21523                 position = temp;
21524                 Utils::replaceToken("ARRAY", position, array, source);
21525                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21526
21527                 Utils::replaceAllTokens("INDEX", index, source);
21528         }
21529         else
21530         {
21531                 switch (test_case)
21532                 {
21533                 case Utils::Shader::GEOMETRY:
21534                         switch (stage)
21535                         {
21536                         case Utils::Shader::VERTEX:
21537                                 source = vs;
21538                                 break;
21539                         default:
21540                                 source = "";
21541                         }
21542                         break;
21543                 case Utils::Shader::TESS_CTRL:
21544                         switch (stage)
21545                         {
21546                         case Utils::Shader::VERTEX:
21547                                 source = vs;
21548                                 break;
21549                         default:
21550                                 source = "";
21551                         }
21552                         break;
21553                 case Utils::Shader::TESS_EVAL:
21554                         switch (stage)
21555                         {
21556                         case Utils::Shader::TESS_CTRL:
21557                                 source = tcs;
21558                                 break;
21559                         case Utils::Shader::VERTEX:
21560                                 source = vs;
21561                                 break;
21562                         default:
21563                                 source = "";
21564                         }
21565                         break;
21566                 case Utils::Shader::VERTEX:
21567                         source = "";
21568                         break;
21569                 default:
21570                         TCU_FAIL("Invalid enum");
21571                         break;
21572                 }
21573         }
21574
21575         return source;
21576 }
21577
21578 /** Get description of test case
21579  *
21580  * @param test_case_index Index of test case
21581  *
21582  * @return Test case description
21583  **/
21584 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21585 {
21586         std::stringstream stream;
21587
21588         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21589
21590         return stream.str();
21591 }
21592
21593 /** Get number of test cases
21594  *
21595  * @return Number of test cases
21596  **/
21597 GLuint XFBBlockStrideTest::getTestCaseNumber()
21598 {
21599         return static_cast<GLuint>(m_test_cases.size());
21600 }
21601
21602 /** Inspects program for xfb stride
21603  *
21604  * @param program Program to query
21605  *
21606  * @return true if query results match expected values, false otherwise
21607  **/
21608 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21609 {
21610         GLint stride = 0;
21611
21612         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21613                                                 1 /* buf_size */, &stride);
21614
21615         return (128 == stride);
21616 }
21617
21618 /** Runs test case
21619  *
21620  * @param test_case_index Id of test case
21621  *
21622  * @return true if test case pass, false otherwise
21623  **/
21624 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21625 {
21626         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21627         Utils::Program   program(m_context);
21628         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21629         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21630         bool                       test_case_result = true;
21631         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21632
21633         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21634
21635         test_case_result = inspectProgram(program);
21636
21637         return test_case_result;
21638 }
21639
21640 /** Prepare all test cases
21641  *
21642  **/
21643 void XFBBlockStrideTest::testInit()
21644 {
21645         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21646         {
21647                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21648                         (Utils::Shader::FRAGMENT == stage))
21649                 {
21650                         continue;
21651                 }
21652
21653                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21654         }
21655 }
21656
21657 /** Constructor
21658  *
21659  * @param context Test context
21660  **/
21661 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21662         : BufferTestBase(context, "xfb_block_member_stride",
21663                                          "Test verifies that xfb_stride qualifier is respected for block member")
21664 {
21665         /* Nothing to be done here */
21666 }
21667
21668 /** Get descriptors of buffers necessary for test
21669  *
21670  * @param ignored
21671  * @param out_descriptors Descriptors of buffers used by test
21672  **/
21673 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21674                                                                                                         bufferDescriptor::Vector& out_descriptors)
21675 {
21676         const Utils::Type& vec4 = Utils::Type::vec4;
21677
21678         /* Test needs single uniform and xfb */
21679         out_descriptors.resize(2);
21680
21681         /* Get references */
21682         bufferDescriptor& uniform = out_descriptors[0];
21683         bufferDescriptor& xfb    = out_descriptors[1];
21684
21685         /* Index */
21686         uniform.m_index = 0;
21687         xfb.m_index             = 0;
21688
21689         /* Target */
21690         uniform.m_target = Utils::Buffer::Uniform;
21691         xfb.m_target     = Utils::Buffer::Transform_feedback;
21692
21693         /* Data */
21694         static const GLuint                     vec4_size   = 16;
21695         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21696         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21697         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21698
21699         /* Uniform data */
21700         uniform.m_initial_data.resize(3 * vec4_size);
21701         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21702         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21703         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21704
21705         /* XFB data */
21706         xfb.m_initial_data.resize(4 * vec4_size);
21707         xfb.m_expected_data.resize(4 * vec4_size);
21708
21709         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21710         {
21711                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21712                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21713         }
21714
21715         // the xfb_offset of "chichi" should be 32
21716         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21717         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21718         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21719 }
21720
21721 /** Get body of main function for given shader stage
21722  *
21723  * @param ignored
21724  * @param stage            Shader stage
21725  * @param out_assignments  Set to empty
21726  * @param out_calculations Set to empty
21727  **/
21728 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21729                                                                                          std::string& out_assignments, std::string& out_calculations)
21730 {
21731         out_calculations = "";
21732
21733         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21734                                                           "    goten  = uni_goten;\n"
21735                                                           "    chichi = uni_chichi;\n";
21736         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21737
21738         const GLchar* assignments = "";
21739         switch (stage)
21740         {
21741         case Utils::Shader::FRAGMENT:
21742                 assignments = fs;
21743                 break;
21744         case Utils::Shader::GEOMETRY:
21745                 assignments = gs;
21746                 break;
21747         default:
21748                 break;
21749         }
21750
21751         out_assignments = assignments;
21752 }
21753
21754 /** Get interface of shader
21755  *
21756  * @param ignored
21757  * @param stage            Shader stage
21758  * @param out_interface    Set to ""
21759  **/
21760 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21761                                                                                                   std::string& out_interface)
21762 {
21763         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21764                                                           "                             vec4 gohan;\n"
21765                                                           "    layout (xfb_stride = 32) vec4 goten;\n"
21766                                                           "                             vec4 chichi;\n"
21767                                                           "};\n"
21768                                                           "layout(binding = 0) uniform gs_block {\n"
21769                                                           "    vec4 uni_gohan;\n"
21770                                                           "    vec4 uni_goten;\n"
21771                                                           "    vec4 uni_chichi;\n"
21772                                                           "};\n";
21773         static const GLchar* fs = "in Goku {\n"
21774                                                           "    vec4 gohan;\n"
21775                                                           "    vec4 goten;\n"
21776                                                           "    vec4 chichi;\n"
21777                                                           "};\n"
21778                                                           "out vec4 fs_out;\n";
21779
21780         switch (stage)
21781         {
21782         case Utils::Shader::FRAGMENT:
21783                 out_interface = fs;
21784                 break;
21785         case Utils::Shader::GEOMETRY:
21786                 out_interface = gs;
21787                 break;
21788         default:
21789                 out_interface = "";
21790                 return;
21791         }
21792 }
21793
21794 /** Inspects program to check if all resources are as expected
21795  *
21796  * @param ignored
21797  * @param program    Program instance
21798  * @param out_stream Error message
21799  *
21800  * @return true if everything is ok, false otherwise
21801  **/
21802 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21803                                                                                           std::stringstream& out_stream)
21804 {
21805         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21806         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21807         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21808
21809         GLint gohan_offset  = 0;
21810         GLint goten_offset  = 0;
21811         GLint chichi_offset = 0;
21812
21813         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21814         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21815         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21816
21817         // the xfb_offset of "chichi" should be 32
21818         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21819         {
21820                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21821                                    << "] expected: [0, 16, 48]";
21822                 return false;
21823         }
21824
21825         return true;
21826 }
21827
21828 /** Constructor
21829  *
21830  * @param context Test framework context
21831  **/
21832 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21833         : NegativeTestBase(context, "xfb_duplicated_stride",
21834                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21835 {
21836 }
21837
21838 /** Source for given test case and stage
21839  *
21840  * @param test_case_index Index of test case
21841  * @param stage           Shader stage
21842  *
21843  * @return Shader source
21844  **/
21845 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21846 {
21847         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21848                                                                                                   "const uint conflicting_stride = 128;\n"
21849                                                                                                   "\n"
21850                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21851                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21852         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21853                                                                                                 "\n"
21854                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21855                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21856         static const GLchar* fs = "#version 430 core\n"
21857                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21858                                                           "\n"
21859                                                           "in  vec4 any_fs;\n"
21860                                                           "out vec4 fs_out;\n"
21861                                                           "\n"
21862                                                           "void main()\n"
21863                                                           "{\n"
21864                                                           "    fs_out = any_fs;\n"
21865                                                           "}\n"
21866                                                           "\n";
21867         static const GLchar* gs_tested = "#version 430 core\n"
21868                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21869                                                                          "\n"
21870                                                                          "layout(points)                           in;\n"
21871                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21872                                                                          "\n"
21873                                                                          "VAR_DEFINITION"
21874                                                                          "\n"
21875                                                                          "in  vec4 vs_any[];\n"
21876                                                                          "out vec4 any_fs;\n"
21877                                                                          "\n"
21878                                                                          "void main()\n"
21879                                                                          "{\n"
21880                                                                          "    vec4 result = vs_any[0];\n"
21881                                                                          "\n"
21882                                                                          "VARIABLE_USE"
21883                                                                          "\n"
21884                                                                          "    any_fs = result;\n"
21885                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21886                                                                          "    EmitVertex();\n"
21887                                                                          "    any_fs = result;\n"
21888                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21889                                                                          "    EmitVertex();\n"
21890                                                                          "    any_fs = result;\n"
21891                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21892                                                                          "    EmitVertex();\n"
21893                                                                          "    any_fs = result;\n"
21894                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21895                                                                          "    EmitVertex();\n"
21896                                                                          "}\n"
21897                                                                          "\n";
21898         static const GLchar* tcs = "#version 430 core\n"
21899                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21900                                                            "\n"
21901                                                            "layout(vertices = 1) out;\n"
21902                                                            "\n"
21903                                                            "in  vec4 vs_any[];\n"
21904                                                            "out vec4 tcs_tes[];\n"
21905                                                            "\n"
21906                                                            "void main()\n"
21907                                                            "{\n"
21908                                                            "\n"
21909                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21910                                                            "\n"
21911                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21912                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21913                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21914                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21915                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21916                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21917                                                            "}\n"
21918                                                            "\n";
21919         static const GLchar* tcs_tested = "#version 430 core\n"
21920                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21921                                                                           "\n"
21922                                                                           "layout(vertices = 1) out;\n"
21923                                                                           "\n"
21924                                                                           "VAR_DEFINITION"
21925                                                                           "\n"
21926                                                                           "in  vec4 vs_any[];\n"
21927                                                                           "out vec4 any_fs[];\n"
21928                                                                           "\n"
21929                                                                           "void main()\n"
21930                                                                           "{\n"
21931                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21932                                                                           "\n"
21933                                                                           "VARIABLE_USE"
21934                                                                           "\n"
21935                                                                           "    any_fs[gl_InvocationID] = result;\n"
21936                                                                           "\n"
21937                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21938                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21939                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21940                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21941                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21942                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21943                                                                           "}\n"
21944                                                                           "\n";
21945         static const GLchar* tes_tested = "#version 430 core\n"
21946                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21947                                                                           "\n"
21948                                                                           "layout(isolines, point_mode) in;\n"
21949                                                                           "\n"
21950                                                                           "VAR_DEFINITION"
21951                                                                           "\n"
21952                                                                           "in  vec4 tcs_tes[];\n"
21953                                                                           "out vec4 any_fs;\n"
21954                                                                           "\n"
21955                                                                           "void main()\n"
21956                                                                           "{\n"
21957                                                                           "    vec4 result = tcs_tes[0];\n"
21958                                                                           "\n"
21959                                                                           "VARIABLE_USE"
21960                                                                           "\n"
21961                                                                           "    any_fs = result;\n"
21962                                                                           "}\n"
21963                                                                           "\n";
21964         static const GLchar* vs = "#version 430 core\n"
21965                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21966                                                           "\n"
21967                                                           "in  vec4 in_vs;\n"
21968                                                           "out vec4 vs_any;\n"
21969                                                           "\n"
21970                                                           "void main()\n"
21971                                                           "{\n"
21972                                                           "    vs_any = in_vs;\n"
21973                                                           "}\n"
21974                                                           "\n";
21975         static const GLchar* vs_tested = "#version 430 core\n"
21976                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21977                                                                          "\n"
21978                                                                          "VAR_DEFINITION"
21979                                                                          "\n"
21980                                                                          "in  vec4 in_vs;\n"
21981                                                                          "out vec4 any_fs;\n"
21982                                                                          "\n"
21983                                                                          "void main()\n"
21984                                                                          "{\n"
21985                                                                          "    vec4 result = in_vs;\n"
21986                                                                          "\n"
21987                                                                          "VARIABLE_USE"
21988                                                                          "\n"
21989                                                                          "    any_fs += result;\n"
21990                                                                          "}\n"
21991                                                                          "\n";
21992
21993         std::string source;
21994         testCase&   test_case = m_test_cases[test_case_index];
21995
21996         if (test_case.m_stage == stage)
21997         {
21998                 size_t            position               = 0;
21999                 const GLchar* var_definition = 0;
22000                 const GLchar* var_use            = "";
22001
22002                 switch (test_case.m_case)
22003                 {
22004                 case VALID:
22005                         var_definition = valid_var_definition;
22006                         break;
22007                 case INVALID:
22008                         var_definition = invalid_var_definition;
22009                         break;
22010                 default:
22011                         TCU_FAIL("Invalid enum");
22012                 }
22013
22014                 switch (stage)
22015                 {
22016                 case Utils::Shader::GEOMETRY:
22017                         source = gs_tested;
22018                         break;
22019                 case Utils::Shader::TESS_CTRL:
22020                         source = tcs_tested;
22021                         break;
22022                 case Utils::Shader::TESS_EVAL:
22023                         source = tes_tested;
22024                         break;
22025                 case Utils::Shader::VERTEX:
22026                         source = vs_tested;
22027                         break;
22028                 default:
22029                         TCU_FAIL("Invalid enum");
22030                 }
22031
22032                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22033                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22034         }
22035         else
22036         {
22037                 switch (test_case.m_stage)
22038                 {
22039                 case Utils::Shader::GEOMETRY:
22040                         switch (stage)
22041                         {
22042                         case Utils::Shader::FRAGMENT:
22043                                 source = fs;
22044                                 break;
22045                         case Utils::Shader::VERTEX:
22046                                 source = vs;
22047                                 break;
22048                         default:
22049                                 source = "";
22050                         }
22051                         break;
22052                 case Utils::Shader::TESS_CTRL:
22053                         switch (stage)
22054                         {
22055                         case Utils::Shader::FRAGMENT:
22056                                 source = fs;
22057                                 break;
22058                         case Utils::Shader::VERTEX:
22059                                 source = vs;
22060                                 break;
22061                         default:
22062                                 source = "";
22063                         }
22064                         break;
22065                 case Utils::Shader::TESS_EVAL:
22066                         switch (stage)
22067                         {
22068                         case Utils::Shader::FRAGMENT:
22069                                 source = fs;
22070                                 break;
22071                         case Utils::Shader::TESS_CTRL:
22072                                 source = tcs;
22073                                 break;
22074                         case Utils::Shader::VERTEX:
22075                                 source = vs;
22076                                 break;
22077                         default:
22078                                 source = "";
22079                         }
22080                         break;
22081                 case Utils::Shader::VERTEX:
22082                         switch (stage)
22083                         {
22084                         case Utils::Shader::FRAGMENT:
22085                                 source = fs;
22086                                 break;
22087                         default:
22088                                 source = "";
22089                         }
22090                         break;
22091                 default:
22092                         TCU_FAIL("Invalid enum");
22093                         break;
22094                 }
22095         }
22096
22097         return source;
22098 }
22099
22100 /** Get description of test case
22101  *
22102  * @param test_case_index Index of test case
22103  *
22104  * @return Test case description
22105  **/
22106 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22107 {
22108         std::stringstream stream;
22109         testCase&                 test_case = m_test_cases[test_case_index];
22110
22111         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22112
22113         switch (test_case.m_case)
22114         {
22115         case VALID:
22116                 stream << "valid";
22117                 break;
22118         case INVALID:
22119                 stream << "invalid";
22120                 break;
22121         default:
22122                 TCU_FAIL("Invalid enum");
22123         }
22124
22125         return stream.str();
22126 }
22127
22128 /** Get number of test cases
22129  *
22130  * @return Number of test cases
22131  **/
22132 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22133 {
22134         return static_cast<GLuint>(m_test_cases.size());
22135 }
22136
22137 /** Selects if "compute" stage is relevant for test
22138  *
22139  * @param ignored
22140  *
22141  * @return false
22142  **/
22143 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22144 {
22145         return false;
22146 }
22147
22148 /** Selects if compilation failure is expected result
22149  *
22150  * @param test_case_index Index of test case
22151  *
22152  * @return true
22153  **/
22154 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22155 {
22156         testCase& test_case = m_test_cases[test_case_index];
22157
22158         return (INVALID == test_case.m_case);
22159 }
22160
22161 /** Prepare all test cases
22162  *
22163  **/
22164 void XFBDuplicatedStrideTest::testInit()
22165 {
22166         for (GLuint c = 0; c < CASE_MAX; ++c)
22167         {
22168                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22169                 {
22170                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22171                                 (Utils::Shader::FRAGMENT == stage))
22172                         {
22173                                 continue;
22174                         }
22175
22176                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22177
22178                         m_test_cases.push_back(test_case);
22179                 }
22180         }
22181 }
22182
22183 /** Constructor
22184  *
22185  * @param context Test framework context
22186  **/
22187 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22188         : TestBase(context, "xfb_get_program_resource_api",
22189                            "Test verifies that get program resource reports correct results for XFB")
22190 {
22191 }
22192
22193 /** Source for given test case and stage
22194  *
22195  * @param test_case_index Index of test case
22196  * @param stage           Shader stage
22197  *
22198  * @return Shader source
22199  **/
22200 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22201 {
22202         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22203                                                                                           "out TYPE b1_v1ARRAY;\n"
22204                                                                                           "out TYPE b0_v3ARRAY;\n"
22205                                                                                           "out TYPE b0_v0ARRAY;\n";
22206         static const GLchar* xfb_var_definition =
22207                 "const uint type_size = SIZE;\n"
22208                 "\n"
22209                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22210                 "\n"
22211                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22212                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22213                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22214                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22215         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22216                                                                    "    b1_v1INDEX = TYPE(1);\n"
22217                                                                    "    b0_v3INDEX = TYPE(0);\n"
22218                                                                    "    b0_v0INDEX = TYPE(1);\n"
22219                                                                    "    if (vec4(0) == result)\n"
22220                                                                    "    {\n"
22221                                                                    "        b0_v1INDEX = TYPE(1);\n"
22222                                                                    "        b1_v1INDEX = TYPE(0);\n"
22223                                                                    "        b0_v3INDEX = TYPE(1);\n"
22224                                                                    "        b0_v0INDEX = TYPE(0);\n"
22225                                                                    "    }\n";
22226         static const GLchar* gs_tested =
22227                 "#version 430 core\n"
22228                 "#extension GL_ARB_enhanced_layouts : require\n"
22229                 "\n"
22230                 "layout(points)                           in;\n"
22231                 "layout(triangle_strip, max_vertices = 4) out;\n"
22232                 "\n"
22233                 "VAR_DEFINITION"
22234                 "\n"
22235                 "out gl_PerVertex \n"
22236                 "{ \n"
22237                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22238                 "}; \n"
22239                 "in  vec4 tes_gs[];\n"
22240                 "out vec4 gs_fs;\n"
22241                 "\n"
22242                 "void main()\n"
22243                 "{\n"
22244                 "    vec4 result = tes_gs[0];\n"
22245                 "\n"
22246                 "VARIABLE_USE"
22247                 "\n"
22248                 "    gs_fs = result;\n"
22249                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22250                 "    EmitVertex();\n"
22251                 "    gs_fs = result;\n"
22252                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22253                 "    EmitVertex();\n"
22254                 "    gs_fs = result;\n"
22255                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22256                 "    EmitVertex();\n"
22257                 "    gs_fs = result;\n"
22258                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22259                 "    EmitVertex();\n"
22260                 "}\n"
22261                 "\n";
22262 #if 0
22263         static const GLchar* tcs_tested =
22264                 "#version 430 core\n"
22265                 "#extension GL_ARB_enhanced_layouts : require\n"
22266                 "\n"
22267                 "layout(vertices = 1) out;\n"
22268                 "\n"
22269                 "VAR_DEFINITION"
22270                 "\n"
22271                 "in  vec4 vs_tcs[];\n"
22272                 "out vec4 tcs_tes[];\n"
22273                 "\n"
22274                 "void main()\n"
22275                 "{\n"
22276                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22277                 "\n"
22278                 "VARIABLE_USE"
22279                 "\n"
22280                 "    tcs_tes[gl_InvocationID] = result;\n"
22281                 "\n"
22282                 "    gl_TessLevelOuter[0] = 1.0;\n"
22283                 "    gl_TessLevelOuter[1] = 1.0;\n"
22284                 "    gl_TessLevelOuter[2] = 1.0;\n"
22285                 "    gl_TessLevelOuter[3] = 1.0;\n"
22286                 "    gl_TessLevelInner[0] = 1.0;\n"
22287                 "    gl_TessLevelInner[1] = 1.0;\n"
22288                 "}\n"
22289                 "\n";
22290 #endif
22291         static const GLchar* tes_tested = "#version 430 core\n"
22292                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22293                                                                           "\n"
22294                                                                           "layout(isolines, point_mode) in;\n"
22295                                                                           "\n"
22296                                                                           "VAR_DEFINITION"
22297                                                                           "\n"
22298                                                                           "in  vec4 tcs_tes[];\n"
22299                                                                           "out vec4 tes_gs;\n"
22300                                                                           "\n"
22301                                                                           "void main()\n"
22302                                                                           "{\n"
22303                                                                           "    vec4 result = tcs_tes[0];\n"
22304                                                                           "\n"
22305                                                                           "VARIABLE_USE"
22306                                                                           "\n"
22307                                                                           "    tes_gs = result;\n"
22308                                                                           "}\n"
22309                                                                           "\n";
22310         static const GLchar* vs_tested = "#version 430 core\n"
22311                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22312                                                                          "\n"
22313                                                                          "VAR_DEFINITION"
22314                                                                          "\n"
22315                                                                          "in  vec4 in_vs;\n"
22316                                                                          "out vec4 vs_tcs;\n"
22317                                                                          "\n"
22318                                                                          "void main()\n"
22319                                                                          "{\n"
22320                                                                          "    vec4 result = in_vs;\n"
22321                                                                          "\n"
22322                                                                          "VARIABLE_USE"
22323                                                                          "\n"
22324                                                                          "    vs_tcs = result;\n"
22325                                                                          "}\n"
22326                                                                          "\n";
22327
22328         std::string              source;
22329         const test_Case& test_case = m_test_cases[test_case_index];
22330
22331         if (test_case.m_stage == stage)
22332         {
22333                 const GLchar* array = "";
22334                 GLchar            buffer[16];
22335                 const GLchar* index     = "";
22336                 size_t            position = 0;
22337                 size_t            temp;
22338                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22339                 const GLchar* var_definition = 0;
22340
22341                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22342
22343                 if (XFB == test_case.m_case)
22344                 {
22345                         var_definition = xfb_var_definition;
22346                 }
22347                 else
22348                 {
22349                         var_definition = api_var_definition;
22350                 }
22351
22352                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22353                 // change array = "[]" to "[1]"
22354                 switch (stage)
22355                 {
22356                 case Utils::Shader::GEOMETRY:
22357                         source = gs_tested;
22358                         array  = "[1]";
22359                         index  = "[0]";
22360                         break;
22361 // It is invalid to output transform feedback varyings in tessellation control shader
22362 #if 0
22363                 case Utils::Shader::TESS_CTRL:
22364                         source = tcs_tested;
22365                         array = "[]";
22366                         index = "[gl_InvocationID]";
22367                         break;
22368 #endif
22369                 case Utils::Shader::TESS_EVAL:
22370                         source = tes_tested;
22371                         array  = "[1]";
22372                         index  = "[0]";
22373                         break;
22374                 case Utils::Shader::VERTEX:
22375                         source = vs_tested;
22376                         break;
22377                 default:
22378                         TCU_FAIL("Invalid enum");
22379                 }
22380
22381                 temp = position;
22382                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22383                 if (XFB == test_case.m_case)
22384                 {
22385                         position = temp;
22386                         Utils::replaceToken("SIZE", position, buffer, source);
22387                 }
22388                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22389
22390                 Utils::replaceAllTokens("ARRAY", array, source);
22391                 Utils::replaceAllTokens("INDEX", index, source);
22392                 Utils::replaceAllTokens("TYPE", type_name, source);
22393         }
22394         else
22395         {
22396                 source = "";
22397         }
22398
22399         return source;
22400 }
22401
22402 /** Get description of test case
22403  *
22404  * @param test_case_index Index of test case
22405  *
22406  * @return Test case description
22407  **/
22408 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22409 {
22410         std::stringstream stream;
22411         const test_Case&  test_case = m_test_cases[test_case_index];
22412
22413         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22414                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22415
22416         switch (test_case.m_case)
22417         {
22418         case INTERLEAVED:
22419                 stream << "interleaved";
22420                 break;
22421         case SEPARATED:
22422                 stream << "separated";
22423                 break;
22424         case XFB:
22425                 stream << "xfb";
22426                 break;
22427         default:
22428                 TCU_FAIL("Invalid enum");
22429         }
22430
22431         return stream.str();
22432 }
22433
22434 /** Get number of test cases
22435  *
22436  * @return Number of test cases
22437  **/
22438 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22439 {
22440         return static_cast<GLuint>(m_test_cases.size());
22441 }
22442
22443 /** Inspects program for offset, buffer index, buffer stride and type
22444  *
22445  * @param test_case_index Index of test case
22446  * @param program         Program to query
22447  *
22448  * @return true if query results match expected values, false otherwise
22449  **/
22450 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22451 {
22452         GLint                    b0_stride      = 0;
22453         GLint                    b1_stride      = 0;
22454         GLint                    b0_v0_buf      = 0;
22455         GLint                    b0_v0_offset = 0;
22456         GLint                    b0_v0_type   = 0;
22457         GLint                    b0_v1_buf      = 0;
22458         GLint                    b0_v1_offset = 0;
22459         GLint                    b0_v1_type   = 0;
22460         GLint                    b0_v3_buf      = 0;
22461         GLint                    b0_v3_offset = 0;
22462         GLint                    b0_v3_type   = 0;
22463         GLint                    b1_v1_buf      = 0;
22464         GLint                    b1_v1_offset = 0;
22465         GLint                    b1_v1_type   = 0;
22466         const test_Case& test_case      = m_test_cases[test_case_index];
22467         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22468         const GLint              type_size      = test_case.m_type.GetSize();
22469
22470         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22471         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22472         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22473         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22474
22475         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22476         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22477         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22478         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22479
22480         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22481         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22482         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22483         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22484
22485         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22486                                                 1 /* buf_size */, &b0_v0_buf);
22487         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22488                                                 1 /* buf_size */, &b0_v1_buf);
22489         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22490                                                 1 /* buf_size */, &b0_v3_buf);
22491         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22492                                                 1 /* buf_size */, &b1_v1_buf);
22493
22494         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22495                                                 &b0_stride);
22496         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22497                                                 &b1_stride);
22498
22499         if (SEPARATED != test_case.m_case)
22500         {
22501                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22502                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22503                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22504                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22505                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22506                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22507                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22508         }
22509         else
22510         {
22511                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22512                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22513                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22514                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22515                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22516         }
22517 }
22518
22519 /** Insert gl_SkipComponents
22520  *
22521  * @param num_components How many gl_SkipComponents1 need to be inserted
22522  * @param varyings The transform feedback varyings string vector
22523  *
22524  **/
22525 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22526 {
22527         int num_component_4 = num_components / 4;
22528         int num_component_1 = num_components % 4;
22529         for (int i = 0; i < num_component_4; i++)
22530         {
22531                 varyings.push_back("gl_SkipComponents4");
22532         }
22533         switch (num_component_1)
22534         {
22535         case 1:
22536                 varyings.push_back("gl_SkipComponents1");
22537                 break;
22538         case 2:
22539                 varyings.push_back("gl_SkipComponents2");
22540                 break;
22541         case 3:
22542                 varyings.push_back("gl_SkipComponents3");
22543                 break;
22544         default:
22545                 break;
22546         }
22547 }
22548
22549 /** Runs test case
22550  *
22551  * @param test_case_index Id of test case
22552  *
22553  * @return true if test case pass, false otherwise
22554  **/
22555 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22556 {
22557         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22558         Utils::Program   program(m_context);
22559         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22560         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22561         const test_Case&   test_case            = m_test_cases[test_case_index];
22562         bool                       test_case_result = true;
22563         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22564
22565         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22566         // 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.
22567
22568         if (INTERLEAVED == test_case.m_case)
22569         {
22570                 /*
22571                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22572                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22573                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22574                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22575
22576                  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,
22577                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22578                  */
22579                 Utils::Program::NameVector captured_varyings;
22580                 captured_varyings.push_back("b0_v0");
22581                 captured_varyings.push_back("b0_v1");
22582                 // Compute how many gl_SkipComponents to be inserted
22583                 int numComponents = test_case.m_type.GetSize() / 4;
22584                 insertSkipComponents(numComponents, captured_varyings);
22585                 captured_varyings.push_back("b0_v3");
22586                 captured_varyings.push_back("gl_NextBuffer");
22587                 insertSkipComponents(numComponents, captured_varyings);
22588                 captured_varyings.push_back("b1_v1");
22589                 insertSkipComponents(numComponents * 2, captured_varyings);
22590
22591                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22592                                          true /* separable */);
22593         }
22594         else if (SEPARATED == test_case.m_case)
22595         {
22596                 Utils::Program::NameVector captured_varyings;
22597
22598                 captured_varyings.push_back("b0_v0");
22599                 captured_varyings.push_back("b0_v1");
22600                 captured_varyings.push_back("b0_v3");
22601                 captured_varyings.push_back("b1_v1");
22602
22603                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22604                                          true /* separable */);
22605         }
22606         else
22607         {
22608
22609                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22610         }
22611
22612         test_case_result = inspectProgram(test_case_index, program);
22613
22614         return test_case_result;
22615 }
22616
22617 /** Prepare all test cases
22618  *
22619  **/
22620 void XFBGetProgramResourceAPITest::testInit()
22621 {
22622         const Functions& gl              = m_context.getRenderContext().getFunctions();
22623         const GLuint     n_types = getTypesNumber();
22624         GLint                    max_xfb_int;
22625         GLint                    max_xfb_sep;
22626
22627         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22628         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22629
22630         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22631         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22632
22633         GLint max_varyings;
22634         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22635
22636         for (GLuint i = 0; i < n_types; ++i)
22637         {
22638                 // 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,
22639                 // 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
22640                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22641                 // to guarantee the number of varying not exceeded.
22642                 /*
22643                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22644                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22645                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22646                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22647                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22648                  in  vec4 in_vs;
22649                  out vec4 vs_tcs;
22650                  */
22651                 if (i == 7 || i == 9)
22652                         continue;
22653                 const Utils::Type& type = getType(i);
22654                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22655                 {
22656                         continue;
22657                 }
22658                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22659                 {
22660                         /*
22661                          It is invalid to define transform feedback output in HS
22662                          */
22663                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22664                                 (Utils::Shader::FRAGMENT == stage))
22665                         {
22666                                 continue;
22667                         }
22668
22669                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22670                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22671                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22672
22673                         if ((int)type.GetSize() <= max_xfb_int)
22674                         {
22675                                 m_test_cases.push_back(test_case_xfb);
22676                                 m_test_cases.push_back(test_case_int);
22677                         }
22678
22679                         if ((int)type.GetSize() <= max_xfb_sep)
22680                         {
22681                                 m_test_cases.push_back(test_case_sep);
22682                         }
22683                 }
22684         }
22685 }
22686
22687 /** Constructor
22688  *
22689  * @param context Test context
22690  **/
22691 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22692         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22693                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22694 {
22695         /* Nothing to be done here */
22696 }
22697
22698 /** Get descriptors of buffers necessary for test
22699  *
22700  * @param test_case_index Index of test case
22701  * @param out_descriptors Descriptors of buffers used by test
22702  **/
22703 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22704                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22705 {
22706         const Utils::Type& type = getType(test_case_index);
22707
22708         /* Test needs single uniform and xfb */
22709         out_descriptors.resize(2);
22710
22711         /* Get references */
22712         bufferDescriptor& uniform = out_descriptors[0];
22713         bufferDescriptor& xfb    = out_descriptors[1];
22714
22715         /* Index */
22716         uniform.m_index = 0;
22717         xfb.m_index             = 0;
22718
22719         /* Target */
22720         uniform.m_target = Utils::Buffer::Uniform;
22721         xfb.m_target     = Utils::Buffer::Transform_feedback;
22722
22723         /* Data */
22724         const GLuint                            gen_start   = Utils::s_rand;
22725         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22726         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22727         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22728         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22729
22730         Utils::s_rand                                                           = gen_start;
22731         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22732         /*
22733          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)
22734          how can make them equal ? is it as designed?  Add the following statement,  which can make sure goku_data_pck equals to goku_data
22735          */
22736         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22737
22738         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22739         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22740
22741         /* Uniform data */
22742         uniform.m_initial_data.resize(4 * type_size);
22743         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22744         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22745         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22746         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &gohan_data[0], type_size);
22747
22748         /* XFB data */
22749         xfb.m_initial_data.resize(4 * type_size_pck);
22750         xfb.m_expected_data.resize(4 * type_size_pck);
22751
22752         for (GLuint i = 0; i < 4 * type_size_pck; ++i)
22753         {
22754                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22755                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22756         }
22757
22758         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22759         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22760 }
22761
22762 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22763  *
22764  * @param ignored
22765  * @param captured_varyings List of names
22766  **/
22767 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
22768                                                                                                                    Utils::Program::NameVector& captured_varyings)
22769 {
22770         captured_varyings.resize(2);
22771
22772         captured_varyings[0] = "trunks";
22773         captured_varyings[1] = "gohan";
22774 }
22775
22776 /** Get body of main function for given shader stage
22777  *
22778  * @param test_case_index  Index of test case
22779  * @param stage            Shader stage
22780  * @param out_assignments  Set to empty
22781  * @param out_calculations Set to empty
22782  **/
22783 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22784                                                                                                          std::string& out_assignments, std::string& out_calculations)
22785 {
22786         out_calculations = "";
22787
22788         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22789                                                           "    trunks = uni_trunks;\n"
22790                                                           "    goku   = uni_goku;\n"
22791                                                           "    gohan  = uni_gohan;\n";
22792         static const GLchar* fs = "    fs_out = vec4(0);\n"
22793                                                           "    if (TYPE(1) == gohan + goku + trunks + vegeta)\n"
22794                                                           "    {\n"
22795                                                           "        fs_out = vec4(1);\n"
22796                                                           "    }\n";
22797
22798         const GLchar* assignments = "";
22799         switch (stage)
22800         {
22801         case Utils::Shader::FRAGMENT:
22802                 assignments = fs;
22803                 break;
22804         case Utils::Shader::GEOMETRY:
22805                 assignments = gs;
22806                 break;
22807         default:
22808                 break;
22809         }
22810
22811         out_assignments = assignments;
22812
22813         if (Utils::Shader::FRAGMENT == stage)
22814         {
22815                 const Utils::Type& type = getType(test_case_index);
22816
22817                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22818         }
22819 }
22820
22821 /** Get interface of shader
22822  *
22823  * @param test_case_index  Index of test case
22824  * @param stage            Shader stage
22825  * @param out_interface    Set to ""
22826  **/
22827 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22828                                                                                                                   std::string& out_interface)
22829 {
22830         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22831                                                           "\n"
22832                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22833                                                           "                                      flat out TYPE trunks;\n"
22834                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22835                                                           "                                      flat out TYPE gohan;\n"
22836                                                           "\n"
22837                                                           /*
22838                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22839                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22840                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22841                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22842                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22843                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22844                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22845                  */
22846                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22847                                                           "    TYPE uni_vegeta;\n"
22848                                                           "    TYPE uni_trunks;\n"
22849                                                           "    TYPE uni_goku;\n"
22850                                                           "    TYPE uni_gohan;\n"
22851                                                           "};\n";
22852         static const GLchar* fs = "flat in TYPE vegeta;\n"
22853                                                           "flat in TYPE trunks;\n"
22854                                                           "flat in TYPE goku;\n"
22855                                                           "flat in TYPE gohan;\n"
22856                                                           "\n"
22857                                                           "out vec4 fs_out;\n";
22858
22859         const Utils::Type& type = getType(test_case_index);
22860
22861         switch (stage)
22862         {
22863         case Utils::Shader::FRAGMENT:
22864                 out_interface = fs;
22865                 break;
22866         case Utils::Shader::GEOMETRY:
22867                 out_interface = gs;
22868                 break;
22869         default:
22870                 out_interface = "";
22871                 return;
22872         }
22873
22874         if (Utils::Shader::GEOMETRY == stage)
22875         {
22876                 GLchar           buffer[16];
22877                 size_t           position  = 0;
22878                 const GLuint type_size = type.GetSize();
22879
22880                 sprintf(buffer, "%d", type_size);
22881
22882                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22883         }
22884
22885         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22886 }
22887
22888 /** Get type name
22889  *
22890  * @param test_case_index Index of test case
22891  *
22892  * @return Name of type test in test_case_index
22893  **/
22894 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22895 {
22896         return getTypeName(test_case_index);
22897 }
22898
22899 /** Returns number of types to test
22900  *
22901  * @return Number of types, 34
22902  **/
22903 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
22904 {
22905         return getTypesNumber();
22906 }
22907
22908 /** Inspects program to check if all resources are as expected
22909  *
22910  * @param test_case_index Index of test case
22911  * @param program         Program instance
22912  * @param out_stream      Error message
22913  *
22914  * @return true if everything is ok, false otherwise
22915  **/
22916 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
22917                                                                                                           std::stringstream& out_stream)
22918 {
22919         GLint                      stride       = 0;
22920         const Utils::Type& type          = getType(test_case_index);
22921         const GLuint       type_size = type.GetSize();
22922
22923         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
22924                                                 1 /* buf_size */, &stride);
22925
22926         if ((GLint)(3 * type_size) != stride)
22927         {
22928                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
22929
22930                 return false;
22931         }
22932
22933         return true;
22934 }
22935
22936 /** Constructor
22937  *
22938  * @param context Test context
22939  **/
22940 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
22941         : BufferTestBase(context, "xfb_vertex_streams",
22942                                          "Test verifies that xfb qualifier works with multiple output streams")
22943 {
22944         /* Nothing to be done here */
22945 }
22946
22947 /** Get descriptors of buffers necessary for test
22948  *
22949  * @param ignored
22950  * @param out_descriptors Descriptors of buffers used by test
22951  **/
22952 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
22953                                                                                                 bufferDescriptor::Vector& out_descriptors)
22954 {
22955         const Utils::Type& type = Utils::Type::vec4;
22956
22957         /* Test needs single uniform and three xfbs */
22958         out_descriptors.resize(4);
22959
22960         /* Get references */
22961         bufferDescriptor& uniform = out_descriptors[0];
22962         bufferDescriptor& xfb_1   = out_descriptors[1];
22963         bufferDescriptor& xfb_2   = out_descriptors[2];
22964         bufferDescriptor& xfb_3   = out_descriptors[3];
22965
22966         /* Index */
22967         uniform.m_index = 0;
22968         xfb_1.m_index   = 1;
22969         xfb_2.m_index   = 2;
22970         xfb_3.m_index   = 3;
22971
22972         /* Target */
22973         uniform.m_target = Utils::Buffer::Uniform;
22974         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
22975         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
22976         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
22977
22978         /* Data */
22979         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22980         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22981         const std::vector<GLubyte>& goten_data  = type.GenerateData();
22982         const std::vector<GLubyte>& picolo_data = type.GenerateData();
22983         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22984         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
22985
22986         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
22987
22988         /* Uniform data */
22989         uniform.m_initial_data.resize(6 * type_size);
22990         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
22991         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
22992         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
22993         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
22994         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
22995         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
22996
22997         /* XFB data */
22998         static const GLuint xfb_stride = 64;
22999         xfb_1.m_initial_data.resize(xfb_stride);
23000         xfb_1.m_expected_data.resize(xfb_stride);
23001         xfb_2.m_initial_data.resize(xfb_stride);
23002         xfb_2.m_expected_data.resize(xfb_stride);
23003         xfb_3.m_initial_data.resize(xfb_stride);
23004         xfb_3.m_expected_data.resize(xfb_stride);
23005
23006         for (GLuint i = 0; i < xfb_stride; ++i)
23007         {
23008                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
23009                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
23010                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
23011                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
23012                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
23013                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
23014         }
23015
23016         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
23017         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
23018         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23019         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23020         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23021         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23022 }
23023
23024 /** Get body of main function for given shader stage
23025  *
23026  * @param ignored
23027  * @param stage            Shader stage
23028  * @param out_assignments  Set to empty
23029  * @param out_calculations Set to empty
23030  **/
23031 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23032                                                                                  std::string& out_assignments, std::string& out_calculations)
23033 {
23034         out_calculations = "";
23035
23036         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23037         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23038         // by the GS is assigned to specific stream.
23039         static const GLchar* gs = "    goku   = uni_goku;\n"
23040                                                           "    gohan  = uni_gohan;\n"
23041                                                           "    goten  = uni_goten;\n"
23042                                                           "    EmitStreamVertex(0);\n"
23043                                                           "    EndStreamPrimitive(0);\n"
23044                                                           "    picolo = uni_picolo;\n"
23045                                                           "    vegeta = uni_vegeta;\n"
23046                                                           "    EmitStreamVertex(1);\n"
23047                                                           "    EndStreamPrimitive(1);\n"
23048                                                           "    bulma  = uni_bulma;\n"
23049                                                           "    EmitStreamVertex(2);\n"
23050                                                           "    EndStreamPrimitive(2);\n";
23051
23052         static const GLchar* fs = "    fs_out = gohan + goku + goten + picolo + vegeta + bulma;\n";
23053
23054         const GLchar* assignments = "";
23055         switch (stage)
23056         {
23057         case Utils::Shader::FRAGMENT:
23058                 assignments = fs;
23059                 break;
23060         case Utils::Shader::GEOMETRY:
23061                 assignments = gs;
23062                 break;
23063         default:
23064                 break;
23065         }
23066
23067         out_assignments = assignments;
23068 }
23069
23070 /** Get interface of shader
23071  *
23072  * @param ignored
23073  * @param stage            Shader stage
23074  * @param out_interface    Set to ""
23075  **/
23076 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23077                                                                                           std::string& out_interface)
23078 {
23079         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23080                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23081                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23082                                                           "\n"
23083                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23084                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23085                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23086                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23087                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23088                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23089                                                           "\n"
23090                                                           "layout(binding = 0) uniform gs_block {\n"
23091                                                           "    vec4 uni_goku;\n"
23092                                                           "    vec4 uni_gohan;\n"
23093                                                           "    vec4 uni_goten;\n"
23094                                                           "    vec4 uni_picolo;\n"
23095                                                           "    vec4 uni_vegeta;\n"
23096                                                           "    vec4 uni_bulma;\n"
23097                                                           "};\n";
23098         /*
23099          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23100          */
23101         static const GLchar* fs = "in vec4 goku;\n"
23102                                                           "in vec4 gohan;\n"
23103                                                           "in vec4 goten;\n"
23104                                                           "in vec4 picolo;\n"
23105                                                           "in vec4 vegeta;\n"
23106                                                           "in vec4 bulma;\n"
23107                                                           "\n"
23108                                                           "out vec4 fs_out;\n";
23109
23110         switch (stage)
23111         {
23112         case Utils::Shader::FRAGMENT:
23113                 out_interface = fs;
23114                 break;
23115         case Utils::Shader::GEOMETRY:
23116                 out_interface = gs;
23117                 break;
23118         default:
23119                 out_interface = "";
23120                 return;
23121         }
23122 }
23123
23124 /** Constructor
23125  *
23126  * @param context Test framework context
23127  **/
23128 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23129         : NegativeTestBase(
23130                   context, "xfb_multiple_vertex_streams",
23131                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23132 {
23133 }
23134
23135 /** Source for given test case and stage
23136  *
23137  * @param ignored
23138  * @param stage           Shader stage
23139  *
23140  * @return Shader source
23141  **/
23142 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23143 {
23144         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23145                                                                                   "\n"
23146                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23147                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23148                                                                                   "\n"
23149                                                                                   "\n"
23150                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23151                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23152                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23153         static const GLchar* var_use = "    goku  = result / 2;\n"
23154                                                                    "    gohan = result / 4;\n"
23155                                                                    "    goten = result / 6;\n";
23156         static const GLchar* fs = "#version 430 core\n"
23157                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23158                                                           "\n"
23159                                                           "in  vec4 gs_fs;\n"
23160                                                           "in  vec4 goku;\n"
23161                                                           "out vec4 fs_out;\n"
23162                                                           "\n"
23163                                                           "void main()\n"
23164                                                           "{\n"
23165                                                           "    fs_out = gs_fs + goku;\n"
23166                                                           "}\n"
23167                                                           "\n";
23168         static const GLchar* gs = "#version 430 core\n"
23169                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23170                                                           "\n"
23171                                                           "layout(points)                           in;\n"
23172                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23173                                                           "\n"
23174                                                           "VAR_DEFINITION"
23175                                                           "\n"
23176                                                           "in  vec4 tes_gs[];\n"
23177                                                           "out vec4 gs_fs;\n"
23178                                                           "\n"
23179                                                           "void main()\n"
23180                                                           "{\n"
23181                                                           "    vec4 result = tes_gs[0];\n"
23182                                                           "\n"
23183                                                           "VARIABLE_USE"
23184                                                           "\n"
23185                                                           "    gs_fs = result;\n"
23186                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23187                                                           "    EmitVertex();\n"
23188                                                           "    gs_fs = result;\n"
23189                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23190                                                           "    EmitVertex();\n"
23191                                                           "    gs_fs = result;\n"
23192                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23193                                                           "    EmitVertex();\n"
23194                                                           "    gs_fs = result;\n"
23195                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23196                                                           "    EmitVertex();\n"
23197                                                           "}\n"
23198                                                           "\n";
23199         static const GLchar* vs = "#version 430 core\n"
23200                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23201                                                           "\n"
23202                                                           "in  vec4 in_vs;\n"
23203                                                           "out vec4 vs_tcs;\n"
23204                                                           "\n"
23205                                                           "void main()\n"
23206                                                           "{\n"
23207                                                           "    vs_tcs = in_vs;\n"
23208                                                           "}\n"
23209                                                           "\n";
23210
23211         std::string source;
23212
23213         if (Utils::Shader::GEOMETRY == stage)
23214         {
23215                 size_t position = 0;
23216
23217                 source = gs;
23218
23219                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23220                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23221         }
23222         else
23223         {
23224                 switch (stage)
23225                 {
23226                 case Utils::Shader::FRAGMENT:
23227                         source = fs;
23228                         break;
23229                 case Utils::Shader::VERTEX:
23230                         source = vs;
23231                         break;
23232                 default:
23233                         source = "";
23234                 }
23235         }
23236
23237         return source;
23238 }
23239
23240 /** Selects if "compute" stage is relevant for test
23241  *
23242  * @param ignored
23243  *
23244  * @return false
23245  **/
23246 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23247 {
23248         return false;
23249 }
23250
23251 /** Constructor
23252  *
23253  * @param context Test framework context
23254  **/
23255 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23256         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23257                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23258 {
23259 }
23260
23261 /** Source for given test case and stage
23262  *
23263  * @param test_case_index Index of test case
23264  * @param stage           Shader stage
23265  *
23266  * @return Shader source
23267  **/
23268 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23269 {
23270         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23271                                                                                                 "\n"
23272                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23273                                                                                                 "    vec4 member;\n"
23274                                                                                                 "} gokuARRAY;\n";
23275         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23276                                                                                                  "\n"
23277                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23278         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23279                                                                                                  "\n"
23280                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23281         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23282         static const GLchar* global_use = "";
23283         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23284         static const GLchar* fs                 = "#version 430 core\n"
23285                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23286                                                           "\n"
23287                                                           "in  vec4 gs_fs;\n"
23288                                                           "out vec4 fs_out;\n"
23289                                                           "\n"
23290                                                           "void main()\n"
23291                                                           "{\n"
23292                                                           "    fs_out = gs_fs;\n"
23293                                                           "}\n"
23294                                                           "\n";
23295         static const GLchar* gs_tested = "#version 430 core\n"
23296                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23297                                                                          "\n"
23298                                                                          "layout(points)                           in;\n"
23299                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23300                                                                          "\n"
23301                                                                          "VAR_DEFINITION"
23302                                                                          "\n"
23303                                                                          "in  vec4 tes_gs[];\n"
23304                                                                          "out vec4 gs_fs;\n"
23305                                                                          "\n"
23306                                                                          "void main()\n"
23307                                                                          "{\n"
23308                                                                          "    vec4 result = tes_gs[0];\n"
23309                                                                          "\n"
23310                                                                          "VARIABLE_USE"
23311                                                                          "\n"
23312                                                                          "    gs_fs = result;\n"
23313                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23314                                                                          "    EmitVertex();\n"
23315                                                                          "    gs_fs = result;\n"
23316                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23317                                                                          "    EmitVertex();\n"
23318                                                                          "    gs_fs = result;\n"
23319                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23320                                                                          "    EmitVertex();\n"
23321                                                                          "    gs_fs = result;\n"
23322                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23323                                                                          "    EmitVertex();\n"
23324                                                                          "}\n"
23325                                                                          "\n";
23326         static const GLchar* tcs = "#version 430 core\n"
23327                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23328                                                            "\n"
23329                                                            "layout(vertices = 1) out;\n"
23330                                                            "\n"
23331                                                            "in  vec4 vs_tcs[];\n"
23332                                                            "out vec4 tcs_tes[];\n"
23333                                                            "\n"
23334                                                            "void main()\n"
23335                                                            "{\n"
23336                                                            "\n"
23337                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23338                                                            "\n"
23339                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23340                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23341                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23342                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23343                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23344                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23345                                                            "}\n"
23346                                                            "\n";
23347         static const GLchar* tcs_tested = "#version 430 core\n"
23348                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23349                                                                           "\n"
23350                                                                           "layout(vertices = 1) out;\n"
23351                                                                           "\n"
23352                                                                           "VAR_DEFINITION"
23353                                                                           "\n"
23354                                                                           "in  vec4 vs_tcs[];\n"
23355                                                                           "out vec4 tcs_tes[];\n"
23356                                                                           "\n"
23357                                                                           "void main()\n"
23358                                                                           "{\n"
23359                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23360                                                                           "\n"
23361                                                                           "VARIABLE_USE"
23362                                                                           "\n"
23363                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23364                                                                           "\n"
23365                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23366                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23367                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23368                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23369                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23370                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23371                                                                           "}\n"
23372                                                                           "\n";
23373         static const GLchar* tes_tested = "#version 430 core\n"
23374                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23375                                                                           "\n"
23376                                                                           "layout(isolines, point_mode) in;\n"
23377                                                                           "\n"
23378                                                                           "VAR_DEFINITION"
23379                                                                           "\n"
23380                                                                           "in  vec4 tcs_tes[];\n"
23381                                                                           "out vec4 tes_gs;\n"
23382                                                                           "\n"
23383                                                                           "void main()\n"
23384                                                                           "{\n"
23385                                                                           "    vec4 result = tcs_tes[0];\n"
23386                                                                           "\n"
23387                                                                           "VARIABLE_USE"
23388                                                                           "\n"
23389                                                                           "    tes_gs += result;\n"
23390                                                                           "}\n"
23391                                                                           "\n";
23392         static const GLchar* vs = "#version 430 core\n"
23393                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23394                                                           "\n"
23395                                                           "in  vec4 in_vs;\n"
23396                                                           "out vec4 vs_tcs;\n"
23397                                                           "\n"
23398                                                           "void main()\n"
23399                                                           "{\n"
23400                                                           "    vs_tcs = in_vs;\n"
23401                                                           "}\n"
23402                                                           "\n";
23403         static const GLchar* vs_tested = "#version 430 core\n"
23404                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23405                                                                          "\n"
23406                                                                          "VAR_DEFINITION"
23407                                                                          "\n"
23408                                                                          "in  vec4 in_vs;\n"
23409                                                                          "out vec4 vs_tcs;\n"
23410                                                                          "\n"
23411                                                                          "void main()\n"
23412                                                                          "{\n"
23413                                                                          "    vec4 result = in_vs;\n"
23414                                                                          "\n"
23415                                                                          "VARIABLE_USE"
23416                                                                          "\n"
23417                                                                          "    vs_tcs = result;\n"
23418                                                                          "}\n"
23419                                                                          "\n";
23420
23421         std::string source;
23422         testCase&   test_case = m_test_cases[test_case_index];
23423
23424         if (test_case.m_stage == stage)
23425         {
23426                 const GLchar*   array = "";
23427                 GLchar                   buffer[16];
23428                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23429                 const GLchar*   index    = "";
23430                 GLint                    max_n_xfb = 0;
23431                 size_t                   position  = 0;
23432                 size_t                   temp;
23433                 const GLchar*   var_definition = 0;
23434                 const GLchar*   var_use         = 0;
23435
23436                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23437                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23438
23439                 sprintf(buffer, "%d", max_n_xfb);
23440
23441                 switch (test_case.m_case)
23442                 {
23443                 case BLOCK:
23444                         var_definition = block_var_definition;
23445                         var_use            = block_use;
23446                         break;
23447                 case GLOBAL:
23448                         var_definition = global_var_definition;
23449                         var_use            = global_use;
23450                         break;
23451                 case VECTOR:
23452                         var_definition = vector_var_definition;
23453                         var_use            = vector_use;
23454                         break;
23455                 default:
23456                         TCU_FAIL("Invalid enum");
23457                 }
23458
23459                 switch (stage)
23460                 {
23461                 case Utils::Shader::GEOMETRY:
23462                         source = gs_tested;
23463                         array  = "[]";
23464                         index  = "[0]";
23465                         break;
23466                 case Utils::Shader::TESS_CTRL:
23467                         source = tcs_tested;
23468                         array  = "[]";
23469                         index  = "[gl_InvocationID]";
23470                         break;
23471                 case Utils::Shader::TESS_EVAL:
23472                         source = tes_tested;
23473                         array  = "[]";
23474                         index  = "[0]";
23475                         break;
23476                 case Utils::Shader::VERTEX:
23477                         source = vs_tested;
23478                         break;
23479                 default:
23480                         TCU_FAIL("Invalid enum");
23481                 }
23482
23483                 temp = position;
23484                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23485                 position = temp;
23486                 Utils::replaceToken("BUFFER", position, buffer, source);
23487                 if (GLOBAL != test_case.m_case)
23488                 {
23489                         Utils::replaceToken("ARRAY", position, array, source);
23490                 }
23491                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23492
23493                 Utils::replaceAllTokens("INDEX", index, source);
23494         }
23495         else
23496         {
23497                 switch (test_case.m_stage)
23498                 {
23499                 case Utils::Shader::GEOMETRY:
23500                         switch (stage)
23501                         {
23502                         case Utils::Shader::FRAGMENT:
23503                                 source = fs;
23504                                 break;
23505                         case Utils::Shader::VERTEX:
23506                                 source = vs;
23507                                 break;
23508                         default:
23509                                 source = "";
23510                         }
23511                         break;
23512                 case Utils::Shader::TESS_CTRL:
23513                         switch (stage)
23514                         {
23515                         case Utils::Shader::FRAGMENT:
23516                                 source = fs;
23517                                 break;
23518                         case Utils::Shader::VERTEX:
23519                                 source = vs;
23520                                 break;
23521                         default:
23522                                 source = "";
23523                         }
23524                         break;
23525                 case Utils::Shader::TESS_EVAL:
23526                         switch (stage)
23527                         {
23528                         case Utils::Shader::FRAGMENT:
23529                                 source = fs;
23530                                 break;
23531                         case Utils::Shader::TESS_CTRL:
23532                                 source = tcs;
23533                                 break;
23534                         case Utils::Shader::VERTEX:
23535                                 source = vs;
23536                                 break;
23537                         default:
23538                                 source = "";
23539                         }
23540                         break;
23541                 case Utils::Shader::VERTEX:
23542                         switch (stage)
23543                         {
23544                         case Utils::Shader::FRAGMENT:
23545                                 source = fs;
23546                                 break;
23547                         default:
23548                                 source = "";
23549                         }
23550                         break;
23551                 default:
23552                         TCU_FAIL("Invalid enum");
23553                         break;
23554                 }
23555         }
23556
23557         return source;
23558 }
23559
23560 /** Get description of test case
23561  *
23562  * @param test_case_index Index of test case
23563  *
23564  * @return Test case description
23565  **/
23566 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23567 {
23568         std::stringstream stream;
23569         testCase&                 test_case = m_test_cases[test_case_index];
23570
23571         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23572
23573         switch (test_case.m_case)
23574         {
23575         case BLOCK:
23576                 stream << "BLOCK";
23577                 break;
23578         case GLOBAL:
23579                 stream << "GLOBAL";
23580                 break;
23581         case VECTOR:
23582                 stream << "VECTOR";
23583                 break;
23584         default:
23585                 TCU_FAIL("Invalid enum");
23586         }
23587
23588         return stream.str();
23589 }
23590
23591 /** Get number of test cases
23592  *
23593  * @return Number of test cases
23594  **/
23595 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23596 {
23597         return static_cast<GLuint>(m_test_cases.size());
23598 }
23599
23600 /** Selects if "compute" stage is relevant for test
23601  *
23602  * @param ignored
23603  *
23604  * @return false
23605  **/
23606 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23607 {
23608         return false;
23609 }
23610
23611 /** Prepare all test cases
23612  *
23613  **/
23614 void XFBExceedBufferLimitTest::testInit()
23615 {
23616         for (GLuint c = 0; c < CASE_MAX; ++c)
23617         {
23618                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23619                 {
23620                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23621                                 (Utils::Shader::FRAGMENT == stage))
23622                         {
23623                                 continue;
23624                         }
23625
23626                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23627
23628                         m_test_cases.push_back(test_case);
23629                 }
23630         }
23631 }
23632
23633 /** Constructor
23634  *
23635  * @param context Test framework context
23636  **/
23637 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23638         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23639                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23640 {
23641 }
23642
23643 /** Source for given test case and stage
23644  *
23645  * @param test_case_index Index of test case
23646  * @param stage           Shader stage
23647  *
23648  * @return Shader source
23649  **/
23650 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23651 {
23652         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23653                                                                                                 "\n"
23654                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23655                                                                                                 "    vec4 member;\n"
23656                                                                                                 "} gokuARRAY;\n";
23657         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23658                                                                                                  "\n"
23659                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23660         static const GLchar* vector_var_definition =
23661                 "const uint max_size = SIZE;\n"
23662                 "\n"
23663                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23664         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23665         static const GLchar* global_use = "";
23666         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23667         static const GLchar* fs                 = "#version 430 core\n"
23668                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23669                                                           "\n"
23670                                                           "in  vec4 gs_fs;\n"
23671                                                           "out vec4 fs_out;\n"
23672                                                           "\n"
23673                                                           "void main()\n"
23674                                                           "{\n"
23675                                                           "    fs_out = gs_fs;\n"
23676                                                           "}\n"
23677                                                           "\n";
23678         static const GLchar* gs_tested = "#version 430 core\n"
23679                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23680                                                                          "\n"
23681                                                                          "layout(points)                           in;\n"
23682                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23683                                                                          "\n"
23684                                                                          "VAR_DEFINITION"
23685                                                                          "\n"
23686                                                                          "in  vec4 tes_gs[];\n"
23687                                                                          "out vec4 gs_fs;\n"
23688                                                                          "\n"
23689                                                                          "void main()\n"
23690                                                                          "{\n"
23691                                                                          "    vec4 result = tes_gs[0];\n"
23692                                                                          "\n"
23693                                                                          "VARIABLE_USE"
23694                                                                          "\n"
23695                                                                          "    gs_fs = result;\n"
23696                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23697                                                                          "    EmitVertex();\n"
23698                                                                          "    gs_fs = result;\n"
23699                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23700                                                                          "    EmitVertex();\n"
23701                                                                          "    gs_fs = result;\n"
23702                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23703                                                                          "    EmitVertex();\n"
23704                                                                          "    gs_fs = result;\n"
23705                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23706                                                                          "    EmitVertex();\n"
23707                                                                          "}\n"
23708                                                                          "\n";
23709         static const GLchar* tcs = "#version 430 core\n"
23710                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23711                                                            "\n"
23712                                                            "layout(vertices = 1) out;\n"
23713                                                            "\n"
23714                                                            "in  vec4 vs_tcs[];\n"
23715                                                            "out vec4 tcs_tes[];\n"
23716                                                            "\n"
23717                                                            "void main()\n"
23718                                                            "{\n"
23719                                                            "\n"
23720                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23721                                                            "\n"
23722                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23723                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23724                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23725                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23726                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23727                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23728                                                            "}\n"
23729                                                            "\n";
23730         static const GLchar* tcs_tested = "#version 430 core\n"
23731                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23732                                                                           "\n"
23733                                                                           "layout(vertices = 1) out;\n"
23734                                                                           "\n"
23735                                                                           "VAR_DEFINITION"
23736                                                                           "\n"
23737                                                                           "in  vec4 vs_tcs[];\n"
23738                                                                           "out vec4 tcs_tes[];\n"
23739                                                                           "\n"
23740                                                                           "void main()\n"
23741                                                                           "{\n"
23742                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23743                                                                           "\n"
23744                                                                           "VARIABLE_USE"
23745                                                                           "\n"
23746                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23747                                                                           "\n"
23748                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23749                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23750                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23751                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23752                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23753                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23754                                                                           "}\n"
23755                                                                           "\n";
23756         static const GLchar* tes_tested = "#version 430 core\n"
23757                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23758                                                                           "\n"
23759                                                                           "layout(isolines, point_mode) in;\n"
23760                                                                           "\n"
23761                                                                           "VAR_DEFINITION"
23762                                                                           "\n"
23763                                                                           "in  vec4 tcs_tes[];\n"
23764                                                                           "out vec4 tes_gs;\n"
23765                                                                           "\n"
23766                                                                           "void main()\n"
23767                                                                           "{\n"
23768                                                                           "    vec4 result = tcs_tes[0];\n"
23769                                                                           "\n"
23770                                                                           "VARIABLE_USE"
23771                                                                           "\n"
23772                                                                           "    tes_gs += result;\n"
23773                                                                           "}\n"
23774                                                                           "\n";
23775         static const GLchar* vs = "#version 430 core\n"
23776                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23777                                                           "\n"
23778                                                           "in  vec4 in_vs;\n"
23779                                                           "out vec4 vs_tcs;\n"
23780                                                           "\n"
23781                                                           "void main()\n"
23782                                                           "{\n"
23783                                                           "    vs_tcs = in_vs;\n"
23784                                                           "}\n"
23785                                                           "\n";
23786         static const GLchar* vs_tested = "#version 430 core\n"
23787                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23788                                                                          "\n"
23789                                                                          "VAR_DEFINITION"
23790                                                                          "\n"
23791                                                                          "in  vec4 in_vs;\n"
23792                                                                          "out vec4 vs_tcs;\n"
23793                                                                          "\n"
23794                                                                          "void main()\n"
23795                                                                          "{\n"
23796                                                                          "    vec4 result = in_vs;\n"
23797                                                                          "\n"
23798                                                                          "VARIABLE_USE"
23799                                                                          "\n"
23800                                                                          "    vs_tcs = result;\n"
23801                                                                          "}\n"
23802                                                                          "\n";
23803
23804         std::string source;
23805         testCase&   test_case = m_test_cases[test_case_index];
23806
23807         if (test_case.m_stage == stage)
23808         {
23809                 const GLchar*   array = "";
23810                 GLchar                   buffer[16];
23811                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23812                 const GLchar*   index                    = "";
23813                 GLint                    max_n_xfb_comp  = 0;
23814                 GLint                    max_n_xfb_bytes = 0;
23815                 size_t                   position                = 0;
23816                 size_t                   temp;
23817                 const GLchar*   var_definition = 0;
23818                 const GLchar*   var_use         = 0;
23819
23820                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23821                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23822
23823                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23824
23825                 sprintf(buffer, "%d", max_n_xfb_bytes);
23826
23827                 switch (test_case.m_case)
23828                 {
23829                 case BLOCK:
23830                         var_definition = block_var_definition;
23831                         var_use            = block_use;
23832                         break;
23833                 case GLOBAL:
23834                         var_definition = global_var_definition;
23835                         var_use            = global_use;
23836                         break;
23837                 case VECTOR:
23838                         var_definition = vector_var_definition;
23839                         var_use            = vector_use;
23840                         break;
23841                 default:
23842                         TCU_FAIL("Invalid enum");
23843                 }
23844                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23845                 // change array = "[]" to "[1]"
23846                 switch (stage)
23847                 {
23848                 case Utils::Shader::GEOMETRY:
23849                         source = gs_tested;
23850                         array  = "[1]";
23851                         index  = "[0]";
23852                         break;
23853                 case Utils::Shader::TESS_CTRL:
23854                         source = tcs_tested;
23855                         array  = "[1]";
23856                         index  = "[gl_InvocationID]";
23857                         break;
23858                 case Utils::Shader::TESS_EVAL:
23859                         source = tes_tested;
23860                         array  = "[1]";
23861                         index  = "[0]";
23862                         break;
23863                 case Utils::Shader::VERTEX:
23864                         source = vs_tested;
23865                         break;
23866                 default:
23867                         TCU_FAIL("Invalid enum");
23868                 }
23869
23870                 temp = position;
23871                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23872                 position = temp;
23873                 Utils::replaceToken("SIZE", position, buffer, source);
23874                 if (GLOBAL != test_case.m_case)
23875                 {
23876                         Utils::replaceToken("ARRAY", position, array, source);
23877                 }
23878                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23879
23880                 Utils::replaceAllTokens("INDEX", index, source);
23881         }
23882         else
23883         {
23884                 switch (test_case.m_stage)
23885                 {
23886                 case Utils::Shader::GEOMETRY:
23887                         switch (stage)
23888                         {
23889                         case Utils::Shader::FRAGMENT:
23890                                 source = fs;
23891                                 break;
23892                         case Utils::Shader::VERTEX:
23893                                 source = vs;
23894                                 break;
23895                         default:
23896                                 source = "";
23897                         }
23898                         break;
23899                 case Utils::Shader::TESS_CTRL:
23900                         switch (stage)
23901                         {
23902                         case Utils::Shader::FRAGMENT:
23903                                 source = fs;
23904                                 break;
23905                         case Utils::Shader::VERTEX:
23906                                 source = vs;
23907                                 break;
23908                         default:
23909                                 source = "";
23910                         }
23911                         break;
23912                 case Utils::Shader::TESS_EVAL:
23913                         switch (stage)
23914                         {
23915                         case Utils::Shader::FRAGMENT:
23916                                 source = fs;
23917                                 break;
23918                         case Utils::Shader::TESS_CTRL:
23919                                 source = tcs;
23920                                 break;
23921                         case Utils::Shader::VERTEX:
23922                                 source = vs;
23923                                 break;
23924                         default:
23925                                 source = "";
23926                         }
23927                         break;
23928                 case Utils::Shader::VERTEX:
23929                         switch (stage)
23930                         {
23931                         case Utils::Shader::FRAGMENT:
23932                                 source = fs;
23933                                 break;
23934                         default:
23935                                 source = "";
23936                         }
23937                         break;
23938                 default:
23939                         TCU_FAIL("Invalid enum");
23940                         break;
23941                 }
23942         }
23943
23944         return source;
23945 }
23946
23947 /** Get description of test case
23948  *
23949  * @param test_case_index Index of test case
23950  *
23951  * @return Test case description
23952  **/
23953 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
23954 {
23955         std::stringstream stream;
23956         testCase&                 test_case = m_test_cases[test_case_index];
23957
23958         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23959
23960         switch (test_case.m_case)
23961         {
23962         case BLOCK:
23963                 stream << "BLOCK";
23964                 break;
23965         case GLOBAL:
23966                 stream << "GLOBAL";
23967                 break;
23968         case VECTOR:
23969                 stream << "VECTOR";
23970                 break;
23971         default:
23972                 TCU_FAIL("Invalid enum");
23973         }
23974
23975         return stream.str();
23976 }
23977
23978 /** Get number of test cases
23979  *
23980  * @return Number of test cases
23981  **/
23982 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
23983 {
23984         return static_cast<GLuint>(m_test_cases.size());
23985 }
23986
23987 /** Selects if "compute" stage is relevant for test
23988  *
23989  * @param ignored
23990  *
23991  * @return false
23992  **/
23993 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23994 {
23995         return false;
23996 }
23997
23998 /** Prepare all test cases
23999  *
24000  **/
24001 void XFBExceedOffsetLimitTest::testInit()
24002 {
24003         for (GLuint c = 0; c < CASE_MAX; ++c)
24004         {
24005                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24006                 {
24007                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
24008                                 (Utils::Shader::FRAGMENT == stage))
24009                         {
24010                                 continue;
24011                         }
24012
24013                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
24014
24015                         m_test_cases.push_back(test_case);
24016                 }
24017         }
24018 }
24019
24020 /** Constructor
24021  *
24022  * @param context Test context
24023  **/
24024 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24025         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24026 {
24027         /* Nothing to be done here */
24028 }
24029
24030 /** Get descriptors of buffers necessary for test
24031  *
24032  * @param test_case_index Index of test case
24033  * @param out_descriptors Descriptors of buffers used by test
24034  **/
24035 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24036 {
24037         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24038         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24039
24040         /* Test needs single uniform and two xfbs */
24041         out_descriptors.resize(3);
24042
24043         /* Get references */
24044         bufferDescriptor& uniform = out_descriptors[0];
24045         bufferDescriptor& xfb_1   = out_descriptors[1];
24046         bufferDescriptor& xfb_3   = out_descriptors[2];
24047
24048         /* Index */
24049         uniform.m_index = 0;
24050         xfb_1.m_index   = 1;
24051         xfb_3.m_index   = 3;
24052
24053         /* Target */
24054         uniform.m_target = Utils::Buffer::Uniform;
24055         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24056         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24057
24058         /* Data */
24059         const GLuint                            gen_start   = Utils::s_rand;
24060         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24061         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24062         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24063         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24064         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24065         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24066
24067         Utils::s_rand                                                           = gen_start;
24068         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24069         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24070         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24071         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24072         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24073         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24074
24075         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24076         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24077
24078         /* Uniform data */
24079         uniform.m_initial_data.resize(6 * type_size);
24080         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24081         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24082         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24083         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24084         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24085         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24086
24087         /* XFB data */
24088         xfb_1.m_initial_data.resize(3 * type_size_pck);
24089         xfb_1.m_expected_data.resize(3 * type_size_pck);
24090         xfb_3.m_initial_data.resize(3 * type_size_pck);
24091         xfb_3.m_expected_data.resize(3 * type_size_pck);
24092
24093         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24094         {
24095                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24096                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24097                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24098                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24099         }
24100
24101         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24102         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24103         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24104         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24105         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24106         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24107 }
24108
24109 /** Source for given test case and stage
24110  *
24111  * @param test_case_index Index of test case
24112  * @param stage           Shader stage
24113  *
24114  * @return Shader source
24115  **/
24116 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24117 {
24118         static const GLchar* fs =
24119                 "#version 430 core\n"
24120                 "#extension GL_ARB_enhanced_layouts : require\n"
24121                 "\n"
24122                 "flat in TYPE chichi;\n"
24123                 "flat in TYPE bulma;\n"
24124                 "in Vegeta {\n"
24125                 "    TYPE trunk;\n"
24126                 "    TYPE bra;\n"
24127                 "} vegeta;\n"
24128                 "in Goku {\n"
24129                 "    TYPE gohan;\n"
24130                 "    TYPE goten;\n"
24131                 "} goku;\n"
24132                 "\n"
24133                 "out vec4 fs_out;\n"
24134                 "\n"
24135                 "void main()\n"
24136                 "{\n"
24137                 "    fs_out = vec4(1);\n"
24138                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24139                 "    {\n"
24140                 "        fs_out = vec4(0);\n"
24141                 "    }\n"
24142                 "}\n"
24143                 "\n";
24144
24145         static const GLchar* gs = "#version 430 core\n"
24146                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24147                                                           "\n"
24148                                                           "layout(points)                   in;\n"
24149                                                           "layout(points, max_vertices = 1) out;\n"
24150                                                           "\n"
24151                                                           "INTERFACE"
24152                                                           "\n"
24153                                                           "void main()\n"
24154                                                           "{\n"
24155                                                           "ASSIGNMENTS"
24156                                                           "    EmitVertex();\n"
24157                                                           "}\n"
24158                                                           "\n";
24159
24160         static const GLchar* tcs = "#version 430 core\n"
24161                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24162                                                            "\n"
24163                                                            "layout(vertices = 1) out;\n"
24164                                                            "\n"
24165                                                            "\n"
24166                                                            "void main()\n"
24167                                                            "{\n"
24168                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24169                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24170                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24171                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24172                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24173                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24174                                                            "}\n"
24175                                                            "\n";
24176
24177         static const GLchar* tes = "#version 430 core\n"
24178                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24179                                                            "\n"
24180                                                            "layout(isolines, point_mode) in;\n"
24181                                                            "\n"
24182                                                            "INTERFACE"
24183                                                            "\n"
24184                                                            "void main()\n"
24185                                                            "{\n"
24186                                                            "ASSIGNMENTS"
24187                                                            "}\n"
24188                                                            "\n";
24189
24190         static const GLchar* vs = "#version 430 core\n"
24191                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24192                                                           "\n"
24193                                                           "void main()\n"
24194                                                           "{\n"
24195                                                           "}\n"
24196                                                           "\n";
24197
24198         static const GLchar* vs_tested = "#version 430 core\n"
24199                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24200                                                                          "\n"
24201                                                                          "INTERFACE"
24202                                                                          "\n"
24203                                                                          "void main()\n"
24204                                                                          "{\n"
24205                                                                          "ASSIGNMENTS"
24206                                                                          "}\n"
24207                                                                          "\n";
24208
24209         std::string              source;
24210         const _testCase& test_case = m_test_cases[test_case_index];
24211         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24212
24213         if (test_case.m_stage == stage)
24214         {
24215                 std::string assignments = "    chichi       = uni_chichi;\n"
24216                                                                   "    bulma        = uni_bulma;\n"
24217                                                                   "    vegeta.trunk = uni_trunk;\n"
24218                                                                   "    vegeta.bra   = uni_bra;\n"
24219                                                                   "    goku.gohan   = uni_gohan;\n"
24220                                                                   "    goku.goten   = uni_goten;\n";
24221
24222                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24223                                                                 "\n"
24224                                                                 "const uint type_size = SIZE;\n"
24225                                                                 "\n"
24226                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24227                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24228                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24229                                                                 "    TYPE trunk;\n"
24230                                                                 "    TYPE bra;\n"
24231                                                                 "} vegeta;\n"
24232                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24233                                                                 "    TYPE gohan;\n"
24234                                                                 "    TYPE goten;\n"
24235                                                                 "} goku;\n"
24236                                                                 "\n"
24237                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24238                                                                 "layout(binding = 0, std140) uniform block {\n"
24239                                                                 "    TYPE uni_chichi;\n"
24240                                                                 "    TYPE uni_bulma;\n"
24241                                                                 "    TYPE uni_trunk;\n"
24242                                                                 "    TYPE uni_bra;\n"
24243                                                                 "    TYPE uni_gohan;\n"
24244                                                                 "    TYPE uni_goten;\n"
24245                                                                 "};\n";
24246
24247                 /* Prepare interface string */
24248                 {
24249                         GLchar           buffer[16];
24250                         size_t           position  = 0;
24251                         const GLuint type_size = test_case.m_type.GetSize();
24252
24253                         sprintf(buffer, "%d", type_size);
24254
24255                         Utils::replaceToken("SIZE", position, buffer, interface);
24256                         Utils::replaceAllTokens("TYPE", type_name, interface);
24257                 }
24258
24259                 switch (stage)
24260                 {
24261                 case Utils::Shader::GEOMETRY:
24262                         source = gs;
24263                         break;
24264                 case Utils::Shader::TESS_EVAL:
24265                         source = tes;
24266                         break;
24267                 case Utils::Shader::VERTEX:
24268                         source = vs_tested;
24269                         break;
24270                 default:
24271                         TCU_FAIL("Invalid enum");
24272                 }
24273
24274                 /* Replace tokens */
24275                 {
24276                         size_t position = 0;
24277
24278                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24279                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24280                 }
24281         }
24282         else
24283         {
24284                 switch (test_case.m_stage)
24285                 {
24286                 case Utils::Shader::GEOMETRY:
24287                         switch (stage)
24288                         {
24289                         case Utils::Shader::FRAGMENT:
24290                                 source = fs;
24291                                 Utils::replaceAllTokens("TYPE", type_name, source);
24292                                 break;
24293                         case Utils::Shader::VERTEX:
24294                                 source = vs;
24295                                 break;
24296                         default:
24297                                 source = "";
24298                         }
24299                         break;
24300                 case Utils::Shader::TESS_EVAL:
24301                         switch (stage)
24302                         {
24303                         case Utils::Shader::FRAGMENT:
24304                                 source = fs;
24305                                 Utils::replaceAllTokens("TYPE", type_name, source);
24306                                 break;
24307                         case Utils::Shader::TESS_CTRL:
24308                                 source = tcs;
24309                                 break;
24310                         case Utils::Shader::VERTEX:
24311                                 source = vs;
24312                                 break;
24313                         default:
24314                                 source = "";
24315                         }
24316                         break;
24317                 case Utils::Shader::VERTEX:
24318                         switch (stage)
24319                         {
24320                         case Utils::Shader::FRAGMENT:
24321                                 source = fs;
24322                                 Utils::replaceAllTokens("TYPE", type_name, source);
24323                                 break;
24324                         default:
24325                                 source = "";
24326                         }
24327                         break;
24328                 default:
24329                         TCU_FAIL("Invalid enum");
24330                         break;
24331                 }
24332         }
24333
24334         return source;
24335 }
24336
24337 /** Get name of test case
24338  *
24339  * @param test_case_index Index of test case
24340  *
24341  * @return Name of case
24342  **/
24343 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24344 {
24345         std::string              name;
24346         const _testCase& test_case = m_test_cases[test_case_index];
24347
24348         name = "Tested stage: ";
24349         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24350         name.append(". Tested type: ");
24351         name.append(test_case.m_type.GetGLSLTypeName());
24352
24353         return name;
24354 }
24355
24356 /** Get number of cases
24357  *
24358  * @return Number of test cases
24359  **/
24360 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24361 {
24362         return static_cast<GLuint>(m_test_cases.size());
24363 }
24364
24365 /** Prepare set of test cases
24366  *
24367  **/
24368 void XFBGlobalBufferTest::testInit()
24369 {
24370         GLuint n_types = getTypesNumber();
24371
24372         for (GLuint i = 0; i < n_types; ++i)
24373         {
24374                 const Utils::Type& type = getType(i);
24375                 /*
24376                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24377                  cause a link time error.
24378                  */
24379                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24380                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24381                 {
24382                         continue;
24383                 }
24384                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24385                                                                                  { Utils::Shader::GEOMETRY, type },
24386                                                                                  { Utils::Shader::TESS_EVAL, type } };
24387
24388                 m_test_cases.push_back(test_cases[0]);
24389                 m_test_cases.push_back(test_cases[1]);
24390                 m_test_cases.push_back(test_cases[2]);
24391         }
24392 }
24393
24394 /** Constructor
24395  *
24396  * @param context Test context
24397  **/
24398 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24399         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24400 {
24401         /* Nothing to be done here */
24402 }
24403
24404 /** Execute drawArrays for single vertex
24405  *
24406  * @param test_case_index
24407  *
24408  * @return true
24409  **/
24410 bool XFBStrideTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
24411 {
24412         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24413         GLenum                   primitive_type = GL_PATCHES;
24414         const testCase&  test_case              = m_test_cases[test_case_index];
24415
24416         if (Utils::Shader::VERTEX == test_case.m_stage)
24417         {
24418                 primitive_type = GL_POINTS;
24419         }
24420
24421         gl.disable(GL_RASTERIZER_DISCARD);
24422         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24423
24424         gl.beginTransformFeedback(GL_POINTS);
24425         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24426
24427         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24428         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24429
24430         gl.endTransformFeedback();
24431         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24432
24433         return true;
24434 }
24435
24436 /** Get descriptors of buffers necessary for test
24437  *
24438  * @param test_case_index Index of test case
24439  * @param out_descriptors Descriptors of buffers used by test
24440  **/
24441 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24442 {
24443         const testCase& test_case = m_test_cases[test_case_index];
24444         const Utils::Type& type          = test_case.m_type;
24445
24446         /* Test needs single uniform and xfb */
24447         out_descriptors.resize(2);
24448
24449         /* Get references */
24450         bufferDescriptor& uniform = out_descriptors[0];
24451         bufferDescriptor& xfb    = out_descriptors[1];
24452
24453         /* Index */
24454         uniform.m_index = 0;
24455         xfb.m_index             = 0;
24456
24457         /* Target */
24458         uniform.m_target = Utils::Buffer::Uniform;
24459         xfb.m_target     = Utils::Buffer::Transform_feedback;
24460
24461         /* Data */
24462         const GLuint                            rand_start   = Utils::s_rand;
24463         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24464
24465         Utils::s_rand                                            = rand_start;
24466         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24467
24468         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24469         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24470         /*
24471          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24472          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24473          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24474          only one valid data should be initialized in xfb.m_expected_data
24475          */
24476         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24477         /* Uniform data */
24478         uniform.m_initial_data.resize(uni_type_size);
24479         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24480
24481         /* XFB data */
24482         xfb.m_initial_data.resize(xfb_data_size);
24483         xfb.m_expected_data.resize(xfb_data_size);
24484
24485         for (GLuint i = 0; i < xfb_data_size; ++i)
24486         {
24487                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24488                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24489         }
24490
24491         if (test_case.m_stage == Utils::Shader::VERTEX)
24492         {
24493                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24494         }
24495         else
24496         {
24497                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24498                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24499         }
24500 }
24501
24502 /** Get body of main function for given shader stage
24503  *
24504  * @param test_case_index  Index of test case
24505  * @param stage            Shader stage
24506  * @param out_assignments  Set to empty
24507  * @param out_calculations Set to empty
24508  **/
24509 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24510                                                                   std::string& out_calculations)
24511 {
24512         const testCase& test_case = m_test_cases[test_case_index];
24513
24514         out_calculations = "";
24515
24516         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24517         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24518                                                           "    if (TYPE(0) == goku)\n"
24519                                                           "    {\n"
24520                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24521                                                           "    }\n";
24522
24523         const GLchar* assignments = "";
24524
24525         if (test_case.m_stage == stage)
24526         {
24527                 switch (stage)
24528                 {
24529                 case Utils::Shader::GEOMETRY:
24530                         assignments = vs_tes_gs;
24531                         break;
24532                 case Utils::Shader::TESS_EVAL:
24533                         assignments = vs_tes_gs;
24534                         break;
24535                 case Utils::Shader::VERTEX:
24536                         assignments = vs_tes_gs;
24537                         break;
24538                 default:
24539                         TCU_FAIL("Invalid enum");
24540                 }
24541         }
24542         else
24543         {
24544                 switch (stage)
24545                 {
24546                 case Utils::Shader::FRAGMENT:
24547                         assignments = fs;
24548                         break;
24549                 case Utils::Shader::GEOMETRY:
24550                 case Utils::Shader::TESS_CTRL:
24551                 case Utils::Shader::TESS_EVAL:
24552                 case Utils::Shader::VERTEX:
24553                         break;
24554                 default:
24555                         TCU_FAIL("Invalid enum");
24556                 }
24557         }
24558
24559         out_assignments = assignments;
24560
24561         if (Utils::Shader::FRAGMENT == stage)
24562         {
24563                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24564         }
24565 }
24566
24567 /** Get interface of shader
24568  *
24569  * @param test_case_index  Index of test case
24570  * @param stage            Shader stage
24571  * @param out_interface    Set to ""
24572  **/
24573 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24574 {
24575         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24576                                                                          "\n"
24577                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24578                                                                          "    TYPE uni_goku;\n"
24579                                                                          "};\n";
24580         static const GLchar* fs = "FLAT in TYPE goku;\n"
24581                                                           "\n"
24582                                                           "out vec4 fs_out;\n";
24583
24584         const testCase& test_case = m_test_cases[test_case_index];
24585         const GLchar*   interface = "";
24586         const GLchar*   flat      = "";
24587
24588         if (test_case.m_stage == stage)
24589         {
24590                 switch (stage)
24591                 {
24592                 case Utils::Shader::GEOMETRY:
24593                         interface = vs_tes_gs;
24594                         break;
24595                 case Utils::Shader::TESS_EVAL:
24596                         interface = vs_tes_gs;
24597                         break;
24598                 case Utils::Shader::VERTEX:
24599                         interface = vs_tes_gs;
24600                         break;
24601                 default:
24602                         TCU_FAIL("Invalid enum");
24603                 }
24604         }
24605         else
24606         {
24607                 switch (stage)
24608                 {
24609                 case Utils::Shader::FRAGMENT:
24610                         interface = fs;
24611                         break;
24612                 case Utils::Shader::GEOMETRY:
24613                 case Utils::Shader::TESS_CTRL:
24614                 case Utils::Shader::TESS_EVAL:
24615                 case Utils::Shader::VERTEX:
24616                         break;
24617                 default:
24618                         TCU_FAIL("Invalid enum");
24619                 }
24620         }
24621
24622         out_interface = interface;
24623
24624         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24625         {
24626                 flat = "flat";
24627         }
24628
24629         Utils::replaceAllTokens("FLAT", flat, out_interface);
24630         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24631 }
24632
24633 /** Get source code of shader
24634  *
24635  * @param test_case_index Index of test case
24636  * @param stage           Shader stage
24637  *
24638  * @return Source
24639  **/
24640 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24641 {
24642         std::string             source;
24643         const testCase& test_case = m_test_cases[test_case_index];
24644
24645         switch (test_case.m_stage)
24646         {
24647         case Utils::Shader::VERTEX:
24648                 switch (stage)
24649                 {
24650                 case Utils::Shader::FRAGMENT:
24651                 case Utils::Shader::VERTEX:
24652                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24653                         break;
24654                 default:
24655                         break;
24656                 }
24657                 break;
24658
24659         case Utils::Shader::TESS_EVAL:
24660                 switch (stage)
24661                 {
24662                 case Utils::Shader::FRAGMENT:
24663                 case Utils::Shader::TESS_CTRL:
24664                 case Utils::Shader::TESS_EVAL:
24665                 case Utils::Shader::VERTEX:
24666                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24667                         break;
24668                 default:
24669                         break;
24670                 }
24671                 break;
24672
24673         case Utils::Shader::GEOMETRY:
24674                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24675                 break;
24676
24677         default:
24678                 TCU_FAIL("Invalid enum");
24679                 break;
24680         }
24681
24682         /* */
24683         return source;
24684 }
24685
24686 /** Get name of test case
24687  *
24688  * @param test_case_index Index of test case
24689  *
24690  * @return Name of tested stage
24691  **/
24692 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24693 {
24694         std::stringstream stream;
24695         const testCase&   test_case = m_test_cases[test_case_index];
24696
24697         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24698                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24699
24700         return stream.str();
24701 }
24702
24703 /** Returns number of test cases
24704  *
24705  * @return TEST_MAX
24706  **/
24707 glw::GLuint XFBStrideTest::getTestCaseNumber()
24708 {
24709         return static_cast<GLuint>(m_test_cases.size());
24710 }
24711
24712 /** Prepare all test cases
24713  *
24714  **/
24715 void XFBStrideTest::testInit()
24716 {
24717         const GLuint n_types = getTypesNumber();
24718
24719         for (GLuint i = 0; i < n_types; ++i)
24720         {
24721                 const Utils::Type& type = getType(i);
24722
24723                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24724                 {
24725                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24726                                 (Utils::Shader::TESS_CTRL == stage))
24727                         {
24728                                 continue;
24729                         }
24730
24731                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24732
24733                         m_test_cases.push_back(test_case);
24734                 }
24735         }
24736 }
24737
24738 /** Constructor
24739  *
24740  * @param context Test framework context
24741  **/
24742 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24743         : NegativeTestBase(
24744                   context, "xfb_block_member_buffer",
24745                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24746 {
24747 }
24748
24749 /** Source for given test case and stage
24750  *
24751  * @param test_case_index Index of test case
24752  * @param stage           Shader stage
24753  *
24754  * @return Shader source
24755  **/
24756 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24757 {
24758         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24759                                                                                   "                            vec4 gohan;\n"
24760                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24761                                                                                   "} gokuARRAY;\n";
24762         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24763                                                                    "    gokuINDEX.goten = result / 4;\n";
24764         static const GLchar* fs = "#version 430 core\n"
24765                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24766                                                           "\n"
24767                                                           "in  vec4 gs_fs;\n"
24768                                                           "out vec4 fs_out;\n"
24769                                                           "\n"
24770                                                           "void main()\n"
24771                                                           "{\n"
24772                                                           "    fs_out = gs_fs;\n"
24773                                                           "}\n"
24774                                                           "\n";
24775         static const GLchar* gs_tested = "#version 430 core\n"
24776                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24777                                                                          "\n"
24778                                                                          "layout(points)                           in;\n"
24779                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24780                                                                          "\n"
24781                                                                          "VAR_DEFINITION"
24782                                                                          "\n"
24783                                                                          "in  vec4 tes_gs[];\n"
24784                                                                          "out vec4 gs_fs;\n"
24785                                                                          "\n"
24786                                                                          "void main()\n"
24787                                                                          "{\n"
24788                                                                          "    vec4 result = tes_gs[0];\n"
24789                                                                          "\n"
24790                                                                          "VARIABLE_USE"
24791                                                                          "\n"
24792                                                                          "    gs_fs = result;\n"
24793                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24794                                                                          "    EmitVertex();\n"
24795                                                                          "    gs_fs = result;\n"
24796                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24797                                                                          "    EmitVertex();\n"
24798                                                                          "    gs_fs = result;\n"
24799                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24800                                                                          "    EmitVertex();\n"
24801                                                                          "    gs_fs = result;\n"
24802                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24803                                                                          "    EmitVertex();\n"
24804                                                                          "}\n"
24805                                                                          "\n";
24806         static const GLchar* tcs = "#version 430 core\n"
24807                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24808                                                            "\n"
24809                                                            "layout(vertices = 1) out;\n"
24810                                                            "\n"
24811                                                            "in  vec4 vs_tcs[];\n"
24812                                                            "out vec4 tcs_tes[];\n"
24813                                                            "\n"
24814                                                            "void main()\n"
24815                                                            "{\n"
24816                                                            "\n"
24817                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24818                                                            "\n"
24819                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24820                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24821                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24822                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24823                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24824                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24825                                                            "}\n"
24826                                                            "\n";
24827         static const GLchar* tcs_tested = "#version 430 core\n"
24828                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24829                                                                           "\n"
24830                                                                           "layout(vertices = 1) out;\n"
24831                                                                           "\n"
24832                                                                           "VAR_DEFINITION"
24833                                                                           "\n"
24834                                                                           "in  vec4 vs_tcs[];\n"
24835                                                                           "out vec4 tcs_tes[];\n"
24836                                                                           "\n"
24837                                                                           "void main()\n"
24838                                                                           "{\n"
24839                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24840                                                                           "\n"
24841                                                                           "VARIABLE_USE"
24842                                                                           "\n"
24843                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24844                                                                           "\n"
24845                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24846                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24847                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24848                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24849                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24850                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24851                                                                           "}\n"
24852                                                                           "\n";
24853         static const GLchar* tes_tested = "#version 430 core\n"
24854                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24855                                                                           "\n"
24856                                                                           "layout(isolines, point_mode) in;\n"
24857                                                                           "\n"
24858                                                                           "VAR_DEFINITION"
24859                                                                           "\n"
24860                                                                           "in  vec4 tcs_tes[];\n"
24861                                                                           "out vec4 tes_gs;\n"
24862                                                                           "\n"
24863                                                                           "void main()\n"
24864                                                                           "{\n"
24865                                                                           "    vec4 result = tcs_tes[0];\n"
24866                                                                           "\n"
24867                                                                           "VARIABLE_USE"
24868                                                                           "\n"
24869                                                                           "    tes_gs += result;\n"
24870                                                                           "}\n"
24871                                                                           "\n";
24872         static const GLchar* vs = "#version 430 core\n"
24873                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24874                                                           "\n"
24875                                                           "in  vec4 in_vs;\n"
24876                                                           "out vec4 vs_tcs;\n"
24877                                                           "\n"
24878                                                           "void main()\n"
24879                                                           "{\n"
24880                                                           "    vs_tcs = in_vs;\n"
24881                                                           "}\n"
24882                                                           "\n";
24883         static const GLchar* vs_tested = "#version 430 core\n"
24884                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24885                                                                          "\n"
24886                                                                          "VAR_DEFINITION"
24887                                                                          "\n"
24888                                                                          "in  vec4 in_vs;\n"
24889                                                                          "out vec4 vs_tcs;\n"
24890                                                                          "\n"
24891                                                                          "void main()\n"
24892                                                                          "{\n"
24893                                                                          "    vec4 result = in_vs;\n"
24894                                                                          "\n"
24895                                                                          "VARIABLE_USE"
24896                                                                          "\n"
24897                                                                          "    vs_tcs = result;\n"
24898                                                                          "}\n"
24899                                                                          "\n";
24900
24901         std::string source;
24902         testCase&   test_case = m_test_cases[test_case_index];
24903
24904         if (test_case.m_stage == stage)
24905         {
24906                 const GLchar* array     = "";
24907                 const GLchar* index     = "";
24908                 size_t            position = 0;
24909
24910                 switch (stage)
24911                 {
24912                 case Utils::Shader::GEOMETRY:
24913                         source = gs_tested;
24914                         array  = "[]";
24915                         index  = "[0]";
24916                         break;
24917                 case Utils::Shader::TESS_CTRL:
24918                         source = tcs_tested;
24919                         array  = "[]";
24920                         index  = "[gl_InvocationID]";
24921                         break;
24922                 case Utils::Shader::TESS_EVAL:
24923                         source = tes_tested;
24924                         array  = "[]";
24925                         index  = "[0]";
24926                         break;
24927                 case Utils::Shader::VERTEX:
24928                         source = vs_tested;
24929                         break;
24930                 default:
24931                         TCU_FAIL("Invalid enum");
24932                 }
24933
24934                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
24935                 position = 0;
24936                 Utils::replaceToken("ARRAY", position, array, source);
24937                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
24938
24939                 Utils::replaceAllTokens("INDEX", index, source);
24940         }
24941         else
24942         {
24943                 switch (test_case.m_stage)
24944                 {
24945                 case Utils::Shader::GEOMETRY:
24946                         switch (stage)
24947                         {
24948                         case Utils::Shader::FRAGMENT:
24949                                 source = fs;
24950                                 break;
24951                         case Utils::Shader::VERTEX:
24952                                 source = vs;
24953                                 break;
24954                         default:
24955                                 source = "";
24956                         }
24957                         break;
24958                 case Utils::Shader::TESS_CTRL:
24959                         switch (stage)
24960                         {
24961                         case Utils::Shader::FRAGMENT:
24962                                 source = fs;
24963                                 break;
24964                         case Utils::Shader::VERTEX:
24965                                 source = vs;
24966                                 break;
24967                         default:
24968                                 source = "";
24969                         }
24970                         break;
24971                 case Utils::Shader::TESS_EVAL:
24972                         switch (stage)
24973                         {
24974                         case Utils::Shader::FRAGMENT:
24975                                 source = fs;
24976                                 break;
24977                         case Utils::Shader::TESS_CTRL:
24978                                 source = tcs;
24979                                 break;
24980                         case Utils::Shader::VERTEX:
24981                                 source = vs;
24982                                 break;
24983                         default:
24984                                 source = "";
24985                         }
24986                         break;
24987                 case Utils::Shader::VERTEX:
24988                         switch (stage)
24989                         {
24990                         case Utils::Shader::FRAGMENT:
24991                                 source = fs;
24992                                 break;
24993                         default:
24994                                 source = "";
24995                         }
24996                         break;
24997                 default:
24998                         TCU_FAIL("Invalid enum");
24999                         break;
25000                 }
25001         }
25002
25003         return source;
25004 }
25005
25006 /** Get description of test case
25007  *
25008  * @param test_case_index Index of test case
25009  *
25010  * @return Test case description
25011  **/
25012 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
25013 {
25014         std::stringstream stream;
25015         testCase&                 test_case = m_test_cases[test_case_index];
25016
25017         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
25018
25019         return stream.str();
25020 }
25021
25022 /** Get number of test cases
25023  *
25024  * @return Number of test cases
25025  **/
25026 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25027 {
25028         return static_cast<GLuint>(m_test_cases.size());
25029 }
25030
25031 /** Selects if "compute" stage is relevant for test
25032  *
25033  * @param ignored
25034  *
25035  * @return false
25036  **/
25037 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25038 {
25039         return false;
25040 }
25041
25042 /** Prepare all test cases
25043  *
25044  **/
25045 void XFBBlockMemberBufferTest::testInit()
25046 {
25047         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25048         {
25049                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25050                         (Utils::Shader::FRAGMENT == stage))
25051                 {
25052                         continue;
25053                 }
25054
25055                 testCase test_case = { (Utils::Shader::STAGES)stage };
25056
25057                 m_test_cases.push_back(test_case);
25058         }
25059 }
25060
25061 /** Constructor
25062  *
25063  * @param context Test framework context
25064  **/
25065 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25066         : NegativeTestBase(context, "xfb_output_overlapping",
25067                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25068 {
25069 }
25070
25071 /** Source for given test case and stage
25072  *
25073  * @param test_case_index Index of test case
25074  * @param stage           Shader stage
25075  *
25076  * @return Shader source
25077  **/
25078 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25079 {
25080         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25081                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25082         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25083                                                                    "    gotenINDEX = TYPE(1);\n"
25084                                                                    "    if (vec4(0) == result)\n"
25085                                                                    "    {\n"
25086                                                                    "        gohanINDEX = TYPE(1);\n"
25087                                                                    "        gotenINDEX = TYPE(0);\n"
25088                                                                    "    }\n";
25089         static const GLchar* fs = "#version 430 core\n"
25090                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25091                                                           "\n"
25092                                                           "in  vec4 gs_fs;\n"
25093                                                           "out vec4 fs_out;\n"
25094                                                           "\n"
25095                                                           "void main()\n"
25096                                                           "{\n"
25097                                                           "    fs_out = gs_fs;\n"
25098                                                           "}\n"
25099                                                           "\n";
25100         static const GLchar* gs_tested = "#version 430 core\n"
25101                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25102                                                                          "\n"
25103                                                                          "layout(points)                           in;\n"
25104                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25105                                                                          "\n"
25106                                                                          "VAR_DEFINITION"
25107                                                                          "\n"
25108                                                                          "in  vec4 tes_gs[];\n"
25109                                                                          "out vec4 gs_fs;\n"
25110                                                                          "\n"
25111                                                                          "void main()\n"
25112                                                                          "{\n"
25113                                                                          "    vec4 result = tes_gs[0];\n"
25114                                                                          "\n"
25115                                                                          "VARIABLE_USE"
25116                                                                          "\n"
25117                                                                          "    gs_fs = result;\n"
25118                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25119                                                                          "    EmitVertex();\n"
25120                                                                          "    gs_fs = result;\n"
25121                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25122                                                                          "    EmitVertex();\n"
25123                                                                          "    gs_fs = result;\n"
25124                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25125                                                                          "    EmitVertex();\n"
25126                                                                          "    gs_fs = result;\n"
25127                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25128                                                                          "    EmitVertex();\n"
25129                                                                          "}\n"
25130                                                                          "\n";
25131         static const GLchar* tcs = "#version 430 core\n"
25132                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25133                                                            "\n"
25134                                                            "layout(vertices = 1) out;\n"
25135                                                            "\n"
25136                                                            "in  vec4 vs_tcs[];\n"
25137                                                            "out vec4 tcs_tes[];\n"
25138                                                            "\n"
25139                                                            "void main()\n"
25140                                                            "{\n"
25141                                                            "\n"
25142                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25143                                                            "\n"
25144                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25145                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25146                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25147                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25148                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25149                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25150                                                            "}\n"
25151                                                            "\n";
25152         static const GLchar* tcs_tested = "#version 430 core\n"
25153                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25154                                                                           "\n"
25155                                                                           "layout(vertices = 1) out;\n"
25156                                                                           "\n"
25157                                                                           "VAR_DEFINITION"
25158                                                                           "\n"
25159                                                                           "in  vec4 vs_tcs[];\n"
25160                                                                           "out vec4 tcs_tes[];\n"
25161                                                                           "\n"
25162                                                                           "void main()\n"
25163                                                                           "{\n"
25164                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25165                                                                           "\n"
25166                                                                           "VARIABLE_USE"
25167                                                                           "\n"
25168                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25169                                                                           "\n"
25170                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25171                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25172                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25173                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25174                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25175                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25176                                                                           "}\n"
25177                                                                           "\n";
25178         static const GLchar* tes_tested = "#version 430 core\n"
25179                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25180                                                                           "\n"
25181                                                                           "layout(isolines, point_mode) in;\n"
25182                                                                           "\n"
25183                                                                           "VAR_DEFINITION"
25184                                                                           "\n"
25185                                                                           "in  vec4 tcs_tes[];\n"
25186                                                                           "out vec4 tes_gs;\n"
25187                                                                           "\n"
25188                                                                           "void main()\n"
25189                                                                           "{\n"
25190                                                                           "    vec4 result = tcs_tes[0];\n"
25191                                                                           "\n"
25192                                                                           "VARIABLE_USE"
25193                                                                           "\n"
25194                                                                           "    tes_gs += result;\n"
25195                                                                           "}\n"
25196                                                                           "\n";
25197         static const GLchar* vs = "#version 430 core\n"
25198                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25199                                                           "\n"
25200                                                           "in  vec4 in_vs;\n"
25201                                                           "out vec4 vs_tcs;\n"
25202                                                           "\n"
25203                                                           "void main()\n"
25204                                                           "{\n"
25205                                                           "    vs_tcs = in_vs;\n"
25206                                                           "}\n"
25207                                                           "\n";
25208         static const GLchar* vs_tested = "#version 430 core\n"
25209                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25210                                                                          "\n"
25211                                                                          "VAR_DEFINITION"
25212                                                                          "\n"
25213                                                                          "in  vec4 in_vs;\n"
25214                                                                          "out vec4 vs_tcs;\n"
25215                                                                          "\n"
25216                                                                          "void main()\n"
25217                                                                          "{\n"
25218                                                                          "    vec4 result = in_vs;\n"
25219                                                                          "\n"
25220                                                                          "VARIABLE_USE"
25221                                                                          "\n"
25222                                                                          "    vs_tcs = result;\n"
25223                                                                          "}\n"
25224                                                                          "\n";
25225
25226         std::string source;
25227         testCase&   test_case = m_test_cases[test_case_index];
25228
25229         if (test_case.m_stage == stage)
25230         {
25231                 const GLchar* array = "";
25232                 GLchar            buffer_gohan[16];
25233                 GLchar            buffer_goten[16];
25234                 const GLchar* index                      = "";
25235                 size_t            position               = 0;
25236                 size_t            position_start = 0;
25237                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25238
25239                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25240                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25241
25242                 switch (stage)
25243                 {
25244                 case Utils::Shader::GEOMETRY:
25245                         source = gs_tested;
25246                         array  = "[]";
25247                         index  = "[0]";
25248                         break;
25249                 case Utils::Shader::TESS_CTRL:
25250                         source = tcs_tested;
25251                         array  = "[]";
25252                         index  = "[gl_InvocationID]";
25253                         break;
25254                 case Utils::Shader::TESS_EVAL:
25255                         source = tes_tested;
25256                         array  = "[]";
25257                         index  = "[0]";
25258                         break;
25259                 case Utils::Shader::VERTEX:
25260                         source = vs_tested;
25261                         break;
25262                 default:
25263                         TCU_FAIL("Invalid enum");
25264                 }
25265
25266                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25267                 position = 0;
25268                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25269                 Utils::replaceToken("TYPE", position, type_name, source);
25270                 Utils::replaceToken("ARRAY", position, array, source);
25271                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25272                 Utils::replaceToken("TYPE", position, type_name, source);
25273                 Utils::replaceToken("ARRAY", position, array, source);
25274                 position_start = position;
25275                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25276                 position = position_start;
25277                 Utils::replaceToken("INDEX", position, index, source);
25278                 Utils::replaceToken("TYPE", position, type_name, source);
25279                 Utils::replaceToken("INDEX", position, index, source);
25280                 Utils::replaceToken("TYPE", position, type_name, source);
25281                 Utils::replaceToken("INDEX", position, index, source);
25282                 Utils::replaceToken("TYPE", position, type_name, source);
25283                 Utils::replaceToken("INDEX", position, index, source);
25284                 Utils::replaceToken("TYPE", position, type_name, source);
25285         }
25286         else
25287         {
25288                 switch (test_case.m_stage)
25289                 {
25290                 case Utils::Shader::GEOMETRY:
25291                         switch (stage)
25292                         {
25293                         case Utils::Shader::FRAGMENT:
25294                                 source = fs;
25295                                 break;
25296                         case Utils::Shader::VERTEX:
25297                                 source = vs;
25298                                 break;
25299                         default:
25300                                 source = "";
25301                         }
25302                         break;
25303                 case Utils::Shader::TESS_CTRL:
25304                         switch (stage)
25305                         {
25306                         case Utils::Shader::FRAGMENT:
25307                                 source = fs;
25308                                 break;
25309                         case Utils::Shader::VERTEX:
25310                                 source = vs;
25311                                 break;
25312                         default:
25313                                 source = "";
25314                         }
25315                         break;
25316                 case Utils::Shader::TESS_EVAL:
25317                         switch (stage)
25318                         {
25319                         case Utils::Shader::FRAGMENT:
25320                                 source = fs;
25321                                 break;
25322                         case Utils::Shader::TESS_CTRL:
25323                                 source = tcs;
25324                                 break;
25325                         case Utils::Shader::VERTEX:
25326                                 source = vs;
25327                                 break;
25328                         default:
25329                                 source = "";
25330                         }
25331                         break;
25332                 case Utils::Shader::VERTEX:
25333                         switch (stage)
25334                         {
25335                         case Utils::Shader::FRAGMENT:
25336                                 source = fs;
25337                                 break;
25338                         default:
25339                                 source = "";
25340                         }
25341                         break;
25342                 default:
25343                         TCU_FAIL("Invalid enum");
25344                         break;
25345                 }
25346         }
25347
25348         return source;
25349 }
25350
25351 /** Get description of test case
25352  *
25353  * @param test_case_index Index of test case
25354  *
25355  * @return Test case description
25356  **/
25357 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25358 {
25359         std::stringstream stream;
25360         testCase&                 test_case = m_test_cases[test_case_index];
25361
25362         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25363                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25364                    << test_case.m_offset_goten;
25365
25366         return stream.str();
25367 }
25368
25369 /** Get number of test cases
25370  *
25371  * @return Number of test cases
25372  **/
25373 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25374 {
25375         return static_cast<GLuint>(m_test_cases.size());
25376 }
25377
25378 /** Selects if "compute" stage is relevant for test
25379  *
25380  * @param ignored
25381  *
25382  * @return false
25383  **/
25384 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25385 {
25386         return false;
25387 }
25388
25389 /** Prepare all test cases
25390  *
25391  **/
25392 void XFBOutputOverlappingTest::testInit()
25393 {
25394         const GLuint n_types = getTypesNumber();
25395
25396         for (GLuint i = 0; i < n_types; ++i)
25397         {
25398                 const Utils::Type& type                   = getType(i);
25399                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25400
25401                 /* Skip scalars, not applicable as:
25402                  *
25403                  *     The offset must be a multiple of the size of the first component of the first
25404                  *     qualified variable or block member, or a compile-time error results.
25405                  */
25406                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25407                 {
25408                         continue;
25409                 }
25410
25411                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25412                 {
25413                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25414                                 (Utils::Shader::FRAGMENT == stage))
25415                         {
25416                                 continue;
25417                         }
25418
25419                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25420                                                                    (Utils::Shader::STAGES)stage, type };
25421
25422                         m_test_cases.push_back(test_case);
25423                 }
25424         }
25425 }
25426
25427 /** Constructor
25428  *
25429  * @param context Test framework context
25430  **/
25431 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25432         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25433                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25434 {
25435 }
25436
25437 /** Source for given test case and stage
25438  *
25439  * @param test_case_index Index of test case
25440  * @param stage           Shader stage
25441  *
25442  * @return Shader source
25443  **/
25444 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25445 {
25446         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25447         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25448                                                                    "    if (vec4(0) == result)\n"
25449                                                                    "    {\n"
25450                                                                    "        gohanINDEX = TYPE(1);\n"
25451                                                                    "    }\n";
25452         static const GLchar* fs = "#version 430 core\n"
25453                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25454                                                           "\n"
25455                                                           "in  vec4 gs_fs;\n"
25456                                                           "out vec4 fs_out;\n"
25457                                                           "\n"
25458                                                           "void main()\n"
25459                                                           "{\n"
25460                                                           "    fs_out = gs_fs;\n"
25461                                                           "}\n"
25462                                                           "\n";
25463         static const GLchar* gs_tested = "#version 430 core\n"
25464                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25465                                                                          "\n"
25466                                                                          "layout(points)                           in;\n"
25467                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25468                                                                          "\n"
25469                                                                          "VAR_DEFINITION"
25470                                                                          "\n"
25471                                                                          "in  vec4 tes_gs[];\n"
25472                                                                          "out vec4 gs_fs;\n"
25473                                                                          "\n"
25474                                                                          "void main()\n"
25475                                                                          "{\n"
25476                                                                          "    vec4 result = tes_gs[0];\n"
25477                                                                          "\n"
25478                                                                          "VARIABLE_USE"
25479                                                                          "\n"
25480                                                                          "    gs_fs = result;\n"
25481                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25482                                                                          "    EmitVertex();\n"
25483                                                                          "    gs_fs = result;\n"
25484                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25485                                                                          "    EmitVertex();\n"
25486                                                                          "    gs_fs = result;\n"
25487                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25488                                                                          "    EmitVertex();\n"
25489                                                                          "    gs_fs = result;\n"
25490                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25491                                                                          "    EmitVertex();\n"
25492                                                                          "}\n"
25493                                                                          "\n";
25494         static const GLchar* tcs = "#version 430 core\n"
25495                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25496                                                            "\n"
25497                                                            "layout(vertices = 1) out;\n"
25498                                                            "\n"
25499                                                            "in  vec4 vs_tcs[];\n"
25500                                                            "out vec4 tcs_tes[];\n"
25501                                                            "\n"
25502                                                            "void main()\n"
25503                                                            "{\n"
25504                                                            "\n"
25505                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25506                                                            "\n"
25507                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25508                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25509                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25510                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25511                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25512                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25513                                                            "}\n"
25514                                                            "\n";
25515         static const GLchar* tcs_tested = "#version 430 core\n"
25516                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25517                                                                           "\n"
25518                                                                           "layout(vertices = 1) out;\n"
25519                                                                           "\n"
25520                                                                           "VAR_DEFINITION"
25521                                                                           "\n"
25522                                                                           "in  vec4 vs_tcs[];\n"
25523                                                                           "out vec4 tcs_tes[];\n"
25524                                                                           "\n"
25525                                                                           "void main()\n"
25526                                                                           "{\n"
25527                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25528                                                                           "\n"
25529                                                                           "VARIABLE_USE"
25530                                                                           "\n"
25531                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25532                                                                           "\n"
25533                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25534                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25535                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25536                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25537                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25538                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25539                                                                           "}\n"
25540                                                                           "\n";
25541         static const GLchar* tes_tested = "#version 430 core\n"
25542                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25543                                                                           "\n"
25544                                                                           "layout(isolines, point_mode) in;\n"
25545                                                                           "\n"
25546                                                                           "VAR_DEFINITION"
25547                                                                           "\n"
25548                                                                           "in  vec4 tcs_tes[];\n"
25549                                                                           "out vec4 tes_gs;\n"
25550                                                                           "\n"
25551                                                                           "void main()\n"
25552                                                                           "{\n"
25553                                                                           "    vec4 result = tcs_tes[0];\n"
25554                                                                           "\n"
25555                                                                           "VARIABLE_USE"
25556                                                                           "\n"
25557                                                                           "    tes_gs += result;\n"
25558                                                                           "}\n"
25559                                                                           "\n";
25560         static const GLchar* vs = "#version 430 core\n"
25561                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25562                                                           "\n"
25563                                                           "in  vec4 in_vs;\n"
25564                                                           "out vec4 vs_tcs;\n"
25565                                                           "\n"
25566                                                           "void main()\n"
25567                                                           "{\n"
25568                                                           "    vs_tcs = in_vs;\n"
25569                                                           "}\n"
25570                                                           "\n";
25571         static const GLchar* vs_tested = "#version 430 core\n"
25572                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25573                                                                          "\n"
25574                                                                          "VAR_DEFINITION"
25575                                                                          "\n"
25576                                                                          "in  vec4 in_vs;\n"
25577                                                                          "out vec4 vs_tcs;\n"
25578                                                                          "\n"
25579                                                                          "void main()\n"
25580                                                                          "{\n"
25581                                                                          "    vec4 result = in_vs;\n"
25582                                                                          "\n"
25583                                                                          "VARIABLE_USE"
25584                                                                          "\n"
25585                                                                          "    vs_tcs = result;\n"
25586                                                                          "}\n"
25587                                                                          "\n";
25588
25589         std::string source;
25590         testCase&   test_case = m_test_cases[test_case_index];
25591
25592         if (test_case.m_stage == stage)
25593         {
25594                 const GLchar* array = "";
25595                 GLchar            buffer[16];
25596                 const GLchar* index                      = "";
25597                 size_t            position               = 0;
25598                 size_t            position_start = 0;
25599                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25600
25601                 sprintf(buffer, "%d", test_case.m_offset);
25602
25603                 switch (stage)
25604                 {
25605                 case Utils::Shader::GEOMETRY:
25606                         source = gs_tested;
25607                         array  = "[]";
25608                         index  = "[0]";
25609                         break;
25610                 case Utils::Shader::TESS_CTRL:
25611                         source = tcs_tested;
25612                         array  = "[]";
25613                         index  = "[gl_InvocationID]";
25614                         break;
25615                 case Utils::Shader::TESS_EVAL:
25616                         source = tes_tested;
25617                         array  = "[]";
25618                         index  = "[0]";
25619                         break;
25620                 case Utils::Shader::VERTEX:
25621                         source = vs_tested;
25622                         break;
25623                 default:
25624                         TCU_FAIL("Invalid enum");
25625                 }
25626
25627                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25628                 position = 0;
25629                 Utils::replaceToken("OFFSET", position, buffer, source);
25630                 Utils::replaceToken("TYPE", position, type_name, source);
25631                 Utils::replaceToken("ARRAY", position, array, source);
25632                 position_start = position;
25633                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25634                 position = position_start;
25635                 Utils::replaceToken("INDEX", position, index, source);
25636                 Utils::replaceToken("TYPE", position, type_name, source);
25637                 Utils::replaceToken("INDEX", position, index, source);
25638                 Utils::replaceToken("TYPE", position, type_name, source);
25639         }
25640         else
25641         {
25642                 switch (test_case.m_stage)
25643                 {
25644                 case Utils::Shader::GEOMETRY:
25645                         switch (stage)
25646                         {
25647                         case Utils::Shader::FRAGMENT:
25648                                 source = fs;
25649                                 break;
25650                         case Utils::Shader::VERTEX:
25651                                 source = vs;
25652                                 break;
25653                         default:
25654                                 source = "";
25655                         }
25656                         break;
25657                 case Utils::Shader::TESS_CTRL:
25658                         switch (stage)
25659                         {
25660                         case Utils::Shader::FRAGMENT:
25661                                 source = fs;
25662                                 break;
25663                         case Utils::Shader::VERTEX:
25664                                 source = vs;
25665                                 break;
25666                         default:
25667                                 source = "";
25668                         }
25669                         break;
25670                 case Utils::Shader::TESS_EVAL:
25671                         switch (stage)
25672                         {
25673                         case Utils::Shader::FRAGMENT:
25674                                 source = fs;
25675                                 break;
25676                         case Utils::Shader::TESS_CTRL:
25677                                 source = tcs;
25678                                 break;
25679                         case Utils::Shader::VERTEX:
25680                                 source = vs;
25681                                 break;
25682                         default:
25683                                 source = "";
25684                         }
25685                         break;
25686                 case Utils::Shader::VERTEX:
25687                         switch (stage)
25688                         {
25689                         case Utils::Shader::FRAGMENT:
25690                                 source = fs;
25691                                 break;
25692                         default:
25693                                 source = "";
25694                         }
25695                         break;
25696                 default:
25697                         TCU_FAIL("Invalid enum");
25698                         break;
25699                 }
25700         }
25701
25702         return source;
25703 }
25704
25705 /** Get description of test case
25706  *
25707  * @param test_case_index Index of test case
25708  *
25709  * @return Test case description
25710  **/
25711 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25712 {
25713         std::stringstream stream;
25714         testCase&                 test_case = m_test_cases[test_case_index];
25715
25716         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25717                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25718
25719         return stream.str();
25720 }
25721
25722 /** Get number of test cases
25723  *
25724  * @return Number of test cases
25725  **/
25726 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25727 {
25728         return static_cast<GLuint>(m_test_cases.size());
25729 }
25730
25731 /** Selects if "compute" stage is relevant for test
25732  *
25733  * @param ignored
25734  *
25735  * @return false
25736  **/
25737 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25738 {
25739         return false;
25740 }
25741
25742 /** Prepare all test cases
25743  *
25744  **/
25745 void XFBInvalidOffsetAlignmentTest::testInit()
25746 {
25747         const GLuint n_types = getTypesNumber();
25748
25749         for (GLuint i = 0; i < n_types; ++i)
25750         {
25751                 const Utils::Type& type                   = getType(i);
25752                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25753
25754                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25755                 {
25756                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25757                                 (Utils::Shader::FRAGMENT == stage))
25758                         {
25759                                 continue;
25760                         }
25761
25762                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25763                         {
25764                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25765
25766                                 m_test_cases.push_back(test_case);
25767                         }
25768                 }
25769         }
25770 }
25771
25772 /** Constructor
25773  *
25774  * @param context Test context
25775  **/
25776 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25777         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25778                                          "Test verifies that inactive variables are captured")
25779 {
25780         /* Nothing to be done here */
25781 }
25782
25783 /** Execute drawArrays for single vertex
25784  *
25785  * @param test_case_index
25786  *
25787  * @return true
25788  **/
25789 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
25790 {
25791         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25792         GLenum                   primitive_type = GL_PATCHES;
25793
25794         if (TEST_VS == test_case_index)
25795         {
25796                 primitive_type = GL_POINTS;
25797         }
25798
25799         gl.disable(GL_RASTERIZER_DISCARD);
25800         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25801
25802         gl.beginTransformFeedback(GL_POINTS);
25803         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25804
25805         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25806         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25807
25808         gl.endTransformFeedback();
25809         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25810
25811         return true;
25812 }
25813
25814 /** Get descriptors of buffers necessary for test
25815  *
25816  * @param ignored
25817  * @param out_descriptors Descriptors of buffers used by test
25818  **/
25819 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25820                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25821 {
25822         const Utils::Type& type = Utils::Type::vec4;
25823
25824         /* Test needs single uniform and xfb */
25825         out_descriptors.resize(2);
25826
25827         /* Get references */
25828         bufferDescriptor& uniform = out_descriptors[0];
25829         bufferDescriptor& xfb    = out_descriptors[1];
25830
25831         /* Index */
25832         uniform.m_index = 0;
25833         xfb.m_index             = 0;
25834
25835         /* Target */
25836         uniform.m_target = Utils::Buffer::Uniform;
25837         xfb.m_target     = Utils::Buffer::Transform_feedback;
25838
25839         /* Data */
25840         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25841         const std::vector<GLubyte>& goten_data = type.GenerateData();
25842
25843         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25844
25845         /* Uniform data */
25846         uniform.m_initial_data.resize(2 * type_size);
25847         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25848         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25849
25850         /* XFB data */
25851         xfb.m_initial_data.resize(3 * type_size);
25852         xfb.m_expected_data.resize(3 * type_size);
25853
25854         for (GLuint i = 0; i < 3 * type_size; ++i)
25855         {
25856                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25857                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25858         }
25859
25860         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25861         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25862 }
25863
25864 /** Get body of main function for given shader stage
25865  *
25866  * @param test_case_index  Index of test case
25867  * @param stage            Shader stage
25868  * @param out_assignments  Set to empty
25869  * @param out_calculations Set to empty
25870  **/
25871 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25872                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25873 {
25874         out_calculations = "";
25875
25876         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25877                                                                          "    gohan = uni_gohan;\n";
25878         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25879
25880         const GLchar* assignments = "";
25881
25882         switch (stage)
25883         {
25884         case Utils::Shader::FRAGMENT:
25885                 assignments = fs;
25886                 break;
25887
25888         case Utils::Shader::GEOMETRY:
25889                 if (TEST_GS == test_case_index)
25890                 {
25891                         assignments = vs_tes_gs;
25892                 }
25893                 break;
25894
25895         case Utils::Shader::TESS_CTRL:
25896                 break;
25897
25898         case Utils::Shader::TESS_EVAL:
25899                 if (TEST_TES == test_case_index)
25900                 {
25901                         assignments = vs_tes_gs;
25902                 }
25903                 break;
25904
25905         case Utils::Shader::VERTEX:
25906                 if (TEST_VS == test_case_index)
25907                 {
25908                         assignments = vs_tes_gs;
25909                 }
25910                 break;
25911
25912         default:
25913                 TCU_FAIL("Invalid enum");
25914         }
25915
25916         out_assignments = assignments;
25917 }
25918
25919 /** Get interface of shader
25920  *
25921  * @param test_case_index  Index of test case
25922  * @param stage            Shader stage
25923  * @param out_interface    Set to ""
25924  **/
25925 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
25926                                                                                                                           std::string& out_interface)
25927 {
25928         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
25929                                                                          "\n"
25930                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
25931                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
25932                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
25933                                                                          "\n"
25934                                                                          "layout(binding = 0) uniform block {\n"
25935                                                                          "    vec4 uni_gohan;\n"
25936                                                                          "    vec4 uni_goten;\n"
25937                                                                          "};\n";
25938         static const GLchar* fs = "in vec4 goku;\n"
25939                                                           "in vec4 gohan;\n"
25940                                                           "in vec4 goten;\n"
25941                                                           "out vec4 fs_out;\n";
25942
25943         const GLchar* interface = "";
25944
25945         switch (stage)
25946         {
25947         case Utils::Shader::FRAGMENT:
25948                 interface = fs;
25949                 break;
25950
25951         case Utils::Shader::GEOMETRY:
25952                 if (TEST_GS == test_case_index)
25953                 {
25954                         interface = vs_tes_gs;
25955                 }
25956                 break;
25957
25958         case Utils::Shader::TESS_CTRL:
25959                 break;
25960
25961         case Utils::Shader::TESS_EVAL:
25962                 if (TEST_TES == test_case_index)
25963                 {
25964                         interface = vs_tes_gs;
25965                 }
25966                 break;
25967
25968         case Utils::Shader::VERTEX:
25969                 if (TEST_VS == test_case_index)
25970                 {
25971                         interface = vs_tes_gs;
25972                 }
25973                 break;
25974
25975         default:
25976                 TCU_FAIL("Invalid enum");
25977         }
25978
25979         out_interface = interface;
25980 }
25981
25982 /** Get source code of shader
25983  *
25984  * @param test_case_index Index of test case
25985  * @param stage           Shader stage
25986  *
25987  * @return Source
25988  **/
25989 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25990 {
25991         std::string source;
25992
25993         switch (test_case_index)
25994         {
25995         case TEST_VS:
25996                 switch (stage)
25997                 {
25998                 case Utils::Shader::FRAGMENT:
25999                 case Utils::Shader::VERTEX:
26000                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26001                         break;
26002                 default:
26003                         break;
26004                 }
26005                 break;
26006
26007         case TEST_TES:
26008                 switch (stage)
26009                 {
26010                 case Utils::Shader::FRAGMENT:
26011                 case Utils::Shader::TESS_CTRL:
26012                 case Utils::Shader::TESS_EVAL:
26013                 case Utils::Shader::VERTEX:
26014                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26015                         break;
26016                 default:
26017                         break;
26018                 }
26019                 break;
26020
26021         case TEST_GS:
26022                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26023                 break;
26024
26025         default:
26026                 TCU_FAIL("Invalid enum");
26027                 break;
26028         }
26029
26030         /* */
26031         return source;
26032 }
26033
26034 /** Get name of test case
26035  *
26036  * @param test_case_index Index of test case
26037  *
26038  * @return Name of tested stage
26039  **/
26040 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26041 {
26042         const GLchar* name = 0;
26043
26044         switch (test_case_index)
26045         {
26046         case TEST_VS:
26047                 name = "vertex";
26048                 break;
26049         case TEST_TES:
26050                 name = "tessellation evaluation";
26051                 break;
26052         case TEST_GS:
26053                 name = "geometry";
26054                 break;
26055         default:
26056                 TCU_FAIL("Invalid enum");
26057         }
26058
26059         return name;
26060 }
26061
26062 /** Returns number of test cases
26063  *
26064  * @return TEST_MAX
26065  **/
26066 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26067 {
26068         return TEST_MAX;
26069 }
26070
26071 /** Inspects program to check if all resources are as expected
26072  *
26073  * @param ignored
26074  * @param program         Program instance
26075  * @param out_stream      Error message
26076  *
26077  * @return true if everything is ok, false otherwise
26078  **/
26079 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26080                                                                                                                   std::stringstream& out_stream)
26081 {
26082         GLint                      stride       = 0;
26083         const Utils::Type& type          = Utils::Type::vec4;
26084         const GLuint       type_size = type.GetSize();
26085
26086         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26087                                                 1 /* buf_size */, &stride);
26088
26089         if ((GLint)(3 * type_size) != stride)
26090         {
26091                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26092
26093                 return false;
26094         }
26095
26096         return true;
26097 }
26098
26099 /** Verify contents of buffers
26100  *
26101  * @param buffers Collection of buffers to be verified
26102  *
26103  * @return true if everything is as expected, false otherwise
26104  **/
26105 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26106 {
26107         bool result = true;
26108
26109         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26110         Utils::Buffer*                  buffer   = pair.m_buffer;
26111         bufferDescriptor*               descriptor = pair.m_descriptor;
26112
26113         /* Get pointer to contents of buffer */
26114         buffer->Bind();
26115         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26116
26117         /* Get pointer to expected data */
26118         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26119
26120         /* Compare */
26121         static const GLuint vec4_size = 16;
26122
26123         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26124         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26125
26126         if ((0 != res_gohan) || (0 != res_goten))
26127         {
26128                 m_context.getTestContext().getLog()
26129                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26130                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26131
26132                 result = false;
26133         }
26134
26135         /* Release buffer mapping */
26136         buffer->UnMap();
26137
26138         return result;
26139 }
26140
26141 /** Constructor
26142  *
26143  * @param context Test context
26144  **/
26145 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26146         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26147                                          "Test verifies that inactive components are not modified")
26148 {
26149         /* Nothing to be done here */
26150 }
26151
26152 /** Execute drawArrays for single vertex
26153  *
26154  * @param test_case_index
26155  *
26156  * @return true
26157  **/
26158 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26159 {
26160         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26161         GLenum                   primitive_type = GL_PATCHES;
26162
26163         if (TEST_VS == test_case_index)
26164         {
26165                 primitive_type = GL_POINTS;
26166         }
26167
26168         gl.disable(GL_RASTERIZER_DISCARD);
26169         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26170
26171         gl.beginTransformFeedback(GL_POINTS);
26172         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26173
26174         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26175         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26176
26177         gl.endTransformFeedback();
26178         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26179
26180         return true;
26181 }
26182
26183 /** Get descriptors of buffers necessary for test
26184  *
26185  * @param ignored
26186  * @param out_descriptors Descriptors of buffers used by test
26187  **/
26188 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26189                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26190 {
26191         const Utils::Type& type = Utils::Type::vec4;
26192
26193         /* Test needs single uniform and xfb */
26194         out_descriptors.resize(2);
26195
26196         /* Get references */
26197         bufferDescriptor& uniform = out_descriptors[0];
26198         bufferDescriptor& xfb    = out_descriptors[1];
26199
26200         /* Index */
26201         uniform.m_index = 0;
26202         xfb.m_index             = 0;
26203
26204         /* Target */
26205         uniform.m_target = Utils::Buffer::Uniform;
26206         xfb.m_target     = Utils::Buffer::Transform_feedback;
26207
26208         /* Data */
26209         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26210         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26211         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26212         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26213         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26214         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26215         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26216         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26217
26218         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26219         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26220
26221         /* Uniform data */
26222         uniform.m_initial_data.resize(8 * type_size);
26223         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26224         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26225         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26226         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26227         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26228         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26229         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26230         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26231
26232         /* XFB data */
26233         xfb.m_initial_data.resize(8 * type_size);
26234         xfb.m_expected_data.resize(8 * type_size);
26235
26236         for (GLuint i = 0; i < 8 * type_size; ++i)
26237         {
26238                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26239                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26240         }
26241
26242         /* goku - x, z - 32 */
26243         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26244         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26245
26246         /* gohan - y, w - 0 */
26247         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26248         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26249
26250         /* goten - x, y - 16 */
26251         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26252         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26253
26254         /* chichi - z, w - 48 */
26255         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26256         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26257
26258         /* vegeta - x - 112 */
26259         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26260
26261         /* trunks - y - 96 */
26262         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26263
26264         /* bra - z - 80 */
26265         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26266
26267         /* bulma - w - 64 */
26268         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26269 }
26270
26271 /** Get body of main function for given shader stage
26272  *
26273  * @param test_case_index  Index of test case
26274  * @param stage            Shader stage
26275  * @param out_assignments  Set to empty
26276  * @param out_calculations Set to empty
26277  **/
26278 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26279                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26280 {
26281         out_calculations = "";
26282
26283         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26284                                                                          "    goku.z    = uni_goku.z   ;\n"
26285                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26286                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26287                                                                          "    goten.x   = uni_goten.x  ;\n"
26288                                                                          "    goten.y   = uni_goten.y  ;\n"
26289                                                                          "    chichi.z  = uni_chichi.z ;\n"
26290                                                                          "    chichi.w  = uni_chichi.w ;\n"
26291                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26292                                                                          "    trunks.y  = uni_trunks.y ;\n"
26293                                                                          "    bra.z     = uni_bra.z    ;\n"
26294                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26295         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26296
26297         const GLchar* assignments = "";
26298
26299         switch (stage)
26300         {
26301         case Utils::Shader::FRAGMENT:
26302                 assignments = fs;
26303                 break;
26304
26305         case Utils::Shader::GEOMETRY:
26306                 if (TEST_GS == test_case_index)
26307                 {
26308                         assignments = vs_tes_gs;
26309                 }
26310                 break;
26311
26312         case Utils::Shader::TESS_CTRL:
26313                 break;
26314
26315         case Utils::Shader::TESS_EVAL:
26316                 if (TEST_TES == test_case_index)
26317                 {
26318                         assignments = vs_tes_gs;
26319                 }
26320                 break;
26321
26322         case Utils::Shader::VERTEX:
26323                 if (TEST_VS == test_case_index)
26324                 {
26325                         assignments = vs_tes_gs;
26326                 }
26327                 break;
26328
26329         default:
26330                 TCU_FAIL("Invalid enum");
26331         }
26332
26333         out_assignments = assignments;
26334 }
26335
26336 /** Get interface of shader
26337  *
26338  * @param test_case_index  Index of test case
26339  * @param stage            Shader stage
26340  * @param out_interface    Set to ""
26341  **/
26342 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26343                                                                                                                            std::string& out_interface)
26344 {
26345         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26346                                                                          "\n"
26347                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26348                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26349                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26350                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26351                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26352                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26353                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26354                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26355                                                                          "\n"
26356                                                                          "layout(binding = 0) uniform block {\n"
26357                                                                          "    vec4 uni_goku;\n"
26358                                                                          "    vec4 uni_gohan;\n"
26359                                                                          "    vec4 uni_goten;\n"
26360                                                                          "    vec4 uni_chichi;\n"
26361                                                                          "    vec4 uni_vegeta;\n"
26362                                                                          "    vec4 uni_trunks;\n"
26363                                                                          "    vec4 uni_bra;\n"
26364                                                                          "    vec4 uni_bulma;\n"
26365                                                                          "};\n";
26366         static const GLchar* fs = "in vec4 vegeta;\n"
26367                                                           "in vec4 trunks;\n"
26368                                                           "in vec4 bra;\n"
26369                                                           "in vec4 bulma;\n"
26370                                                           "in vec4 goku;\n"
26371                                                           "in vec4 gohan;\n"
26372                                                           "in vec4 goten;\n"
26373                                                           "in vec4 chichi;\n"
26374                                                           "\n"
26375                                                           "out vec4 fs_out;\n";
26376
26377         const GLchar* interface = "";
26378
26379         switch (stage)
26380         {
26381         case Utils::Shader::FRAGMENT:
26382                 interface = fs;
26383                 break;
26384
26385         case Utils::Shader::GEOMETRY:
26386                 if (TEST_GS == test_case_index)
26387                 {
26388                         interface = vs_tes_gs;
26389                 }
26390                 break;
26391
26392         case Utils::Shader::TESS_CTRL:
26393                 break;
26394
26395         case Utils::Shader::TESS_EVAL:
26396                 if (TEST_TES == test_case_index)
26397                 {
26398                         interface = vs_tes_gs;
26399                 }
26400                 break;
26401
26402         case Utils::Shader::VERTEX:
26403                 if (TEST_VS == test_case_index)
26404                 {
26405                         interface = vs_tes_gs;
26406                 }
26407                 break;
26408
26409         default:
26410                 TCU_FAIL("Invalid enum");
26411         }
26412
26413         out_interface = interface;
26414 }
26415
26416 /** Get source code of shader
26417  *
26418  * @param test_case_index Index of test case
26419  * @param stage           Shader stage
26420  *
26421  * @return Source
26422  **/
26423 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26424 {
26425         std::string source;
26426
26427         switch (test_case_index)
26428         {
26429         case TEST_VS:
26430                 switch (stage)
26431                 {
26432                 case Utils::Shader::FRAGMENT:
26433                 case Utils::Shader::VERTEX:
26434                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26435                         break;
26436                 default:
26437                         break;
26438                 }
26439                 break;
26440
26441         case TEST_TES:
26442                 switch (stage)
26443                 {
26444                 case Utils::Shader::FRAGMENT:
26445                 case Utils::Shader::TESS_CTRL:
26446                 case Utils::Shader::TESS_EVAL:
26447                 case Utils::Shader::VERTEX:
26448                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26449                         break;
26450                 default:
26451                         break;
26452                 }
26453                 break;
26454
26455         case TEST_GS:
26456                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26457                 break;
26458
26459         default:
26460                 TCU_FAIL("Invalid enum");
26461                 break;
26462         }
26463
26464         /* */
26465         return source;
26466 }
26467
26468 /** Get name of test case
26469  *
26470  * @param test_case_index Index of test case
26471  *
26472  * @return Name of tested stage
26473  **/
26474 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26475 {
26476         const GLchar* name = 0;
26477
26478         switch (test_case_index)
26479         {
26480         case TEST_VS:
26481                 name = "vertex";
26482                 break;
26483         case TEST_TES:
26484                 name = "tessellation evaluation";
26485                 break;
26486         case TEST_GS:
26487                 name = "geometry";
26488                 break;
26489         default:
26490                 TCU_FAIL("Invalid enum");
26491         }
26492
26493         return name;
26494 }
26495
26496 /** Returns number of test cases
26497  *
26498  * @return TEST_MAX
26499  **/
26500 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26501 {
26502         return TEST_MAX;
26503 }
26504
26505 /** Verify contents of buffers
26506  *
26507  * @param buffers Collection of buffers to be verified
26508  *
26509  * @return true if everything is as expected, false otherwise
26510  **/
26511 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26512 {
26513         bool result = true;
26514
26515         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26516         Utils::Buffer*                  buffer   = pair.m_buffer;
26517         bufferDescriptor*               descriptor = pair.m_descriptor;
26518
26519         /* Get pointer to contents of buffer */
26520         buffer->Bind();
26521         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26522
26523         /* Get pointer to expected data */
26524         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26525
26526         /* Compare */
26527         static const GLuint comp_size = 4;
26528         static const GLuint vec4_size = 16;
26529
26530         int res_goku_x =
26531                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26532         int res_goku_z =
26533                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26534
26535         int res_gohan_y =
26536                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26537         int res_gohan_w =
26538                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26539
26540         int res_goten_x =
26541                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26542         int res_goten_y =
26543                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26544
26545         int res_chichi_z =
26546                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26547         int res_chichi_w =
26548                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26549
26550         int res_vegeta_x =
26551                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26552
26553         int res_trunks_y =
26554                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26555
26556         int res_bra_z =
26557                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26558
26559         int res_bulma_w =
26560                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26561
26562         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26563                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26564                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26565         {
26566                 m_context.getTestContext().getLog()
26567                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26568                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26569
26570                 result = false;
26571         }
26572
26573         /* Release buffer mapping */
26574         buffer->UnMap();
26575
26576         return result;
26577 }
26578
26579 /** Constructor
26580  *
26581  * @param context Test context
26582  **/
26583 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26584         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26585                                          "Test verifies that inactive block members are captured")
26586 {
26587         /* Nothing to be done here */
26588 }
26589
26590 /** Execute drawArrays for single vertex
26591  *
26592  * @param test_case_index
26593  *
26594  * @return true
26595  **/
26596 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26597 {
26598         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26599         GLenum                   primitive_type = GL_PATCHES;
26600
26601         if (TEST_VS == test_case_index)
26602         {
26603                 primitive_type = GL_POINTS;
26604         }
26605
26606         gl.disable(GL_RASTERIZER_DISCARD);
26607         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26608
26609         gl.beginTransformFeedback(GL_POINTS);
26610         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26611
26612         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26613         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26614
26615         gl.endTransformFeedback();
26616         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26617
26618         return true;
26619 }
26620
26621 /** Get descriptors of buffers necessary for test
26622  *
26623  * @param ignored
26624  * @param out_descriptors Descriptors of buffers used by test
26625  **/
26626 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26627                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26628 {
26629         const Utils::Type& type = Utils::Type::vec4;
26630
26631         /* Test needs single uniform and xfb */
26632         out_descriptors.resize(2);
26633
26634         /* Get references */
26635         bufferDescriptor& uniform = out_descriptors[0];
26636         bufferDescriptor& xfb    = out_descriptors[1];
26637
26638         /* Index */
26639         uniform.m_index = 0;
26640         xfb.m_index             = 0;
26641
26642         /* Target */
26643         uniform.m_target = Utils::Buffer::Uniform;
26644         xfb.m_target     = Utils::Buffer::Transform_feedback;
26645
26646         /* Data */
26647         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26648         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26649
26650         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26651
26652         /* Uniform data */
26653         uniform.m_initial_data.resize(2 * type_size);
26654         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26655         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26656
26657         /* XFB data */
26658         xfb.m_initial_data.resize(4 * type_size);
26659         xfb.m_expected_data.resize(4 * type_size);
26660
26661         for (GLuint i = 0; i < 4 * type_size; ++i)
26662         {
26663                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26664                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26665         }
26666
26667         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26668         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26669 }
26670
26671 /** Get body of main function for given shader stage
26672  *
26673  * @param test_case_index  Index of test case
26674  * @param stage            Shader stage
26675  * @param out_assignments  Set to empty
26676  * @param out_calculations Set to empty
26677  **/
26678 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26679                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26680 {
26681         out_calculations = "";
26682
26683         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26684                                                                          "    gohan  = uni_gohan;\n";
26685         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26686
26687         const GLchar* assignments = "";
26688
26689         switch (stage)
26690         {
26691         case Utils::Shader::FRAGMENT:
26692                 assignments = fs;
26693                 break;
26694
26695         case Utils::Shader::GEOMETRY:
26696                 if (TEST_GS == test_case_index)
26697                 {
26698                         assignments = vs_tes_gs;
26699                 }
26700                 break;
26701
26702         case Utils::Shader::TESS_CTRL:
26703                 break;
26704
26705         case Utils::Shader::TESS_EVAL:
26706                 if (TEST_TES == test_case_index)
26707                 {
26708                         assignments = vs_tes_gs;
26709                 }
26710                 break;
26711
26712         case Utils::Shader::VERTEX:
26713                 if (TEST_VS == test_case_index)
26714                 {
26715                         assignments = vs_tes_gs;
26716                 }
26717                 break;
26718
26719         default:
26720                 TCU_FAIL("Invalid enum");
26721         }
26722
26723         out_assignments = assignments;
26724 }
26725
26726 /** Get interface of shader
26727  *
26728  * @param test_case_index  Index of test case
26729  * @param stage            Shader stage
26730  * @param out_interface    Set to ""
26731  **/
26732 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26733                                                                                                                                  std::string& out_interface)
26734 {
26735         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26736                                                                          "\n"
26737                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26738                                                                          "    vec4 gohan;\n"
26739                                                                          "    vec4 goten;\n"
26740                                                                          "    vec4 chichi;\n"
26741                                                                          "};\n"
26742                                                                          "\n"
26743                                                                          "layout(binding = 0) uniform block {\n"
26744                                                                          "    vec4 uni_gohan;\n"
26745                                                                          "    vec4 uni_chichi;\n"
26746                                                                          "};\n";
26747         static const GLchar* fs = "in Goku {\n"
26748                                                           "    vec4 gohan;\n"
26749                                                           "    vec4 goten;\n"
26750                                                           "    vec4 chichi;\n"
26751                                                           "};\n"
26752                                                           "out vec4 fs_out;\n";
26753
26754         const GLchar* interface = "";
26755
26756         switch (stage)
26757         {
26758         case Utils::Shader::FRAGMENT:
26759                 interface = fs;
26760                 break;
26761
26762         case Utils::Shader::GEOMETRY:
26763                 if (TEST_GS == test_case_index)
26764                 {
26765                         interface = vs_tes_gs;
26766                 }
26767                 break;
26768
26769         case Utils::Shader::TESS_CTRL:
26770                 break;
26771
26772         case Utils::Shader::TESS_EVAL:
26773                 if (TEST_TES == test_case_index)
26774                 {
26775                         interface = vs_tes_gs;
26776                 }
26777                 break;
26778
26779         case Utils::Shader::VERTEX:
26780                 if (TEST_VS == test_case_index)
26781                 {
26782                         interface = vs_tes_gs;
26783                 }
26784                 break;
26785
26786         default:
26787                 TCU_FAIL("Invalid enum");
26788         }
26789
26790         out_interface = interface;
26791 }
26792
26793 /** Get source code of shader
26794  *
26795  * @param test_case_index Index of test case
26796  * @param stage           Shader stage
26797  *
26798  * @return Source
26799  **/
26800 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26801                                                                                                                                          Utils::Shader::STAGES stage)
26802 {
26803         std::string source;
26804
26805         switch (test_case_index)
26806         {
26807         case TEST_VS:
26808                 switch (stage)
26809                 {
26810                 case Utils::Shader::FRAGMENT:
26811                 case Utils::Shader::VERTEX:
26812                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26813                         break;
26814                 default:
26815                         break;
26816                 }
26817                 break;
26818
26819         case TEST_TES:
26820                 switch (stage)
26821                 {
26822                 case Utils::Shader::FRAGMENT:
26823                 case Utils::Shader::TESS_CTRL:
26824                 case Utils::Shader::TESS_EVAL:
26825                 case Utils::Shader::VERTEX:
26826                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26827                         break;
26828                 default:
26829                         break;
26830                 }
26831                 break;
26832
26833         case TEST_GS:
26834                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26835                 break;
26836
26837         default:
26838                 TCU_FAIL("Invalid enum");
26839                 break;
26840         }
26841
26842         /* */
26843         return source;
26844 }
26845
26846 /** Get name of test case
26847  *
26848  * @param test_case_index Index of test case
26849  *
26850  * @return Name of tested stage
26851  **/
26852 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26853 {
26854         const GLchar* name = 0;
26855
26856         switch (test_case_index)
26857         {
26858         case TEST_VS:
26859                 name = "vertex";
26860                 break;
26861         case TEST_TES:
26862                 name = "tessellation evaluation";
26863                 break;
26864         case TEST_GS:
26865                 name = "geometry";
26866                 break;
26867         default:
26868                 TCU_FAIL("Invalid enum");
26869         }
26870
26871         return name;
26872 }
26873
26874 /** Returns number of test cases
26875  *
26876  * @return TEST_MAX
26877  **/
26878 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26879 {
26880         return TEST_MAX;
26881 }
26882
26883 /** Verify contents of buffers
26884  *
26885  * @param buffers Collection of buffers to be verified
26886  *
26887  * @return true if everything is as expected, false otherwise
26888  **/
26889 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26890 {
26891         bool result = true;
26892
26893         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26894         Utils::Buffer*                  buffer   = pair.m_buffer;
26895         bufferDescriptor*               descriptor = pair.m_descriptor;
26896
26897         /* Get pointer to contents of buffer */
26898         buffer->Bind();
26899         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26900
26901         /* Get pointer to expected data */
26902         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26903
26904         /* Compare */
26905         static const GLuint vec4_size = 16;
26906
26907         int res_before = memcmp(buffer_data, expected_data, vec4_size);
26908         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
26909         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
26910
26911         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
26912         {
26913                 m_context.getTestContext().getLog()
26914                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26915                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26916
26917                 result = false;
26918         }
26919
26920         /* Release buffer mapping */
26921         buffer->UnMap();
26922
26923         return result;
26924 }
26925
26926 /** Constructor
26927  *
26928  * @param context Test context
26929  **/
26930 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
26931         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
26932 {
26933         /* Nothing to be done here */
26934 }
26935
26936 /** Execute drawArrays for single vertex
26937  *
26938  * @param test_case_index
26939  *
26940  * @return true
26941  **/
26942 bool XFBCaptureStructTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26943 {
26944         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26945         GLenum                   primitive_type = GL_PATCHES;
26946
26947         if (TEST_VS == test_case_index)
26948         {
26949                 primitive_type = GL_POINTS;
26950         }
26951
26952         gl.disable(GL_RASTERIZER_DISCARD);
26953         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26954
26955         gl.beginTransformFeedback(GL_POINTS);
26956         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26957
26958         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26959         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26960
26961         gl.endTransformFeedback();
26962         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26963
26964         return true;
26965 }
26966
26967 /** Get descriptors of buffers necessary for test
26968  *
26969  * @param ignored
26970  * @param out_descriptors Descriptors of buffers used by test
26971  **/
26972 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26973                                                                                                 bufferDescriptor::Vector& out_descriptors)
26974 {
26975         const Utils::Type& type = Utils::Type::vec4;
26976
26977         /* Test needs single uniform and xfb */
26978         out_descriptors.resize(2);
26979
26980         /* Get references */
26981         bufferDescriptor& uniform = out_descriptors[0];
26982         bufferDescriptor& xfb    = out_descriptors[1];
26983
26984         /* Index */
26985         uniform.m_index = 0;
26986         xfb.m_index             = 0;
26987
26988         /* Target */
26989         uniform.m_target = Utils::Buffer::Uniform;
26990         xfb.m_target     = Utils::Buffer::Transform_feedback;
26991
26992         /* Data */
26993         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26994         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26995
26996         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26997
26998         /* Uniform data */
26999         uniform.m_initial_data.resize(2 * type_size);
27000         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
27001         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
27002
27003         /* XFB data */
27004         xfb.m_initial_data.resize(4 * type_size);
27005         xfb.m_expected_data.resize(4 * type_size);
27006
27007         for (GLuint i = 0; i < 4 * type_size; ++i)
27008         {
27009                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
27010                 xfb.m_expected_data[i] = (glw::GLubyte)i;
27011         }
27012
27013         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
27014         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
27015 }
27016
27017 /** Get body of main function for given shader stage
27018  *
27019  * @param test_case_index  Index of test case
27020  * @param stage            Shader stage
27021  * @param out_assignments  Set to empty
27022  * @param out_calculations Set to empty
27023  **/
27024 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27025                                                                                  std::string& out_assignments, std::string& out_calculations)
27026 {
27027         out_calculations = "";
27028
27029         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27030                                                                          "    goku.gohan  = uni_gohan;\n";
27031         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27032
27033         const GLchar* assignments = "";
27034
27035         switch (stage)
27036         {
27037         case Utils::Shader::FRAGMENT:
27038                 assignments = fs;
27039                 break;
27040
27041         case Utils::Shader::GEOMETRY:
27042                 if (TEST_GS == test_case_index)
27043                 {
27044                         assignments = vs_tes_gs;
27045                 }
27046                 break;
27047
27048         case Utils::Shader::TESS_CTRL:
27049                 break;
27050
27051         case Utils::Shader::TESS_EVAL:
27052                 if (TEST_TES == test_case_index)
27053                 {
27054                         assignments = vs_tes_gs;
27055                 }
27056                 break;
27057
27058         case Utils::Shader::VERTEX:
27059                 if (TEST_VS == test_case_index)
27060                 {
27061                         assignments = vs_tes_gs;
27062                 }
27063                 break;
27064
27065         default:
27066                 TCU_FAIL("Invalid enum");
27067         }
27068
27069         out_assignments = assignments;
27070 }
27071
27072 /** Get interface of shader
27073  *
27074  * @param test_case_index  Index of test case
27075  * @param stage            Shader stage
27076  * @param out_interface    Set to ""
27077  **/
27078 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27079                                                                                           std::string& out_interface)
27080 {
27081         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27082                                                                          "\n"
27083                                                                          "struct Goku {\n"
27084                                                                          "    vec4 gohan;\n"
27085                                                                          "    vec4 goten;\n"
27086                                                                          "    vec4 chichi;\n"
27087                                                                          "};\n"
27088                                                                          "\n"
27089                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27090                                                                          "\n"
27091                                                                          "layout(binding = 0, std140) uniform block {\n"
27092                                                                          "    vec4 uni_gohan;\n"
27093                                                                          "    vec4 uni_chichi;\n"
27094                                                                          "};\n";
27095         static const GLchar* fs = "struct Goku {\n"
27096                                                           "    vec4 gohan;\n"
27097                                                           "    vec4 goten;\n"
27098                                                           "    vec4 chichi;\n"
27099                                                           "};\n"
27100                                                           "\n"
27101                                                           "in Goku goku;\n"
27102                                                           "\n"
27103                                                           "out vec4 fs_out;\n";
27104
27105         const GLchar* interface = "";
27106
27107         switch (stage)
27108         {
27109         case Utils::Shader::FRAGMENT:
27110                 interface = fs;
27111                 break;
27112
27113         case Utils::Shader::GEOMETRY:
27114                 if (TEST_GS == test_case_index)
27115                 {
27116                         interface = vs_tes_gs;
27117                 }
27118                 break;
27119
27120         case Utils::Shader::TESS_CTRL:
27121                 break;
27122
27123         case Utils::Shader::TESS_EVAL:
27124                 if (TEST_TES == test_case_index)
27125                 {
27126                         interface = vs_tes_gs;
27127                 }
27128                 break;
27129
27130         case Utils::Shader::VERTEX:
27131                 if (TEST_VS == test_case_index)
27132                 {
27133                         interface = vs_tes_gs;
27134                 }
27135                 break;
27136
27137         default:
27138                 TCU_FAIL("Invalid enum");
27139         }
27140
27141         out_interface = interface;
27142 }
27143
27144 /** Get source code of shader
27145  *
27146  * @param test_case_index Index of test case
27147  * @param stage           Shader stage
27148  *
27149  * @return Source
27150  **/
27151 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27152 {
27153         std::string source;
27154
27155         switch (test_case_index)
27156         {
27157         case TEST_VS:
27158                 switch (stage)
27159                 {
27160                 case Utils::Shader::FRAGMENT:
27161                 case Utils::Shader::VERTEX:
27162                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27163                         break;
27164                 default:
27165                         break;
27166                 }
27167                 break;
27168
27169         case TEST_TES:
27170                 switch (stage)
27171                 {
27172                 case Utils::Shader::FRAGMENT:
27173                 case Utils::Shader::TESS_CTRL:
27174                 case Utils::Shader::TESS_EVAL:
27175                 case Utils::Shader::VERTEX:
27176                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27177                         break;
27178                 default:
27179                         break;
27180                 }
27181                 break;
27182
27183         case TEST_GS:
27184                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27185                 break;
27186
27187         default:
27188                 TCU_FAIL("Invalid enum");
27189                 break;
27190         }
27191
27192         /* */
27193         return source;
27194 }
27195
27196 /** Get name of test case
27197  *
27198  * @param test_case_index Index of test case
27199  *
27200  * @return Name of tested stage
27201  **/
27202 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27203 {
27204         const GLchar* name = 0;
27205
27206         switch (test_case_index)
27207         {
27208         case TEST_VS:
27209                 name = "vertex";
27210                 break;
27211         case TEST_TES:
27212                 name = "tessellation evaluation";
27213                 break;
27214         case TEST_GS:
27215                 name = "geometry";
27216                 break;
27217         default:
27218                 TCU_FAIL("Invalid enum");
27219         }
27220
27221         return name;
27222 }
27223
27224 /** Returns number of test cases
27225  *
27226  * @return TEST_MAX
27227  **/
27228 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27229 {
27230         return TEST_MAX;
27231 }
27232
27233 /** Verify contents of buffers
27234  *
27235  * @param buffers Collection of buffers to be verified
27236  *
27237  * @return true if everything is as expected, false otherwise
27238  **/
27239 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27240 {
27241         bool result = true;
27242
27243         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27244         Utils::Buffer*                  buffer   = pair.m_buffer;
27245         bufferDescriptor*               descriptor = pair.m_descriptor;
27246
27247         /* Get pointer to contents of buffer */
27248         buffer->Bind();
27249         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27250
27251         /* Get pointer to expected data */
27252         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27253
27254         /* Compare */
27255         static const GLuint vec4_size = 16;
27256
27257         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27258         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27259         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27260
27261         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27262         {
27263                 m_context.getTestContext().getLog()
27264                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27265                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27266
27267                 result = false;
27268         }
27269
27270         /* Release buffer mapping */
27271         buffer->UnMap();
27272
27273         return result;
27274 }
27275
27276 /** Constructor
27277  *
27278  * @param context Test framework context
27279  **/
27280 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27281         : NegativeTestBase(context, "xfb_capture_unsized_array",
27282                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27283 {
27284 }
27285
27286 /** Source for given test case and stage
27287  *
27288  * @param test_case_index Index of test case
27289  * @param stage           Shader stage
27290  *
27291  * @return Shader source
27292  **/
27293 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27294 {
27295         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27296         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27297         static const GLchar* fs                         = "#version 430 core\n"
27298                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27299                                                           "\n"
27300                                                           "in  vec4 gs_fs;\n"
27301                                                           "out vec4 fs_out;\n"
27302                                                           "\n"
27303                                                           "void main()\n"
27304                                                           "{\n"
27305                                                           "    fs_out = gs_fs;\n"
27306                                                           "}\n"
27307                                                           "\n";
27308         static const GLchar* gs_tested = "#version 430 core\n"
27309                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27310                                                                          "\n"
27311                                                                          "layout(points)                           in;\n"
27312                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27313                                                                          "\n"
27314                                                                          "VAR_DEFINITION"
27315                                                                          "\n"
27316                                                                          "in  vec4 tes_gs[];\n"
27317                                                                          "out vec4 gs_fs;\n"
27318                                                                          "\n"
27319                                                                          "void main()\n"
27320                                                                          "{\n"
27321                                                                          "    vec4 result = tes_gs[0];\n"
27322                                                                          "\n"
27323                                                                          "VARIABLE_USE"
27324                                                                          "\n"
27325                                                                          "    gs_fs = result;\n"
27326                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27327                                                                          "    EmitVertex();\n"
27328                                                                          "    gs_fs = result;\n"
27329                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27330                                                                          "    EmitVertex();\n"
27331                                                                          "    gs_fs = result;\n"
27332                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27333                                                                          "    EmitVertex();\n"
27334                                                                          "    gs_fs = result;\n"
27335                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27336                                                                          "    EmitVertex();\n"
27337                                                                          "}\n"
27338                                                                          "\n";
27339         static const GLchar* tcs = "#version 430 core\n"
27340                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27341                                                            "\n"
27342                                                            "layout(vertices = 1) out;\n"
27343                                                            "\n"
27344                                                            "in  vec4 vs_tcs[];\n"
27345                                                            "out vec4 tcs_tes[];\n"
27346                                                            "\n"
27347                                                            "void main()\n"
27348                                                            "{\n"
27349                                                            "\n"
27350                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27351                                                            "\n"
27352                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27353                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27354                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27355                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27356                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27357                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27358                                                            "}\n"
27359                                                            "\n";
27360         static const GLchar* tcs_tested = "#version 430 core\n"
27361                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27362                                                                           "\n"
27363                                                                           "layout(vertices = 1) out;\n"
27364                                                                           "\n"
27365                                                                           "VAR_DEFINITION"
27366                                                                           "\n"
27367                                                                           "in  vec4 vs_tcs[];\n"
27368                                                                           "out vec4 tcs_tes[];\n"
27369                                                                           "\n"
27370                                                                           "void main()\n"
27371                                                                           "{\n"
27372                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27373                                                                           "\n"
27374                                                                           "VARIABLE_USE"
27375                                                                           "\n"
27376                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27377                                                                           "\n"
27378                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27379                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27380                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27381                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27382                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27383                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27384                                                                           "}\n"
27385                                                                           "\n";
27386         static const GLchar* tes_tested = "#version 430 core\n"
27387                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27388                                                                           "\n"
27389                                                                           "layout(isolines, point_mode) in;\n"
27390                                                                           "\n"
27391                                                                           "VAR_DEFINITION"
27392                                                                           "\n"
27393                                                                           "in  vec4 tcs_tes[];\n"
27394                                                                           "out vec4 tes_gs;\n"
27395                                                                           "\n"
27396                                                                           "void main()\n"
27397                                                                           "{\n"
27398                                                                           "    vec4 result = tcs_tes[0];\n"
27399                                                                           "\n"
27400                                                                           "VARIABLE_USE"
27401                                                                           "\n"
27402                                                                           "    tes_gs += result;\n"
27403                                                                           "}\n"
27404                                                                           "\n";
27405         static const GLchar* vs = "#version 430 core\n"
27406                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27407                                                           "\n"
27408                                                           "in  vec4 in_vs;\n"
27409                                                           "out vec4 vs_tcs;\n"
27410                                                           "\n"
27411                                                           "void main()\n"
27412                                                           "{\n"
27413                                                           "    vs_tcs = in_vs;\n"
27414                                                           "}\n"
27415                                                           "\n";
27416         static const GLchar* vs_tested = "#version 430 core\n"
27417                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27418                                                                          "\n"
27419                                                                          "VAR_DEFINITION"
27420                                                                          "\n"
27421                                                                          "in  vec4 in_vs;\n"
27422                                                                          "out vec4 vs_tcs;\n"
27423                                                                          "\n"
27424                                                                          "void main()\n"
27425                                                                          "{\n"
27426                                                                          "    vec4 result = in_vs;\n"
27427                                                                          "\n"
27428                                                                          "VARIABLE_USE"
27429                                                                          "\n"
27430                                                                          "    vs_tcs = result;\n"
27431                                                                          "}\n"
27432                                                                          "\n";
27433
27434         std::string source;
27435         testCase&   test_case = m_test_cases[test_case_index];
27436
27437         if (test_case.m_stage == stage)
27438         {
27439                 const GLchar* array     = "";
27440                 const GLchar* index     = "";
27441                 size_t            position = 0;
27442
27443                 switch (stage)
27444                 {
27445                 case Utils::Shader::GEOMETRY:
27446                         source = gs_tested;
27447                         array  = "[]";
27448                         index  = "[0]";
27449                         break;
27450                 case Utils::Shader::TESS_CTRL:
27451                         source = tcs_tested;
27452                         array  = "[]";
27453                         index  = "[gl_InvocationID]";
27454                         break;
27455                 case Utils::Shader::TESS_EVAL:
27456                         source = tes_tested;
27457                         array  = "[]";
27458                         index  = "[0]";
27459                         break;
27460                 case Utils::Shader::VERTEX:
27461                         source = vs_tested;
27462                         break;
27463                 default:
27464                         TCU_FAIL("Invalid enum");
27465                 }
27466
27467                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27468                 position = 0;
27469                 Utils::replaceToken("ARRAY", position, array, source);
27470                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27471
27472                 Utils::replaceAllTokens("INDEX", index, source);
27473         }
27474         else
27475         {
27476                 switch (test_case.m_stage)
27477                 {
27478                 case Utils::Shader::GEOMETRY:
27479                         switch (stage)
27480                         {
27481                         case Utils::Shader::FRAGMENT:
27482                                 source = fs;
27483                                 break;
27484                         case Utils::Shader::VERTEX:
27485                                 source = vs;
27486                                 break;
27487                         default:
27488                                 source = "";
27489                         }
27490                         break;
27491                 case Utils::Shader::TESS_CTRL:
27492                         switch (stage)
27493                         {
27494                         case Utils::Shader::FRAGMENT:
27495                                 source = fs;
27496                                 break;
27497                         case Utils::Shader::VERTEX:
27498                                 source = vs;
27499                                 break;
27500                         default:
27501                                 source = "";
27502                         }
27503                         break;
27504                 case Utils::Shader::TESS_EVAL:
27505                         switch (stage)
27506                         {
27507                         case Utils::Shader::FRAGMENT:
27508                                 source = fs;
27509                                 break;
27510                         case Utils::Shader::TESS_CTRL:
27511                                 source = tcs;
27512                                 break;
27513                         case Utils::Shader::VERTEX:
27514                                 source = vs;
27515                                 break;
27516                         default:
27517                                 source = "";
27518                         }
27519                         break;
27520                 case Utils::Shader::VERTEX:
27521                         switch (stage)
27522                         {
27523                         case Utils::Shader::FRAGMENT:
27524                                 source = fs;
27525                                 break;
27526                         default:
27527                                 source = "";
27528                         }
27529                         break;
27530                 default:
27531                         TCU_FAIL("Invalid enum");
27532                         break;
27533                 }
27534         }
27535
27536         return source;
27537 }
27538
27539 /** Get description of test case
27540  *
27541  * @param test_case_index Index of test case
27542  *
27543  * @return Test case description
27544  **/
27545 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27546 {
27547         std::stringstream stream;
27548         testCase&                 test_case = m_test_cases[test_case_index];
27549
27550         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27551
27552         return stream.str();
27553 }
27554
27555 /** Get number of test cases
27556  *
27557  * @return Number of test cases
27558  **/
27559 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27560 {
27561         return static_cast<GLuint>(m_test_cases.size());
27562 }
27563
27564 /** Selects if "compute" stage is relevant for test
27565  *
27566  * @param ignored
27567  *
27568  * @return false
27569  **/
27570 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27571 {
27572         return false;
27573 }
27574
27575 /** Prepare all test cases
27576  *
27577  **/
27578 void XFBCaptureUnsizedArrayTest::testInit()
27579 {
27580         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27581         {
27582                 /* Not aplicable for */
27583                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27584                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27585                 {
27586                         continue;
27587                 }
27588
27589                 testCase test_case = { (Utils::Shader::STAGES)stage };
27590
27591                 m_test_cases.push_back(test_case);
27592         }
27593 }
27594 } /* EnhancedLayouts namespace */
27595
27596 /** Constructor.
27597  *
27598  *  @param context Rendering context.
27599  **/
27600 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27601         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27602 {
27603         /* Left blank on purpose */
27604 }
27605
27606 /** Initializes a texture_storage_multisample test group.
27607  *
27608  **/
27609 void EnhancedLayoutsTests::init(void)
27610 {
27611         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27612         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27613         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27614         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27615         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27616         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27617         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27618         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27619         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27620         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27621         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27622         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27623         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27624         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27625         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27626         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27627         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27628         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27629
27630         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27631         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27632         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27633         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27634         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27635         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27636         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27637         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27638         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27639         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27640         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27641         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27642         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27643         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27644         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27645         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27646         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27647         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27648         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27649         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27650         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27651         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27652         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27653         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27654         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27655         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27656         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27657         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27658         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27659         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27660         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27661         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27662         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27663         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27664         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27665         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27666         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27667         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27668         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27669         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27670         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27671         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27672         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27673         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27674         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27675 }
27676
27677 } /* gl4cts namespace */