• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2014-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  gl4cShadingLanguage420PackTests.cpp
26  * \brief Implements conformance tests for "Shading Language 420Pack" functionality.
27  */ /*-------------------------------------------------------------------*/
28 
29 #include "gl4cShadingLanguage420PackTests.hpp"
30 
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestLog.hpp"
36 
37 #include <algorithm>
38 #include <iomanip>
39 #include <stdio.h>
40 #include <string.h>
41 #include <string>
42 #include <vector>
43 
44 #define IS_DEBUG 0
45 
46 using namespace glw;
47 
48 namespace gl4cts
49 {
50 
51 namespace GLSL420Pack
52 {
53 /** Check binding of uniform
54  *
55  * @param program          Program object
56  * @param name             Array name
57  * @param expected_binding Expected binding value
58  *
59  * @return true if binding is as expected, false otherwise
60  **/
checkUniformBinding(Utils::program & program,const glw::GLchar * name,glw::GLint expected_binding)61 bool Utils::checkUniformBinding(Utils::program& program, const glw::GLchar* name, glw::GLint expected_binding)
62 {
63 	const GLint uniform_location = program.getUniformLocation(name);
64 	if (-1 == uniform_location)
65 	{
66 		TCU_FAIL("Uniform is inactive");
67 	}
68 
69 	GLint binding = program.getUniform1i(uniform_location);
70 
71 	return (expected_binding == binding);
72 }
73 /** Check binding of uniform array element at <index>
74  *
75  * @param program          Program object
76  * @param name             Array name
77  * @param index            Index
78  * @param expected_binding Expected binding value
79  *
80  * @return true if binding is as expected, false otherwise
81  **/
checkUniformArrayBinding(Utils::program & program,const glw::GLchar * name,glw::GLuint index,glw::GLint expected_binding)82 bool Utils::checkUniformArrayBinding(Utils::program& program, const glw::GLchar* name, glw::GLuint index,
83 									 glw::GLint expected_binding)
84 {
85 	GLchar buffer[64];
86 	sprintf(buffer, "%s[%d]", name, index);
87 
88 	const GLint uniform_location = program.getUniformLocation(buffer);
89 	if (-1 == uniform_location)
90 	{
91 		TCU_FAIL("Uniform is inactive");
92 	}
93 
94 	GLint binding = program.getUniform1i(uniform_location);
95 
96 	return (expected_binding == binding);
97 }
98 
99 /** Check if given qualifier is present in set
100  *
101  * @param qualifier  Specific qualifier
102  * @param qualifiers Qualifiers' set
103  *
104  * @return true if qualifier is present, false otherwise
105  **/
doesContainQualifier(Utils::QUALIFIERS qualifier,const Utils::qualifierSet & qualifiers)106 bool Utils::doesContainQualifier(Utils::QUALIFIERS qualifier, const Utils::qualifierSet& qualifiers)
107 {
108 	for (GLuint i = 0; i < qualifiers.size(); ++i)
109 	{
110 		if (qualifiers[i] == qualifier)
111 		{
112 			return true;
113 		}
114 	}
115 
116 	return false;
117 }
118 
119 /** Check if given stage supports specific qualifier
120  *
121  * @param stage     Shader stage
122  * @param storage   Storage of variable
123  * @param qualifier Qualifier
124  *
125  * @return true if qualifier can be used in given stage, false otherwise
126  **/
doesStageSupportQualifier(Utils::SHADER_STAGES stage,Utils::VARIABLE_STORAGE storage,Utils::QUALIFIERS qualifier)127 bool Utils::doesStageSupportQualifier(Utils::SHADER_STAGES stage, Utils::VARIABLE_STORAGE storage,
128 									  Utils::QUALIFIERS qualifier)
129 {
130 	bool result = true;
131 
132 	switch (stage)
133 	{
134 	case COMPUTE_SHADER:
135 		switch (qualifier)
136 		{
137 		case QUAL_NONE:
138 		case QUAL_UNIFORM:
139 		case QUAL_LOWP:
140 		case QUAL_MEDIUMP:
141 		case QUAL_HIGHP:
142 		case QUAL_INVARIANT:
143 			result = true;
144 			break;
145 		default:
146 			result = false;
147 			break;
148 		}
149 		break;
150 	case FRAGMENT_SHADER:
151 		if (QUAL_PATCH == qualifier)
152 		{
153 			result = false;
154 		}
155 		else if ((OUTPUT == storage) &&
156 				 ((QUAL_SMOOTH == qualifier) || (QUAL_NOPERSPECTIVE == qualifier) || (QUAL_FLAT == qualifier)))
157 		{
158 			result = false;
159 		}
160 		break;
161 	case VERTEX_SHADER:
162 		if (QUAL_PATCH == qualifier)
163 		{
164 			result = false;
165 		}
166 		else if ((INPUT == storage) &&
167 				 ((QUAL_SMOOTH == qualifier) || (QUAL_NOPERSPECTIVE == qualifier) || (QUAL_FLAT == qualifier) ||
168 				  (QUAL_INVARIANT == qualifier) || (QUAL_CENTROID == qualifier) || (QUAL_SAMPLE == qualifier)))
169 		{
170 			result = false;
171 		}
172 		break;
173 	case GEOMETRY_SHADER:
174 		if (QUAL_PATCH == qualifier)
175 		{
176 			result = false;
177 		}
178 		break;
179 	case TESS_CTRL_SHADER:
180 		if ((INPUT == storage) && (QUAL_PATCH == qualifier))
181 		{
182 			result = false;
183 		}
184 		break;
185 	case TESS_EVAL_SHADER:
186 		if ((OUTPUT == storage) && (QUAL_PATCH == qualifier))
187 		{
188 			result = false;
189 		}
190 		break;
191 	default:
192 		break;
193 	}
194 
195 	return result;
196 }
197 
198 /** Get string for qualifier
199  *
200  * @param qualifier Qualifier
201  *
202  * @return A string for given qualifier
203  **/
getQualifierString(Utils::QUALIFIERS qualifier)204 const GLchar* Utils::getQualifierString(Utils::QUALIFIERS qualifier)
205 {
206 	const GLchar* result = 0;
207 	switch (qualifier)
208 	{
209 	case QUAL_NONE:
210 		result = "";
211 		break;
212 	case QUAL_CONST:
213 		result = "const";
214 		break;
215 	case QUAL_IN:
216 		result = "in";
217 		break;
218 	case QUAL_OUT:
219 		result = "out";
220 		break;
221 	case QUAL_INOUT:
222 		result = "inout";
223 		break;
224 	case QUAL_UNIFORM:
225 		result = "uniform";
226 		break;
227 	case QUAL_PATCH:
228 		result = "patch";
229 		break;
230 	case QUAL_CENTROID:
231 		result = "centroid";
232 		break;
233 	case QUAL_SAMPLE:
234 		result = "sample";
235 		break;
236 	case QUAL_FLAT:
237 		result = "flat";
238 		break;
239 	case QUAL_NOPERSPECTIVE:
240 		result = "noperspective";
241 		break;
242 	case QUAL_SMOOTH:
243 		result = "smooth";
244 		break;
245 	case QUAL_LOCATION:
246 		result = "layout (location = LOC_VALUE)";
247 		break;
248 	case QUAL_LOWP:
249 		result = "lowp";
250 		break;
251 	case QUAL_MEDIUMP:
252 		result = "mediump";
253 		break;
254 	case QUAL_HIGHP:
255 		result = "highp";
256 		break;
257 	case QUAL_PRECISE:
258 		result = "precise";
259 		break;
260 	case QUAL_INVARIANT:
261 		result = "invariant";
262 		break;
263 	default:
264 		TCU_FAIL("Invalid enum");
265 	};
266 
267 	return result;
268 }
269 
270 /** Returns a string with set of qualifiers.
271  *
272  * @param qualifiers Set of qualifiers
273  *
274  * @return String
275  **/
getQualifiersListString(const qualifierSet & qualifiers)276 std::string Utils::getQualifiersListString(const qualifierSet& qualifiers)
277 {
278 	static const GLchar* qualifier_list		   = "QUALIFIER QUALIFIER_LIST";
279 	const GLuint		 qualifier_list_length = static_cast<GLuint>(strlen(qualifier_list));
280 
281 	/* Tokens */
282 	static const GLchar* token_qualifier = "QUALIFIER";
283 	static const GLchar* token_qual_list = "QUALIFIER_LIST";
284 
285 	/* Variables */
286 	std::string list	 = token_qual_list;
287 	size_t		position = 0;
288 
289 	/* Replace tokens */
290 	for (GLuint i = 0; i < qualifiers.size(); ++i)
291 	{
292 		Utils::replaceToken(token_qual_list, position, qualifier_list, list);
293 		position -= qualifier_list_length;
294 
295 		const GLchar* qualifier_str = getQualifierString(qualifiers[i]);
296 
297 		Utils::replaceToken(token_qualifier, position, qualifier_str, list);
298 	}
299 
300 	Utils::replaceToken(token_qual_list, position, "", list);
301 
302 	return list;
303 }
304 
305 /** Prepare a set of qualifiers for given shader stage and variable storage.
306  * Filters out not supported qualifiers from in_qualifiers
307  *
308  * @param in_qualifiers Origiranl set of qualifiers
309  * @param stage         Shader stage
310  * @param storage       Variable storage
311  *
312  * @return Set of qualifiers
313  **/
prepareQualifiersSet(const qualifierSet & in_qualifiers,SHADER_STAGES stage,VARIABLE_STORAGE storage)314 Utils::qualifierSet Utils::prepareQualifiersSet(const qualifierSet& in_qualifiers, SHADER_STAGES stage,
315 												VARIABLE_STORAGE storage)
316 {
317 	qualifierSet result;
318 
319 	for (GLuint i = 0; i < in_qualifiers.size(); ++i)
320 	{
321 		Utils::QUALIFIERS qualifier = in_qualifiers[i];
322 
323 		if (false == doesStageSupportQualifier(stage, storage, qualifier))
324 		{
325 			continue;
326 		};
327 
328 		/* Replace wrong storage qualifiers */
329 		if ((Utils::INPUT == storage) && ((Utils::QUAL_UNIFORM == qualifier) || (Utils::QUAL_OUT == qualifier)))
330 		{
331 			qualifier = QUAL_IN;
332 		}
333 		else if ((Utils::OUTPUT == storage) && ((Utils::QUAL_IN == qualifier) || (Utils::QUAL_UNIFORM == qualifier)))
334 		{
335 			qualifier = QUAL_OUT;
336 		}
337 		else if ((Utils::UNIFORM == storage) && ((Utils::QUAL_IN == qualifier) || (Utils::QUAL_OUT == qualifier)))
338 		{
339 			qualifier = QUAL_UNIFORM;
340 		}
341 
342 		result.push_back(qualifier);
343 	}
344 
345 	return result;
346 }
347 
348 /** Get image type for given texture type
349  *
350  * @param type Texture type
351  *
352  * @return String representing sampler type
353  **/
getImageType(Utils::TEXTURE_TYPES type)354 const GLchar* Utils::getImageType(Utils::TEXTURE_TYPES type)
355 {
356 	const GLchar* result = 0;
357 
358 	switch (type)
359 	{
360 	case TEX_BUFFER:
361 		result = "imageBuffer";
362 		break;
363 	case TEX_2D:
364 		result = "image2D";
365 		break;
366 	case TEX_2D_RECT:
367 		result = "image2DRect";
368 		break;
369 	case TEX_2D_ARRAY:
370 		result = "image2DArray";
371 		break;
372 	case TEX_3D:
373 		result = "image3D";
374 		break;
375 	case TEX_CUBE:
376 		result = "imageCube";
377 		break;
378 	case TEX_1D:
379 		result = "image1D";
380 		break;
381 	case TEX_1D_ARRAY:
382 		result = "image1DArray";
383 		break;
384 	default:
385 		TCU_FAIL("Invalid enum");
386 	}
387 
388 	return result;
389 }
390 
391 /** Get number of coordinates required to address texture of given type
392  *
393  * @param type Type of texture
394  *
395  * @return Number of coordinates
396  **/
getNumberOfCoordinates(Utils::TEXTURE_TYPES type)397 GLuint Utils::getNumberOfCoordinates(Utils::TEXTURE_TYPES type)
398 {
399 	GLuint result = 0;
400 
401 	switch (type)
402 	{
403 	case TEX_BUFFER:
404 		result = 1;
405 		break;
406 	case TEX_2D:
407 		result = 2;
408 		break;
409 	case TEX_2D_RECT:
410 		result = 2;
411 		break;
412 	case TEX_2D_ARRAY:
413 		result = 3;
414 		break;
415 	case TEX_3D:
416 		result = 3;
417 		break;
418 	case TEX_CUBE:
419 		result = 3;
420 		break;
421 	case TEX_1D:
422 		result = 1;
423 		break;
424 	case TEX_1D_ARRAY:
425 		result = 2;
426 		break;
427 	default:
428 		TCU_FAIL("Invalid enum");
429 	}
430 
431 	return result;
432 }
433 
434 /** Get sampler type for given texture type
435  *
436  * @param type Texture type
437  *
438  * @return String representing sampler type
439  **/
getSamplerType(Utils::TEXTURE_TYPES type)440 const GLchar* Utils::getSamplerType(Utils::TEXTURE_TYPES type)
441 {
442 	const GLchar* result = 0;
443 
444 	switch (type)
445 	{
446 	case TEX_BUFFER:
447 		result = "samplerBuffer";
448 		break;
449 	case TEX_2D:
450 		result = "sampler2D";
451 		break;
452 	case TEX_2D_RECT:
453 		result = "sampler2DRect";
454 		break;
455 	case TEX_2D_ARRAY:
456 		result = "sampler2DArray";
457 		break;
458 	case TEX_3D:
459 		result = "sampler3D";
460 		break;
461 	case TEX_CUBE:
462 		result = "samplerCube";
463 		break;
464 	case TEX_1D:
465 		result = "sampler1D";
466 		break;
467 	case TEX_1D_ARRAY:
468 		result = "sampler1DArray";
469 		break;
470 	default:
471 		TCU_FAIL("Invalid enum");
472 	}
473 
474 	return result;
475 }
476 
477 /** Get target for given texture type
478  *
479  * @param type Type of texture
480  *
481  * @return Target
482  **/
getTextureTartet(Utils::TEXTURE_TYPES type)483 GLenum Utils::getTextureTartet(Utils::TEXTURE_TYPES type)
484 {
485 	GLenum result = 0;
486 
487 	switch (type)
488 	{
489 	case TEX_BUFFER:
490 		result = GL_TEXTURE_BUFFER;
491 		break;
492 	case TEX_2D:
493 		result = GL_TEXTURE_2D;
494 		break;
495 	case TEX_2D_RECT:
496 		result = GL_TEXTURE_RECTANGLE;
497 		break;
498 	case TEX_2D_ARRAY:
499 		result = GL_TEXTURE_2D_ARRAY;
500 		break;
501 	case TEX_3D:
502 		result = GL_TEXTURE_3D;
503 		break;
504 	case TEX_CUBE:
505 		result = GL_TEXTURE_CUBE_MAP;
506 		break;
507 	case TEX_1D:
508 		result = GL_TEXTURE_1D;
509 		break;
510 	case TEX_1D_ARRAY:
511 		result = GL_TEXTURE_1D_ARRAY;
512 		break;
513 	default:
514 		TCU_FAIL("Invalid enum");
515 	}
516 
517 	return result;
518 }
519 
520 /** Get name of given texture type
521  *
522  * @param type Texture type
523  *
524  * @return String representing name of texture type
525  **/
getTextureTypeName(Utils::TEXTURE_TYPES type)526 const GLchar* Utils::getTextureTypeName(Utils::TEXTURE_TYPES type)
527 {
528 	const GLchar* result = 0;
529 
530 	switch (type)
531 	{
532 	case TEX_BUFFER:
533 		result = "buffer";
534 		break;
535 	case TEX_2D:
536 		result = "2D";
537 		break;
538 	case TEX_2D_RECT:
539 		result = "2D rectangle";
540 		break;
541 	case TEX_2D_ARRAY:
542 		result = "2D array";
543 		break;
544 	case TEX_3D:
545 		result = "3D";
546 		break;
547 	case TEX_CUBE:
548 		result = "cube";
549 		break;
550 	case TEX_1D:
551 		result = "1D";
552 		break;
553 	case TEX_1D_ARRAY:
554 		result = "1D array";
555 		break;
556 	default:
557 		TCU_FAIL("Invalid enum");
558 	}
559 
560 	return result;
561 }
562 
563 /** Check if glsl support matrices for specific basic type
564  *
565  * @param type Basic type
566  *
567  * @return true if matrices of <type> are supported, false otherwise
568  **/
doesTypeSupportMatrix(TYPES type)569 bool Utils::doesTypeSupportMatrix(TYPES type)
570 {
571 	bool result = false;
572 
573 	switch (type)
574 	{
575 	case FLOAT:
576 	case DOUBLE:
577 		result = true;
578 		break;
579 	case INT:
580 	case UINT:
581 		result = false;
582 		break;
583 	default:
584 		TCU_FAIL("Invliad enum");
585 	}
586 
587 	return result;
588 }
589 
590 /** Get string representing name of shader stage
591  *
592  * @param stage Shader stage
593  *
594  * @return String with name of shader stage
595  **/
getShaderStageName(Utils::SHADER_STAGES stage)596 const glw::GLchar* Utils::getShaderStageName(Utils::SHADER_STAGES stage)
597 {
598 	const GLchar* result = 0;
599 
600 	switch (stage)
601 	{
602 	case COMPUTE_SHADER:
603 		result = "compute";
604 		break;
605 	case VERTEX_SHADER:
606 		result = "vertex";
607 		break;
608 	case TESS_CTRL_SHADER:
609 		result = "tesselation control";
610 		break;
611 	case TESS_EVAL_SHADER:
612 		result = "tesselation evaluation";
613 		break;
614 	case GEOMETRY_SHADER:
615 		result = "geomtery";
616 		break;
617 	case FRAGMENT_SHADER:
618 		result = "fragment";
619 		break;
620 	default:
621 		TCU_FAIL("Invalid enum");
622 	}
623 
624 	return result;
625 }
626 
627 /** Get glsl name of specified type
628  *
629  * @param type      Basic type
630  * @param n_columns Number of columns
631  * @param n_rows    Number of rows
632  *
633  * @return Name of glsl type
634  **/
getTypeName(TYPES type,glw::GLuint n_columns,glw::GLuint n_rows)635 const glw::GLchar* Utils::getTypeName(TYPES type, glw::GLuint n_columns, glw::GLuint n_rows)
636 {
637 	static const GLchar* float_lut[4][4] = {
638 		{ "float", "vec2", "vec3", "vec4" },
639 		{ 0, "mat2", "mat2x3", "mat2x4" },
640 		{ 0, "mat3x2", "mat3", "mat3x4" },
641 		{ 0, "mat4x2", "mat4x3", "mat4" },
642 	};
643 
644 	static const GLchar* double_lut[4][4] = {
645 		{ "double", "dvec2", "dvec3", "dvec4" },
646 		{ 0, "dmat2", "dmat2x3", "dmat2x4" },
647 		{ 0, "dmat3x2", "dmat3", "dmat3x4" },
648 		{ 0, "dmat4x2", "dmat4x3", "dmat4" },
649 	};
650 
651 	static const GLchar* int_lut[4] = { "int", "ivec2", "ivec3", "ivec4" };
652 
653 	static const GLchar* uint_lut[4] = { "uint", "uvec2", "uvec3", "uvec4" };
654 
655 	const GLchar* result = 0;
656 
657 	if ((1 > n_columns) || (1 > n_rows) || (4 < n_columns) || (4 < n_rows))
658 	{
659 		return 0;
660 	}
661 
662 	switch (type)
663 	{
664 	case FLOAT:
665 		result = float_lut[n_columns - 1][n_rows - 1];
666 		break;
667 	case DOUBLE:
668 		result = double_lut[n_columns - 1][n_rows - 1];
669 		break;
670 	case INT:
671 		result = int_lut[n_rows - 1];
672 		break;
673 	case UINT:
674 		result = uint_lut[n_rows - 1];
675 		break;
676 	default:
677 		TCU_FAIL("Invliad enum");
678 	}
679 
680 	return result;
681 }
682 
683 /** Get proper glUniformNdv routine for vectors with specified number of rows
684  *
685  * @param gl     GL functions
686  * @param n_rows Number of rows
687  *
688  * @return Function address
689  **/
getUniformNdv(const glw::Functions & gl,glw::GLuint n_rows)690 Utils::uniformNdv Utils::getUniformNdv(const glw::Functions& gl, glw::GLuint n_rows)
691 {
692 	uniformNdv result = 0;
693 
694 	switch (n_rows)
695 	{
696 	case 1:
697 		result = gl.uniform1dv;
698 		break;
699 	case 2:
700 		result = gl.uniform2dv;
701 		break;
702 	case 3:
703 		result = gl.uniform3dv;
704 		break;
705 	case 4:
706 		result = gl.uniform4dv;
707 		break;
708 	default:
709 		TCU_FAIL("Invalid number of rows");
710 	}
711 
712 	return result;
713 }
714 
715 /** Get proper glUniformNfv routine for vectors with specified number of rows
716  *
717  * @param gl     GL functions
718  * @param n_rows Number of rows
719  *
720  * @return Function address
721  **/
getUniformNfv(const glw::Functions & gl,glw::GLuint n_rows)722 Utils::uniformNfv Utils::getUniformNfv(const glw::Functions& gl, glw::GLuint n_rows)
723 {
724 	uniformNfv result = 0;
725 
726 	switch (n_rows)
727 	{
728 	case 1:
729 		result = gl.uniform1fv;
730 		break;
731 	case 2:
732 		result = gl.uniform2fv;
733 		break;
734 	case 3:
735 		result = gl.uniform3fv;
736 		break;
737 	case 4:
738 		result = gl.uniform4fv;
739 		break;
740 	default:
741 		TCU_FAIL("Invalid number of rows");
742 	}
743 
744 	return result;
745 }
746 
747 /** Get proper glUniformNiv routine for vectors with specified number of rows
748  *
749  * @param gl     GL functions
750  * @param n_rows Number of rows
751  *
752  * @return Function address
753  **/
getUniformNiv(const glw::Functions & gl,glw::GLuint n_rows)754 Utils::uniformNiv Utils::getUniformNiv(const glw::Functions& gl, glw::GLuint n_rows)
755 {
756 	uniformNiv result = 0;
757 
758 	switch (n_rows)
759 	{
760 	case 1:
761 		result = gl.uniform1iv;
762 		break;
763 	case 2:
764 		result = gl.uniform2iv;
765 		break;
766 	case 3:
767 		result = gl.uniform3iv;
768 		break;
769 	case 4:
770 		result = gl.uniform4iv;
771 		break;
772 	default:
773 		TCU_FAIL("Invalid number of rows");
774 	}
775 
776 	return result;
777 }
778 
779 /** Get proper glUniformNuiv routine for vectors with specified number of rows
780  *
781  * @param gl     GL functions
782  * @param n_rows Number of rows
783  *
784  * @return Function address
785  **/
getUniformNuiv(const glw::Functions & gl,glw::GLuint n_rows)786 Utils::uniformNuiv Utils::getUniformNuiv(const glw::Functions& gl, glw::GLuint n_rows)
787 {
788 	uniformNuiv result = 0;
789 
790 	switch (n_rows)
791 	{
792 	case 1:
793 		result = gl.uniform1uiv;
794 		break;
795 	case 2:
796 		result = gl.uniform2uiv;
797 		break;
798 	case 3:
799 		result = gl.uniform3uiv;
800 		break;
801 	case 4:
802 		result = gl.uniform4uiv;
803 		break;
804 	default:
805 		TCU_FAIL("Invalid number of rows");
806 	}
807 
808 	return result;
809 }
810 
811 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
812  *
813  * @param gl     GL functions
814  * @param n_rows Number of rows
815  *
816  * @return Function address
817  **/
getUniformMatrixNdv(const glw::Functions & gl,glw::GLuint n_columns,glw::GLuint n_rows)818 Utils::uniformMatrixNdv Utils::getUniformMatrixNdv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
819 {
820 	uniformMatrixNdv result = 0;
821 
822 	switch (n_columns)
823 	{
824 	case 2:
825 		switch (n_rows)
826 		{
827 		case 2:
828 			result = gl.uniformMatrix2dv;
829 			break;
830 		case 3:
831 			result = gl.uniformMatrix2x3dv;
832 			break;
833 		case 4:
834 			result = gl.uniformMatrix2x4dv;
835 			break;
836 		default:
837 			TCU_FAIL("Invalid number of rows");
838 		}
839 		break;
840 	case 3:
841 		switch (n_rows)
842 		{
843 		case 2:
844 			result = gl.uniformMatrix3x2dv;
845 			break;
846 		case 3:
847 			result = gl.uniformMatrix3dv;
848 			break;
849 		case 4:
850 			result = gl.uniformMatrix3x4dv;
851 			break;
852 		default:
853 			TCU_FAIL("Invalid number of rows");
854 		}
855 		break;
856 	case 4:
857 		switch (n_rows)
858 		{
859 		case 2:
860 			result = gl.uniformMatrix4x2dv;
861 			break;
862 		case 3:
863 			result = gl.uniformMatrix4x3dv;
864 			break;
865 		case 4:
866 			result = gl.uniformMatrix4dv;
867 			break;
868 		default:
869 			TCU_FAIL("Invalid number of rows");
870 		}
871 		break;
872 	default:
873 		TCU_FAIL("Invalid number of columns");
874 	}
875 
876 	return result;
877 }
878 
879 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
880  *
881  * @param gl     GL functions
882  * @param n_rows Number of rows
883  *
884  * @return Function address
885  **/
getUniformMatrixNfv(const glw::Functions & gl,glw::GLuint n_columns,glw::GLuint n_rows)886 Utils::uniformMatrixNfv Utils::getUniformMatrixNfv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
887 {
888 	uniformMatrixNfv result = 0;
889 
890 	switch (n_columns)
891 	{
892 	case 2:
893 		switch (n_rows)
894 		{
895 		case 2:
896 			result = gl.uniformMatrix2fv;
897 			break;
898 		case 3:
899 			result = gl.uniformMatrix2x3fv;
900 			break;
901 		case 4:
902 			result = gl.uniformMatrix2x4fv;
903 			break;
904 		default:
905 			TCU_FAIL("Invalid number of rows");
906 		}
907 		break;
908 	case 3:
909 		switch (n_rows)
910 		{
911 		case 2:
912 			result = gl.uniformMatrix3x2fv;
913 			break;
914 		case 3:
915 			result = gl.uniformMatrix3fv;
916 			break;
917 		case 4:
918 			result = gl.uniformMatrix3x4fv;
919 			break;
920 		default:
921 			TCU_FAIL("Invalid number of rows");
922 		}
923 		break;
924 	case 4:
925 		switch (n_rows)
926 		{
927 		case 2:
928 			result = gl.uniformMatrix4x2fv;
929 			break;
930 		case 3:
931 			result = gl.uniformMatrix4x3fv;
932 			break;
933 		case 4:
934 			result = gl.uniformMatrix4fv;
935 			break;
936 		default:
937 			TCU_FAIL("Invalid number of rows");
938 		}
939 		break;
940 	default:
941 		TCU_FAIL("Invalid number of columns");
942 	}
943 
944 	return result;
945 }
946 
947 /** Prepare definition of input or output block's variable
948  *
949  * @param qualifiers    Set of qualifiers
950  * @param type_name     Name of type
951  * @param variable_name Meaningful part of variable name, eg. tex_coord
952  *
953  * @return Definition of variable
954  **/
getBlockVariableDefinition(const qualifierSet & qualifiers,const glw::GLchar * type_name,const glw::GLchar * variable_name)955 std::string Utils::getBlockVariableDefinition(const qualifierSet& qualifiers, const glw::GLchar* type_name,
956 											  const glw::GLchar* variable_name)
957 {
958 	/* Templates */
959 	static const GLchar* def_template = "QUALIFIER_LISTTYPE VARIABLE_NAME";
960 
961 	/* Tokens */
962 	static const GLchar* token_type			 = "TYPE";
963 	static const GLchar* token_variable_name = "VARIABLE_NAME";
964 	static const GLchar* token_qual_list	 = "QUALIFIER_LIST";
965 
966 	/* Variables */
967 	std::string variable_definition = def_template;
968 	size_t		position			= 0;
969 
970 	/* Get qualifiers list */
971 	const std::string& list = getQualifiersListString(qualifiers);
972 
973 	/* Replace tokens */
974 	Utils::replaceToken(token_qual_list, position, list.c_str(), variable_definition);
975 	Utils::replaceToken(token_type, position, type_name, variable_definition);
976 	Utils::replaceToken(token_variable_name, position, variable_name, variable_definition);
977 
978 	/* Done */
979 	return variable_definition;
980 }
981 
982 /** Prepare reference to input or output variable
983  *
984  * @param flavour       "Flavour" of variable
985  * @param variable_name Meaningful part of variable name, eg. tex_coord
986  * @param block_name    Name of block
987  *
988  * @return Reference to variable
989  **/
getBlockVariableReference(VARIABLE_FLAVOUR flavour,const glw::GLchar * variable_name,const glw::GLchar * block_name)990 std::string Utils::getBlockVariableReference(VARIABLE_FLAVOUR flavour, const glw::GLchar* variable_name,
991 											 const glw::GLchar* block_name)
992 {
993 	/* Templates */
994 	static const GLchar* ref_template		= "BLOCK_NAME.VARIABLE_NAME";
995 	static const GLchar* array_ref_template = "BLOCK_NAME[0].VARIABLE_NAME";
996 	static const GLchar* tcs_ref_template   = "BLOCK_NAME[gl_InvocationID].VARIABLE_NAME";
997 
998 	/* Token */
999 	static const GLchar* token_block_name	= "BLOCK_NAME";
1000 	static const GLchar* token_variable_name = "VARIABLE_NAME";
1001 
1002 	/* Variables */
1003 	std::string variable_definition;
1004 	size_t		position = 0;
1005 
1006 	/* Select variable reference template */
1007 	switch (flavour)
1008 	{
1009 	case BASIC:
1010 		variable_definition = ref_template;
1011 		break;
1012 	case ARRAY:
1013 		variable_definition = array_ref_template;
1014 		break;
1015 	case INDEXED_BY_INVOCATION_ID:
1016 		variable_definition = tcs_ref_template;
1017 		break;
1018 	default:
1019 		variable_definition = ref_template;
1020 		break;
1021 	}
1022 
1023 	/* Replace tokens */
1024 	replaceAllTokens(token_block_name, block_name, variable_definition);
1025 	replaceToken(token_variable_name, position, variable_name, variable_definition);
1026 
1027 	/* Done */
1028 	return variable_definition;
1029 }
1030 
1031 /** Prepare definition of input or output variable
1032  *
1033  * @param flavour       "Flavour" of variable
1034  * @param qualifiers    Set of qualifiers
1035  * @param type_name     Name of type
1036  * @param variable_name Meaningful part of variable name, eg. tex_coord
1037  *
1038  * @return Definition of variable
1039  **/
getVariableDefinition(VARIABLE_FLAVOUR flavour,const qualifierSet & qualifiers,const glw::GLchar * type_name,const glw::GLchar * variable_name)1040 std::string Utils::getVariableDefinition(VARIABLE_FLAVOUR flavour, const qualifierSet& qualifiers,
1041 										 const glw::GLchar* type_name, const glw::GLchar* variable_name)
1042 {
1043 	/* Templates */
1044 	static const GLchar* def_template		= "QUALIFIER_LISTTYPE VARIABLE_NAME";
1045 	static const GLchar* def_array_template = "QUALIFIER_LISTTYPE VARIABLE_NAME[]";
1046 
1047 	/* Tokens */
1048 	static const GLchar* token_type			 = "TYPE";
1049 	static const GLchar* token_variable_name = "VARIABLE_NAME";
1050 	static const GLchar* token_qual_list	 = "QUALIFIER_LIST";
1051 
1052 	/* Variables */
1053 	std::string variable_definition;
1054 	size_t		position = 0;
1055 
1056 	/* Select variable definition template */
1057 	switch (flavour)
1058 	{
1059 	case BASIC:
1060 		variable_definition = def_template;
1061 		break;
1062 	case ARRAY:
1063 	case INDEXED_BY_INVOCATION_ID:
1064 		variable_definition = def_array_template;
1065 		break;
1066 	default:
1067 		TCU_FAIL("Invliad enum");
1068 		break;
1069 	}
1070 
1071 	/* Get qualifiers list */
1072 	const std::string& list = getQualifiersListString(qualifiers);
1073 
1074 	/* Replace tokens */
1075 	replaceToken(token_qual_list, position, list.c_str(), variable_definition);
1076 	replaceToken(token_type, position, type_name, variable_definition);
1077 	replaceToken(token_variable_name, position, variable_name, variable_definition);
1078 
1079 	/* Done */
1080 	return variable_definition;
1081 }
1082 
1083 /** Get "flavour" of variable
1084  *
1085  * @param stage      Shader stage
1086  * @param storage    Storage of variable
1087  * @param qualifiers Set of qualifiers for variable
1088  *
1089  * @return "Flavour" of variable
1090  **/
getVariableFlavour(SHADER_STAGES stage,VARIABLE_STORAGE storage,const qualifierSet & qualifiers)1091 Utils::VARIABLE_FLAVOUR Utils::getVariableFlavour(SHADER_STAGES stage, VARIABLE_STORAGE storage,
1092 												  const qualifierSet& qualifiers)
1093 {
1094 	VARIABLE_FLAVOUR result;
1095 
1096 	if (UNIFORM == storage)
1097 	{
1098 		result = BASIC;
1099 	}
1100 	else
1101 	{
1102 		switch (stage)
1103 		{
1104 		case Utils::GEOMETRY_SHADER:
1105 			if (Utils::INPUT == storage)
1106 			{
1107 				result = ARRAY;
1108 			}
1109 			else /* OUTPUT */
1110 			{
1111 				result = BASIC;
1112 			}
1113 			break;
1114 		case Utils::TESS_EVAL_SHADER:
1115 			if ((false == Utils::doesContainQualifier(Utils::QUAL_PATCH, qualifiers)) && (Utils::INPUT == storage))
1116 			{
1117 				result = ARRAY;
1118 			}
1119 			else /* OUTPUT */
1120 			{
1121 				result = BASIC;
1122 			}
1123 			break;
1124 		case Utils::TESS_CTRL_SHADER:
1125 			if ((true == Utils::doesContainQualifier(Utils::QUAL_PATCH, qualifiers)) && (Utils::OUTPUT == storage))
1126 			{
1127 				result = BASIC;
1128 			}
1129 			else
1130 			{
1131 				result = INDEXED_BY_INVOCATION_ID;
1132 			}
1133 			break;
1134 		case Utils::VERTEX_SHADER:
1135 		case Utils::FRAGMENT_SHADER:
1136 			result = BASIC;
1137 			break;
1138 		default:
1139 			TCU_FAIL("Invliad enum");
1140 			break;
1141 		}
1142 	}
1143 
1144 	return result;
1145 }
1146 
1147 /** Prepare name of input or output variable
1148  *
1149  * @param stage         Shader stage
1150  * @param storage       Storage of variable
1151  * @param variable_name Meaningful part of variable name, eg. tex_coord
1152  *
1153  * @return Name of variable
1154  **/
getVariableName(SHADER_STAGES stage,VARIABLE_STORAGE storage,const glw::GLchar * variable_name)1155 std::string Utils::getVariableName(SHADER_STAGES stage, VARIABLE_STORAGE storage, const glw::GLchar* variable_name)
1156 {
1157 	/* Variable name template */
1158 	static const GLchar* variable_name_template = "PRECEEDING_PREFIX_VARIABLE_NAME";
1159 
1160 	/* Tokens */
1161 	static const GLchar* token_preceeding	= "PRECEEDING";
1162 	static const GLchar* token_prefix		 = "PREFIX";
1163 	static const GLchar* token_variable_name = "VARIABLE_NAME";
1164 
1165 	static const GLchar* prefixes[Utils::STORAGE_MAX][Utils::SHADER_STAGES_MAX][2] = {
1166 		/* COMPUTE,					VERTEX,				TCS,				TES,				GEOMETRY,			FRAGMENT					*/
1167 		{ { "", "" },
1168 		  { "in", "vs" },
1169 		  { "vs", "tcs" },
1170 		  { "tcs", "tes" },
1171 		  { "tes", "gs" },
1172 		  { "gs", "fs" } }, /* INPUT	*/
1173 		{ { "", "" },
1174 		  { "vs", "tcs" },
1175 		  { "tcs", "tes" },
1176 		  { "tes", "gs" },
1177 		  { "gs", "fs" },
1178 		  { "fs", "out" } }, /* OUTPUT	*/
1179 		{ { "uni", "comp" },
1180 		  { "uni", "vs" },
1181 		  { "uni", "tcs" },
1182 		  { "uni", "tes" },
1183 		  { "uni", "gs" },
1184 		  { "uni", "fs" } } /* UNIFORM	*/
1185 	};
1186 
1187 	/* Variables */
1188 	const GLchar* preceeding = prefixes[storage][stage][0];
1189 	const GLchar* prefix	 = prefixes[storage][stage][1];
1190 	std::string   name		 = variable_name_template;
1191 	size_t		  position   = 0;
1192 
1193 	/* Replace tokens */
1194 	Utils::replaceToken(token_preceeding, position, preceeding, name);
1195 	Utils::replaceToken(token_prefix, position, prefix, name);
1196 	Utils::replaceToken(token_variable_name, position, variable_name, name);
1197 
1198 	/* Done */
1199 	return name;
1200 }
1201 
1202 /** Prepare reference to input or output variable
1203  *
1204  * @param flavour       "Flavour" of variable
1205  * @param variable_name Meaningful part of variable name, eg. tex_coord
1206  *
1207  * @return Reference to variable
1208  **/
getVariableReference(VARIABLE_FLAVOUR flavour,const glw::GLchar * variable_name)1209 std::string Utils::getVariableReference(VARIABLE_FLAVOUR flavour, const glw::GLchar* variable_name)
1210 {
1211 	/* Templates */
1212 	static const GLchar* ref_template		= "VARIABLE_NAME";
1213 	static const GLchar* array_ref_template = "VARIABLE_NAME[0]";
1214 	static const GLchar* tcs_ref_template   = "VARIABLE_NAME[gl_InvocationID]";
1215 
1216 	/* Token */
1217 	static const GLchar* token_variable_name = "VARIABLE_NAME";
1218 
1219 	/* Variables */
1220 	std::string variable_definition;
1221 	size_t		position = 0;
1222 
1223 	/* Select variable reference template */
1224 	switch (flavour)
1225 	{
1226 	case BASIC:
1227 		variable_definition = ref_template;
1228 		break;
1229 	case ARRAY:
1230 		variable_definition = array_ref_template;
1231 		break;
1232 	case INDEXED_BY_INVOCATION_ID:
1233 		variable_definition = tcs_ref_template;
1234 		break;
1235 	default:
1236 		variable_definition = ref_template;
1237 		break;
1238 	}
1239 
1240 	/* Replace token */
1241 	Utils::replaceToken(token_variable_name, position, variable_name, variable_definition);
1242 
1243 	/* Done */
1244 	return variable_definition;
1245 }
1246 
1247 /** Prepare definition and reference string for block varaible
1248  *
1249  * @param in_stage         Shader stage
1250  * @param in_storage       Storage of variable
1251  * @param in_qualifiers    Set of qualifiers
1252  * @param in_type_name     Type name
1253  * @param in_variable_name Meaningful part of variable name, like "color"
1254  * @param in_block_name    Name of block, like "input"
1255  * @param out_definition   Definition string
1256  * @param out_reference    Reference string
1257  **/
prepareBlockVariableStrings(Utils::SHADER_STAGES in_stage,Utils::VARIABLE_STORAGE in_storage,const Utils::qualifierSet & in_qualifiers,const glw::GLchar * in_type_name,const glw::GLchar * in_variable_name,const glw::GLchar * in_block_name,std::string & out_definition,std::string & out_reference)1258 void Utils::prepareBlockVariableStrings(Utils::SHADER_STAGES in_stage, Utils::VARIABLE_STORAGE in_storage,
1259 										const Utils::qualifierSet& in_qualifiers, const glw::GLchar* in_type_name,
1260 										const glw::GLchar* in_variable_name, const glw::GLchar* in_block_name,
1261 										std::string& out_definition, std::string& out_reference)
1262 {
1263 	VARIABLE_FLAVOUR	flavour	= getVariableFlavour(in_stage, in_storage, in_qualifiers);
1264 	const qualifierSet& qualifiers = prepareQualifiersSet(in_qualifiers, in_stage, in_storage);
1265 	const std::string&  name	   = getVariableName(in_stage, in_storage, in_variable_name);
1266 
1267 	out_definition = getBlockVariableDefinition(qualifiers, in_type_name, name.c_str());
1268 	out_reference  = getBlockVariableReference(flavour, name.c_str(), in_block_name);
1269 }
1270 
1271 /** Prepare definition and reference string for block varaible
1272  *
1273  * @param in_stage         Shader stage
1274  * @param in_storage       Storage of variable
1275  * @param in_qualifiers    Set of qualifiers
1276  * @param in_type_name     Type name
1277  * @param in_variable_name Meaningful part of variable name, like "color"
1278  * @param out_definition   Definition string
1279  * @param out_reference    Reference string
1280  **/
prepareVariableStrings(Utils::SHADER_STAGES in_stage,Utils::VARIABLE_STORAGE in_storage,const Utils::qualifierSet & in_qualifiers,const glw::GLchar * in_type_name,const glw::GLchar * in_variable_name,std::string & out_definition,std::string & out_reference)1281 void Utils::prepareVariableStrings(Utils::SHADER_STAGES in_stage, Utils::VARIABLE_STORAGE in_storage,
1282 								   const Utils::qualifierSet& in_qualifiers, const glw::GLchar* in_type_name,
1283 								   const glw::GLchar* in_variable_name, std::string& out_definition,
1284 								   std::string& out_reference)
1285 {
1286 	VARIABLE_FLAVOUR	flavour	= getVariableFlavour(in_stage, in_storage, in_qualifiers);
1287 	const qualifierSet& qualifiers = prepareQualifiersSet(in_qualifiers, in_stage, in_storage);
1288 	const std::string&  name	   = getVariableName(in_stage, in_storage, in_variable_name);
1289 
1290 	out_definition = getVariableDefinition(flavour, qualifiers, in_type_name, name.c_str());
1291 	out_reference  = getVariableReference(flavour, name.c_str());
1292 }
1293 
1294 /** Returns string with UTF8 character for current test case
1295  *
1296  * @return String with UTF8 character
1297  **/
getUtf8Character(Utils::UTF8_CHARACTERS character)1298 const GLchar* Utils::getUtf8Character(Utils::UTF8_CHARACTERS character)
1299 {
1300 	static const unsigned char two_bytes[]		 = { 0xd7, 0x84, 0x00 };
1301 	static const unsigned char three_bytes[]	 = { 0xe3, 0x82, 0x81, 0x00 };
1302 	static const unsigned char four_bytes[]		 = { 0xf0, 0x93, 0x83, 0x93, 0x00 };
1303 	static const unsigned char five_bytes[]		 = { 0xfa, 0x82, 0x82, 0x82, 0x82, 0x00 };
1304 	static const unsigned char six_bytes[]		 = { 0xfd, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00 };
1305 	static const unsigned char redundant_bytes[] = { 0xf2, 0x80, 0x80, 0x5e, 0x00 };
1306 
1307 	const GLchar* result = 0;
1308 
1309 	switch (character)
1310 	{
1311 	case TWO_BYTES:
1312 		result = (const GLchar*)two_bytes;
1313 		break;
1314 	case THREE_BYTES:
1315 		result = (const GLchar*)three_bytes;
1316 		break;
1317 	case FOUR_BYTES:
1318 		result = (const GLchar*)four_bytes;
1319 		break;
1320 	case FIVE_BYTES:
1321 		result = (const GLchar*)five_bytes;
1322 		break;
1323 	case SIX_BYTES:
1324 		result = (const GLchar*)six_bytes;
1325 		break;
1326 	case REDUNDANT_ASCII:
1327 		result = (const GLchar*)redundant_bytes;
1328 		break;
1329 	case EMPTY:
1330 		result = "";
1331 		break;
1332 	default:
1333 		TCU_FAIL("Invalid enum");
1334 	}
1335 
1336 	return result;
1337 }
1338 /** Check if extension is supported
1339  *
1340  * @param context        Test context
1341  * @param extension_name Name of extension
1342  *
1343  * @return true if extension is supported, false otherwise
1344  **/
isExtensionSupported(deqp::Context & context,const GLchar * extension_name)1345 bool Utils::isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1346 {
1347 	const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1348 
1349 	if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1350 	{
1351 		return false;
1352 	}
1353 
1354 	return true;
1355 }
1356 
1357 /** Check if GL context meets version requirements
1358  *
1359  * @param gl             Functions
1360  * @param required_major Minimum required MAJOR_VERSION
1361  * @param required_minor Minimum required MINOR_VERSION
1362  *
1363  * @return true if GL context version is at least as requested, false otherwise
1364  **/
isGLVersionAtLeast(const glw::Functions & gl,glw::GLint required_major,glw::GLint required_minor)1365 bool Utils::isGLVersionAtLeast(const glw::Functions& gl, glw::GLint required_major, glw::GLint required_minor)
1366 {
1367 	glw::GLint major = 0;
1368 	glw::GLint minor = 0;
1369 
1370 	gl.getIntegerv(GL_MAJOR_VERSION, &major);
1371 	gl.getIntegerv(GL_MINOR_VERSION, &minor);
1372 
1373 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1374 
1375 	if (major > required_major)
1376 	{
1377 		/* Major is higher than required one */
1378 		return true;
1379 	}
1380 	else if (major == required_major)
1381 	{
1382 		if (minor >= required_minor)
1383 		{
1384 			/* Major is equal to required one */
1385 			/* Minor is higher than or equal to required one */
1386 			return true;
1387 		}
1388 		else
1389 		{
1390 			/* Major is equal to required one */
1391 			/* Minor is lower than required one */
1392 			return false;
1393 		}
1394 	}
1395 	else
1396 	{
1397 		/* Major is lower than required one */
1398 		return false;
1399 	}
1400 }
1401 
1402 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1403  *
1404  * @param token           Token string
1405  * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1406  * @param text            String that will be used as replacement for <token>
1407  * @param string          String to work on
1408  **/
replaceToken(const glw::GLchar * token,size_t & search_position,const glw::GLchar * text,std::string & string)1409 void Utils::replaceToken(const glw::GLchar* token, size_t& search_position, const glw::GLchar* text,
1410 						 std::string& string)
1411 {
1412 	const size_t text_length	= strlen(text);
1413 	const size_t token_length   = strlen(token);
1414 	const size_t token_position = string.find(token, search_position);
1415 
1416 	string.replace(token_position, token_length, text, text_length);
1417 
1418 	search_position = token_position + text_length;
1419 }
1420 
1421 /** Replace all occurances of <token> with <text> in <string>
1422  *
1423  * @param token           Token string
1424  * @param text            String that will be used as replacement for <token>
1425  * @param string          String to work on
1426  **/
replaceAllTokens(const glw::GLchar * token,const glw::GLchar * text,std::string & string)1427 void Utils::replaceAllTokens(const glw::GLchar* token, const glw::GLchar* text, std::string& string)
1428 {
1429 	const size_t text_length  = strlen(text);
1430 	const size_t token_length = strlen(token);
1431 
1432 	size_t search_position = 0;
1433 
1434 	while (1)
1435 	{
1436 		const size_t token_position = string.find(token, search_position);
1437 
1438 		if (std::string::npos == token_position)
1439 		{
1440 			break;
1441 		}
1442 
1443 		search_position = token_position + text_length;
1444 
1445 		string.replace(token_position, token_length, text, text_length);
1446 	}
1447 }
1448 
1449 /** Constructor
1450  *
1451  * @param context          Test context
1452  * @param test_name        Test name
1453  * @param test_description Test description
1454  **/
TestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1455 TestBase::TestBase(deqp::Context& context, const glw::GLchar* test_name, const glw::GLchar* test_description)
1456 	: TestCase(context, test_name, test_description)
1457 	, m_is_compute_shader_supported(false)
1458 	, m_is_explicit_uniform_location(false)
1459 	, m_is_shader_language_420pack(false)
1460 {
1461 	/* Nothing to be done here */
1462 }
1463 
1464 /** Execute test
1465  *
1466  * @return tcu::TestNode::CONTINUE after executing test case, tcu::TestNode::STOP otherwise
1467  **/
iterate()1468 tcu::TestNode::IterateResult TestBase::iterate()
1469 {
1470 	/* GL entry points */
1471 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1472 
1473 	/* Check extension support and version */
1474 	m_is_explicit_uniform_location = Utils::isExtensionSupported(m_context, "GL_ARB_explicit_uniform_location");
1475 	m_is_shader_language_420pack   = Utils::isExtensionSupported(m_context, "GL_ARB_shading_language_420pack");
1476 	m_is_compute_shader_supported  = Utils::isGLVersionAtLeast(gl, 4, 3);
1477 
1478 	/* Execute test */
1479 	bool test_result = test();
1480 
1481 	/* Set result */
1482 	if (true == test_result)
1483 	{
1484 		m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
1485 	}
1486 	else
1487 	{
1488 		m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1489 	}
1490 
1491 	/* Done */
1492 	return tcu::TestNode::STOP;
1493 }
1494 
1495 /** Basic implementation of getShaderSourceConfig method.
1496  *
1497  * @param out_n_parts     Number of source parts used by this test case
1498  * @param out_use_lengths If source lengths shall be provided to compiler
1499  **/
getShaderSourceConfig(glw::GLuint & out_n_parts,bool & out_use_lengths)1500 void TestBase::getShaderSourceConfig(glw::GLuint& out_n_parts, bool& out_use_lengths)
1501 {
1502 	out_n_parts		= 1;
1503 	out_use_lengths = false;
1504 }
1505 
1506 /** Basic implementation of prepareNextTestCase method.
1507  *
1508  * @param test_case_index Index of test case
1509  *
1510  * @return true if index is -1 or 0, false otherwise
1511  **/
prepareNextTestCase(GLuint test_case_index)1512 bool TestBase::prepareNextTestCase(GLuint test_case_index)
1513 {
1514 	if (((GLuint)-1 == test_case_index) || (0 == test_case_index))
1515 	{
1516 		return true;
1517 	}
1518 	else
1519 	{
1520 		return false;
1521 	}
1522 }
1523 
1524 /** Basic implementation of prepareUniforms method
1525  *
1526  * @param ignored
1527  **/
prepareUniforms(Utils::program &)1528 void TestBase::prepareUniforms(Utils::program& /* program */)
1529 {
1530 	/* Nothing to be done */
1531 }
1532 
1533 /** Basic implementation of testInit method
1534  *
1535  * @return true if test can be executed, false otherwise
1536  **/
testInit()1537 bool TestBase::testInit()
1538 {
1539 	return true;
1540 }
1541 
1542 /** Get layout specific for given stage
1543  *
1544  * @param stage Shader stage
1545  *
1546  * @return Stage specific part
1547  **/
getStageSpecificLayout(Utils::SHADER_STAGES stage) const1548 const GLchar* TestBase::getStageSpecificLayout(Utils::SHADER_STAGES stage) const
1549 {
1550 	static const GLchar* stage_layout_geometry = "layout(points)                           in;\n"
1551 												 "layout(triangle_strip, max_vertices = 4) out;\n";
1552 	static const GLchar* stage_layout_tess_ctrl = "layout(vertices = 1)                     out;\n";
1553 	static const GLchar* stage_layout_tess_eval = "layout(isolines, point_mode)             in;\n";
1554 
1555 	const GLchar* result = "";
1556 
1557 	switch (stage)
1558 	{
1559 	case Utils::GEOMETRY_SHADER:
1560 		result = stage_layout_geometry;
1561 		break;
1562 	case Utils::TESS_CTRL_SHADER:
1563 		result = stage_layout_tess_ctrl;
1564 		break;
1565 	case Utils::TESS_EVAL_SHADER:
1566 		result = stage_layout_tess_eval;
1567 		break;
1568 	case Utils::VERTEX_SHADER:
1569 	case Utils::FRAGMENT_SHADER:
1570 	default:
1571 		break;
1572 	}
1573 
1574 	return result;
1575 }
1576 
1577 /** Get "version" string
1578  *
1579  * @param stage           Shader stage, compute shader will use 430
1580  * @param use_version_400 Select if 400 or 420 should be used
1581  *
1582  * @return Version string
1583  **/
getVersionString(Utils::SHADER_STAGES stage,bool use_version_400) const1584 const GLchar* TestBase::getVersionString(Utils::SHADER_STAGES stage, bool use_version_400) const
1585 {
1586 	static const GLchar* version_400 = "#version 400\n"
1587 									   "#extension GL_ARB_shading_language_420pack : require\n"
1588 									   "#extension GL_ARB_separate_shader_objects : enable";
1589 	static const GLchar* version_420 = "#version 420";
1590 	static const GLchar* version_430 = "#version 430";
1591 
1592 	const GLchar* result = "";
1593 
1594 	if (Utils::COMPUTE_SHADER == stage)
1595 	{
1596 		result = version_430;
1597 	}
1598 	else if (true == use_version_400)
1599 	{
1600 		result = version_400;
1601 	}
1602 	else
1603 	{
1604 		result = version_420;
1605 	}
1606 
1607 	return result;
1608 }
1609 
1610 /** Initialize shaderSource instance, reserve storage and prepare shader source
1611  *
1612  * @param in_stage           Shader stage
1613  * @param in_use_version_400 If version 400 or 420 should be used
1614  * @param out_source         Shader source instance
1615  **/
initShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)1616 void TestBase::initShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400, Utils::shaderSource& out_source)
1617 {
1618 	/* Shader source configuration */
1619 	glw::GLuint n_parts		= 0;
1620 	bool		use_lengths = false;
1621 
1622 	getShaderSourceConfig(n_parts, use_lengths);
1623 
1624 	out_source.m_parts.resize(n_parts);
1625 	out_source.m_use_lengths = use_lengths;
1626 
1627 	/* Request child class to prepare shader sources */
1628 	prepareShaderSource(in_stage, in_use_version_400, out_source);
1629 
1630 	/* Prepare source lengths */
1631 	if (true == use_lengths)
1632 	{
1633 		for (GLuint i = 0; i < n_parts; ++i)
1634 		{
1635 			out_source.m_parts[i].m_length = static_cast<glw::GLint>(out_source.m_parts[i].m_code.length());
1636 
1637 			out_source.m_parts[i].m_code.append("This should be ignored by compiler, as source length is provided");
1638 		}
1639 	}
1640 	else
1641 	{
1642 		for (GLuint i = 0; i < n_parts; ++i)
1643 		{
1644 			out_source.m_parts[i].m_length = 0;
1645 		}
1646 	}
1647 }
1648 
1649 /** Execute test
1650  *
1651  * @return true if test pass, false otherwise
1652  **/
test()1653 bool TestBase::test()
1654 {
1655 	bool   result		   = true;
1656 	GLuint test_case_index = 0;
1657 
1658 	/* Prepare test cases */
1659 	testInit();
1660 
1661 	/* GL entry points */
1662 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1663 
1664 	/* Tesselation patch set up */
1665 	gl.patchParameteri(GL_PATCH_VERTICES, 1);
1666 	GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
1667 
1668 	while (true == prepareNextTestCase(test_case_index))
1669 	{
1670 		bool case_result = true;
1671 
1672 		/* Execute drawing case */
1673 		if (false == testDrawArray(false))
1674 		{
1675 			case_result = false;
1676 		}
1677 
1678 		if (true == m_is_shader_language_420pack)
1679 		{
1680 			if (false == testDrawArray(true))
1681 			{
1682 				case_result = false;
1683 			}
1684 		}
1685 
1686 		/* Execute compute shader case */
1687 		if (true == m_is_compute_shader_supported)
1688 		{
1689 			if (false == testCompute())
1690 			{
1691 				case_result = false;
1692 			}
1693 		}
1694 
1695 		/* Log failure */
1696 		if (false == case_result)
1697 		{
1698 			m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case failed."
1699 												<< tcu::TestLog::EndMessage;
1700 
1701 			result = false;
1702 		}
1703 
1704 		/* Go to next test case */
1705 		test_case_index += 1;
1706 	}
1707 
1708 	/* Done */
1709 	return result;
1710 }
1711 
maxImageUniforms(Utils::SHADER_STAGES stage) const1712 int TestBase::maxImageUniforms(Utils::SHADER_STAGES stage) const
1713 {
1714 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1715 	GLint max_image_uniforms;
1716 
1717 	switch (stage)
1718 	{
1719 	case Utils::COMPUTE_SHADER:
1720 		gl.getIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &max_image_uniforms);
1721 		break;
1722 	case Utils::FRAGMENT_SHADER:
1723 		gl.getIntegerv(GL_MAX_FRAGMENT_IMAGE_UNIFORMS, &max_image_uniforms);
1724 		break;
1725 	case Utils::GEOMETRY_SHADER:
1726 		gl.getIntegerv(GL_MAX_GEOMETRY_IMAGE_UNIFORMS, &max_image_uniforms);
1727 		break;
1728 	case Utils::TESS_CTRL_SHADER:
1729 		gl.getIntegerv(GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS, &max_image_uniforms);
1730 		break;
1731 	case Utils::TESS_EVAL_SHADER:
1732 		gl.getIntegerv(GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS, &max_image_uniforms);
1733 		break;
1734 	case Utils::VERTEX_SHADER:
1735 		gl.getIntegerv(GL_MAX_VERTEX_IMAGE_UNIFORMS, &max_image_uniforms);
1736 		break;
1737 	default:
1738 		TCU_FAIL("Invalid enum");
1739 		break;
1740 	}
1741 	return max_image_uniforms;
1742 }
1743 
1744 /** Constructor
1745  *
1746  * @param context          Test context
1747  * @param test_name        Name of test
1748  * @param test_description Description of test
1749  **/
APITestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1750 APITestBase::APITestBase(deqp::Context& context, const glw::GLchar* test_name, const glw::GLchar* test_description)
1751 	: TestBase(context, test_name, test_description)
1752 {
1753 	/* Nothing to be done here */
1754 }
1755 
1756 /** Execute test with compute shader
1757  *
1758  * @return true if test pass, false otherwise
1759  **/
testCompute()1760 bool APITestBase::testCompute()
1761 {
1762 	/* GL objects */
1763 	Utils::program program(m_context);
1764 
1765 	/* Shaders */
1766 	Utils::shaderSource compute_shader;
1767 	initShaderSource(Utils::COMPUTE_SHADER, false, compute_shader);
1768 
1769 	/* Check if test support compute shaders */
1770 	if (true == compute_shader.m_parts[0].m_code.empty())
1771 	{
1772 		return true;
1773 	}
1774 
1775 	/* Build program */
1776 	try
1777 	{
1778 		program.build(compute_shader, 0 /* fragment shader */, 0 /* geometry shader */,
1779 					  0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
1780 					  0 /* varying names */, 0 /* n varying names */, false);
1781 	}
1782 	catch (Utils::shaderCompilationException& exc)
1783 	{
1784 		/* Something wrong with compilation, test case failed */
1785 		tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
1786 
1787 		message << "Shader compilation failed. Error message: " << exc.m_error_message;
1788 
1789 		Utils::program::printShaderSource(exc.m_shader_source, message);
1790 
1791 		message << tcu::TestLog::EndMessage;
1792 
1793 		return false;
1794 	}
1795 	catch (Utils::programLinkageException& exc)
1796 	{
1797 		/* Something wrong with linking, test case failed */
1798 		m_context.getTestContext().getLog() << tcu::TestLog::Message
1799 											<< "Program linking failed. Error message: " << exc.m_error_message
1800 											<< tcu::TestLog::EndMessage;
1801 		return false;
1802 	}
1803 
1804 	/* Set current program */
1805 	program.use();
1806 
1807 	/* Return result of verification */
1808 	return checkResults(program);
1809 }
1810 
1811 /** Execute test with VS, TCS, TES, GS and FS
1812  *
1813  * @param use_version_400 Select if 400 or 420 should be used
1814  *
1815  * @return true if test pass, false otherwise
1816  **/
testDrawArray(bool use_version_400)1817 bool APITestBase::testDrawArray(bool use_version_400)
1818 {
1819 	/* GL objects */
1820 	Utils::program program(m_context);
1821 
1822 	/* Shaders */
1823 	Utils::shaderSource fragment_data;
1824 	Utils::shaderSource geometry_data;
1825 	Utils::shaderSource tess_ctrl_data;
1826 	Utils::shaderSource tess_eval_data;
1827 	Utils::shaderSource vertex_data;
1828 
1829 	initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
1830 	initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
1831 	initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
1832 	initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
1833 	initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
1834 
1835 	/* Build program */
1836 	try
1837 	{
1838 		program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
1839 					  0 /* varying names */, 0 /* n varying names */, false);
1840 	}
1841 	catch (Utils::shaderCompilationException& exc)
1842 	{
1843 		/* Something wrong with compilation, test case failed */
1844 		tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
1845 
1846 		message << "Shader compilation failed. Error message: " << exc.m_error_message;
1847 
1848 		Utils::program::printShaderSource(exc.m_shader_source, message);
1849 
1850 		message << tcu::TestLog::EndMessage;
1851 
1852 		return false;
1853 	}
1854 	catch (Utils::programLinkageException& exc)
1855 	{
1856 		/* Something wrong with linking, test case failed */
1857 		m_context.getTestContext().getLog() << tcu::TestLog::Message
1858 											<< "Program linking failed. Error message: " << exc.m_error_message
1859 											<< tcu::TestLog::EndMessage;
1860 		return false;
1861 	}
1862 
1863 	/* Set current program */
1864 	program.use();
1865 
1866 	/* Return result of verification */
1867 	return checkResults(program);
1868 }
1869 
1870 /* Constants used by GLSLTestBase */
1871 const glw::GLenum GLSLTestBase::m_color_texture_internal_format = GL_RGBA8;
1872 const glw::GLenum GLSLTestBase::m_color_texture_format			= GL_RGBA;
1873 const glw::GLenum GLSLTestBase::m_color_texture_type			= GL_UNSIGNED_BYTE;
1874 const glw::GLuint GLSLTestBase::m_color_texture_width			= 16;
1875 const glw::GLuint GLSLTestBase::m_color_texture_height			= 16;
1876 
1877 /** Constructor
1878  *
1879  * @param context          Test context
1880  * @param test_name        Test name
1881  * @param test_description Test description
1882  **/
GLSLTestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1883 GLSLTestBase::GLSLTestBase(deqp::Context& context, const glw::GLchar* test_name, const glw::GLchar* test_description)
1884 	: TestBase(context, test_name, test_description)
1885 {
1886 	/* Nothing to be done here */
1887 }
1888 
1889 /** Basic implementation of prepareSourceTexture method.
1890  *
1891  * @param ignored Texture instance
1892  *
1893  * @return 0
1894  **/
prepareSourceTexture(Utils::texture &)1895 const GLchar* GLSLTestBase::prepareSourceTexture(Utils::texture&)
1896 {
1897 	return 0;
1898 }
1899 
1900 /** Basic implementation of prepareVertexBuffer method.
1901  *
1902  * @param ignored Program instance
1903  * @param ignored Buffer instance
1904  * @param vao     VertexArray instance
1905  *
1906  * @return 0
1907  **/
prepareVertexBuffer(const Utils::program &,Utils::buffer &,Utils::vertexArray & vao)1908 void GLSLTestBase::prepareVertexBuffer(const Utils::program&, Utils::buffer&, Utils::vertexArray& vao)
1909 {
1910 	vao.generate();
1911 	vao.bind();
1912 }
1913 
1914 /** Basic implementation of verifyAdditionalResults
1915  *
1916  * @return true
1917  **/
verifyAdditionalResults() const1918 bool GLSLTestBase::verifyAdditionalResults() const
1919 {
1920 	return true;
1921 }
1922 
1923 /** Basic implementation of releaseResource method
1924  *
1925  * @param ignored
1926  **/
releaseResource()1927 void GLSLTestBase::releaseResource()
1928 {
1929 	/* Nothing to be done */
1930 }
1931 
1932 /** Bind texture to first image unit and set image uniform to that unit
1933  *
1934  * @param program      Program object
1935  * @param texture      Texture object
1936  * @param uniform_name Name of image uniform
1937  **/
bindTextureToimage(Utils::program & program,Utils::texture & texture,const glw::GLchar * uniform_name) const1938 void GLSLTestBase::bindTextureToimage(Utils::program& program, Utils::texture& texture,
1939 									  const glw::GLchar* uniform_name) const
1940 {
1941 	/* GL entry points */
1942 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1943 
1944 	gl.bindImageTexture(0 /* unit */, texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* layer */, GL_WRITE_ONLY,
1945 						GL_RGBA8);
1946 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
1947 
1948 	GLint location = program.getUniformLocation(uniform_name);
1949 	gl.uniform1i(location, 0);
1950 	GLU_EXPECT_NO_ERROR(gl.getError(), "Uniform1i");
1951 }
1952 
1953 /** Bind texture to first texture unit and set sampler uniform to that unit
1954  *
1955  * @param program      Program object
1956  * @param texture      Texture object
1957  * @param uniform_name Name of sampler uniform
1958  **/
bindTextureToSampler(Utils::program & program,Utils::texture & texture,const glw::GLchar * uniform_name) const1959 void GLSLTestBase::bindTextureToSampler(Utils::program& program, Utils::texture& texture,
1960 										const glw::GLchar* uniform_name) const
1961 {
1962 	/* GL entry points */
1963 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1964 
1965 	gl.activeTexture(GL_TEXTURE0);
1966 	GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
1967 
1968 	texture.bind();
1969 
1970 	GLint location = program.getUniformLocation(uniform_name);
1971 	gl.uniform1i(location, 0);
1972 	GLU_EXPECT_NO_ERROR(gl.getError(), "Uniform1i");
1973 }
1974 
1975 /** Check contents of texture. It is expected that it will be filled with green color
1976  *
1977  * @param color_texture Texture that will be verified
1978  *
1979  * @return true if texture is all green, false otherwise
1980  **/
checkResults(Utils::texture & color_texture) const1981 bool GLSLTestBase::checkResults(Utils::texture& color_texture) const
1982 {
1983 	static const GLuint		 green_color	   = 0xff00ff00;
1984 	const GLuint			 texture_data_size = m_color_texture_width * m_color_texture_height;
1985 	std::vector<glw::GLuint> texture_data;
1986 
1987 	texture_data.resize(texture_data_size);
1988 
1989 	color_texture.get(m_color_texture_format, m_color_texture_type, &texture_data[0]);
1990 
1991 	for (GLuint i = 0; i < texture_data_size; ++i)
1992 	{
1993 		if (green_color != texture_data[i])
1994 		{
1995 			m_context.getTestContext().getLog() << tcu::TestLog::Message << "Invalid texel: " << std::setbase(16)
1996 												<< std::setfill('0') << std::setw(8) << texture_data[i]
1997 												<< " at index: " << i << tcu::TestLog::EndMessage;
1998 
1999 			return false;
2000 		}
2001 	}
2002 
2003 	return verifyAdditionalResults();
2004 }
2005 
2006 /** Prepare framebuffer with texture used as attachment
2007  *
2008  * @param framebuffer   Framebuffer
2009  * @param color_texture Textue used as color attachment 0
2010  **/
prepareFramebuffer(Utils::framebuffer & framebuffer,Utils::texture & color_texture) const2011 void GLSLTestBase::prepareFramebuffer(Utils::framebuffer& framebuffer, Utils::texture& color_texture) const
2012 {
2013 	framebuffer.generate();
2014 
2015 	color_texture.create(m_color_texture_width, m_color_texture_height, m_color_texture_internal_format);
2016 
2017 	framebuffer.attachTexture(GL_COLOR_ATTACHMENT0, color_texture.m_id, m_color_texture_width, m_color_texture_height);
2018 
2019 	framebuffer.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2020 	framebuffer.clear(GL_COLOR_BUFFER_BIT);
2021 }
2022 
2023 /** Prepare texture and bind it to image uniform
2024  *
2025  * @param framebuffer   Framebuffer
2026  * @param color_texture Textue used as color attachment 0
2027  **/
prepareImage(Utils::program & program,Utils::texture & color_texture) const2028 void GLSLTestBase::prepareImage(Utils::program& program, Utils::texture& color_texture) const
2029 {
2030 	color_texture.create(m_color_texture_width, m_color_texture_height, m_color_texture_internal_format);
2031 
2032 	bindTextureToimage(program, color_texture, "uni_image");
2033 }
2034 
2035 /** Execute test with compute shader
2036  *
2037  * @return true if test pass, false otherwise
2038  **/
testCompute()2039 bool GLSLTestBase::testCompute()
2040 {
2041 	/* Test Result */
2042 	bool result = true;
2043 
2044 	/* GL objects */
2045 	Utils::texture color_tex(m_context);
2046 	Utils::program program(m_context);
2047 	Utils::texture source_tex(m_context);
2048 
2049 	/* Shaders */
2050 	Utils::shaderSource compute_shader;
2051 	initShaderSource(Utils::COMPUTE_SHADER, false, compute_shader);
2052 
2053 	/* Check if test support compute shaders */
2054 	if (true == compute_shader.m_parts[0].m_code.empty())
2055 	{
2056 		return true;
2057 	}
2058 
2059 	/* Build program */
2060 	try
2061 	{
2062 		program.build(compute_shader, 0 /* fragment shader */, 0 /* geometry shader */,
2063 					  0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
2064 					  0 /* varying names */, 0 /* n varying names */, false);
2065 	}
2066 	catch (Utils::shaderCompilationException& exc)
2067 	{
2068 		/* Something wrong with compilation, test case failed */
2069 		tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2070 
2071 		message << "Shader compilation failed. Error message: " << exc.m_error_message;
2072 
2073 		Utils::program::printShaderSource(exc.m_shader_source, message);
2074 
2075 		message << tcu::TestLog::EndMessage;
2076 
2077 		return false;
2078 	}
2079 	catch (Utils::programLinkageException& exc)
2080 	{
2081 		/* Something wrong with linking, test case failed */
2082 		m_context.getTestContext().getLog() << tcu::TestLog::Message
2083 											<< "Program linking failed. Error message: " << exc.m_error_message
2084 											<< tcu::TestLog::EndMessage;
2085 		return false;
2086 	}
2087 
2088 /* Log shaders, for debugging */
2089 #if IS_DEBUG
2090 	{
2091 		tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2092 
2093 		Utils::program::printShaderSource(compute_shader, message);
2094 
2095 		message << tcu::TestLog::EndMessage;
2096 	}
2097 #endif /* IS_DEBUG */
2098 
2099 	/* Set current program */
2100 	program.use();
2101 
2102 	/* Prepare image unit */
2103 	prepareImage(program, color_tex);
2104 
2105 	/* Test specific preparation of source texture */
2106 	const GLchar* sampler_name = prepareSourceTexture(source_tex);
2107 	if (0 != sampler_name)
2108 	{
2109 		bindTextureToSampler(program, source_tex, sampler_name);
2110 	}
2111 
2112 	/* Set up uniforms */
2113 	prepareUniforms(program);
2114 
2115 	/* GL entry points */
2116 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2117 
2118 	/* Draw */
2119 	gl.dispatchCompute(m_color_texture_width, m_color_texture_height, 1);
2120 	GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
2121 
2122 	/* Return result of verification */
2123 	result = checkResults(color_tex);
2124 
2125 	/* Release extra resource for the test */
2126 	releaseResource();
2127 
2128 	return result;
2129 }
2130 
2131 /** Execute test with draw array operation
2132  *
2133  * @param use_version_400 Select if 400 or 420 should be used
2134  *
2135  * @return true if test pass, false otherwise
2136  **/
testDrawArray(bool use_version_400)2137 bool GLSLTestBase::testDrawArray(bool use_version_400)
2138 {
2139 	/* Test Result */
2140 	bool result = true;
2141 
2142 	/* GL objects */
2143 	Utils::texture	 color_tex(m_context);
2144 	Utils::framebuffer framebuffer(m_context);
2145 	Utils::program	 program(m_context);
2146 	Utils::texture	 source_tex(m_context);
2147 	Utils::vertexArray vao(m_context);
2148 	Utils::buffer	  vertex_buffer(m_context);
2149 
2150 	/* Shaders */
2151 	Utils::shaderSource fragment_data;
2152 	Utils::shaderSource geometry_data;
2153 	Utils::shaderSource tess_ctrl_data;
2154 	Utils::shaderSource tess_eval_data;
2155 	Utils::shaderSource vertex_data;
2156 
2157 	initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
2158 	initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
2159 	initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
2160 	initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
2161 	initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
2162 
2163 	/* Build program */
2164 	try
2165 	{
2166 		program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
2167 					  0 /* varying names */, 0 /* n varying names */, false);
2168 	}
2169 	catch (Utils::shaderCompilationException& exc)
2170 	{
2171 		/* Something wrong with compilation, test case failed */
2172 		tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2173 
2174 		message << "Shader compilation failed. Error message: " << exc.m_error_message;
2175 
2176 		Utils::program::printShaderSource(exc.m_shader_source, message);
2177 
2178 		message << tcu::TestLog::EndMessage;
2179 
2180 		return false;
2181 	}
2182 	catch (Utils::programLinkageException& exc)
2183 	{
2184 		/* Something wrong with linking, test case failed */
2185 		m_context.getTestContext().getLog() << tcu::TestLog::Message
2186 											<< "Program linking failed. Error message: " << exc.m_error_message
2187 											<< tcu::TestLog::EndMessage;
2188 		return false;
2189 	}
2190 
2191 /* Log shaders, for debugging */
2192 #if IS_DEBUG
2193 	{
2194 		const Utils::shaderSource* data[] = { &vertex_data, &tess_ctrl_data, &tess_eval_data, &geometry_data,
2195 											  &fragment_data };
2196 
2197 		tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2198 
2199 		for (GLuint i = 0; i < 5; ++i)
2200 		{
2201 			Utils::program::printShaderSource(*data[i], message);
2202 		}
2203 
2204 		message << tcu::TestLog::EndMessage;
2205 	}
2206 #endif /* IS_DEBUG */
2207 
2208 	/* Test specific preparation of vertex buffer and vao*/
2209 	prepareVertexBuffer(program, vertex_buffer, vao);
2210 
2211 	/* Set current program */
2212 	program.use();
2213 
2214 	/* Prepare framebuffer */
2215 	prepareFramebuffer(framebuffer, color_tex);
2216 
2217 	/* Test specific preparation of source texture */
2218 	const GLchar* sampler_name = prepareSourceTexture(source_tex);
2219 	if (0 != sampler_name)
2220 	{
2221 		bindTextureToSampler(program, source_tex, sampler_name);
2222 	}
2223 
2224 	/* Set up uniforms */
2225 	prepareUniforms(program);
2226 
2227 	/* GL entry points */
2228 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2229 
2230 	/* Draw */
2231 	gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
2232 	GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
2233 
2234 	/* Return result of verification */
2235 	result = checkResults(color_tex);
2236 
2237 	/* Release extra resource for the test */
2238 	releaseResource();
2239 
2240 	return result;
2241 }
2242 
2243 /** Constructor
2244  *
2245  * @param context          Test context
2246  * @param test_name        Test name
2247  * @param test_description Test description
2248  **/
NegativeTestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)2249 NegativeTestBase::NegativeTestBase(deqp::Context& context, const glw::GLchar* test_name,
2250 								   const glw::GLchar* test_description)
2251 	: TestBase(context, test_name, test_description)
2252 {
2253 	/* Nothing to be done here */
2254 }
2255 
2256 /** Execute test with compute shader
2257  *
2258  * @return true if test pass, false otherwise
2259  **/
testCompute()2260 bool NegativeTestBase::testCompute()
2261 {
2262 	/* GL objects */
2263 	Utils::program program(m_context);
2264 
2265 	/* Shaders */
2266 	Utils::shaderSource conmpute_data;
2267 	initShaderSource(Utils::COMPUTE_SHADER, false, conmpute_data);
2268 
2269 	/* Build program */
2270 	try
2271 	{
2272 		program.build(conmpute_data /* compute shader */, 0 /* fragment shader */, 0 /* geometry shader */,
2273 					  0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
2274 					  0 /* varying names */, 0 /* n varying names */, false);
2275 	}
2276 	catch (Utils::shaderCompilationException& exc)
2277 	{
2278 		/* Compilation failed, as expected. Verify that reason of failure is as expected */
2279 		m_context.getTestContext().getLog() << tcu::TestLog::Message
2280 											<< "Shader compilation error message: " << exc.m_error_message
2281 											<< tcu::TestLog::EndMessage;
2282 		return true;
2283 	}
2284 	catch (Utils::programLinkageException& exc)
2285 	{
2286 		/* Something wrong with linking, test case failed */
2287 		m_context.getTestContext().getLog() << tcu::TestLog::Message
2288 											<< "Program linking failed. Error message: " << exc.m_error_message
2289 											<< tcu::TestLog::EndMessage;
2290 		return true;
2291 	}
2292 
2293 	/* Build process succeded */
2294 	return false;
2295 }
2296 
2297 /** Execute test with draw array operation
2298  *
2299  * @param use_version_400 Select if 400 or 420 should be used
2300  *
2301  * @return true if test pass, false otherwise
2302  **/
testDrawArray(bool use_version_400)2303 bool NegativeTestBase::testDrawArray(bool use_version_400)
2304 {
2305 	/* GL objects */
2306 	Utils::program program(m_context);
2307 
2308 	/* Shaders */
2309 	Utils::shaderSource fragment_data;
2310 	Utils::shaderSource geometry_data;
2311 	Utils::shaderSource tess_ctrl_data;
2312 	Utils::shaderSource tess_eval_data;
2313 	Utils::shaderSource vertex_data;
2314 
2315 	initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
2316 	initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
2317 	initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
2318 	initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
2319 	initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
2320 
2321 	/* Build program */
2322 	try
2323 	{
2324 		program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
2325 					  0 /* varying names */, 0 /* n varying names */, false);
2326 	}
2327 	catch (Utils::shaderCompilationException& exc)
2328 	{
2329 		/* Compilation failed, as expected. Verify that reason of failure is as expected */
2330 		m_context.getTestContext().getLog() << tcu::TestLog::Message
2331 											<< "Shader compilation error message: " << exc.m_error_message
2332 											<< tcu::TestLog::EndMessage;
2333 		return true;
2334 	}
2335 	catch (Utils::programLinkageException& exc)
2336 	{
2337 		/* Something wrong with linking, test case failed */
2338 		m_context.getTestContext().getLog() << tcu::TestLog::Message
2339 											<< "Program linking failed. Error message: " << exc.m_error_message
2340 											<< tcu::TestLog::EndMessage;
2341 		return true;
2342 	}
2343 
2344 	/* Build process succeded */
2345 	return false;
2346 }
2347 
2348 /* Constants used by BindingImageTest */
2349 const GLuint BindingImageTest::m_width		 = 16;
2350 const GLuint BindingImageTest::m_green_color = 0xff00ff00;
2351 const GLuint BindingImageTest::m_height		 = 16;
2352 const GLuint BindingImageTest::m_depth		 = 6;
2353 
2354 /** Constructor
2355  *
2356  * @param context Test context
2357  **/
BindingImageTest(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)2358 BindingImageTest::BindingImageTest(deqp::Context& context, const glw::GLchar* test_name,
2359 								   const glw::GLchar* test_description)
2360 	: GLSLTestBase(context, test_name, test_description)
2361 {
2362 	/* Nothing to be done */
2363 }
2364 
2365 /** Prepare buffer, filled with given color
2366  *
2367  * @param buffer Buffer object
2368  * @param color  Color
2369  **/
prepareBuffer(Utils::buffer & buffer,GLuint color)2370 void BindingImageTest::prepareBuffer(Utils::buffer& buffer, GLuint color)
2371 {
2372 	std::vector<GLuint> texture_data;
2373 	texture_data.resize(m_width);
2374 
2375 	buffer.generate(GL_TEXTURE_BUFFER);
2376 
2377 	for (GLuint i = 0; i < texture_data.size(); ++i)
2378 	{
2379 		texture_data[i] = color;
2380 	}
2381 
2382 	buffer.update(m_width * sizeof(GLuint), &texture_data[0], GL_STATIC_DRAW);
2383 }
2384 
2385 /** Prepare texture of given type filled with given color and bind to specified image unit
2386  *
2387  * @param texture      Texture
2388  * @param buffer       Buffer
2389  * @param texture_type Type of texture
2390  * @param color        Color
2391  **/
prepareTexture(Utils::texture & texture,const Utils::buffer & buffer,Utils::TEXTURE_TYPES texture_type,GLuint color,GLuint unit)2392 void BindingImageTest::prepareTexture(Utils::texture& texture, const Utils::buffer& buffer,
2393 									  Utils::TEXTURE_TYPES texture_type, GLuint color, GLuint unit)
2394 {
2395 	std::vector<GLuint> texture_data;
2396 	texture_data.resize(m_width * m_height * m_depth);
2397 
2398 	GLboolean is_layered = GL_FALSE;
2399 
2400 	for (GLuint i = 0; i < texture_data.size(); ++i)
2401 	{
2402 		texture_data[i] = color;
2403 	}
2404 
2405 	if (Utils::TEX_BUFFER != texture_type)
2406 	{
2407 		texture.create(m_width, m_height, m_depth, GL_RGBA8, texture_type);
2408 
2409 		texture.update(m_width, m_height, m_depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
2410 	}
2411 	else
2412 	{
2413 		buffer.bind();
2414 
2415 		texture.createBuffer(GL_RGBA8, buffer.m_id);
2416 	}
2417 
2418 	switch (texture_type)
2419 	{
2420 	case Utils::TEX_1D_ARRAY:
2421 	case Utils::TEX_2D_ARRAY:
2422 	case Utils::TEX_3D:
2423 	case Utils::TEX_CUBE:
2424 		is_layered = GL_TRUE;
2425 		break;
2426 	default:
2427 		break;
2428 	}
2429 
2430 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2431 
2432 	gl.bindImageTexture(unit, texture.m_id, 0 /* level */, is_layered /* layered */, 0 /* layer */, GL_READ_WRITE,
2433 						GL_RGBA8);
2434 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
2435 }
2436 
2437 /** Verifies that texel at offset 0 is green
2438  *
2439  * @param buffer Buffer object
2440  *
2441  * @return true if texel at offset 0 is green, false otherwise
2442  **/
verifyBuffer(const Utils::buffer & buffer) const2443 bool BindingImageTest::verifyBuffer(const Utils::buffer& buffer) const
2444 {
2445 	GLuint* data = (GLuint*)buffer.map(GL_READ_ONLY);
2446 
2447 	GLuint color = data[0];
2448 
2449 	buffer.unmap();
2450 
2451 	return (m_green_color == color);
2452 }
2453 
2454 /** Verifies that texel at offset 0 is green
2455  *
2456  * @param buffer Buffer object
2457  *
2458  * @return true if texel at offset 0 is green, false otherwise
2459  **/
verifyTexture(const Utils::texture & texture) const2460 bool BindingImageTest::verifyTexture(const Utils::texture& texture) const
2461 {
2462 	static const GLuint texture_data_size = m_width * m_height * m_depth;
2463 
2464 	std::vector<glw::GLuint> texture_data;
2465 	texture_data.resize(texture_data_size);
2466 
2467 	texture.get(GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
2468 
2469 	GLuint color = texture_data[0];
2470 
2471 	return (m_green_color == color);
2472 }
2473 
2474 /* Constants used by LineContinuationTest */
2475 const GLuint  LineContinuationTest::m_n_repetitions			   = 20;
2476 const GLchar* LineContinuationTest::m_texture_coordinates_name = "texture_coordinates";
2477 
2478 /** Constructor
2479  *
2480  * @param context Test context
2481  **/
LineContinuationTest(deqp::Context & context)2482 LineContinuationTest::LineContinuationTest(deqp::Context& context) : GLSLTestBase(context, "line_continuation", "desc")
2483 {
2484 	/* Nothing to be done here */
2485 }
2486 
2487 /** Overwrite getShaderSourceConfig method
2488  *
2489  * @param out_n_parts     Number of source parts used by this test case
2490  * @param out_use_lengths If source lengths shall be provided to compiler
2491  **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)2492 void LineContinuationTest::getShaderSourceConfig(GLuint& out_n_parts, bool& out_use_lengths)
2493 {
2494 	out_n_parts		= (true == isShaderMultipart()) ? 2 : 1;
2495 	out_use_lengths = useSourceLengths();
2496 }
2497 
2498 /** Set up next test case
2499  *
2500  * @param test_case_index Index of next test case
2501  *
2502  * @return false if there is no more test cases, true otherwise
2503  **/
prepareNextTestCase(glw::GLuint test_case_index)2504 bool LineContinuationTest::prepareNextTestCase(glw::GLuint test_case_index)
2505 {
2506 	static const testCase test_cases[] = { { ASSIGNMENT_BEFORE_OPERATOR, ONCE, UNIX },
2507 										   { ASSIGNMENT_BEFORE_OPERATOR, ONCE, DOS },
2508 										   { ASSIGNMENT_BEFORE_OPERATOR, MULTIPLE_TIMES, UNIX },
2509 										   { ASSIGNMENT_BEFORE_OPERATOR, MULTIPLE_TIMES, DOS },
2510 										   { ASSIGNMENT_AFTER_OPERATOR, ONCE, UNIX },
2511 										   { ASSIGNMENT_AFTER_OPERATOR, ONCE, DOS },
2512 										   { ASSIGNMENT_AFTER_OPERATOR, MULTIPLE_TIMES, UNIX },
2513 										   { ASSIGNMENT_AFTER_OPERATOR, MULTIPLE_TIMES, DOS },
2514 										   { VECTOR_VARIABLE_INITIALIZER, ONCE, UNIX },
2515 										   { VECTOR_VARIABLE_INITIALIZER, ONCE, DOS },
2516 										   { VECTOR_VARIABLE_INITIALIZER, MULTIPLE_TIMES, UNIX },
2517 										   { VECTOR_VARIABLE_INITIALIZER, MULTIPLE_TIMES, DOS },
2518 										   { TOKEN_INSIDE_FUNCTION_NAME, ONCE, UNIX },
2519 										   { TOKEN_INSIDE_FUNCTION_NAME, ONCE, DOS },
2520 										   { TOKEN_INSIDE_FUNCTION_NAME, MULTIPLE_TIMES, UNIX },
2521 										   { TOKEN_INSIDE_FUNCTION_NAME, MULTIPLE_TIMES, DOS },
2522 										   { TOKEN_INSIDE_TYPE_NAME, ONCE, UNIX },
2523 										   { TOKEN_INSIDE_TYPE_NAME, ONCE, DOS },
2524 										   { TOKEN_INSIDE_TYPE_NAME, MULTIPLE_TIMES, UNIX },
2525 										   { TOKEN_INSIDE_TYPE_NAME, MULTIPLE_TIMES, DOS },
2526 										   { TOKEN_INSIDE_VARIABLE_NAME, ONCE, UNIX },
2527 										   { TOKEN_INSIDE_VARIABLE_NAME, ONCE, DOS },
2528 										   { TOKEN_INSIDE_VARIABLE_NAME, MULTIPLE_TIMES, UNIX },
2529 										   { TOKEN_INSIDE_VARIABLE_NAME, MULTIPLE_TIMES, DOS },
2530 										   { PREPROCESSOR_TOKEN_INSIDE, ONCE, UNIX },
2531 										   { PREPROCESSOR_TOKEN_INSIDE, ONCE, DOS },
2532 										   { PREPROCESSOR_TOKEN_INSIDE, MULTIPLE_TIMES, UNIX },
2533 										   { PREPROCESSOR_TOKEN_INSIDE, MULTIPLE_TIMES, DOS },
2534 										   { PREPROCESSOR_TOKEN_BETWEEN, ONCE, UNIX },
2535 										   { PREPROCESSOR_TOKEN_BETWEEN, ONCE, DOS },
2536 										   { PREPROCESSOR_TOKEN_BETWEEN, MULTIPLE_TIMES, UNIX },
2537 										   { PREPROCESSOR_TOKEN_BETWEEN, MULTIPLE_TIMES, DOS },
2538 										   { COMMENT, ONCE, UNIX },
2539 										   { COMMENT, ONCE, DOS },
2540 										   { COMMENT, MULTIPLE_TIMES, UNIX },
2541 										   { COMMENT, MULTIPLE_TIMES, DOS },
2542 										   { SOURCE_TERMINATION_NULL, ONCE, UNIX },
2543 										   { SOURCE_TERMINATION_NULL, ONCE, DOS },
2544 										   { SOURCE_TERMINATION_NULL, MULTIPLE_TIMES, UNIX },
2545 										   { SOURCE_TERMINATION_NULL, MULTIPLE_TIMES, DOS },
2546 										   { SOURCE_TERMINATION_NON_NULL, ONCE, UNIX },
2547 										   { SOURCE_TERMINATION_NON_NULL, ONCE, DOS },
2548 										   { SOURCE_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX },
2549 										   { SOURCE_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS },
2550 										   { PART_TERMINATION_NULL, ONCE, UNIX },
2551 										   { PART_TERMINATION_NULL, ONCE, DOS },
2552 										   { PART_TERMINATION_NULL, MULTIPLE_TIMES, UNIX },
2553 										   { PART_TERMINATION_NULL, MULTIPLE_TIMES, DOS },
2554 										   { PART_NEXT_TO_TERMINATION_NULL, ONCE, UNIX },
2555 										   { PART_NEXT_TO_TERMINATION_NULL, ONCE, DOS },
2556 										   { PART_NEXT_TO_TERMINATION_NULL, MULTIPLE_TIMES, UNIX },
2557 										   { PART_NEXT_TO_TERMINATION_NULL, MULTIPLE_TIMES, DOS },
2558 										   { PART_TERMINATION_NON_NULL, ONCE, UNIX },
2559 										   { PART_TERMINATION_NON_NULL, ONCE, DOS },
2560 										   { PART_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX },
2561 										   { PART_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS },
2562 										   { PART_NEXT_TO_TERMINATION_NON_NULL, ONCE, UNIX },
2563 										   { PART_NEXT_TO_TERMINATION_NON_NULL, ONCE, DOS },
2564 										   { PART_NEXT_TO_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX },
2565 										   { PART_NEXT_TO_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS } };
2566 
2567 	static const GLuint max_test_cases = sizeof(test_cases) / sizeof(testCase);
2568 
2569 	if ((GLuint)-1 == test_case_index)
2570 	{
2571 		m_test_case.m_case = DEBUG_CASE;
2572 	}
2573 	else if (max_test_cases <= test_case_index)
2574 	{
2575 		return false;
2576 	}
2577 	else
2578 	{
2579 		m_test_case = test_cases[test_case_index];
2580 	}
2581 
2582 	m_context.getTestContext().getLog() << tcu::TestLog::Message
2583 										<< "Test case: " << repetitionsToStr((REPETITIONS)m_test_case.m_repetitions)
2584 										<< " line continuation, with "
2585 										<< lineEndingsToStr((LINE_ENDINGS)m_test_case.m_line_endings)
2586 										<< " line endings, is placed " << casesToStr((CASES)m_test_case.m_case)
2587 										<< tcu::TestLog::EndMessage;
2588 
2589 	return true;
2590 }
2591 
2592 /** Prepare source for given shader stage
2593  *
2594  * @param in_stage           Shader stage, compute shader will use 430
2595  * @param in_use_version_400 Select if 400 or 420 should be used
2596  * @param out_source         Prepared shader source instance
2597  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)2598 void LineContinuationTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
2599 											   Utils::shaderSource& out_source)
2600 {
2601 	if (Utils::COMPUTE_SHADER == in_stage)
2602 	{
2603 		prepareComputShaderSource(out_source);
2604 	}
2605 	else
2606 	{
2607 		prepareShaderSourceForDraw(in_stage, in_use_version_400, out_source);
2608 	}
2609 }
2610 
2611 /** Prepare compute shader source
2612  *
2613  * @param source Result shader source
2614  **/
prepareComputShaderSource(Utils::shaderSource & source)2615 void LineContinuationTest::prepareComputShaderSource(Utils::shaderSource& source)
2616 {
2617 	static const GLchar* shader_template_part_0 =
2618 		"#version 430\n"
2619 		"\n"
2620 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2621 		"\n"
2622 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
2623 		"\n"
2624 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2625 		"\n"
2626 		"writeonly uniform image2D   uni_image;\n"
2627 		"          uniform sampler2D uni_sampler;\n"
2628 		"\n"
2629 		"void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2630 		"{\n"
2631 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), inVARIABLE_CASE_value);\n"
2632 		"}\n"
2633 		"\n"
2634 		"#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2635 		"PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2636 		"NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2637 
2638 	static const GLchar* shader_template_part_1 =
2639 		"void main()\n"
2640 		"{\n"
2641 		"    ivec2 coordinates   ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE "
2642 		"ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
2643 		"    vec4 sampled_color = texelFetch(uni_sampler, coordinates, 0 /* lod */);\n"
2644 		"    vec4 result        = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2645 		"\n"
2646 		"    if (vec4(0, 0, 1, 1) == sampled_color)\n"
2647 		"    {\n"
2648 		"        result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2649 		"    }\n"
2650 		"    else\n"
2651 		"    {\n"
2652 		"        result = vec4(coordinates.xy, sampled_color.rg);\n"
2653 		"    }\n"
2654 		"\n"
2655 		"    SET_RESULT(result);"
2656 		"}\n";
2657 
2658 	/* Init strings with templates and replace all CASE tokens */
2659 	if (true == isShaderMultipart())
2660 	{
2661 		source.m_parts[0].m_code = shader_template_part_0;
2662 		source.m_parts[1].m_code = shader_template_part_1;
2663 
2664 		replaceAllCaseTokens(source.m_parts[0].m_code);
2665 		replaceAllCaseTokens(source.m_parts[1].m_code);
2666 	}
2667 	else
2668 	{
2669 		source.m_parts[0].m_code = shader_template_part_0;
2670 		source.m_parts[0].m_code.append(shader_template_part_1);
2671 
2672 		replaceAllCaseTokens(source.m_parts[0].m_code);
2673 	}
2674 }
2675 
2676 /** Prepare source for given shader stage
2677  *
2678  * @param stage           Shader stage, compute shader will use 430
2679  * @param use_version_400 Select if 400 or 420 should be used
2680  * @param source          Result shader sources
2681  **/
prepareShaderSourceForDraw(Utils::SHADER_STAGES stage,bool use_version_400,Utils::shaderSource & source)2682 void LineContinuationTest::prepareShaderSourceForDraw(Utils::SHADER_STAGES stage, bool use_version_400,
2683 													  Utils::shaderSource& source)
2684 {
2685 	/* Templates */
2686 	static const GLchar* shader_template_part_0 =
2687 		"VERSION\n"
2688 		"\n"
2689 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2690 		"\n"
2691 		"STAGE_SPECIFIC\n"
2692 		"\n"
2693 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2694 		"\n"
2695 		"IN_COLOR_DEFINITION\n"
2696 		"IN_TEXTURE_COORDINATES_DEFINITION\n"
2697 		"OUT_COLOR_DEFINITION\n"
2698 		"OUT_TEXTURE_COORDINATES_DEFINITION\n"
2699 		"uniform sampler2D uni_sampler;\n"
2700 		"\n"
2701 		"void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2702 		"{\n"
2703 		"    OUT_COLOR ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE inVARIABLE_CASE_value;\n"
2704 		"}\n"
2705 		"\n"
2706 		"#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2707 		"PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2708 		"NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2709 
2710 	static const GLchar* shader_template_part_1 =
2711 		"void main()\n"
2712 		"{\n"
2713 		"    vec2 coordinates   = TEXTURE_COORDINATES;\n"
2714 		"    vec4 sampled_color = texture(uni_sampler, coordinates);\n"
2715 		"    vec4 result        = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2716 		"\n"
2717 		"    if (PASS_CONDITION)\n"
2718 		"    {\n"
2719 		"        result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2720 		"    }\n"
2721 		"    else\n"
2722 		"    {\n"
2723 		"        result = vec4(coordinates.xy, sampled_color.rg);\n"
2724 		"    }\n"
2725 		"\n"
2726 		"STORE_RESULTS"
2727 		"}\n"
2728 		"NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2729 
2730 	static const GLchar* store_results_template = "    SET_RESULT(result);\n"
2731 												  "    TEXTURE_COORDINATES = coordinates;\n";
2732 
2733 	static const GLchar* store_results_tcs_template = "    SET_RESULT(result);\n"
2734 													  "    TEXTURE_COORDINATES = coordinates;\n"
2735 													  "    gl_TessLevelOuter[0] = 1.0;\n"
2736 													  "    gl_TessLevelOuter[1] = 1.0;\n"
2737 													  "    gl_TessLevelOuter[2] = 1.0;\n"
2738 													  "    gl_TessLevelOuter[3] = 1.0;\n"
2739 													  "    gl_TessLevelInner[0] = 1.0;\n"
2740 													  "    gl_TessLevelInner[1] = 1.0;\n";
2741 
2742 	static const GLchar* store_results_fs_template = "    SET_RESULT(result);\n";
2743 
2744 	static const GLchar* store_results_gs_template = "    gl_Position = vec4(-1, -1, 0, 1);\n"
2745 													 "    SET_RESULT(result);\n"
2746 													 "    TEXTURE_COORDINATES = coordinates + vec2(-0.25, -0.25);\n"
2747 													 "    EmitVertex();\n"
2748 													 "    gl_Position = vec4(-1, 1, 0, 1);\n"
2749 													 "    SET_RESULT(result);\n"
2750 													 "    TEXTURE_COORDINATES = coordinates + vec2(-0.25, 0.25);\n"
2751 													 "    EmitVertex();\n"
2752 													 "    gl_Position = vec4(1, -1, 0, 1);\n"
2753 													 "    SET_RESULT(result);\n"
2754 													 "    TEXTURE_COORDINATES = coordinates + vec2(0.25, -0.25);\n"
2755 													 "    EmitVertex();\n"
2756 													 "    gl_Position = vec4(1, 1, 0, 1);\n"
2757 													 "    SET_RESULT(result);\n"
2758 													 "    TEXTURE_COORDINATES = coordinates + vec2(0.25, 0.25);\n"
2759 													 "    EmitVertex();\n";
2760 
2761 	static const GLchar* pass_condition_template = "(EXPECTED_VALUE == sampled_color) &&\n"
2762 												   "        (vec4(0, 1, 0, 1) == IN_COLOR) ";
2763 
2764 	static const GLchar* pass_condition_vs_template = "EXPECTED_VALUE == sampled_color";
2765 
2766 	/* Tokens to be replaced with GLSL stuff */
2767 	static const GLchar* token_version		  = "VERSION";
2768 	static const GLchar* token_stage_specific = "STAGE_SPECIFIC";
2769 
2770 	static const GLchar* token_in_color_definition		= "IN_COLOR_DEFINITION";
2771 	static const GLchar* token_in_tex_coord_definition  = "IN_TEXTURE_COORDINATES_DEFINITION";
2772 	static const GLchar* token_out_color_definition		= "OUT_COLOR_DEFINITION";
2773 	static const GLchar* token_out_tex_coord_definition = "OUT_TEXTURE_COORDINATES_DEFINITION";
2774 
2775 	static const GLchar* token_expected_value	  = "EXPECTED_VALUE";
2776 	static const GLchar* token_texture_coordinates = "TEXTURE_COORDINATES";
2777 	static const GLchar* token_in_color			   = "IN_COLOR";
2778 	static const GLchar* token_out_color		   = "OUT_COLOR";
2779 
2780 	static const GLchar* token_store_results  = "STORE_RESULTS";
2781 	static const GLchar* token_pass_condition = "PASS_CONDITION";
2782 
2783 	/* Name of variable and empty string*/
2784 	static const GLchar* color_name = "color";
2785 	static const GLchar* empty		= "";
2786 
2787 	/* GLSL stuff */
2788 	const GLchar* version				= getVersionString(stage, use_version_400);
2789 	const GLchar* stage_specific_layout = getStageSpecificLayout(stage);
2790 	const GLchar* expected_value		= getExpectedValueString();
2791 
2792 	/* Qualifiers */
2793 	Utils::qualifierSet in;
2794 	Utils::qualifierSet out;
2795 	in.push_back(Utils::QUAL_IN);
2796 	out.push_back(Utils::QUAL_OUT);
2797 
2798 	/* In/Out variables definitions and references */
2799 	std::string in_tex_coord_reference;
2800 	std::string out_tex_coord_reference;
2801 	std::string in_color_reference;
2802 	std::string out_color_reference;
2803 	std::string in_tex_coord_definition;
2804 	std::string out_tex_coord_definition;
2805 	std::string in_color_definition;
2806 	std::string out_color_definition;
2807 
2808 	Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec2", m_texture_coordinates_name, in_tex_coord_definition,
2809 								  in_tex_coord_reference);
2810 	Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec2", m_texture_coordinates_name,
2811 								  out_tex_coord_definition, out_tex_coord_reference);
2812 	Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec4", color_name, in_color_definition, in_color_reference);
2813 	Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec4", color_name, out_color_definition,
2814 								  out_color_reference);
2815 
2816 	in_tex_coord_definition.append(";");
2817 	out_tex_coord_definition.append(";");
2818 	in_color_definition.append(";");
2819 	out_color_definition.append(";");
2820 
2821 	/* Select pass condition and store results tempaltes */
2822 	const GLchar* store_results  = store_results_template;
2823 	const GLchar* pass_condition = pass_condition_template;
2824 
2825 	switch (stage)
2826 	{
2827 	case Utils::FRAGMENT_SHADER:
2828 		store_results = store_results_fs_template;
2829 		break;
2830 	case Utils::GEOMETRY_SHADER:
2831 		store_results = store_results_gs_template;
2832 		break;
2833 	case Utils::TESS_CTRL_SHADER:
2834 		store_results = store_results_tcs_template;
2835 		break;
2836 	case Utils::VERTEX_SHADER:
2837 		pass_condition = pass_condition_vs_template;
2838 		break;
2839 	default:
2840 		break;
2841 	};
2842 	const GLuint store_results_length  = static_cast<GLuint>(strlen(store_results));
2843 	const GLuint pass_condition_length = static_cast<GLuint>(strlen(pass_condition));
2844 
2845 	/* Init strings with templates and replace all CASE tokens */
2846 	if (true == isShaderMultipart())
2847 	{
2848 		source.m_parts[0].m_code = shader_template_part_0;
2849 		source.m_parts[1].m_code = shader_template_part_1;
2850 
2851 		replaceAllCaseTokens(source.m_parts[0].m_code);
2852 		replaceAllCaseTokens(source.m_parts[1].m_code);
2853 	}
2854 	else
2855 	{
2856 		source.m_parts[0].m_code = shader_template_part_0;
2857 		source.m_parts[0].m_code.append(shader_template_part_1);
2858 
2859 		replaceAllCaseTokens(source.m_parts[0].m_code);
2860 	}
2861 
2862 	/* Get memory for shader source parts */
2863 	const bool   is_multipart		  = isShaderMultipart();
2864 	size_t		 position			  = 0;
2865 	std::string& shader_source_part_0 = source.m_parts[0].m_code;
2866 	std::string& shader_source_part_1 = (true == is_multipart) ? source.m_parts[1].m_code : source.m_parts[0].m_code;
2867 
2868 	/* Replace tokens */
2869 	/* Part 0 */
2870 	Utils::replaceToken(token_version, position, version, shader_source_part_0);
2871 
2872 	Utils::replaceToken(token_stage_specific, position, stage_specific_layout, shader_source_part_0);
2873 
2874 	if (Utils::VERTEX_SHADER != stage)
2875 	{
2876 		Utils::replaceToken(token_in_color_definition, position, in_color_definition.c_str(), shader_source_part_0);
2877 	}
2878 	else
2879 	{
2880 		Utils::replaceToken(token_in_color_definition, position, empty, shader_source_part_0);
2881 	}
2882 	Utils::replaceToken(token_in_tex_coord_definition, position, in_tex_coord_definition.c_str(), shader_source_part_0);
2883 	Utils::replaceToken(token_out_color_definition, position, out_color_definition.c_str(), shader_source_part_0);
2884 	if (Utils::FRAGMENT_SHADER == stage)
2885 	{
2886 		Utils::replaceToken(token_out_tex_coord_definition, position, empty, shader_source_part_0);
2887 	}
2888 	else
2889 	{
2890 		Utils::replaceToken(token_out_tex_coord_definition, position, out_tex_coord_definition.c_str(),
2891 							shader_source_part_0);
2892 	}
2893 
2894 	Utils::replaceToken(token_out_color, position, out_color_reference.c_str(), shader_source_part_0);
2895 
2896 	/* Part 1 */
2897 	if (true == is_multipart)
2898 	{
2899 		position = 0;
2900 	}
2901 
2902 	Utils::replaceToken(token_texture_coordinates, position, in_tex_coord_reference.c_str(), shader_source_part_1);
2903 
2904 	Utils::replaceToken(token_pass_condition, position, pass_condition, shader_source_part_1);
2905 	position -= pass_condition_length;
2906 
2907 	Utils::replaceToken(token_expected_value, position, expected_value, shader_source_part_1);
2908 	if (Utils::VERTEX_SHADER != stage)
2909 	{
2910 		Utils::replaceToken(token_in_color, position, in_color_reference.c_str(), shader_source_part_1);
2911 	}
2912 
2913 	Utils::replaceToken(token_store_results, position, store_results, shader_source_part_1);
2914 	position -= store_results_length;
2915 
2916 	if (Utils::GEOMETRY_SHADER == stage)
2917 	{
2918 		for (GLuint i = 0; i < 4; ++i)
2919 		{
2920 			Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(),
2921 								shader_source_part_1);
2922 		}
2923 	}
2924 	else if (Utils::FRAGMENT_SHADER == stage)
2925 	{
2926 		/* Nothing to be done */
2927 	}
2928 	else
2929 	{
2930 		Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(), shader_source_part_1);
2931 	}
2932 }
2933 
2934 /** Prepare texture
2935  *
2936  * @param texture Texutre to be created and filled with content
2937  *
2938  * @return Name of sampler uniform that should be used for the texture
2939  **/
prepareSourceTexture(Utils::texture & texture)2940 const GLchar* LineContinuationTest::prepareSourceTexture(Utils::texture& texture)
2941 {
2942 	std::vector<GLuint> data;
2943 	static const GLuint width	  = 64;
2944 	static const GLuint height	 = 64;
2945 	static const GLuint data_size  = width * height;
2946 	static const GLuint blue_color = 0xffff0000;
2947 	static const GLuint grey_color = 0xaaaaaaaa;
2948 
2949 	data.resize(data_size);
2950 
2951 	for (GLuint i = 0; i < data_size; ++i)
2952 	{
2953 		data[i] = grey_color;
2954 	}
2955 
2956 	for (GLuint y = 16; y < 48; ++y)
2957 	{
2958 		const GLuint line_offset = y * 64;
2959 
2960 		for (GLuint x = 16; x < 48; ++x)
2961 		{
2962 			const GLuint pixel_offset = x + line_offset;
2963 
2964 			data[pixel_offset] = blue_color;
2965 		}
2966 	}
2967 
2968 	texture.create(width, height, GL_RGBA8);
2969 
2970 	texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
2971 
2972 	return "uni_sampler";
2973 }
2974 
2975 /** Prepare vertex buffer, vec2 tex_coord
2976  *
2977  * @param program Program object
2978  * @param buffer  Vertex buffer
2979  * @param vao     Vertex array object
2980  **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)2981 void LineContinuationTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
2982 											   Utils::vertexArray& vao)
2983 {
2984 	std::string tex_coord_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, m_texture_coordinates_name);
2985 	GLint		tex_coord_loc  = program.getAttribLocation(tex_coord_name.c_str());
2986 
2987 	if (-1 == tex_coord_loc)
2988 	{
2989 		TCU_FAIL("Vertex attribute location is invalid");
2990 	}
2991 
2992 	vao.generate();
2993 	vao.bind();
2994 
2995 	buffer.generate(GL_ARRAY_BUFFER);
2996 
2997 	GLfloat	data[]	= { 0.5f, 0.5f, 0.5f, 0.5f };
2998 	GLsizeiptr data_size = sizeof(data);
2999 
3000 	buffer.update(data_size, data, GL_STATIC_DRAW);
3001 
3002 	/* GL entry points */
3003 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3004 
3005 	/* Set up vao */
3006 	gl.vertexAttribPointer(tex_coord_loc, 2 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
3007 						   0 /* offset */);
3008 	GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3009 
3010 	/* Enable attribute */
3011 	gl.enableVertexAttribArray(tex_coord_loc);
3012 	GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3013 }
3014 
3015 /** Get string describing test cases
3016  *
3017  * @param cases Test case
3018  *
3019  * @return String describing current test case
3020  **/
casesToStr(CASES cases) const3021 const GLchar* LineContinuationTest::casesToStr(CASES cases) const
3022 {
3023 	const GLchar* result = 0;
3024 	switch (cases)
3025 	{
3026 	case ASSIGNMENT_BEFORE_OPERATOR:
3027 		result = "just before assignment operator";
3028 		break;
3029 	case ASSIGNMENT_AFTER_OPERATOR:
3030 		result = "just after assignment operator";
3031 		break;
3032 	case VECTOR_VARIABLE_INITIALIZER:
3033 		result = "inside vector variable initializer";
3034 		break;
3035 	case TOKEN_INSIDE_FUNCTION_NAME:
3036 		result = "inside function name";
3037 		break;
3038 	case TOKEN_INSIDE_TYPE_NAME:
3039 		result = "inside type name";
3040 		break;
3041 	case TOKEN_INSIDE_VARIABLE_NAME:
3042 		result = "inside variable name";
3043 		break;
3044 	case PREPROCESSOR_TOKEN_INSIDE:
3045 		result = "inside preprocessor token";
3046 		break;
3047 	case PREPROCESSOR_TOKEN_BETWEEN:
3048 		result = "between preprocessor token";
3049 		break;
3050 	case COMMENT:
3051 		result = "inside comment";
3052 		break;
3053 	case SOURCE_TERMINATION_NULL:
3054 		result = "just before null terminating source";
3055 		break;
3056 	case SOURCE_TERMINATION_NON_NULL:
3057 		result = "as last character in source string, without null termination";
3058 		break;
3059 	case PART_TERMINATION_NULL:
3060 		result = "just before null terminating part of source";
3061 		break;
3062 	case PART_NEXT_TO_TERMINATION_NULL:
3063 		result = "just before last character in part of source";
3064 		break;
3065 	case PART_TERMINATION_NON_NULL:
3066 		result = "as last character in part string, without null termination";
3067 		break;
3068 	case PART_NEXT_TO_TERMINATION_NON_NULL:
3069 		result = "just before last character in part string, without null termination";
3070 		break;
3071 	case DEBUG_CASE: /* intended fall through */
3072 	default:
3073 		result = "nowhere at all. This is debug!";
3074 		break;
3075 	}
3076 
3077 	return result;
3078 }
3079 
3080 /** Get expected value, blue color as vec4
3081  *
3082  * @return blue color
3083  **/
getExpectedValueString() const3084 const GLchar* LineContinuationTest::getExpectedValueString() const
3085 {
3086 	return "vec4(0, 0, 1, 1)";
3087 }
3088 
3089 /** Get line continuation string, single or multiple \
3090          *
3091  * @return String
3092  **/
getLineContinuationString() const3093 std::string LineContinuationTest::getLineContinuationString() const
3094 {
3095 	static const GLchar line_continuation_ending_dos[]  = { '\\', 0x0d, 0x0a, 0x00 };
3096 	static const GLchar line_continuation_ending_unix[] = { '\\', 0x0a, 0x00 };
3097 
3098 	std::string   result;
3099 	const GLchar* selected_string;
3100 
3101 	if (DOS == m_test_case.m_line_endings)
3102 	{
3103 		selected_string = line_continuation_ending_dos;
3104 	}
3105 	else
3106 	{
3107 		selected_string = line_continuation_ending_unix;
3108 	}
3109 
3110 	GLuint n_repetitions = (ONCE == m_test_case.m_repetitions) ? 1 : m_n_repetitions;
3111 
3112 	for (GLuint i = 0; i < n_repetitions; ++i)
3113 	{
3114 		result.append(selected_string);
3115 	}
3116 
3117 	return result;
3118 }
3119 
3120 /** Decides if shader should consist of multiple parts for the current test case
3121  *
3122  * @return true if test case requires multiple parts, false otherwise
3123  **/
isShaderMultipart() const3124 bool LineContinuationTest::isShaderMultipart() const
3125 {
3126 	bool result;
3127 
3128 	switch (m_test_case.m_case)
3129 	{
3130 	case ASSIGNMENT_BEFORE_OPERATOR:
3131 	case ASSIGNMENT_AFTER_OPERATOR:
3132 	case VECTOR_VARIABLE_INITIALIZER:
3133 	case TOKEN_INSIDE_FUNCTION_NAME:
3134 	case TOKEN_INSIDE_TYPE_NAME:
3135 	case TOKEN_INSIDE_VARIABLE_NAME:
3136 	case PREPROCESSOR_TOKEN_INSIDE:
3137 	case PREPROCESSOR_TOKEN_BETWEEN:
3138 	case COMMENT:
3139 	case SOURCE_TERMINATION_NULL:
3140 	case SOURCE_TERMINATION_NON_NULL:
3141 	default:
3142 		result = false;
3143 		break;
3144 	case PART_TERMINATION_NULL:
3145 	case PART_NEXT_TO_TERMINATION_NULL:
3146 	case PART_TERMINATION_NON_NULL:
3147 	case PART_NEXT_TO_TERMINATION_NON_NULL:
3148 		result = true;
3149 		break;
3150 	};
3151 
3152 	return result;
3153 }
3154 
3155 /** String describing line endings
3156  *
3157  * @param line_ending Line ending enum
3158  *
3159  * @return "unix" or "dos" strings
3160  **/
lineEndingsToStr(LINE_ENDINGS line_ending) const3161 const GLchar* LineContinuationTest::lineEndingsToStr(LINE_ENDINGS line_ending) const
3162 {
3163 	const GLchar* result = 0;
3164 
3165 	if (UNIX == line_ending)
3166 	{
3167 		result = "unix";
3168 	}
3169 	else
3170 	{
3171 		result = "dos";
3172 	}
3173 
3174 	return result;
3175 }
3176 
3177 /** String describing number of repetitions
3178  *
3179  * @param repetitions Repetitions enum
3180  *
3181  * @return "single" or "multiple" strings
3182  **/
repetitionsToStr(REPETITIONS repetitions) const3183 const GLchar* LineContinuationTest::repetitionsToStr(REPETITIONS repetitions) const
3184 {
3185 	const GLchar* result = 0;
3186 
3187 	if (ONCE == repetitions)
3188 	{
3189 		result = "single";
3190 	}
3191 	else
3192 	{
3193 		result = "multiple";
3194 	}
3195 
3196 	return result;
3197 }
3198 
3199 /** Replace all CASES tokens
3200  *
3201  * @param source String with shader template
3202  **/
replaceAllCaseTokens(std::string & source) const3203 void LineContinuationTest::replaceAllCaseTokens(std::string& source) const
3204 {
3205 
3206 	/* Tokens to be replaced with line continuation */
3207 	static const GLchar* token_assignment_before_operator_case = "ASSIGNMENT_BEFORE_OPERATOR_CASE";
3208 	static const GLchar* token_assignment_after_operator_case  = "ASSIGNMENT_AFTER_OPERATOR_CASE";
3209 	static const GLchar* token_vector_initializer			   = "VECTOR_VARIABLE_INITIALIZER_CASE";
3210 	static const GLchar* token_function_case				   = "FUNCTION_CASE";
3211 	static const GLchar* token_type_case					   = "TYPE_CASE";
3212 	static const GLchar* token_variable_case				   = "VARIABLE_CASE";
3213 	static const GLchar* token_preprocessor_inside_case		   = "PREPROCESSOR_INSIDE_CASE";
3214 	static const GLchar* token_preprocessor_between_case	   = "PREPROCESSOR_BETWEEN_CASE";
3215 	static const GLchar* token_comment						   = "COMMENT_CASE";
3216 	static const GLchar* token_termination					   = "TERMINATION_CASE";
3217 	static const GLchar* token_next_to_termination			   = "NEXT_TO_TERMINATION_CASE";
3218 
3219 	/* Line continuation and empty string*/
3220 	static const GLchar* empty			   = "";
3221 	const std::string&   line_continuation = getLineContinuationString();
3222 
3223 	/* These strings will used to replace "CASE" tokens */
3224 	const GLchar* assignment_before_operator_case  = empty;
3225 	const GLchar* assignment_after_operator_case   = empty;
3226 	const GLchar* vector_variable_initializer_case = empty;
3227 	const GLchar* function_case					   = empty;
3228 	const GLchar* type_case						   = empty;
3229 	const GLchar* variable_case					   = empty;
3230 	const GLchar* preprocessor_inside_case		   = empty;
3231 	const GLchar* preprocessor_between_case		   = empty;
3232 	const GLchar* comment_case					   = empty;
3233 	const GLchar* source_termination_case		   = empty;
3234 	const GLchar* part_termination_case			   = empty;
3235 	const GLchar* next_to_part_termination_case	= empty;
3236 
3237 	/* Configuration of test case */
3238 	switch (m_test_case.m_case)
3239 	{
3240 	case ASSIGNMENT_BEFORE_OPERATOR:
3241 		assignment_before_operator_case = line_continuation.c_str();
3242 		break;
3243 	case ASSIGNMENT_AFTER_OPERATOR:
3244 		assignment_after_operator_case = line_continuation.c_str();
3245 		break;
3246 	case VECTOR_VARIABLE_INITIALIZER:
3247 		vector_variable_initializer_case = line_continuation.c_str();
3248 		break;
3249 	case TOKEN_INSIDE_FUNCTION_NAME:
3250 		function_case = line_continuation.c_str();
3251 		break;
3252 	case TOKEN_INSIDE_TYPE_NAME:
3253 		type_case = line_continuation.c_str();
3254 		break;
3255 	case TOKEN_INSIDE_VARIABLE_NAME:
3256 		variable_case = line_continuation.c_str();
3257 		break;
3258 	case PREPROCESSOR_TOKEN_INSIDE:
3259 		preprocessor_inside_case = line_continuation.c_str();
3260 		break;
3261 	case PREPROCESSOR_TOKEN_BETWEEN:
3262 		preprocessor_between_case = line_continuation.c_str();
3263 		break;
3264 	case COMMENT:
3265 		comment_case = line_continuation.c_str();
3266 		break;
3267 	case SOURCE_TERMINATION_NULL: /* intended fall through */
3268 	case SOURCE_TERMINATION_NON_NULL:
3269 		source_termination_case = line_continuation.c_str();
3270 		break;
3271 	case PART_TERMINATION_NULL: /* intended fall through */
3272 	case PART_TERMINATION_NON_NULL:
3273 		part_termination_case   = line_continuation.c_str();
3274 		source_termination_case = line_continuation.c_str();
3275 		break;
3276 	case PART_NEXT_TO_TERMINATION_NULL: /* intended fall through */
3277 	case PART_NEXT_TO_TERMINATION_NON_NULL:
3278 		next_to_part_termination_case = line_continuation.c_str();
3279 		break;
3280 	case DEBUG_CASE: /* intended fall through */
3281 	default:
3282 		break; /* no line continuations */
3283 	};
3284 
3285 	Utils::replaceAllTokens(token_assignment_after_operator_case, assignment_after_operator_case, source);
3286 	Utils::replaceAllTokens(token_assignment_before_operator_case, assignment_before_operator_case, source);
3287 	Utils::replaceAllTokens(token_comment, comment_case, source);
3288 	Utils::replaceAllTokens(token_function_case, function_case, source);
3289 	Utils::replaceAllTokens(token_next_to_termination, next_to_part_termination_case, source);
3290 	Utils::replaceAllTokens(token_termination, part_termination_case, source);
3291 	Utils::replaceAllTokens(token_preprocessor_between_case, preprocessor_between_case, source);
3292 	Utils::replaceAllTokens(token_preprocessor_inside_case, preprocessor_inside_case, source);
3293 	Utils::replaceAllTokens(token_termination, source_termination_case, source);
3294 	Utils::replaceAllTokens(token_type_case, type_case, source);
3295 	Utils::replaceAllTokens(token_variable_case, variable_case, source);
3296 	Utils::replaceAllTokens(token_vector_initializer, vector_variable_initializer_case, source);
3297 }
3298 
3299 /** Decides if the current test case requires source lengths
3300  *
3301  * @return true if test requires lengths, false otherwise
3302  **/
useSourceLengths() const3303 bool LineContinuationTest::useSourceLengths() const
3304 {
3305 	bool result;
3306 
3307 	switch (m_test_case.m_case)
3308 	{
3309 	case ASSIGNMENT_BEFORE_OPERATOR:
3310 	case ASSIGNMENT_AFTER_OPERATOR:
3311 	case VECTOR_VARIABLE_INITIALIZER:
3312 	case TOKEN_INSIDE_FUNCTION_NAME:
3313 	case TOKEN_INSIDE_TYPE_NAME:
3314 	case TOKEN_INSIDE_VARIABLE_NAME:
3315 	case PREPROCESSOR_TOKEN_INSIDE:
3316 	case PREPROCESSOR_TOKEN_BETWEEN:
3317 	case COMMENT:
3318 	case SOURCE_TERMINATION_NULL:
3319 	case PART_TERMINATION_NULL:
3320 	case PART_NEXT_TO_TERMINATION_NULL:
3321 	default:
3322 		result = false;
3323 		break;
3324 	case SOURCE_TERMINATION_NON_NULL:
3325 	case PART_TERMINATION_NON_NULL:
3326 	case PART_NEXT_TO_TERMINATION_NON_NULL:
3327 		result = true;
3328 		break;
3329 	};
3330 
3331 	return result;
3332 }
3333 
3334 /** Constructor
3335  *
3336  * @param context Test context
3337  **/
LineNumberingTest(deqp::Context & context)3338 LineNumberingTest::LineNumberingTest(deqp::Context& context)
3339 	: GLSLTestBase(context, "line_numbering", "Verify if line numbering is correct after line continuation")
3340 {
3341 	/* Nothing to be done here */
3342 }
3343 
3344 /** Prepare source for given shader stage
3345  *
3346  * @param in_stage           Shader stage, compute shader will use 430
3347  * @param in_use_version_400 Select if 400 or 420 should be used
3348  * @param out_source         Prepared shader source instance
3349  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3350 void LineNumberingTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3351 											Utils::shaderSource& out_source)
3352 {
3353 	static const GLchar* test_result_snippet_normal[6] = { /* Utils::COMPUTE_SHADER */
3354 														   "ivec4(11, 1, 2, 3)",
3355 														   /* Utils::VERTEX_SHADER */
3356 														   "ivec4(9, 1, 2, 3)",
3357 														   /* Utils::TESS_CTRL_SHADER */
3358 														   "ivec4(12, 1, 2, 3)",
3359 														   /* Utils::TESS_EVAL_SHADER */
3360 														   "ivec4(12, 1, 2, 3)",
3361 														   /* Utils::GEOMETRY_SHADER */
3362 														   "ivec4(13, 1, 2, 3)",
3363 														   /* Utils::FRAGMENT_SHADER */
3364 														   "ivec4(10, 1, 2, 3)"
3365 	};
3366 
3367 	static const GLchar* test_result_snippet_400[6] = { /* Utils::COMPUTE_SHADER */
3368 														"ivec4(13, 1, 2, 3)",
3369 														/* Utils::VERTEX_SHADER */
3370 														"ivec4(11, 1, 2, 3)",
3371 														/* Utils::TESS_CTRL_SHADER */
3372 														"ivec4(14, 1, 2, 3)",
3373 														/* Utils::TESS_EVAL_SHADER */
3374 														"ivec4(14, 1, 2, 3)",
3375 														/* Utils::GEOMETRY_SHADER */
3376 														"ivec4(15, 1, 2, 3)",
3377 														/* Utils::FRAGMENT_SHADER */
3378 														"ivec4(12, 1, 2, 3)"
3379 	};
3380 
3381 	static const GLchar* line_numbering_snippet = "ivec4 glsl\\\n"
3382 												  "Test\\\n"
3383 												  "Function(in ivec3 arg)\n"
3384 												  "{\n"
3385 												  "    return ivec4(__LINE__, arg.xyz);\n"
3386 												  "}\n";
3387 
3388 	static const GLchar* compute_shader_template =
3389 		"VERSION\n"
3390 		"\n"
3391 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3392 		"\n"
3393 		"writeonly uniform image2D uni_image;\n"
3394 		"\n"
3395 		"GLSL_TEST_FUNCTION"
3396 		"\n"
3397 		"void main()\n"
3398 		"{\n"
3399 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3400 		"\n"
3401 		"    if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3402 		"    {\n"
3403 		"        result = vec4(0, 1, 0, 1);\n"
3404 		"    }\n"
3405 		"\n"
3406 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3407 		"}\n"
3408 		"\n";
3409 
3410 	static const GLchar* fragment_shader_template =
3411 		"VERSION\n"
3412 		"\n"
3413 		"in  vec4 gs_fs_result;\n"
3414 		"out vec4 fs_out_result;\n"
3415 		"\n"
3416 		"GLSL_TEST_FUNCTION"
3417 		"\n"
3418 		"void main()\n"
3419 		"{\n"
3420 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3421 		"\n"
3422 		"    if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3423 		"        (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3424 		"    {\n"
3425 		"         result = vec4(0, 1, 0, 1);\n"
3426 		"    }\n"
3427 		"\n"
3428 		"    fs_out_result = result;\n"
3429 		"}\n"
3430 		"\n";
3431 
3432 	static const GLchar* geometry_shader_template =
3433 		"VERSION\n"
3434 		"\n"
3435 		"layout(points)                           in;\n"
3436 		"layout(triangle_strip, max_vertices = 4) out;\n"
3437 		"\n"
3438 		"in  vec4 tes_gs_result[];\n"
3439 		"out vec4 gs_fs_result;\n"
3440 		"\n"
3441 		"GLSL_TEST_FUNCTION"
3442 		"\n"
3443 		"void main()\n"
3444 		"{\n"
3445 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3446 		"\n"
3447 		"    if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3448 		"        (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3449 		"    {\n"
3450 		"         result = vec4(0, 1, 0, 1);\n"
3451 		"    }\n"
3452 		"\n"
3453 		"    gs_fs_result = result;\n"
3454 		"    gl_Position  = vec4(-1, -1, 0, 1);\n"
3455 		"    EmitVertex();\n"
3456 		"    gs_fs_result = result;\n"
3457 		"    gl_Position  = vec4(-1, 1, 0, 1);\n"
3458 		"    EmitVertex();\n"
3459 		"    gs_fs_result = result;\n"
3460 		"    gl_Position  = vec4(1, -1, 0, 1);\n"
3461 		"    EmitVertex();\n"
3462 		"    gs_fs_result = result;\n"
3463 		"    gl_Position  = vec4(1, 1, 0, 1);\n"
3464 		"    EmitVertex();\n"
3465 		"}\n"
3466 		"\n";
3467 
3468 	static const GLchar* tess_ctrl_shader_template =
3469 		"VERSION\n"
3470 		"\n"
3471 		"layout(vertices = 1) out;\n"
3472 		"\n"
3473 		"in  vec4 vs_tcs_result[];\n"
3474 		"out vec4 tcs_tes_result[];\n"
3475 		"\n"
3476 		"GLSL_TEST_FUNCTION"
3477 		"\n"
3478 		"void main()\n"
3479 		"{\n"
3480 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3481 		"\n"
3482 		"    if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3483 		"        (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3484 		"    {\n"
3485 		"         result = vec4(0, 1, 0, 1);\n"
3486 		"    }\n"
3487 		"\n"
3488 		"    tcs_tes_result[gl_InvocationID] = result;\n"
3489 		"\n"
3490 		"    gl_TessLevelOuter[0] = 1.0;\n"
3491 		"    gl_TessLevelOuter[1] = 1.0;\n"
3492 		"    gl_TessLevelOuter[2] = 1.0;\n"
3493 		"    gl_TessLevelOuter[3] = 1.0;\n"
3494 		"    gl_TessLevelInner[0] = 1.0;\n"
3495 		"    gl_TessLevelInner[1] = 1.0;\n"
3496 		"}\n"
3497 		"\n";
3498 
3499 	static const GLchar* tess_eval_shader_template =
3500 		"VERSION\n"
3501 		"\n"
3502 		"layout(isolines, point_mode) in;\n"
3503 		"\n"
3504 		"in  vec4 tcs_tes_result[];\n"
3505 		"out vec4 tes_gs_result;\n"
3506 		"\n"
3507 		"GLSL_TEST_FUNCTION"
3508 		"\n"
3509 		"void main()\n"
3510 		"{\n"
3511 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3512 		"\n"
3513 		"    if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3514 		"        (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3515 		"    {\n"
3516 		"         result = vec4(0, 1, 0, 1);\n"
3517 		"    }\n"
3518 		"\n"
3519 		"    tes_gs_result = result;\n"
3520 		"}\n"
3521 		"\n";
3522 
3523 	static const GLchar* vertex_shader_template = "VERSION\n"
3524 												  "\n"
3525 												  "out vec4 vs_tcs_result;\n"
3526 												  "\n"
3527 												  "GLSL_TEST_FUNCTION"
3528 												  "\n"
3529 												  "void main()\n"
3530 												  "{\n"
3531 												  "    vec4 result = vec4(1, 0, 0, 1);\n"
3532 												  "\n"
3533 												  "    if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3534 												  "    {\n"
3535 												  "         result = vec4(0, 1, 0, 1);\n"
3536 												  "    }\n"
3537 												  "\n"
3538 												  "    vs_tcs_result = result;\n"
3539 												  "}\n"
3540 												  "\n";
3541 
3542 	const GLchar* shader_template = 0;
3543 
3544 	switch (in_stage)
3545 	{
3546 	case Utils::COMPUTE_SHADER:
3547 		shader_template = compute_shader_template;
3548 		break;
3549 	case Utils::FRAGMENT_SHADER:
3550 		shader_template = fragment_shader_template;
3551 		break;
3552 	case Utils::GEOMETRY_SHADER:
3553 		shader_template = geometry_shader_template;
3554 		break;
3555 	case Utils::TESS_CTRL_SHADER:
3556 		shader_template = tess_ctrl_shader_template;
3557 		break;
3558 	case Utils::TESS_EVAL_SHADER:
3559 		shader_template = tess_eval_shader_template;
3560 		break;
3561 	case Utils::VERTEX_SHADER:
3562 		shader_template = vertex_shader_template;
3563 		break;
3564 	default:
3565 		TCU_FAIL("Invalid enum");
3566 		break;
3567 	}
3568 
3569 	out_source.m_parts[0].m_code = shader_template;
3570 
3571 	size_t position = 0;
3572 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3573 						out_source.m_parts[0].m_code);
3574 
3575 	Utils::replaceToken("GLSL_TEST_FUNCTION", position, line_numbering_snippet, out_source.m_parts[0].m_code);
3576 
3577 	Utils::replaceToken("GLSL_TEST_RESULT", position,
3578 						in_use_version_400 ? test_result_snippet_400[in_stage] : test_result_snippet_normal[in_stage],
3579 						out_source.m_parts[0].m_code);
3580 }
3581 
3582 /** Constructor
3583  *
3584  * @param context Test context
3585  **/
UTF8CharactersTest(deqp::Context & context)3586 UTF8CharactersTest::UTF8CharactersTest(deqp::Context& context)
3587 	: GLSLTestBase(context, "utf8_characters", "UTF8 character used in comment or preprocessor")
3588 {
3589 	/* Nothing to be done here */
3590 }
3591 
3592 /** Overwrite getShaderSourceConfig method
3593  *
3594  * @param out_n_parts     Number of source parts used by this test case
3595  * @param out_use_lengths If source lengths shall be provided to compiler
3596  **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)3597 void UTF8CharactersTest::getShaderSourceConfig(GLuint& out_n_parts, bool& out_use_lengths)
3598 {
3599 	out_n_parts		= 1;
3600 	out_use_lengths = (AS_LAST_CHARACTER_NON_NULL_TERMINATED == m_test_case.m_case) ? true : false;
3601 }
3602 
3603 /** Set up next test case
3604  *
3605  * @param test_case_index Index of next test case
3606  *
3607  * @return false if there is no more test cases, true otherwise
3608  **/
prepareNextTestCase(glw::GLuint test_case_index)3609 bool UTF8CharactersTest::prepareNextTestCase(glw::GLuint test_case_index)
3610 {
3611 	static const testCase test_cases[] = {
3612 		{ IN_COMMENT, Utils::TWO_BYTES },
3613 		{ IN_COMMENT, Utils::THREE_BYTES },
3614 		{ IN_COMMENT, Utils::FOUR_BYTES },
3615 		{ IN_COMMENT, Utils::FIVE_BYTES },
3616 		{ IN_COMMENT, Utils::SIX_BYTES },
3617 		{ IN_COMMENT, Utils::REDUNDANT_ASCII },
3618 		{ IN_PREPROCESSOR, Utils::TWO_BYTES },
3619 		{ IN_PREPROCESSOR, Utils::THREE_BYTES },
3620 		{ IN_PREPROCESSOR, Utils::FOUR_BYTES },
3621 		{ IN_PREPROCESSOR, Utils::FIVE_BYTES },
3622 		{ IN_PREPROCESSOR, Utils::SIX_BYTES },
3623 		{ IN_PREPROCESSOR, Utils::REDUNDANT_ASCII },
3624 		{ AS_LAST_CHARACTER_NULL_TERMINATED, Utils::TWO_BYTES },
3625 		{ AS_LAST_CHARACTER_NULL_TERMINATED, Utils::THREE_BYTES },
3626 		{ AS_LAST_CHARACTER_NULL_TERMINATED, Utils::FOUR_BYTES },
3627 		{ AS_LAST_CHARACTER_NULL_TERMINATED, Utils::FIVE_BYTES },
3628 		{ AS_LAST_CHARACTER_NULL_TERMINATED, Utils::SIX_BYTES },
3629 		{ AS_LAST_CHARACTER_NULL_TERMINATED, Utils::REDUNDANT_ASCII },
3630 		{ AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::TWO_BYTES },
3631 		{ AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::THREE_BYTES },
3632 		{ AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::FOUR_BYTES },
3633 		{ AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::FIVE_BYTES },
3634 		{ AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::SIX_BYTES },
3635 		{ AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::REDUNDANT_ASCII },
3636 	};
3637 
3638 	static const GLuint max_test_cases = sizeof(test_cases) / sizeof(testCase);
3639 
3640 	if ((GLuint)-1 == test_case_index)
3641 	{
3642 		m_test_case.m_case		= DEBUG_CASE;
3643 		m_test_case.m_character = Utils::EMPTY;
3644 	}
3645 	else if (max_test_cases <= test_case_index)
3646 	{
3647 		return false;
3648 	}
3649 	else
3650 	{
3651 		m_test_case = test_cases[test_case_index];
3652 	}
3653 
3654 	m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case: utf8 character: "
3655 										<< Utils::getUtf8Character(m_test_case.m_character) << " is placed "
3656 										<< casesToStr() << tcu::TestLog::EndMessage;
3657 
3658 	return true;
3659 }
3660 
3661 /** Prepare source for given shader stage
3662  *
3663  * @param in_stage           Shader stage, compute shader will use 430
3664  * @param in_use_version_400 Select if 400 or 420 should be used
3665  * @param out_source         Prepared shader source instance
3666  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3667 void UTF8CharactersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3668 											 Utils::shaderSource& out_source)
3669 {
3670 	static const GLchar* compute_shader_template =
3671 		"VERSION\n"
3672 		"\n"
3673 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3674 		"\n"
3675 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3676 		"\n"
3677 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3678 		"\n"
3679 		"writeonly uniform image2D   uni_image;\n"
3680 		"          uniform sampler2D uni_sampler;\n"
3681 		"\n"
3682 		"#if 0\n"
3683 		"    #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3684 		"#else\n"
3685 		"    #define SET_RESULT(XX) result = XX\n"
3686 		"#endif\n"
3687 		"\n"
3688 		"void main()\n"
3689 		"{\n"
3690 		"    ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
3691 		"    vec4  result      = vec4(1, 0, 0, 1);\n"
3692 		"\n"
3693 		"    if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
3694 		"    {\n"
3695 		"        SET_RESULT(vec4(0, 1, 0, 1));\n"
3696 		"    }\n"
3697 		"\n"
3698 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3699 		"}\n"
3700 		"// Lorem ipsum LAST_CHARACTER_CASE";
3701 
3702 	static const GLchar* fragment_shader_template =
3703 		"VERSION\n"
3704 		"\n"
3705 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3706 		"\n"
3707 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3708 		"\n"
3709 		"in      vec4      gs_fs_result;\n"
3710 		"in      vec2      gs_fs_tex_coord;\n"
3711 		"out     vec4      fs_out_result;\n"
3712 		"uniform sampler2D uni_sampler;\n"
3713 		"\n"
3714 		"#if 0\n"
3715 		"    #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3716 		"#else\n"
3717 		"    #define SET_RESULT(XX) result = XX\n"
3718 		"#endif\n"
3719 		"\n"
3720 		"void main()\n"
3721 		"{\n"
3722 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3723 		"\n"
3724 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
3725 		"        (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3726 		"    {\n"
3727 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
3728 		"    }\n"
3729 		"\n"
3730 		"    fs_out_result = result;\n"
3731 		"}\n"
3732 		"// Lorem ipsum LAST_CHARACTER_CASE";
3733 
3734 	static const GLchar* geometry_shader_template =
3735 		"VERSION\n"
3736 		"\n"
3737 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3738 		"\n"
3739 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3740 		"\n"
3741 		"layout(points)                           in;\n"
3742 		"layout(triangle_strip, max_vertices = 4) out;\n"
3743 		"\n"
3744 		"in      vec4      tes_gs_result[];\n"
3745 		"out     vec2      gs_fs_tex_coord;\n"
3746 		"out     vec4      gs_fs_result;\n"
3747 		"uniform sampler2D uni_sampler;\n"
3748 		"\n"
3749 		"#if 0\n"
3750 		"    #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3751 		"#else\n"
3752 		"    #define SET_RESULT(XX) result = XX\n"
3753 		"#endif\n"
3754 		"\n"
3755 		"void main()\n"
3756 		"{\n"
3757 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3758 		"\n"
3759 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
3760 		"        (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3761 		"    {\n"
3762 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
3763 		"    }\n"
3764 		"\n"
3765 		"    gs_fs_tex_coord = vec2(0.25, 0.25);\n"
3766 		"    gs_fs_result    = result;\n"
3767 		"    gl_Position     = vec4(-1, -1, 0, 1);\n"
3768 		"    EmitVertex();\n"
3769 		"    gs_fs_tex_coord = vec2(0.25, 0.75);\n"
3770 		"    gs_fs_result    = result;\n"
3771 		"    gl_Position     = vec4(-1, 1, 0, 1);\n"
3772 		"    EmitVertex();\n"
3773 		"    gs_fs_tex_coord = vec2(0.75, 0.25);\n"
3774 		"    gs_fs_result    = result;\n"
3775 		"    gl_Position     = vec4(1, -1, 0, 1);\n"
3776 		"    EmitVertex();\n"
3777 		"    gs_fs_tex_coord = vec2(0.75, 0.75);\n"
3778 		"    gs_fs_result    = result;\n"
3779 		"    gl_Position     = vec4(1, 1, 0, 1);\n"
3780 		"    EmitVertex();\n"
3781 		"}\n"
3782 		"// Lorem ipsum LAST_CHARACTER_CASE";
3783 
3784 	static const GLchar* tess_ctrl_shader_template =
3785 		"VERSION\n"
3786 		"\n"
3787 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3788 		"\n"
3789 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3790 		"\n"
3791 		"layout(vertices = 1) out;\n"
3792 		"\n"
3793 		"in      vec4      vs_tcs_result[];\n"
3794 		"out     vec4      tcs_tes_result[];\n"
3795 		"uniform sampler2D uni_sampler;\n"
3796 		"\n"
3797 		"#if 0\n"
3798 		"    #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3799 		"#else\n"
3800 		"    #define SET_RESULT(XX) result = XX\n"
3801 		"#endif\n"
3802 		"\n"
3803 		"void main()\n"
3804 		"{\n"
3805 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3806 		"\n"
3807 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
3808 		"        (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3809 		"    {\n"
3810 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
3811 		"    }\n"
3812 		"\n"
3813 		"    tcs_tes_result[gl_InvocationID] = result;\n"
3814 		"\n"
3815 		"    gl_TessLevelOuter[0] = 1.0;\n"
3816 		"    gl_TessLevelOuter[1] = 1.0;\n"
3817 		"    gl_TessLevelOuter[2] = 1.0;\n"
3818 		"    gl_TessLevelOuter[3] = 1.0;\n"
3819 		"    gl_TessLevelInner[0] = 1.0;\n"
3820 		"    gl_TessLevelInner[1] = 1.0;\n"
3821 		"}\n"
3822 		"// Lorem ipsum LAST_CHARACTER_CASE";
3823 
3824 	static const GLchar* tess_eval_shader_template =
3825 		"VERSION\n"
3826 		"\n"
3827 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3828 		"\n"
3829 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3830 		"\n"
3831 		"layout(isolines, point_mode) in;\n"
3832 		"\n"
3833 		"in      vec4      tcs_tes_result[];\n"
3834 		"out     vec4      tes_gs_result;\n"
3835 		"uniform sampler2D uni_sampler;\n"
3836 		"\n"
3837 		"#if 0\n"
3838 		"    #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3839 		"#else\n"
3840 		"    #define SET_RESULT(XX) result = XX\n"
3841 		"#endif\n"
3842 		"\n"
3843 		"void main()\n"
3844 		"{\n"
3845 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3846 		"\n"
3847 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
3848 		"        (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3849 		"    {\n"
3850 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
3851 		"    }\n"
3852 		"\n"
3853 		"    tes_gs_result = result;\n"
3854 		"}\n"
3855 		"// Lorem ipsum LAST_CHARACTER_CASE";
3856 
3857 	static const GLchar* vertex_shader_template =
3858 		"VERSION\n"
3859 		"\n"
3860 		"// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3861 		"\n"
3862 		"/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3863 		"\n"
3864 		"out     vec4      vs_tcs_result;\n"
3865 		"uniform sampler2D uni_sampler;\n"
3866 		"\n"
3867 		"#if 0\n"
3868 		"    #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3869 		"#else\n"
3870 		"    #define SET_RESULT(XX) result = XX\n"
3871 		"#endif\n"
3872 		"\n"
3873 		"void main()\n"
3874 		"{\n"
3875 		"    vec4 result = vec4(1, 0, 0, 1);\n"
3876 		"\n"
3877 		"    if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
3878 		"    {\n"
3879 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
3880 		"    }\n"
3881 		"\n"
3882 		"    vs_tcs_result = result;\n"
3883 		"}\n"
3884 		"// Lorem ipsum LAST_CHARACTER_CASE";
3885 
3886 	const GLchar* shader_template	 = 0;
3887 	const GLchar* comment_case		  = "";
3888 	const GLchar* preprocessor_case   = "";
3889 	const GLchar* last_character_case = "";
3890 	const GLchar* utf8_character	  = Utils::getUtf8Character(m_test_case.m_character);
3891 
3892 	switch (in_stage)
3893 	{
3894 	case Utils::COMPUTE_SHADER:
3895 		shader_template = compute_shader_template;
3896 		break;
3897 	case Utils::FRAGMENT_SHADER:
3898 		shader_template = fragment_shader_template;
3899 		break;
3900 	case Utils::GEOMETRY_SHADER:
3901 		shader_template = geometry_shader_template;
3902 		break;
3903 	case Utils::TESS_CTRL_SHADER:
3904 		shader_template = tess_ctrl_shader_template;
3905 		break;
3906 	case Utils::TESS_EVAL_SHADER:
3907 		shader_template = tess_eval_shader_template;
3908 		break;
3909 	case Utils::VERTEX_SHADER:
3910 		shader_template = vertex_shader_template;
3911 		break;
3912 	default:
3913 		TCU_FAIL("Invalid enum");
3914 		break;
3915 	}
3916 
3917 	switch (m_test_case.m_case)
3918 	{
3919 	case IN_COMMENT:
3920 		comment_case = utf8_character;
3921 		break;
3922 	case IN_PREPROCESSOR:
3923 		preprocessor_case = utf8_character;
3924 		break;
3925 	case AS_LAST_CHARACTER_NULL_TERMINATED:
3926 		last_character_case = utf8_character;
3927 		break;
3928 	case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
3929 		last_character_case = utf8_character;
3930 		break;
3931 	case DEBUG_CASE:
3932 		break;
3933 	default:
3934 		TCU_FAIL("Invalid enum");
3935 	}
3936 
3937 	out_source.m_parts[0].m_code = shader_template;
3938 
3939 	size_t position = 0;
3940 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3941 						out_source.m_parts[0].m_code);
3942 
3943 	Utils::replaceAllTokens("COMMENT_CASE", comment_case, out_source.m_parts[0].m_code);
3944 
3945 	Utils::replaceAllTokens("PREPROCESSOR_CASE", preprocessor_case, out_source.m_parts[0].m_code);
3946 
3947 	Utils::replaceAllTokens("LAST_CHARACTER_CASE", last_character_case, out_source.m_parts[0].m_code);
3948 }
3949 
3950 /** Prepare texture
3951  *
3952  * @param texture Texutre to be created and filled with content
3953  *
3954  * @return Name of sampler uniform that should be used for the texture
3955  **/
prepareSourceTexture(Utils::texture & texture)3956 const GLchar* UTF8CharactersTest::prepareSourceTexture(Utils::texture& texture)
3957 {
3958 	std::vector<GLuint> data;
3959 	static const GLuint width	  = 64;
3960 	static const GLuint height	 = 64;
3961 	static const GLuint data_size  = width * height;
3962 	static const GLuint blue_color = 0xffff0000;
3963 	static const GLuint grey_color = 0xaaaaaaaa;
3964 
3965 	data.resize(data_size);
3966 
3967 	for (GLuint i = 0; i < data_size; ++i)
3968 	{
3969 		data[i] = grey_color;
3970 	}
3971 
3972 	for (GLuint y = 16; y < 48; ++y)
3973 	{
3974 		const GLuint line_offset = y * 64;
3975 
3976 		for (GLuint x = 16; x < 48; ++x)
3977 		{
3978 			const GLuint pixel_offset = x + line_offset;
3979 
3980 			data[pixel_offset] = blue_color;
3981 		}
3982 	}
3983 
3984 	texture.create(width, height, GL_RGBA8);
3985 
3986 	texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
3987 
3988 	return "uni_sampler";
3989 }
3990 
3991 /** Returns description of current test case
3992  *
3993  * @return String with description
3994  **/
casesToStr() const3995 const GLchar* UTF8CharactersTest::casesToStr() const
3996 {
3997 	const GLchar* result = 0;
3998 
3999 	switch (m_test_case.m_case)
4000 	{
4001 	case IN_COMMENT:
4002 		result = "in comment";
4003 		break;
4004 	case IN_PREPROCESSOR:
4005 		result = "in preprocessor";
4006 		break;
4007 	case AS_LAST_CHARACTER_NULL_TERMINATED:
4008 		result = "just before null";
4009 		break;
4010 	case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
4011 		result = "as last character";
4012 		break;
4013 	case DEBUG_CASE:
4014 		result = "nowhere. This is debug!";
4015 		break;
4016 	default:
4017 		TCU_FAIL("Invalid enum");
4018 	}
4019 
4020 	return result;
4021 }
4022 
4023 /** Constructor
4024  *
4025  * @param context Test context
4026  **/
UTF8InSourceTest(deqp::Context & context)4027 UTF8InSourceTest::UTF8InSourceTest(deqp::Context& context)
4028 	: NegativeTestBase(context, "utf8_in_source", "UTF8 characters used in shader source")
4029 {
4030 	/* Nothing to be done here */
4031 }
4032 
4033 /** Set up next test case
4034  *
4035  * @param test_case_index Index of next test case
4036  *
4037  * @return false if there is no more test cases, true otherwise
4038  **/
prepareNextTestCase(glw::GLuint test_case_index)4039 bool UTF8InSourceTest::prepareNextTestCase(glw::GLuint test_case_index)
4040 {
4041 	static const Utils::UTF8_CHARACTERS test_cases[] = {
4042 		Utils::TWO_BYTES,  Utils::THREE_BYTES, Utils::FOUR_BYTES,
4043 		Utils::FIVE_BYTES, Utils::SIX_BYTES,   Utils::REDUNDANT_ASCII
4044 	};
4045 
4046 	static const GLuint max_test_cases = sizeof(test_cases) / sizeof(Utils::UTF8_CHARACTERS);
4047 
4048 	if ((GLuint)-1 == test_case_index)
4049 	{
4050 		m_character = Utils::EMPTY;
4051 	}
4052 	else if (max_test_cases <= test_case_index)
4053 	{
4054 		return false;
4055 	}
4056 	else
4057 	{
4058 		m_character = test_cases[test_case_index];
4059 	}
4060 
4061 	m_context.getTestContext().getLog() << tcu::TestLog::Message
4062 										<< "Test case: utf8 character: " << Utils::getUtf8Character(m_character)
4063 										<< tcu::TestLog::EndMessage;
4064 
4065 	return true;
4066 }
4067 
4068 /** Prepare source for given shader stage
4069  *
4070  * @param in_stage           Shader stage, compute shader will use 430
4071  * @param in_use_version_400 Select if 400 or 420 should be used
4072  * @param out_source         Prepared shader source instance
4073  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4074 void UTF8InSourceTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4075 										   Utils::shaderSource& out_source)
4076 {
4077 	static const GLchar* compute_shader_template =
4078 		"VERSION\n"
4079 		"\n"
4080 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4081 		"\n"
4082 		"writeonly uniform image2D   uni_image;\n"
4083 		"          uniform sampler2D uni_sampler;\n"
4084 		"\n"
4085 		"#define SET_RESULT(XX) resHEREult = XX\n"
4086 		"\n"
4087 		"void main()\n"
4088 		"{\n"
4089 		"    ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
4090 		"    vec4  resHEREult      = vec4(1, 0, 0, 1);\n"
4091 		"\n"
4092 		"    if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
4093 		"    {\n"
4094 		"        SET_RESULT(vec4(0, 1, 0, 1));\n"
4095 		"    }\n"
4096 		"\n"
4097 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), resHEREult);\n"
4098 		"}\n"
4099 		"";
4100 
4101 	static const GLchar* fragment_shader_template =
4102 		"VERSION\n"
4103 		"\n"
4104 		"in      vec4      gs_fs_result;\n"
4105 		"in      vec2      gs_fs_tex_coord;\n"
4106 		"out     vec4      fs_out_result;\n"
4107 		"uniform sampler2D uni_sampler;\n"
4108 		"\n"
4109 		"#define SET_RESULT(XX) resHEREult = XX\n"
4110 		"\n"
4111 		"void main()\n"
4112 		"{\n"
4113 		"    vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4114 		"\n"
4115 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
4116 		"        (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
4117 		"    {\n"
4118 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
4119 		"    }\n"
4120 		"\n"
4121 		"    fs_out_result = resHEREult;\n"
4122 		"}\n"
4123 		"\n";
4124 
4125 	static const GLchar* geometry_shader_template =
4126 		"VERSION\n"
4127 		"\n"
4128 		"layout(points)                           in;\n"
4129 		"layout(triangle_strip, max_vertices = 4) out;\n"
4130 		"\n"
4131 		"in      vec4      tes_gHEREs_result[];\n"
4132 		"out     vec2      gs_fs_tex_coord;\n"
4133 		"out     vec4      gs_fs_result;\n"
4134 		"uniform sampler2D uni_sampler;\n"
4135 		"\n"
4136 		"#define SET_RESULT(XX) result = XX\n"
4137 		"\n"
4138 		"void main()\n"
4139 		"{\n"
4140 		"    vec4 result = vec4(1, 0, 0, 1);\n"
4141 		"\n"
4142 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
4143 		"        (vec4(0, 1, 0, 1) == tes_gHEREs_result[0]) )\n"
4144 		"    {\n"
4145 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
4146 		"    }\n"
4147 		"\n"
4148 		"    gs_fs_tex_coord = vec2(0.25, 0.25);\n"
4149 		"    gs_fs_result    = result;\n"
4150 		"    gl_Position     = vec4(-1, -1, 0, 1);\n"
4151 		"    EmitVertex();\n"
4152 		"    gs_fs_tex_coord = vec2(0.25, 0.75);\n"
4153 		"    gs_fs_result    = result;\n"
4154 		"    gl_Position     = vec4(-1, 1, 0, 1);\n"
4155 		"    EmitVertex();\n"
4156 		"    gs_fs_tex_coord = vec2(0.75, 0.25);\n"
4157 		"    gs_fs_result    = result;\n"
4158 		"    gl_Position     = vec4(1, -1, 0, 1);\n"
4159 		"    EmitVertex();\n"
4160 		"    gs_fs_tex_coord = vec2(0.75, 0.75);\n"
4161 		"    gs_fs_result    = result;\n"
4162 		"    gl_Position     = vec4(1, 1, 0, 1);\n"
4163 		"    EmitVertex();\n"
4164 		"}\n"
4165 		"\n";
4166 
4167 	static const GLchar* tess_ctrl_shader_template =
4168 		"VERSION\n"
4169 		"\n"
4170 		"layout(vertices = 1) out;\n"
4171 		"\n"
4172 		"in      vec4      vs_tcs_result[];\n"
4173 		"out     vec4      tcHEREs_tes_result[];\n"
4174 		"uniform sampler2D uni_sampler;\n"
4175 		"\n"
4176 		"#define SET_RESULT(XX) resulHEREt = XX\n"
4177 		"\n"
4178 		"void main()\n"
4179 		"{\n"
4180 		"    vec4 resulHEREt = vec4(1, 0, 0, 1);\n"
4181 		"\n"
4182 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
4183 		"        (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
4184 		"    {\n"
4185 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
4186 		"    }\n"
4187 		"\n"
4188 		"    tcHEREs_tes_result[gl_InvocationID] = resulHEREt;\n"
4189 		"\n"
4190 		"    gl_TessLevelOuter[0] = 1.0;\n"
4191 		"    gl_TessLevelOuter[1] = 1.0;\n"
4192 		"    gl_TessLevelOuter[2] = 1.0;\n"
4193 		"    gl_TessLevelOuter[3] = 1.0;\n"
4194 		"    gl_TessLevelInner[0] = 1.0;\n"
4195 		"    gl_TessLevelInner[1] = 1.0;\n"
4196 		"}\n"
4197 		"\n";
4198 
4199 	static const GLchar* tess_eval_shader_template =
4200 		"VERSION\n"
4201 		"\n"
4202 		"layout(isolines, point_mode) in;\n"
4203 		"\n"
4204 		"in      vec4      tcs_tes_result[];\n"
4205 		"out     vec4      teHEREs_gs_result;\n"
4206 		"uniform sampler2D uni_sampler;\n"
4207 		"\n"
4208 		"#define SET_RESULT(XX) reHEREsult = XX\n"
4209 		"\n"
4210 		"void main()\n"
4211 		"{\n"
4212 		"    vec4 reHEREsult = vec4(1, 0, 0, 1);\n"
4213 		"\n"
4214 		"    if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
4215 		"        (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
4216 		"    {\n"
4217 		"         SET_RESULT(vec4(0, 1, 0, 1));\n"
4218 		"    }\n"
4219 		"\n"
4220 		"    teHEREs_gs_result = reHEREsult;\n"
4221 		"}\n"
4222 		"\n";
4223 
4224 	static const GLchar* vertex_shader_template = "VERSION\n"
4225 												  "\n"
4226 												  "out     vec4      vs_tcs_HEREresult;\n"
4227 												  "uniform sampler2D uni_sampler;\n"
4228 												  "\n"
4229 												  "#define SET_RHEREESULT(XX) resHEREult = XX\n"
4230 												  "\n"
4231 												  "void main()\n"
4232 												  "{\n"
4233 												  "    vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4234 												  "\n"
4235 												  "    if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
4236 												  "    {\n"
4237 												  "         SET_RHEREESULT(vec4(0, 1, 0, 1));\n"
4238 												  "    }\n"
4239 												  "\n"
4240 												  "    vs_tcs_HEREresult = resHEREult;\n"
4241 												  "}\n"
4242 												  "\n";
4243 
4244 	const GLchar* shader_template = 0;
4245 	const GLchar* utf8_character  = Utils::getUtf8Character(m_character);
4246 
4247 	switch (in_stage)
4248 	{
4249 	case Utils::COMPUTE_SHADER:
4250 		shader_template = compute_shader_template;
4251 		break;
4252 	case Utils::FRAGMENT_SHADER:
4253 		shader_template = fragment_shader_template;
4254 		break;
4255 	case Utils::GEOMETRY_SHADER:
4256 		shader_template = geometry_shader_template;
4257 		break;
4258 	case Utils::TESS_CTRL_SHADER:
4259 		shader_template = tess_ctrl_shader_template;
4260 		break;
4261 	case Utils::TESS_EVAL_SHADER:
4262 		shader_template = tess_eval_shader_template;
4263 		break;
4264 	case Utils::VERTEX_SHADER:
4265 		shader_template = vertex_shader_template;
4266 		break;
4267 	default:
4268 		TCU_FAIL("Invalid enum");
4269 		break;
4270 	}
4271 
4272 	out_source.m_parts[0].m_code = shader_template;
4273 
4274 	size_t position = 0;
4275 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4276 						out_source.m_parts[0].m_code);
4277 
4278 	Utils::replaceAllTokens("HERE", utf8_character, out_source.m_parts[0].m_code);
4279 }
4280 
4281 /** Constructor
4282  *
4283  * @param context Test context
4284  **/
ImplicitConversionsValidTest(deqp::Context & context)4285 ImplicitConversionsValidTest::ImplicitConversionsValidTest(deqp::Context& context)
4286 	: GLSLTestBase(context, "implicit_conversions", "Verifies that implicit conversions are allowed")
4287 {
4288 	/* Nothing to be done */
4289 }
4290 
4291 /** Set up next test case
4292  *
4293  * @param test_case_index Index of next test case
4294  *
4295  * @return false if there is no more test cases, true otherwise
4296  **/
prepareNextTestCase(glw::GLuint test_case_index)4297 bool ImplicitConversionsValidTest::prepareNextTestCase(glw::GLuint test_case_index)
4298 {
4299 	m_current_test_case_index = test_case_index;
4300 
4301 	if ((glw::GLuint)-1 == test_case_index)
4302 	{
4303 		return true;
4304 	}
4305 	else if (m_test_cases.size() <= test_case_index)
4306 	{
4307 		return false;
4308 	}
4309 
4310 	const testCase& test_case = m_test_cases[test_case_index];
4311 
4312 	m_context.getTestContext().getLog() << tcu::TestLog::Message
4313 										<< "T1:" << Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols,
4314 																	   test_case.m_n_rows)
4315 										<< " T2:" << Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols,
4316 																		test_case.m_n_rows)
4317 										<< tcu::TestLog::EndMessage;
4318 
4319 	return true;
4320 }
4321 
4322 /** Prepare source for given shader stage
4323  *
4324  * @param in_stage           Shader stage, compute shader will use 430
4325  * @param in_use_version_400 Select if 400 or 420 should be used
4326  * @param out_source         Prepared shader source instance
4327  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4328 void ImplicitConversionsValidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4329 													   Utils::shaderSource& out_source)
4330 {
4331 	static const GLchar* function_definition = "T1 function(in T2 left, in T2 right)\n"
4332 											   "{\n"
4333 											   "    return left + right;\n"
4334 											   "}\n";
4335 
4336 	static const GLchar* verification_snippet = "    const T2 const_left  = T2(VALUE_LIST);\n"
4337 												"    const T2 const_right = T2(VALUE_LIST);\n"
4338 												"\n"
4339 												"    T1 const_result = function(const_left, const_right);\n"
4340 												"\n"
4341 												"    T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4342 												"\n"
4343 												"    T2 var_left  = uni_left;\n"
4344 												"    T2 var_right = uni_right;\n"
4345 												"\n"
4346 												"    T1 var_result = function(var_left, var_right);\n"
4347 												"\n"
4348 												"    if ((literal_result != const_result) ||\n"
4349 												"        (const_result   != var_result) )\n"
4350 												"    {\n"
4351 												"        result = vec4(1, 0, 0, 1);\n"
4352 												"    }\n";
4353 
4354 	static const GLchar* compute_shader_template =
4355 		"VERSION\n"
4356 		"\n"
4357 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4358 		"\n"
4359 		"writeonly uniform image2D uni_image;\n"
4360 		"          uniform T2 uni_left;\n"
4361 		"          uniform T2 uni_right;\n"
4362 		"\n"
4363 		"FUNCTION_DEFINITION"
4364 		"\n"
4365 		"void main()\n"
4366 		"{\n"
4367 		"    vec4 result = vec4(0, 1, 0, 1);\n"
4368 		"\n"
4369 		"VERIFICATION"
4370 		"\n"
4371 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4372 		"}\n"
4373 		"\n";
4374 
4375 	static const GLchar* fragment_shader_template = "VERSION\n"
4376 													"\n"
4377 													"in  vec4 gs_fs_result;\n"
4378 													"out vec4 fs_out_result;\n"
4379 													"uniform T2 uni_left;\n"
4380 													"uniform T2 uni_right;\n"
4381 													"\n"
4382 													"FUNCTION_DEFINITION"
4383 													"\n"
4384 													"void main()\n"
4385 													"{\n"
4386 													"    vec4 result = vec4(0, 1, 0, 1);\n"
4387 													"\n"
4388 													"VERIFICATION"
4389 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4390 													"    {\n"
4391 													"         result = vec4(1, 0, 0, 1);\n"
4392 													"    }\n"
4393 													"\n"
4394 													"    fs_out_result = result;\n"
4395 													"}\n"
4396 													"\n";
4397 
4398 	static const GLchar* geometry_shader_template = "VERSION\n"
4399 													"\n"
4400 													"layout(points)                           in;\n"
4401 													"layout(triangle_strip, max_vertices = 4) out;\n"
4402 													"\n"
4403 													"in  vec4 tes_gs_result[];\n"
4404 													"out vec4 gs_fs_result;\n"
4405 													"uniform T2 uni_left;\n"
4406 													"uniform T2 uni_right;\n"
4407 													"\n"
4408 													"FUNCTION_DEFINITION"
4409 													"\n"
4410 													"void main()\n"
4411 													"{\n"
4412 													"    vec4 result = vec4(0, 1, 0, 1);\n"
4413 													"\n"
4414 													"VERIFICATION"
4415 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4416 													"    {\n"
4417 													"         result = vec4(1, 0, 0, 1);\n"
4418 													"    }\n"
4419 													"\n"
4420 													"    gs_fs_result = result;\n"
4421 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
4422 													"    EmitVertex();\n"
4423 													"    gs_fs_result = result;\n"
4424 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
4425 													"    EmitVertex();\n"
4426 													"    gs_fs_result = result;\n"
4427 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
4428 													"    EmitVertex();\n"
4429 													"    gs_fs_result = result;\n"
4430 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
4431 													"    EmitVertex();\n"
4432 													"}\n"
4433 													"\n";
4434 
4435 	static const GLchar* tess_ctrl_shader_template =
4436 		"VERSION\n"
4437 		"\n"
4438 		"layout(vertices = 1) out;\n"
4439 		"\n"
4440 		"in  vec4 vs_tcs_result[];\n"
4441 		"out vec4 tcs_tes_result[];\n"
4442 		"uniform T2 uni_left;\n"
4443 		"uniform T2 uni_right;\n"
4444 		"\n"
4445 		"FUNCTION_DEFINITION"
4446 		"\n"
4447 		"void main()\n"
4448 		"{\n"
4449 		"    vec4 result = vec4(0, 1, 0, 1);\n"
4450 		"\n"
4451 		"VERIFICATION"
4452 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4453 		"    {\n"
4454 		"         result = vec4(1, 0, 0, 1);\n"
4455 		"    }\n"
4456 		"\n"
4457 		"    tcs_tes_result[gl_InvocationID] = result;\n"
4458 		"\n"
4459 		"    gl_TessLevelOuter[0] = 1.0;\n"
4460 		"    gl_TessLevelOuter[1] = 1.0;\n"
4461 		"    gl_TessLevelOuter[2] = 1.0;\n"
4462 		"    gl_TessLevelOuter[3] = 1.0;\n"
4463 		"    gl_TessLevelInner[0] = 1.0;\n"
4464 		"    gl_TessLevelInner[1] = 1.0;\n"
4465 		"}\n"
4466 		"\n";
4467 
4468 	static const GLchar* tess_eval_shader_template = "VERSION\n"
4469 													 "\n"
4470 													 "layout(isolines, point_mode) in;\n"
4471 													 "\n"
4472 													 "in  vec4 tcs_tes_result[];\n"
4473 													 "out vec4 tes_gs_result;\n"
4474 													 "uniform T2 uni_left;\n"
4475 													 "uniform T2 uni_right;\n"
4476 													 "\n"
4477 													 "FUNCTION_DEFINITION"
4478 													 "\n"
4479 													 "void main()\n"
4480 													 "{\n"
4481 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
4482 													 "\n"
4483 													 "VERIFICATION"
4484 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4485 													 "    {\n"
4486 													 "         result = vec4(1, 0, 0, 1);\n"
4487 													 "    }\n"
4488 													 "\n"
4489 													 "    tes_gs_result = result;\n"
4490 													 "}\n"
4491 													 "\n";
4492 
4493 	static const GLchar* vertex_shader_template = "VERSION\n"
4494 												  "\n"
4495 												  "out vec4 vs_tcs_result;\n"
4496 												  "uniform T2 uni_left;\n"
4497 												  "uniform T2 uni_right;\n"
4498 												  "\n"
4499 												  "FUNCTION_DEFINITION"
4500 												  "\n"
4501 												  "void main()\n"
4502 												  "{\n"
4503 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
4504 												  "\n"
4505 												  "VERIFICATION"
4506 												  "\n"
4507 												  "    vs_tcs_result = result;\n"
4508 												  "}\n"
4509 												  "\n";
4510 
4511 	const testCase&	test_case  = getCurrentTestCase();
4512 	const GLchar*	  t1		  = Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols, test_case.m_n_rows);
4513 	const GLchar*	  t2		  = Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols, test_case.m_n_rows);
4514 	const std::string& value_list = getValueList(test_case.m_n_cols, test_case.m_n_rows);
4515 	const GLchar*	  shader_template = 0;
4516 
4517 	switch (in_stage)
4518 	{
4519 	case Utils::COMPUTE_SHADER:
4520 		shader_template = compute_shader_template;
4521 		break;
4522 	case Utils::FRAGMENT_SHADER:
4523 		shader_template = fragment_shader_template;
4524 		break;
4525 	case Utils::GEOMETRY_SHADER:
4526 		shader_template = geometry_shader_template;
4527 		break;
4528 	case Utils::TESS_CTRL_SHADER:
4529 		shader_template = tess_ctrl_shader_template;
4530 		break;
4531 	case Utils::TESS_EVAL_SHADER:
4532 		shader_template = tess_eval_shader_template;
4533 		break;
4534 	case Utils::VERTEX_SHADER:
4535 		shader_template = vertex_shader_template;
4536 		break;
4537 	default:
4538 		TCU_FAIL("Invalid enum");
4539 		break;
4540 	}
4541 
4542 	out_source.m_parts[0].m_code = shader_template;
4543 
4544 	size_t position = 0;
4545 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4546 						out_source.m_parts[0].m_code);
4547 
4548 	Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4549 
4550 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4551 
4552 	Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4553 
4554 	Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4555 
4556 	Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4557 }
4558 
4559 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
4560  *
4561  * @param program Current program
4562  **/
prepareUniforms(Utils::program & program)4563 void ImplicitConversionsValidTest::prepareUniforms(Utils::program& program)
4564 {
4565 	static const GLdouble double_data[16] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
4566 											  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
4567 	static const GLfloat float_data[16] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
4568 											1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
4569 	static const GLint  int_data[4]  = { 1, 1, 1, 1 };
4570 	static const GLuint uint_data[4] = { 1u, 1u, 1u, 1u };
4571 
4572 	const testCase& test_case = getCurrentTestCase();
4573 
4574 	switch (test_case.m_types.m_t2)
4575 	{
4576 	case Utils::DOUBLE:
4577 		program.uniform("uni_left", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4578 		program.uniform("uni_right", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4579 		break;
4580 	case Utils::FLOAT:
4581 		program.uniform("uni_left", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4582 		program.uniform("uni_right", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4583 		break;
4584 	case Utils::INT:
4585 		program.uniform("uni_left", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4586 		program.uniform("uni_right", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4587 		break;
4588 	case Utils::UINT:
4589 		program.uniform("uni_left", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4590 		program.uniform("uni_right", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4591 		break;
4592 	default:
4593 		TCU_FAIL("Invalid enum");
4594 	}
4595 }
4596 
4597 /** Prepare test cases
4598  *
4599  * @return true
4600  **/
testInit()4601 bool ImplicitConversionsValidTest::testInit()
4602 {
4603 	static const typesPair allowed_conversions[] = {
4604 		{ Utils::UINT, Utils::INT },   { Utils::FLOAT, Utils::INT },   { Utils::DOUBLE, Utils::INT },
4605 		{ Utils::FLOAT, Utils::UINT }, { Utils::DOUBLE, Utils::UINT }, { Utils::FLOAT, Utils::FLOAT },
4606 	};
4607 
4608 	static GLuint n_allowed_conversions = sizeof(allowed_conversions) / sizeof(typesPair);
4609 
4610 	m_debug_test_case.m_types.m_t1 = Utils::FLOAT;
4611 	m_debug_test_case.m_types.m_t2 = Utils::FLOAT;
4612 	m_debug_test_case.m_n_cols	 = 4;
4613 	m_debug_test_case.m_n_rows	 = 4;
4614 
4615 	for (GLuint i = 0; i < n_allowed_conversions; ++i)
4616 	{
4617 		const typesPair& types = allowed_conversions[i];
4618 
4619 		GLuint allowed_columns = 1;
4620 		if ((true == Utils::doesTypeSupportMatrix(types.m_t1)) && (true == Utils::doesTypeSupportMatrix(types.m_t2)))
4621 		{
4622 			allowed_columns = 4;
4623 		}
4624 
4625 		{
4626 			testCase test_case = { types, 1, 1 };
4627 
4628 			m_test_cases.push_back(test_case);
4629 		}
4630 
4631 		for (GLuint row = 2; row <= 4; ++row)
4632 		{
4633 			for (GLuint col = 1; col <= allowed_columns; ++col)
4634 			{
4635 				testCase test_case = { types, col, row };
4636 
4637 				m_test_cases.push_back(test_case);
4638 			}
4639 		}
4640 	}
4641 
4642 	return true;
4643 }
4644 
4645 /** Returns reference to current test case
4646  *
4647  * @return Reference to testCase
4648  **/
getCurrentTestCase()4649 const ImplicitConversionsValidTest::testCase& ImplicitConversionsValidTest::getCurrentTestCase()
4650 {
4651 	if ((glw::GLuint)-1 == m_current_test_case_index)
4652 	{
4653 		return m_debug_test_case;
4654 	}
4655 	else
4656 	{
4657 		return m_test_cases[m_current_test_case_index];
4658 	}
4659 }
4660 
4661 /** Get list of values to for glsl constants
4662  *
4663  * @param n_columns Number of columns
4664  * @param n_rows    Number of rows
4665  *
4666  * @return String with list of values separated with comma
4667  **/
getValueList(glw::GLuint n_columns,glw::GLuint n_rows)4668 std::string ImplicitConversionsValidTest::getValueList(glw::GLuint n_columns, glw::GLuint n_rows)
4669 {
4670 	std::string result;
4671 
4672 	for (GLuint i = 0; i < n_columns * n_rows; ++i)
4673 	{
4674 		if (i != n_columns * n_rows - 1)
4675 		{
4676 			result.append("1, ");
4677 		}
4678 		else
4679 		{
4680 			result.append("1");
4681 		}
4682 	}
4683 
4684 	return result;
4685 }
4686 
4687 /** Constructor
4688  *
4689  * @param context Test context
4690  **/
ImplicitConversionsInvalidTest(deqp::Context & context)4691 ImplicitConversionsInvalidTest::ImplicitConversionsInvalidTest(deqp::Context& context)
4692 	: NegativeTestBase(context, "implicit_conversions_invalid",
4693 					   "Verifies that implicit conversions from uint to int are forbidden")
4694 {
4695 	/* Nothing to be done here */
4696 }
4697 
4698 /** Set up next test case
4699  *
4700  * @param test_case_index Index of next test case
4701  *
4702  * @return false if there is no more test cases, true otherwise
4703  **/
prepareNextTestCase(glw::GLuint test_case_index)4704 bool ImplicitConversionsInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
4705 {
4706 	m_current_test_case_index = test_case_index;
4707 
4708 	if ((glw::GLuint)-1 == test_case_index)
4709 	{
4710 		return false;
4711 	}
4712 	else if (4 <= test_case_index)
4713 	{
4714 		return false;
4715 	}
4716 
4717 	m_context.getTestContext().getLog() << tcu::TestLog::Message
4718 										<< "T1:" << Utils::getTypeName(Utils::UINT, 1, test_case_index + 1)
4719 										<< " T2:" << Utils::getTypeName(Utils::INT, 1, test_case_index + 1)
4720 										<< tcu::TestLog::EndMessage;
4721 
4722 	return true;
4723 }
4724 
4725 /** Prepare source for given shader stage
4726  *
4727  * @param in_stage           Shader stage, compute shader will use 430
4728  * @param in_use_version_400 Select if 400 or 420 should be used
4729  * @param out_source         Prepared shader source instance
4730  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4731 void ImplicitConversionsInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4732 														 Utils::shaderSource& out_source)
4733 {
4734 	static const GLchar* function_definition = "T1 function(in T2 left, in T2 right)\n"
4735 											   "{\n"
4736 											   "    return left + right;\n"
4737 											   "}\n";
4738 
4739 	static const GLchar* verification_snippet = "    const T2 const_left  = T2(VALUE_LIST);\n"
4740 												"    const T2 const_right = T2(VALUE_LIST);\n"
4741 												"\n"
4742 												"    T1 const_result = function(const_left, const_right);\n"
4743 												"\n"
4744 												"    T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4745 												"\n"
4746 												"    T2 var_left  = uni_left;\n"
4747 												"    T2 var_right = uni_right;\n"
4748 												"\n"
4749 												"    T1 var_result = function(var_left, var_right);\n"
4750 												"\n"
4751 												"    if ((literal_result != const_result) ||\n"
4752 												"        (const_result   != var_result) )\n"
4753 												"    {\n"
4754 												"        result = vec4(1, 0, 0, 1);\n"
4755 												"    }\n";
4756 
4757 	static const GLchar* compute_shader_template =
4758 		"VERSION\n"
4759 		"\n"
4760 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4761 		"\n"
4762 		"writeonly uniform image2D uni_image;\n"
4763 		"          uniform T2 uni_left;\n"
4764 		"          uniform T2 uni_right;\n"
4765 		"\n"
4766 		"FUNCTION_DEFINITION"
4767 		"\n"
4768 		"void main()\n"
4769 		"{\n"
4770 		"    vec4 result = vec4(0, 1, 0, 1);\n"
4771 		"\n"
4772 		"VERIFICATION"
4773 		"\n"
4774 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4775 		"}\n"
4776 		"\n";
4777 
4778 	static const GLchar* fragment_shader_template = "VERSION\n"
4779 													"\n"
4780 													"in  vec4 gs_fs_result;\n"
4781 													"out vec4 fs_out_result;\n"
4782 													"uniform T2 uni_left;\n"
4783 													"uniform T2 uni_right;\n"
4784 													"\n"
4785 													"FUNCTION_DEFINITION"
4786 													"\n"
4787 													"void main()\n"
4788 													"{\n"
4789 													"    vec4 result = vec4(0, 1, 0, 1);\n"
4790 													"\n"
4791 													"VERIFICATION"
4792 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4793 													"    {\n"
4794 													"         result = vec4(1, 0, 0, 1);\n"
4795 													"    }\n"
4796 													"\n"
4797 													"    fs_out_result = result;\n"
4798 													"}\n"
4799 													"\n";
4800 
4801 	static const GLchar* geometry_shader_template = "VERSION\n"
4802 													"\n"
4803 													"layout(points)                           in;\n"
4804 													"layout(triangle_strip, max_vertices = 4) out;\n"
4805 													"\n"
4806 													"in  vec4 tes_gs_result[];\n"
4807 													"out vec4 gs_fs_result;\n"
4808 													"uniform T2 uni_left;\n"
4809 													"uniform T2 uni_right;\n"
4810 													"\n"
4811 													"FUNCTION_DEFINITION"
4812 													"\n"
4813 													"void main()\n"
4814 													"{\n"
4815 													"    vec4 result = vec4(0, 1, 0, 1);\n"
4816 													"\n"
4817 													"VERIFICATION"
4818 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4819 													"    {\n"
4820 													"         result = vec4(1, 0, 0, 1);\n"
4821 													"    }\n"
4822 													"\n"
4823 													"    gs_fs_result = result;\n"
4824 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
4825 													"    EmitVertex();\n"
4826 													"    gs_fs_result = result;\n"
4827 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
4828 													"    EmitVertex();\n"
4829 													"    gs_fs_result = result;\n"
4830 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
4831 													"    EmitVertex();\n"
4832 													"    gs_fs_result = result;\n"
4833 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
4834 													"    EmitVertex();\n"
4835 													"}\n"
4836 													"\n";
4837 
4838 	static const GLchar* tess_ctrl_shader_template =
4839 		"VERSION\n"
4840 		"\n"
4841 		"layout(vertices = 1) out;\n"
4842 		"\n"
4843 		"in  vec4 vs_tcs_result[];\n"
4844 		"out vec4 tcs_tes_result[];\n"
4845 		"uniform T2 uni_left;\n"
4846 		"uniform T2 uni_right;\n"
4847 		"\n"
4848 		"FUNCTION_DEFINITION"
4849 		"\n"
4850 		"void main()\n"
4851 		"{\n"
4852 		"    vec4 result = vec4(0, 1, 0, 1);\n"
4853 		"\n"
4854 		"VERIFICATION"
4855 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4856 		"    {\n"
4857 		"         result = vec4(1, 0, 0, 1);\n"
4858 		"    }\n"
4859 		"\n"
4860 		"    tcs_tes_result[gl_InvocationID] = result;\n"
4861 		"\n"
4862 		"    gl_TessLevelOuter[0] = 1.0;\n"
4863 		"    gl_TessLevelOuter[1] = 1.0;\n"
4864 		"    gl_TessLevelOuter[2] = 1.0;\n"
4865 		"    gl_TessLevelOuter[3] = 1.0;\n"
4866 		"    gl_TessLevelInner[0] = 1.0;\n"
4867 		"    gl_TessLevelInner[1] = 1.0;\n"
4868 		"}\n"
4869 		"\n";
4870 
4871 	static const GLchar* tess_eval_shader_template = "VERSION\n"
4872 													 "\n"
4873 													 "layout(isolines, point_mode) in;\n"
4874 													 "\n"
4875 													 "in  vec4 tcs_tes_result[];\n"
4876 													 "out vec4 tes_gs_result;\n"
4877 													 "uniform T2 uni_left;\n"
4878 													 "uniform T2 uni_right;\n"
4879 													 "\n"
4880 													 "FUNCTION_DEFINITION"
4881 													 "\n"
4882 													 "void main()\n"
4883 													 "{\n"
4884 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
4885 													 "\n"
4886 													 "VERIFICATION"
4887 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4888 													 "    {\n"
4889 													 "         result = vec4(1, 0, 0, 1);\n"
4890 													 "    }\n"
4891 													 "\n"
4892 													 "    tes_gs_result = result;\n"
4893 													 "}\n"
4894 													 "\n";
4895 
4896 	static const GLchar* vertex_shader_template = "VERSION\n"
4897 												  "\n"
4898 												  "out vec4 vs_tcs_result;\n"
4899 												  "uniform T2 uni_left;\n"
4900 												  "uniform T2 uni_right;\n"
4901 												  "\n"
4902 												  "FUNCTION_DEFINITION"
4903 												  "\n"
4904 												  "void main()\n"
4905 												  "{\n"
4906 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
4907 												  "\n"
4908 												  "VERIFICATION"
4909 												  "\n"
4910 												  "    vs_tcs_result = result;\n"
4911 												  "}\n"
4912 												  "\n";
4913 
4914 	GLuint			   n_rows		   = m_current_test_case_index + 1;
4915 	const GLchar*	  t1			   = Utils::getTypeName(Utils::INT, 1, n_rows);
4916 	const GLchar*	  t2			   = Utils::getTypeName(Utils::UINT, 1, n_rows);
4917 	const std::string& value_list	  = getValueList(n_rows);
4918 	const GLchar*	  shader_template = 0;
4919 
4920 	switch (in_stage)
4921 	{
4922 	case Utils::COMPUTE_SHADER:
4923 		shader_template = compute_shader_template;
4924 		break;
4925 	case Utils::FRAGMENT_SHADER:
4926 		shader_template = fragment_shader_template;
4927 		break;
4928 	case Utils::GEOMETRY_SHADER:
4929 		shader_template = geometry_shader_template;
4930 		break;
4931 	case Utils::TESS_CTRL_SHADER:
4932 		shader_template = tess_ctrl_shader_template;
4933 		break;
4934 	case Utils::TESS_EVAL_SHADER:
4935 		shader_template = tess_eval_shader_template;
4936 		break;
4937 	case Utils::VERTEX_SHADER:
4938 		shader_template = vertex_shader_template;
4939 		break;
4940 	default:
4941 		TCU_FAIL("Invalid enum");
4942 		break;
4943 	}
4944 
4945 	out_source.m_parts[0].m_code = shader_template;
4946 
4947 	size_t position = 0;
4948 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4949 						out_source.m_parts[0].m_code);
4950 
4951 	Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4952 
4953 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4954 
4955 	Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4956 
4957 	Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4958 
4959 	Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4960 }
4961 
4962 /** Get list of values to for glsl constants
4963  *
4964  * @return String with list of values separated with comma
4965  **/
getValueList(glw::GLuint n_rows)4966 std::string ImplicitConversionsInvalidTest::getValueList(glw::GLuint n_rows)
4967 {
4968 	std::string result;
4969 
4970 	for (GLuint i = 0; i < n_rows; ++i)
4971 	{
4972 		if (i != n_rows - 1)
4973 		{
4974 			result.append("1, ");
4975 		}
4976 		else
4977 		{
4978 			result.append("1");
4979 		}
4980 	}
4981 
4982 	return result;
4983 }
4984 
4985 /** Constructor
4986  *
4987  * @param context Test context
4988  **/
ConstDynamicValueTest(deqp::Context & context)4989 ConstDynamicValueTest::ConstDynamicValueTest(deqp::Context& context)
4990 	: GLSLTestBase(context, "const_dynamic_value", "Test if constants can be initialized with dynamic values")
4991 {
4992 	/* Nothing to be done here */
4993 }
4994 
4995 /** Prepare source for given shader stage
4996  *
4997  * @param in_stage           Shader stage, compute shader will use 430
4998  * @param in_use_version_400 Select if 400 or 420 should be used
4999  * @param out_source         Prepared shader source instance
5000  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5001 void ConstDynamicValueTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5002 												Utils::shaderSource& out_source)
5003 {
5004 	static const GLchar* struct_definition = "struct S {\n"
5005 											 "    float scalar;\n"
5006 											 "    vec4  vector;\n"
5007 											 "    mat2  matrix;\n"
5008 											 "};\n";
5009 
5010 	static const GLchar* verification_snippet = "    const float c1     = uni_scalar;\n"
5011 												"    const vec4  c2     = uni_vector;\n"
5012 												"    const mat2  c3     = uni_matrix;\n"
5013 												"    const S     c4     = { uni_scalar, uni_vector, uni_matrix };\n"
5014 												"    const vec4  c5[15] = { uni_vector,\n"
5015 												"                           uni_vector,\n"
5016 												"                           uni_vector,\n"
5017 												"                           uni_vector,\n"
5018 												"                           uni_vector,\n"
5019 												"                           uni_vector,\n"
5020 												"                           uni_vector,\n"
5021 												"                           uni_vector,\n"
5022 												"                           uni_vector,\n"
5023 												"                           uni_vector,\n"
5024 												"                           uni_vector,\n"
5025 												"                           uni_vector,\n"
5026 												"                           uni_vector,\n"
5027 												"                           uni_vector,\n"
5028 												"                           uni_vector };\n"
5029 												"    if ((SCALAR != c1)        ||\n"
5030 												"        (VECTOR != c2)        ||\n"
5031 												"        (MATRIX != c3)        ||\n"
5032 												"        (SCALAR != c4.scalar) ||\n"
5033 												"        (VECTOR != c4.vector) ||\n"
5034 												"        (MATRIX != c4.matrix) ||\n"
5035 												"        (VECTOR != c5[0])     ||\n"
5036 												"        (VECTOR != c5[1])     ||\n"
5037 												"        (VECTOR != c5[2])     ||\n"
5038 												"        (VECTOR != c5[3])     ||\n"
5039 												"        (VECTOR != c5[4])     ||\n"
5040 												"        (VECTOR != c5[5])     ||\n"
5041 												"        (VECTOR != c5[6])     ||\n"
5042 												"        (VECTOR != c5[7])     ||\n"
5043 												"        (VECTOR != c5[8])     ||\n"
5044 												"        (VECTOR != c5[9])     ||\n"
5045 												"        (VECTOR != c5[10])    ||\n"
5046 												"        (VECTOR != c5[11])    ||\n"
5047 												"        (VECTOR != c5[12])    ||\n"
5048 												"        (VECTOR != c5[13])    ||\n"
5049 												"        (VECTOR != c5[14])    )\n"
5050 												"    {\n"
5051 												"        result = vec4(1, 0, 0, 1);\n"
5052 												"    }\n";
5053 
5054 	static const GLchar* compute_shader_template =
5055 		"VERSION\n"
5056 		"\n"
5057 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5058 		"\n"
5059 		"writeonly uniform image2D uni_image;\n"
5060 		"          uniform float uni_scalar;\n"
5061 		"          uniform vec4  uni_vector;\n"
5062 		"          uniform mat2  uni_matrix;\n"
5063 		"\n"
5064 		"STRUCTURE_DEFINITION"
5065 		"\n"
5066 		"void main()\n"
5067 		"{\n"
5068 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5069 		"\n"
5070 		"VERIFICATION"
5071 		"\n"
5072 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5073 		"}\n"
5074 		"\n";
5075 
5076 	static const GLchar* fragment_shader_template = "VERSION\n"
5077 													"\n"
5078 													"in  vec4 gs_fs_result;\n"
5079 													"out vec4 fs_out_result;\n"
5080 													"uniform float uni_scalar;\n"
5081 													"uniform vec4  uni_vector;\n"
5082 													"uniform mat2  uni_matrix;\n"
5083 													"\n"
5084 													"STRUCTURE_DEFINITION"
5085 													"\n"
5086 													"void main()\n"
5087 													"{\n"
5088 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5089 													"\n"
5090 													"VERIFICATION"
5091 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5092 													"    {\n"
5093 													"         result = vec4(1, 0, 0, 1);\n"
5094 													"    }\n"
5095 													"\n"
5096 													"    fs_out_result = result;\n"
5097 													"}\n"
5098 													"\n";
5099 
5100 	static const GLchar* geometry_shader_template = "VERSION\n"
5101 													"\n"
5102 													"layout(points)                           in;\n"
5103 													"layout(triangle_strip, max_vertices = 4) out;\n"
5104 													"\n"
5105 													"in  vec4 tes_gs_result[];\n"
5106 													"out vec4 gs_fs_result;\n"
5107 													"uniform float uni_scalar;\n"
5108 													"uniform vec4  uni_vector;\n"
5109 													"uniform mat2  uni_matrix;\n"
5110 													"\n"
5111 													"STRUCTURE_DEFINITION"
5112 													"\n"
5113 													"void main()\n"
5114 													"{\n"
5115 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5116 													"\n"
5117 													"VERIFICATION"
5118 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5119 													"    {\n"
5120 													"         result = vec4(1, 0, 0, 1);\n"
5121 													"    }\n"
5122 													"\n"
5123 													"    gs_fs_result = result;\n"
5124 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
5125 													"    EmitVertex();\n"
5126 													"    gs_fs_result = result;\n"
5127 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
5128 													"    EmitVertex();\n"
5129 													"    gs_fs_result = result;\n"
5130 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
5131 													"    EmitVertex();\n"
5132 													"    gs_fs_result = result;\n"
5133 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
5134 													"    EmitVertex();\n"
5135 													"}\n"
5136 													"\n";
5137 
5138 	static const GLchar* tess_ctrl_shader_template =
5139 		"VERSION\n"
5140 		"\n"
5141 		"layout(vertices = 1) out;\n"
5142 		"\n"
5143 		"in  vec4 vs_tcs_result[];\n"
5144 		"out vec4 tcs_tes_result[];\n"
5145 		"uniform float uni_scalar;\n"
5146 		"uniform vec4  uni_vector;\n"
5147 		"uniform mat2  uni_matrix;\n"
5148 		"\n"
5149 		"STRUCTURE_DEFINITION"
5150 		"\n"
5151 		"void main()\n"
5152 		"{\n"
5153 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5154 		"\n"
5155 		"VERIFICATION"
5156 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5157 		"    {\n"
5158 		"         result = vec4(1, 0, 0, 1);\n"
5159 		"    }\n"
5160 		"\n"
5161 		"    tcs_tes_result[gl_InvocationID] = result;\n"
5162 		"\n"
5163 		"    gl_TessLevelOuter[0] = 1.0;\n"
5164 		"    gl_TessLevelOuter[1] = 1.0;\n"
5165 		"    gl_TessLevelOuter[2] = 1.0;\n"
5166 		"    gl_TessLevelOuter[3] = 1.0;\n"
5167 		"    gl_TessLevelInner[0] = 1.0;\n"
5168 		"    gl_TessLevelInner[1] = 1.0;\n"
5169 		"}\n"
5170 		"\n";
5171 
5172 	static const GLchar* tess_eval_shader_template = "VERSION\n"
5173 													 "\n"
5174 													 "layout(isolines, point_mode) in;\n"
5175 													 "\n"
5176 													 "in  vec4 tcs_tes_result[];\n"
5177 													 "out vec4 tes_gs_result;\n"
5178 													 "uniform float uni_scalar;\n"
5179 													 "uniform vec4  uni_vector;\n"
5180 													 "uniform mat2  uni_matrix;\n"
5181 													 "\n"
5182 													 "STRUCTURE_DEFINITION"
5183 													 "\n"
5184 													 "void main()\n"
5185 													 "{\n"
5186 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
5187 													 "\n"
5188 													 "VERIFICATION"
5189 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5190 													 "    {\n"
5191 													 "         result = vec4(1, 0, 0, 1);\n"
5192 													 "    }\n"
5193 													 "\n"
5194 													 "    tes_gs_result = result;\n"
5195 													 "}\n"
5196 													 "\n";
5197 
5198 	static const GLchar* vertex_shader_template = "VERSION\n"
5199 												  "\n"
5200 												  "out vec4 vs_tcs_result;\n"
5201 												  "uniform float uni_scalar;\n"
5202 												  "uniform vec4  uni_vector;\n"
5203 												  "uniform mat2  uni_matrix;\n"
5204 												  "\n"
5205 												  "STRUCTURE_DEFINITION"
5206 												  "\n"
5207 												  "void main()\n"
5208 												  "{\n"
5209 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
5210 												  "\n"
5211 												  "VERIFICATION"
5212 												  "\n"
5213 												  "    vs_tcs_result = result;\n"
5214 												  "}\n"
5215 												  "\n";
5216 
5217 	static const GLchar* scalar = "0.5";
5218 	static const GLchar* vector = "vec4(0.5, 0.125, 0.375, 0)";
5219 	static const GLchar* matrix = "mat2(0.5, 0.125, 0.375, 0)";
5220 
5221 	const GLchar* shader_template = 0;
5222 
5223 	switch (in_stage)
5224 	{
5225 	case Utils::COMPUTE_SHADER:
5226 		shader_template = compute_shader_template;
5227 		break;
5228 	case Utils::FRAGMENT_SHADER:
5229 		shader_template = fragment_shader_template;
5230 		break;
5231 	case Utils::GEOMETRY_SHADER:
5232 		shader_template = geometry_shader_template;
5233 		break;
5234 	case Utils::TESS_CTRL_SHADER:
5235 		shader_template = tess_ctrl_shader_template;
5236 		break;
5237 	case Utils::TESS_EVAL_SHADER:
5238 		shader_template = tess_eval_shader_template;
5239 		break;
5240 	case Utils::VERTEX_SHADER:
5241 		shader_template = vertex_shader_template;
5242 		break;
5243 	default:
5244 		TCU_FAIL("Invalid enum");
5245 		break;
5246 	}
5247 
5248 	out_source.m_parts[0].m_code = shader_template;
5249 
5250 	size_t position = 0;
5251 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5252 						out_source.m_parts[0].m_code);
5253 
5254 	Utils::replaceToken("STRUCTURE_DEFINITION", position, struct_definition, out_source.m_parts[0].m_code);
5255 
5256 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5257 
5258 	Utils::replaceAllTokens("SCALAR", scalar, out_source.m_parts[0].m_code);
5259 
5260 	Utils::replaceAllTokens("VECTOR", vector, out_source.m_parts[0].m_code);
5261 
5262 	Utils::replaceAllTokens("MATRIX", matrix, out_source.m_parts[0].m_code);
5263 }
5264 
5265 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
5266  *
5267  * @param program Current program
5268  **/
prepareUniforms(Utils::program & program)5269 void ConstDynamicValueTest::prepareUniforms(Utils::program& program)
5270 {
5271 	static const GLfloat float_data[4] = { 0.5f, 0.125f, 0.375f, 0.0f };
5272 	static const GLfloat scalar		   = 0.5f;
5273 
5274 	program.uniform("uni_scalar", Utils::FLOAT, 1, 1, &scalar);
5275 	program.uniform("uni_vector", Utils::FLOAT, 1, 4, float_data);
5276 	program.uniform("uni_matrix", Utils::FLOAT, 2, 2, float_data);
5277 }
5278 
5279 /** Constructor
5280  *
5281  * @param context Test context
5282  **/
ConstAssignmentTest(deqp::Context & context)5283 ConstAssignmentTest::ConstAssignmentTest(deqp::Context& context)
5284 	: NegativeTestBase(context, "const_assignment", "Verifies that constants cannot be overwritten")
5285 {
5286 	/* Nothing to be done here */
5287 }
5288 
5289 /** Set up next test case
5290  *
5291  * @param test_case_index Index of next test case
5292  *
5293  * @return false if there is no more test cases, true otherwise
5294  **/
prepareNextTestCase(glw::GLuint test_case_index)5295 bool ConstAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
5296 {
5297 	m_current_test_case_index = test_case_index;
5298 
5299 	if ((glw::GLuint)-1 == test_case_index)
5300 	{
5301 		return true;
5302 	}
5303 	else if (2 <= test_case_index)
5304 	{
5305 		return false;
5306 	}
5307 
5308 	return true;
5309 }
5310 
5311 /** Prepare source for given shader stage
5312  *
5313  * @param in_stage           Shader stage, compute shader will use 430
5314  * @param in_use_version_400 Select if 400 or 420 should be used
5315  * @param out_source         Prepared shader source instance
5316  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5317 void ConstAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5318 											  Utils::shaderSource& out_source)
5319 {
5320 	static const GLchar* verification_snippet = "    const float c1 = INIT;\n"
5321 												"\n"
5322 												"    float temp = c1;\n"
5323 												"\n"
5324 												"    for (uint i = 0; i < 4; ++i)"
5325 												"    {\n"
5326 												"        temp += c1 + uni_value;\n"
5327 												"        c1 -= 0.125;\n"
5328 												"    }\n"
5329 												"\n"
5330 												"    if (0.0 == temp)\n"
5331 												"    {\n"
5332 												"        result = vec4(1, 0, 0, 1);\n"
5333 												"    }\n";
5334 
5335 	static const GLchar* compute_shader_template =
5336 		"VERSION\n"
5337 		"\n"
5338 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5339 		"\n"
5340 		"writeonly uniform image2D uni_image;\n"
5341 		"          uniform float uni_value;\n"
5342 		"\n"
5343 		"void main()\n"
5344 		"{\n"
5345 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5346 		"\n"
5347 		"VERIFICATION"
5348 		"\n"
5349 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5350 		"}\n"
5351 		"\n";
5352 
5353 	static const GLchar* fragment_shader_template = "VERSION\n"
5354 													"\n"
5355 													"in  vec4 gs_fs_result;\n"
5356 													"out vec4 fs_out_result;\n"
5357 													"uniform float uni_value;\n"
5358 													"\n"
5359 													"void main()\n"
5360 													"{\n"
5361 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5362 													"\n"
5363 													"VERIFICATION"
5364 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5365 													"    {\n"
5366 													"         result = vec4(1, 0, 0, 1);\n"
5367 													"    }\n"
5368 													"\n"
5369 													"    fs_out_result = result;\n"
5370 													"}\n"
5371 													"\n";
5372 
5373 	static const GLchar* geometry_shader_template = "VERSION\n"
5374 													"\n"
5375 													"layout(points)                           in;\n"
5376 													"layout(triangle_strip, max_vertices = 4) out;\n"
5377 													"\n"
5378 													"in  vec4 tes_gs_result[];\n"
5379 													"out vec4 gs_fs_result;\n"
5380 													"uniform float uni_value;\n"
5381 													"\n"
5382 													"void main()\n"
5383 													"{\n"
5384 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5385 													"\n"
5386 													"VERIFICATION"
5387 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5388 													"    {\n"
5389 													"         result = vec4(1, 0, 0, 1);\n"
5390 													"    }\n"
5391 													"\n"
5392 													"    gs_fs_result = result;\n"
5393 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
5394 													"    EmitVertex();\n"
5395 													"    gs_fs_result = result;\n"
5396 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
5397 													"    EmitVertex();\n"
5398 													"    gs_fs_result = result;\n"
5399 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
5400 													"    EmitVertex();\n"
5401 													"    gs_fs_result = result;\n"
5402 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
5403 													"    EmitVertex();\n"
5404 													"}\n"
5405 													"\n";
5406 
5407 	static const GLchar* tess_ctrl_shader_template =
5408 		"VERSION\n"
5409 		"\n"
5410 		"layout(vertices = 1) out;\n"
5411 		"\n"
5412 		"in  vec4 vs_tcs_result[];\n"
5413 		"out vec4 tcs_tes_result[];\n"
5414 		"uniform float uni_value;\n"
5415 		"\n"
5416 		"void main()\n"
5417 		"{\n"
5418 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5419 		"\n"
5420 		"VERIFICATION"
5421 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5422 		"    {\n"
5423 		"         result = vec4(1, 0, 0, 1);\n"
5424 		"    }\n"
5425 		"\n"
5426 		"    tcs_tes_result[gl_InvocationID] = result;\n"
5427 		"\n"
5428 		"    gl_TessLevelOuter[0] = 1.0;\n"
5429 		"    gl_TessLevelOuter[1] = 1.0;\n"
5430 		"    gl_TessLevelOuter[2] = 1.0;\n"
5431 		"    gl_TessLevelOuter[3] = 1.0;\n"
5432 		"    gl_TessLevelInner[0] = 1.0;\n"
5433 		"    gl_TessLevelInner[1] = 1.0;\n"
5434 		"}\n"
5435 		"\n";
5436 
5437 	static const GLchar* tess_eval_shader_template = "VERSION\n"
5438 													 "\n"
5439 													 "layout(isolines, point_mode) in;\n"
5440 													 "\n"
5441 													 "in  vec4 tcs_tes_result[];\n"
5442 													 "out vec4 tes_gs_result;\n"
5443 													 "uniform float uni_value;\n"
5444 													 "\n"
5445 													 "void main()\n"
5446 													 "{\n"
5447 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
5448 													 "\n"
5449 													 "VERIFICATION"
5450 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5451 													 "    {\n"
5452 													 "         result = vec4(1, 0, 0, 1);\n"
5453 													 "    }\n"
5454 													 "\n"
5455 													 "    tes_gs_result = result;\n"
5456 													 "}\n"
5457 													 "\n";
5458 
5459 	static const GLchar* vertex_shader_template = "VERSION\n"
5460 												  "\n"
5461 												  "out vec4 vs_tcs_result;\n"
5462 												  "uniform float uni_value;\n"
5463 												  "\n"
5464 												  "void main()\n"
5465 												  "{\n"
5466 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
5467 												  "\n"
5468 												  "VERIFICATION"
5469 												  "\n"
5470 												  "    vs_tcs_result = result;\n"
5471 												  "}\n"
5472 												  "\n";
5473 
5474 	static const GLchar* dynamic_init = "uni_value";
5475 	static const GLchar* const_init   = "0.75";
5476 
5477 	const GLchar* shader_template = 0;
5478 	const GLchar* l_init		  = 0;
5479 
5480 	switch (in_stage)
5481 	{
5482 	case Utils::COMPUTE_SHADER:
5483 		shader_template = compute_shader_template;
5484 		break;
5485 	case Utils::FRAGMENT_SHADER:
5486 		shader_template = fragment_shader_template;
5487 		break;
5488 	case Utils::GEOMETRY_SHADER:
5489 		shader_template = geometry_shader_template;
5490 		break;
5491 	case Utils::TESS_CTRL_SHADER:
5492 		shader_template = tess_ctrl_shader_template;
5493 		break;
5494 	case Utils::TESS_EVAL_SHADER:
5495 		shader_template = tess_eval_shader_template;
5496 		break;
5497 	case Utils::VERTEX_SHADER:
5498 		shader_template = vertex_shader_template;
5499 		break;
5500 	default:
5501 		TCU_FAIL("Invalid enum");
5502 		break;
5503 	}
5504 
5505 	if (0 == m_current_test_case_index)
5506 	{
5507 		l_init = dynamic_init;
5508 	}
5509 	else
5510 	{
5511 		l_init = const_init;
5512 	}
5513 
5514 	out_source.m_parts[0].m_code = shader_template;
5515 
5516 	size_t position = 0;
5517 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5518 						out_source.m_parts[0].m_code);
5519 
5520 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5521 
5522 	Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5523 }
5524 
5525 /** Constructor
5526  *
5527  * @param context Test context
5528  **/
ConstDynamicValueAsConstExprTest(deqp::Context & context)5529 ConstDynamicValueAsConstExprTest::ConstDynamicValueAsConstExprTest(deqp::Context& context)
5530 	: NegativeTestBase(context, "const_dynamic_value_as_const_expr",
5531 					   "Verifies that dynamic constants cannot be used as constant foldable expressions")
5532 {
5533 	/* Nothing to be done here */
5534 }
5535 
5536 /** Prepare source for given shader stage
5537  *
5538  * @param in_stage           Shader stage, compute shader will use 430
5539  * @param in_use_version_400 Select if 400 or 420 should be used
5540  * @param out_source         Prepared shader source instance
5541  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5542 void ConstDynamicValueAsConstExprTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5543 														   Utils::shaderSource& out_source)
5544 {
5545 	static const GLchar* verification_snippet = "    const uint c1 = INIT;\n"
5546 												"\n"
5547 												"    float temp[c1];\n"
5548 												"\n"
5549 												"    for (uint i = 0; i < c1; ++i)"
5550 												"    {\n"
5551 												"        temp[i] += uni_value;\n"
5552 												"    }\n"
5553 												"\n"
5554 												"    if (0.0 == temp[c1 - 1])\n"
5555 												"    {\n"
5556 												"        result = vec4(1, 0, 0, 1);\n"
5557 												"    }\n";
5558 
5559 	static const GLchar* compute_shader_template =
5560 		"VERSION\n"
5561 		"\n"
5562 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5563 		"\n"
5564 		"writeonly uniform image2D uni_image;\n"
5565 		"          uniform uint    uni_value;\n"
5566 		"\n"
5567 		"void main()\n"
5568 		"{\n"
5569 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5570 		"\n"
5571 		"VERIFICATION"
5572 		"\n"
5573 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5574 		"}\n"
5575 		"\n";
5576 
5577 	static const GLchar* fragment_shader_template = "VERSION\n"
5578 													"\n"
5579 													"in  vec4 gs_fs_result;\n"
5580 													"out vec4 fs_out_result;\n"
5581 													"uniform uint uni_value;\n"
5582 													"\n"
5583 													"void main()\n"
5584 													"{\n"
5585 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5586 													"\n"
5587 													"VERIFICATION"
5588 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5589 													"    {\n"
5590 													"         result = vec4(1, 0, 0, 1);\n"
5591 													"    }\n"
5592 													"\n"
5593 													"    fs_out_result = result;\n"
5594 													"}\n"
5595 													"\n";
5596 
5597 	static const GLchar* geometry_shader_template = "VERSION\n"
5598 													"\n"
5599 													"layout(points)                           in;\n"
5600 													"layout(triangle_strip, max_vertices = 4) out;\n"
5601 													"\n"
5602 													"in  vec4 tes_gs_result[];\n"
5603 													"out vec4 gs_fs_result;\n"
5604 													"uniform uint uni_value;\n"
5605 													"\n"
5606 													"void main()\n"
5607 													"{\n"
5608 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5609 													"\n"
5610 													"VERIFICATION"
5611 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5612 													"    {\n"
5613 													"         result = vec4(1, 0, 0, 1);\n"
5614 													"    }\n"
5615 													"\n"
5616 													"    gs_fs_result = result;\n"
5617 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
5618 													"    EmitVertex();\n"
5619 													"    gs_fs_result = result;\n"
5620 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
5621 													"    EmitVertex();\n"
5622 													"    gs_fs_result = result;\n"
5623 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
5624 													"    EmitVertex();\n"
5625 													"    gs_fs_result = result;\n"
5626 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
5627 													"    EmitVertex();\n"
5628 													"}\n"
5629 													"\n";
5630 
5631 	static const GLchar* tess_ctrl_shader_template =
5632 		"VERSION\n"
5633 		"\n"
5634 		"layout(vertices = 1) out;\n"
5635 		"\n"
5636 		"in  vec4 vs_tcs_result[];\n"
5637 		"out vec4 tcs_tes_result[];\n"
5638 		"uniform uint uni_value;\n"
5639 		"\n"
5640 		"void main()\n"
5641 		"{\n"
5642 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5643 		"\n"
5644 		"VERIFICATION"
5645 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5646 		"    {\n"
5647 		"         result = vec4(1, 0, 0, 1);\n"
5648 		"    }\n"
5649 		"\n"
5650 		"    tcs_tes_result[gl_InvocationID] = result;\n"
5651 		"\n"
5652 		"    gl_TessLevelOuter[0] = 1.0;\n"
5653 		"    gl_TessLevelOuter[1] = 1.0;\n"
5654 		"    gl_TessLevelOuter[2] = 1.0;\n"
5655 		"    gl_TessLevelOuter[3] = 1.0;\n"
5656 		"    gl_TessLevelInner[0] = 1.0;\n"
5657 		"    gl_TessLevelInner[1] = 1.0;\n"
5658 		"}\n"
5659 		"\n";
5660 
5661 	static const GLchar* tess_eval_shader_template = "VERSION\n"
5662 													 "\n"
5663 													 "layout(isolines, point_mode) in;\n"
5664 													 "\n"
5665 													 "in  vec4 tcs_tes_result[];\n"
5666 													 "out vec4 tes_gs_result;\n"
5667 													 "uniform uint uni_value;\n"
5668 													 "\n"
5669 													 "void main()\n"
5670 													 "{\n"
5671 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
5672 													 "\n"
5673 													 "VERIFICATION"
5674 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5675 													 "    {\n"
5676 													 "         result = vec4(1, 0, 0, 1);\n"
5677 													 "    }\n"
5678 													 "\n"
5679 													 "    tes_gs_result = result;\n"
5680 													 "}\n"
5681 													 "\n";
5682 
5683 	static const GLchar* vertex_shader_template = "VERSION\n"
5684 												  "\n"
5685 												  "out vec4 vs_tcs_result;\n"
5686 												  "uniform uint uni_value;\n"
5687 												  "\n"
5688 												  "void main()\n"
5689 												  "{\n"
5690 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
5691 												  "\n"
5692 												  "VERIFICATION"
5693 												  "\n"
5694 												  "    vs_tcs_result = result;\n"
5695 												  "}\n"
5696 												  "\n";
5697 
5698 	static const GLchar* l_init = "uni_value";
5699 
5700 	const GLchar* shader_template = 0;
5701 
5702 	switch (in_stage)
5703 	{
5704 	case Utils::COMPUTE_SHADER:
5705 		shader_template = compute_shader_template;
5706 		break;
5707 	case Utils::FRAGMENT_SHADER:
5708 		shader_template = fragment_shader_template;
5709 		break;
5710 	case Utils::GEOMETRY_SHADER:
5711 		shader_template = geometry_shader_template;
5712 		break;
5713 	case Utils::TESS_CTRL_SHADER:
5714 		shader_template = tess_ctrl_shader_template;
5715 		break;
5716 	case Utils::TESS_EVAL_SHADER:
5717 		shader_template = tess_eval_shader_template;
5718 		break;
5719 	case Utils::VERTEX_SHADER:
5720 		shader_template = vertex_shader_template;
5721 		break;
5722 	default:
5723 		TCU_FAIL("Invalid enum");
5724 		break;
5725 	}
5726 
5727 	out_source.m_parts[0].m_code = shader_template;
5728 
5729 	size_t position = 0;
5730 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5731 						out_source.m_parts[0].m_code);
5732 
5733 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5734 
5735 	Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5736 }
5737 
5738 /** Constructor
5739  *
5740  * @param context Test context
5741  **/
QualifierOrderTest(deqp::Context & context)5742 QualifierOrderTest::QualifierOrderTest(deqp::Context& context)
5743 	: GLSLTestBase(context, "qualifier_order",
5744 				   "Test verifies that valid permutation of input and output qalifiers are accepted")
5745 {
5746 	/* Nothing to be done */
5747 }
5748 
5749 /** Set up next test case
5750  *
5751  * @param test_case_index Index of next test case
5752  *
5753  * @return false if there is no more test cases, true otherwise
5754  **/
prepareNextTestCase(glw::GLuint test_case_index)5755 bool QualifierOrderTest::prepareNextTestCase(glw::GLuint test_case_index)
5756 {
5757 	m_current_test_case_index = test_case_index;
5758 
5759 	if ((glw::GLuint)-1 == test_case_index)
5760 	{
5761 		/* Nothing to be done here */;
5762 	}
5763 	else if (m_test_cases.size() <= test_case_index)
5764 	{
5765 		return false;
5766 	}
5767 
5768 	const Utils::qualifierSet& set = getCurrentTestCase();
5769 
5770 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
5771 
5772 	for (GLuint i = 0; i < set.size(); ++i)
5773 	{
5774 		message << Utils::getQualifierString(set[i]) << " ";
5775 	}
5776 
5777 	message << tcu::TestLog::EndMessage;
5778 
5779 	return true;
5780 }
5781 
5782 /** Prepare source for given shader stage
5783  *
5784  * @param in_stage           Shader stage, compute shader will use 430
5785  * @param in_use_version_400 Select if 400 or 420 should be used
5786  * @param out_source         Prepared shader source instance
5787  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5788 void QualifierOrderTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5789 											 Utils::shaderSource& out_source)
5790 {
5791 	static const GLchar* verification_snippet =
5792 		"    vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
5793 		"    if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
5794 		"    {\n"
5795 		"        result = INPUT_VARIABLE_NAME;\n"
5796 		"    }\n";
5797 
5798 	static const GLchar* fragment_shader_template = "VERSION\n"
5799 													"\n"
5800 													"in  vec4 gs_fs_result;\n"
5801 													"layout (location = 0) out vec4 fs_out_result;\n"
5802 													"\n"
5803 													"VARIABLE_DECLARATION;\n"
5804 													"VARIABLE_DECLARATION;\n"
5805 													"\n"
5806 													"void main()\n"
5807 													"{\n"
5808 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5809 													"\n"
5810 													"VERIFICATION"
5811 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5812 													"    {\n"
5813 													"         result = vec4(1, 0, 0, 1);\n"
5814 													"    }\n"
5815 													"\n"
5816 													"    fs_out_result = result;\n"
5817 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5818 													"}\n"
5819 													"\n";
5820 
5821 	static const GLchar* geometry_shader_template = "VERSION\n"
5822 													"\n"
5823 													"layout(points)                           in;\n"
5824 													"layout(triangle_strip, max_vertices = 4) out;\n"
5825 													"\n"
5826 													"in  vec4 tes_gs_result[];\n"
5827 													"out vec4 gs_fs_result;\n"
5828 													"\n"
5829 													"VARIABLE_DECLARATION;\n"
5830 													"VARIABLE_DECLARATION;\n"
5831 													"\n"
5832 													"void main()\n"
5833 													"{\n"
5834 													"    vec4 result = vec4(0, 1, 0, 1);\n"
5835 													"\n"
5836 													"VERIFICATION"
5837 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5838 													"    {\n"
5839 													"         result = vec4(1, 0, 0, 1);\n"
5840 													"    }\n"
5841 													"\n"
5842 													"    gs_fs_result = result;\n"
5843 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5844 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
5845 													"    EmitVertex();\n"
5846 													"    gs_fs_result = result;\n"
5847 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5848 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
5849 													"    EmitVertex();\n"
5850 													"    gs_fs_result = result;\n"
5851 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5852 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
5853 													"    EmitVertex();\n"
5854 													"    gs_fs_result = result;\n"
5855 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5856 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
5857 													"    EmitVertex();\n"
5858 													"}\n"
5859 													"\n";
5860 
5861 	static const GLchar* tess_ctrl_shader_template =
5862 		"VERSION\n"
5863 		"\n"
5864 		"layout(vertices = 1) out;\n"
5865 		"\n"
5866 		"in  vec4 vs_tcs_result[];\n"
5867 		"out vec4 tcs_tes_result[];\n"
5868 		"\n"
5869 		"VARIABLE_DECLARATION;\n"
5870 		"VARIABLE_DECLARATION;\n"
5871 		"\n"
5872 		"void main()\n"
5873 		"{\n"
5874 		"    vec4 result = vec4(0, 1, 0, 1);\n"
5875 		"\n"
5876 		"VERIFICATION"
5877 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5878 		"    {\n"
5879 		"         result = vec4(1, 0, 0, 1);\n"
5880 		"    }\n"
5881 		"\n"
5882 		"    tcs_tes_result[gl_InvocationID] = result;\n"
5883 		"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5884 		"\n"
5885 		"    gl_TessLevelOuter[0] = 1.0;\n"
5886 		"    gl_TessLevelOuter[1] = 1.0;\n"
5887 		"    gl_TessLevelOuter[2] = 1.0;\n"
5888 		"    gl_TessLevelOuter[3] = 1.0;\n"
5889 		"    gl_TessLevelInner[0] = 1.0;\n"
5890 		"    gl_TessLevelInner[1] = 1.0;\n"
5891 		"}\n"
5892 		"\n";
5893 
5894 	static const GLchar* tess_eval_shader_template = "VERSION\n"
5895 													 "\n"
5896 													 "layout(isolines, point_mode) in;\n"
5897 													 "\n"
5898 													 "in  vec4 tcs_tes_result[];\n"
5899 													 "out vec4 tes_gs_result;\n"
5900 													 "\n"
5901 													 "VARIABLE_DECLARATION;\n"
5902 													 "VARIABLE_DECLARATION;\n"
5903 													 "\n"
5904 													 "void main()\n"
5905 													 "{\n"
5906 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
5907 													 "\n"
5908 													 "VERIFICATION"
5909 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5910 													 "    {\n"
5911 													 "         result = vec4(1, 0, 0, 1);\n"
5912 													 "    }\n"
5913 													 "\n"
5914 													 "    tes_gs_result = result;\n"
5915 													 "    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5916 													 "}\n"
5917 													 "\n";
5918 
5919 	static const GLchar* vertex_shader_template = "VERSION\n"
5920 												  "\n"
5921 												  "out vec4 vs_tcs_result;\n"
5922 												  "\n"
5923 												  "VARIABLE_DECLARATION;\n"
5924 												  "VARIABLE_DECLARATION;\n"
5925 												  "\n"
5926 												  "void main()\n"
5927 												  "{\n"
5928 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
5929 												  "\n"
5930 												  "VERIFICATION"
5931 												  "\n"
5932 												  "    vs_tcs_result = result;\n"
5933 												  "    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5934 												  "}\n"
5935 												  "\n";
5936 
5937 	const GLchar* shader_template = 0;
5938 
5939 	switch (in_stage)
5940 	{
5941 	case Utils::COMPUTE_SHADER:
5942 		return;
5943 		break;
5944 	case Utils::FRAGMENT_SHADER:
5945 		shader_template = fragment_shader_template;
5946 		break;
5947 	case Utils::GEOMETRY_SHADER:
5948 		shader_template = geometry_shader_template;
5949 		break;
5950 	case Utils::TESS_CTRL_SHADER:
5951 		shader_template = tess_ctrl_shader_template;
5952 		break;
5953 	case Utils::TESS_EVAL_SHADER:
5954 		shader_template = tess_eval_shader_template;
5955 		break;
5956 	case Utils::VERTEX_SHADER:
5957 		shader_template = vertex_shader_template;
5958 		break;
5959 	default:
5960 		TCU_FAIL("Invalid enum");
5961 		break;
5962 	}
5963 
5964 	const Utils::qualifierSet& test_case = getCurrentTestCase();
5965 
5966 	std::string in_test_decl;
5967 	std::string in_test_ref;
5968 	std::string out_test_decl;
5969 	std::string out_test_ref;
5970 
5971 	Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
5972 	Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
5973 
5974 	// sample storage qualifier is not a valid qualifier for fragment output
5975 	if (in_stage == Utils::FRAGMENT_SHADER)
5976 	{
5977 		if (out_test_decl.find("sample") != std::string::npos)
5978 			out_test_decl.erase(out_test_decl.find("sample"), 7);
5979 	}
5980 
5981 	out_source.m_parts[0].m_code = shader_template;
5982 
5983 	size_t position = 0;
5984 
5985 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5986 						out_source.m_parts[0].m_code);
5987 
5988 	Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
5989 
5990 	Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
5991 
5992 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5993 
5994 	position -= strlen(verification_snippet);
5995 
5996 	Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
5997 
5998 	Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
5999 
6000 	Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
6001 }
6002 
6003 /**Prepare vertex buffer and vertex array object.
6004  *
6005  * @param program Program instance
6006  * @param buffer  Buffer instance
6007  * @param vao     VertexArray instance
6008  *
6009  * @return 0
6010  **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)6011 void QualifierOrderTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
6012 											 Utils::vertexArray& vao)
6013 {
6014 	std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
6015 	GLint		test_loc  = program.getAttribLocation(test_name.c_str());
6016 
6017 	if (-1 == test_loc)
6018 	{
6019 		TCU_FAIL("Vertex attribute location is invalid");
6020 	}
6021 
6022 	vao.generate();
6023 	vao.bind();
6024 
6025 	buffer.generate(GL_ARRAY_BUFFER);
6026 
6027 	GLfloat	data[]	= { 0.0f, 0.0f, 1.0f, 1.0f };
6028 	GLsizeiptr data_size = sizeof(data);
6029 
6030 	buffer.update(data_size, data, GL_STATIC_DRAW);
6031 
6032 	/* GL entry points */
6033 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6034 
6035 	/* Set up vao */
6036 	gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6037 						   0 /* offset */);
6038 	GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6039 
6040 	/* Enable attribute */
6041 	gl.enableVertexAttribArray(test_loc);
6042 	GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6043 }
6044 
6045 /** Prepare test cases
6046  *
6047  * @return true
6048  **/
testInit()6049 bool QualifierOrderTest::testInit()
6050 {
6051 	m_test_cases.resize(5);
6052 
6053 	m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6054 	m_test_cases[0].push_back(Utils::QUAL_IN);
6055 	m_test_cases[0].push_back(Utils::QUAL_LOCATION);
6056 	m_test_cases[0].push_back(Utils::QUAL_SMOOTH);
6057 	m_test_cases[0].push_back(Utils::QUAL_INVARIANT);
6058 
6059 	m_test_cases[1].push_back(Utils::QUAL_LOWP);
6060 	m_test_cases[1].push_back(Utils::QUAL_IN);
6061 	m_test_cases[1].push_back(Utils::QUAL_SAMPLE);
6062 	m_test_cases[1].push_back(Utils::QUAL_LOCATION);
6063 	m_test_cases[1].push_back(Utils::QUAL_NOPERSPECTIVE);
6064 	m_test_cases[1].push_back(Utils::QUAL_INVARIANT);
6065 
6066 	m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6067 	m_test_cases[2].push_back(Utils::QUAL_IN);
6068 	m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6069 	m_test_cases[2].push_back(Utils::QUAL_SMOOTH);
6070 	m_test_cases[2].push_back(Utils::QUAL_INVARIANT);
6071 	m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6072 
6073 	m_test_cases[3].push_back(Utils::QUAL_LOWP);
6074 	m_test_cases[3].push_back(Utils::QUAL_IN);
6075 	m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6076 	m_test_cases[3].push_back(Utils::QUAL_SAMPLE);
6077 	m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6078 	m_test_cases[3].push_back(Utils::QUAL_NOPERSPECTIVE);
6079 	m_test_cases[3].push_back(Utils::QUAL_INVARIANT);
6080 
6081 	m_test_cases[4].push_back(Utils::QUAL_HIGHP);
6082 	m_test_cases[4].push_back(Utils::QUAL_IN);
6083 	m_test_cases[4].push_back(Utils::QUAL_PATCH);
6084 	m_test_cases[4].push_back(Utils::QUAL_LOCATION);
6085 	m_test_cases[4].push_back(Utils::QUAL_INVARIANT);
6086 
6087 	return true;
6088 }
6089 
6090 /** Returns reference to current test case
6091  *
6092  * @return Reference to testCase
6093  **/
getCurrentTestCase()6094 const Utils::qualifierSet& QualifierOrderTest::getCurrentTestCase()
6095 {
6096 	if ((glw::GLuint)-1 == m_current_test_case_index)
6097 	{
6098 		return m_test_cases[0];
6099 	}
6100 	else
6101 	{
6102 		return m_test_cases[m_current_test_case_index];
6103 	}
6104 }
6105 
6106 /** Constructor
6107  *
6108  * @param context Test context
6109  **/
QualifierOrderBlockTest(deqp::Context & context)6110 QualifierOrderBlockTest::QualifierOrderBlockTest(deqp::Context& context)
6111 	: GLSLTestBase(context, "qualifier_order_block",
6112 				   "Verifies that qualifiers of members of input block can be arranged in any order")
6113 {
6114 	/* Nothing to be done here */
6115 }
6116 
6117 /** Set up next test case
6118  *
6119  * @param test_case_index Index of next test case
6120  *
6121  * @return false if there is no more test cases, true otherwise
6122  **/
prepareNextTestCase(glw::GLuint test_case_index)6123 bool QualifierOrderBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
6124 {
6125 	m_current_test_case_index = test_case_index;
6126 
6127 	if ((glw::GLuint)-1 == test_case_index)
6128 	{
6129 		/* Nothing to be done here */;
6130 	}
6131 	else if (m_test_cases.size() <= test_case_index)
6132 	{
6133 		return false;
6134 	}
6135 
6136 	const Utils::qualifierSet& set = getCurrentTestCase();
6137 
6138 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6139 
6140 	for (GLuint i = 0; i < set.size(); ++i)
6141 	{
6142 		message << Utils::getQualifierString(set[i]) << " ";
6143 	}
6144 
6145 	message << tcu::TestLog::EndMessage;
6146 
6147 	return true;
6148 }
6149 
6150 /** Prepare source for given shader stage
6151  *
6152  * @param in_stage           Shader stage, compute shader will use 430
6153  * @param in_use_version_400 Select if 400 or 420 should be used
6154  * @param out_source         Prepared shader source instance
6155  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6156 void QualifierOrderBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6157 												  Utils::shaderSource& out_source)
6158 {
6159 	static const GLchar* verification_snippet =
6160 		"    vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6161 		"    if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6162 		"    {\n"
6163 		"        result = INPUT_VARIABLE_NAME;\n"
6164 		"    }\n";
6165 
6166 	static const GLchar* fragment_shader_template = "VERSION\n"
6167 													"\n"
6168 													"in  vec4 gs_fs_result;\n"
6169 													"layout (location = 0) out vec4 fs_out_result;\n"
6170 													"\n"
6171 													"in GSOutputBlock {\n"
6172 													"    VARIABLE_DECLARATION;\n"
6173 													"} input_block;\n"
6174 													"out VARIABLE_DECLARATION;\n"
6175 													"\n"
6176 													"void main()\n"
6177 													"{\n"
6178 													"    vec4 result = vec4(0, 1, 0, 1);\n"
6179 													"\n"
6180 													"VERIFICATION"
6181 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6182 													"    {\n"
6183 													"         result = vec4(1, 0, 0, 1);\n"
6184 													"    }\n"
6185 													"\n"
6186 													"    fs_out_result = result;\n"
6187 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6188 													"}\n"
6189 													"\n";
6190 
6191 	static const GLchar* geometry_shader_template = "VERSION\n"
6192 													"\n"
6193 													"layout(points)                           in;\n"
6194 													"layout(triangle_strip, max_vertices = 4) out;\n"
6195 													"\n"
6196 													"in  vec4 tes_gs_result[];\n"
6197 													"out vec4 gs_fs_result;\n"
6198 													"\n"
6199 													"in TCSOutputBlock {\n"
6200 													"    VARIABLE_DECLARATION;\n"
6201 													"} input_block [];\n"
6202 													"out GSOutputBlock {\n"
6203 													"    VARIABLE_DECLARATION;\n"
6204 													"} output_block;\n"
6205 													"\n"
6206 													"void main()\n"
6207 													"{\n"
6208 													"    vec4 result = vec4(0, 1, 0, 1);\n"
6209 													"\n"
6210 													"VERIFICATION"
6211 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6212 													"    {\n"
6213 													"         result = vec4(1, 0, 0, 1);\n"
6214 													"    }\n"
6215 													"\n"
6216 													"    gs_fs_result = result;\n"
6217 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6218 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
6219 													"    EmitVertex();\n"
6220 													"    gs_fs_result = result;\n"
6221 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6222 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
6223 													"    EmitVertex();\n"
6224 													"    gs_fs_result = result;\n"
6225 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6226 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
6227 													"    EmitVertex();\n"
6228 													"    gs_fs_result = result;\n"
6229 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6230 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
6231 													"    EmitVertex();\n"
6232 													"}\n"
6233 													"\n";
6234 
6235 	static const GLchar* tess_ctrl_shader_template =
6236 		"VERSION\n"
6237 		"\n"
6238 		"layout(vertices = 1) out;\n"
6239 		"\n"
6240 		"in  vec4 vs_tcs_result[];\n"
6241 		"out vec4 tcs_tes_result[];\n"
6242 		"\n"
6243 		"in VSOutputBlock {\n"
6244 		"    VARIABLE_DECLARATION;\n"
6245 		"} input_block [];\n"
6246 		"out TCSOutputBlock {\n"
6247 		"    VARIABLE_DECLARATION;\n"
6248 		"} output_block [];\n"
6249 		"\n"
6250 		"void main()\n"
6251 		"{\n"
6252 		"    vec4 result = vec4(0, 1, 0, 1);\n"
6253 		"\n"
6254 		"VERIFICATION"
6255 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6256 		"    {\n"
6257 		"         result = vec4(1, 0, 0, 1);\n"
6258 		"    }\n"
6259 		"\n"
6260 		"    tcs_tes_result[gl_InvocationID] = result;\n"
6261 		"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6262 		"\n"
6263 		"    gl_TessLevelOuter[0] = 1.0;\n"
6264 		"    gl_TessLevelOuter[1] = 1.0;\n"
6265 		"    gl_TessLevelOuter[2] = 1.0;\n"
6266 		"    gl_TessLevelOuter[3] = 1.0;\n"
6267 		"    gl_TessLevelInner[0] = 1.0;\n"
6268 		"    gl_TessLevelInner[1] = 1.0;\n"
6269 		"}\n"
6270 		"\n";
6271 
6272 	static const GLchar* tess_eval_shader_template = "VERSION\n"
6273 													 "\n"
6274 													 "layout(isolines, point_mode) in;\n"
6275 													 "\n"
6276 													 "in  vec4 tcs_tes_result[];\n"
6277 													 "out vec4 tes_gs_result;\n"
6278 													 "\n"
6279 													 "in TCSOutputBlock {\n"
6280 													 "    VARIABLE_DECLARATION;\n"
6281 													 "} input_block [];\n"
6282 													 "out TCSOutputBlock {\n"
6283 													 "    VARIABLE_DECLARATION;\n"
6284 													 "} output_block;\n"
6285 													 "\n"
6286 													 "void main()\n"
6287 													 "{\n"
6288 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
6289 													 "\n"
6290 													 "VERIFICATION"
6291 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6292 													 "    {\n"
6293 													 "         result = vec4(1, 0, 0, 1);\n"
6294 													 "    }\n"
6295 													 "\n"
6296 													 "    tes_gs_result = result;\n"
6297 													 "    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6298 													 "}\n"
6299 													 "\n";
6300 
6301 	static const GLchar* vertex_shader_template = "VERSION\n"
6302 												  "\n"
6303 												  "out vec4 vs_tcs_result;\n"
6304 												  "\n"
6305 												  "in VARIABLE_DECLARATION;\n"
6306 												  "out VSOutputBlock {\n"
6307 												  "    VARIABLE_DECLARATION;\n"
6308 												  "} output_block;\n"
6309 												  "\n"
6310 												  "void main()\n"
6311 												  "{\n"
6312 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
6313 												  "\n"
6314 												  "VERIFICATION"
6315 												  "\n"
6316 												  "    vs_tcs_result = result;\n"
6317 												  "    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6318 												  "}\n"
6319 												  "\n";
6320 
6321 	const GLchar* shader_template = 0;
6322 
6323 	switch (in_stage)
6324 	{
6325 	case Utils::COMPUTE_SHADER:
6326 		return;
6327 		break;
6328 	case Utils::FRAGMENT_SHADER:
6329 		shader_template = fragment_shader_template;
6330 		break;
6331 	case Utils::GEOMETRY_SHADER:
6332 		shader_template = geometry_shader_template;
6333 		break;
6334 	case Utils::TESS_CTRL_SHADER:
6335 		shader_template = tess_ctrl_shader_template;
6336 		break;
6337 	case Utils::TESS_EVAL_SHADER:
6338 		shader_template = tess_eval_shader_template;
6339 		break;
6340 	case Utils::VERTEX_SHADER:
6341 		shader_template = vertex_shader_template;
6342 		break;
6343 	default:
6344 		TCU_FAIL("Invalid enum");
6345 		break;
6346 	}
6347 
6348 	const Utils::qualifierSet& test_case = getCurrentTestCase();
6349 
6350 	std::string in_test_decl;
6351 	std::string in_test_ref;
6352 	std::string out_test_decl;
6353 	std::string out_test_ref;
6354 
6355 	switch (in_stage)
6356 	{
6357 	case Utils::VERTEX_SHADER:
6358 		Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
6359 		break;
6360 	default:
6361 		Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", "input_block",
6362 										   in_test_decl, in_test_ref);
6363 		break;
6364 	}
6365 
6366 	switch (in_stage)
6367 	{
6368 	case Utils::FRAGMENT_SHADER:
6369 		Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
6370 		break;
6371 	default:
6372 		Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", "output_block",
6373 										   out_test_decl, out_test_ref);
6374 		break;
6375 	}
6376 
6377 	// sample storage qualifier is not a valid qualifier for fragment output
6378 	if (in_stage == Utils::FRAGMENT_SHADER)
6379 	{
6380 		if (out_test_decl.find("sample") != std::string::npos)
6381 			out_test_decl.erase(out_test_decl.find("sample"), 7);
6382 	}
6383 	out_source.m_parts[0].m_code = shader_template;
6384 
6385 	size_t position = 0;
6386 
6387 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6388 						out_source.m_parts[0].m_code);
6389 
6390 	Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
6391 
6392 	Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
6393 
6394 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6395 
6396 	position -= strlen(verification_snippet);
6397 
6398 	Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
6399 
6400 	Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
6401 
6402 	Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
6403 }
6404 
6405 /**Prepare vertex buffer and vertex array object.
6406  *
6407  * @param program Program instance
6408  * @param buffer  Buffer instance
6409  * @param vao     VertexArray instance
6410  *
6411  * @return 0
6412  **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)6413 void QualifierOrderBlockTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
6414 												  Utils::vertexArray& vao)
6415 {
6416 	std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
6417 	GLint		test_loc  = program.getAttribLocation(test_name.c_str());
6418 
6419 	if (-1 == test_loc)
6420 	{
6421 		TCU_FAIL("Vertex attribute location is invalid");
6422 	}
6423 
6424 	vao.generate();
6425 	vao.bind();
6426 
6427 	buffer.generate(GL_ARRAY_BUFFER);
6428 
6429 	GLfloat	data[]	= { 0.0f, 0.0f, 1.0f, 1.0f };
6430 	GLsizeiptr data_size = sizeof(data);
6431 
6432 	buffer.update(data_size, data, GL_STATIC_DRAW);
6433 
6434 	/* GL entry points */
6435 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6436 
6437 	/* Set up vao */
6438 	gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6439 						   0 /* offset */);
6440 	GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6441 
6442 	/* Enable attribute */
6443 	gl.enableVertexAttribArray(test_loc);
6444 	GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6445 }
6446 
6447 /** Prepare test cases
6448  *
6449  * @return true
6450  **/
testInit()6451 bool QualifierOrderBlockTest::testInit()
6452 {
6453 	m_test_cases.resize(4);
6454 
6455 	m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6456 	m_test_cases[0].push_back(Utils::QUAL_FLAT);
6457 	m_test_cases[0].push_back(Utils::QUAL_INVARIANT);
6458 
6459 	m_test_cases[1].push_back(Utils::QUAL_LOWP);
6460 	m_test_cases[1].push_back(Utils::QUAL_SAMPLE);
6461 	m_test_cases[1].push_back(Utils::QUAL_NOPERSPECTIVE);
6462 	m_test_cases[1].push_back(Utils::QUAL_INVARIANT);
6463 
6464 	m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6465 	m_test_cases[2].push_back(Utils::QUAL_SMOOTH);
6466 	m_test_cases[2].push_back(Utils::QUAL_INVARIANT);
6467 
6468 	m_test_cases[3].push_back(Utils::QUAL_LOWP);
6469 	m_test_cases[3].push_back(Utils::QUAL_SAMPLE);
6470 	m_test_cases[3].push_back(Utils::QUAL_NOPERSPECTIVE);
6471 	m_test_cases[3].push_back(Utils::QUAL_INVARIANT);
6472 
6473 	return true;
6474 }
6475 
6476 /** Returns reference to current test case
6477  *
6478  * @return Reference to testCase
6479  **/
getCurrentTestCase()6480 const Utils::qualifierSet& QualifierOrderBlockTest::getCurrentTestCase()
6481 {
6482 	if ((glw::GLuint)-1 == m_current_test_case_index)
6483 	{
6484 		return m_test_cases[0];
6485 	}
6486 	else
6487 	{
6488 		return m_test_cases[m_current_test_case_index];
6489 	}
6490 }
6491 
6492 /** Constructor
6493  *
6494  * @param context Test context
6495  **/
QualifierOrderUniformTest(deqp::Context & context)6496 QualifierOrderUniformTest::QualifierOrderUniformTest(deqp::Context& context)
6497 	: GLSLTestBase(context, "qualifier_order_uniform",
6498 				   "Test verifies that all valid permutation of input qalifiers are accepted")
6499 {
6500 	/* Nothing to be done here */
6501 }
6502 
6503 /** Set up next test case
6504  *
6505  * @param test_case_index Index of next test case
6506  *
6507  * @return false if there is no more test cases, true otherwise
6508  **/
prepareNextTestCase(glw::GLuint test_case_index)6509 bool QualifierOrderUniformTest::prepareNextTestCase(glw::GLuint test_case_index)
6510 {
6511 	m_current_test_case_index = test_case_index;
6512 
6513 	if ((glw::GLuint)-1 == test_case_index)
6514 	{
6515 		/* Nothing to be done here */;
6516 	}
6517 	else if (m_test_cases.size() <= test_case_index)
6518 	{
6519 		return false;
6520 	}
6521 
6522 	const Utils::qualifierSet& set = getCurrentTestCase();
6523 
6524 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6525 
6526 	for (GLuint i = 0; i < set.size(); ++i)
6527 	{
6528 		message << Utils::getQualifierString(set[i]) << " ";
6529 	}
6530 
6531 	message << tcu::TestLog::EndMessage;
6532 
6533 	return true;
6534 }
6535 
6536 /** Prepare source for given shader stage
6537  *
6538  * @param in_stage           Shader stage, compute shader will use 430
6539  * @param in_use_version_400 Select if 400 or 420 should be used
6540  * @param out_source         Prepared shader source instance
6541  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6542 void QualifierOrderUniformTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6543 													Utils::shaderSource& out_source)
6544 {
6545 	static const GLchar* verification_snippet =
6546 		"    vec4 diff = VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6547 		"    if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6548 		"    {\n"
6549 		"        result = VARIABLE_NAME;\n"
6550 		"    }\n";
6551 
6552 	static const GLchar* variable_declaration = "    QUALIFIERS VARIABLE_NAME";
6553 
6554 	static const GLchar* fragment_shader_template = "VERSION\n"
6555 													"#extension GL_ARB_explicit_uniform_location : enable\n"
6556 													"\n"
6557 													"in  vec4 gs_fs_result;\n"
6558 													"out vec4 fs_out_result;\n"
6559 													"\n"
6560 													"VARIABLE_DECLARATION;\n"
6561 													"\n"
6562 													"void main()\n"
6563 													"{\n"
6564 													"    vec4 result = vec4(0, 1, 0, 1);\n"
6565 													"\n"
6566 													"VERIFICATION"
6567 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6568 													"    {\n"
6569 													"         result = vec4(1, 0, 0, 1);\n"
6570 													"    }\n"
6571 													"\n"
6572 													"    fs_out_result = result;\n"
6573 													"}\n"
6574 													"\n";
6575 
6576 	static const GLchar* geometry_shader_template = "VERSION\n"
6577 													"#extension GL_ARB_explicit_uniform_location : enable\n"
6578 													"\n"
6579 													"layout(points)                           in;\n"
6580 													"layout(triangle_strip, max_vertices = 4) out;\n"
6581 													"\n"
6582 													"in  vec4 tes_gs_result[];\n"
6583 													"out vec4 gs_fs_result;\n"
6584 													"\n"
6585 													"VARIABLE_DECLARATION;\n"
6586 													"\n"
6587 													"void main()\n"
6588 													"{\n"
6589 													"    vec4 result = vec4(0, 1, 0, 1);\n"
6590 													"\n"
6591 													"VERIFICATION"
6592 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6593 													"    {\n"
6594 													"         result = vec4(1, 0, 0, 1);\n"
6595 													"    }\n"
6596 													"\n"
6597 													"    gs_fs_result = result;\n"
6598 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
6599 													"    EmitVertex();\n"
6600 													"    gs_fs_result = result;\n"
6601 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
6602 													"    EmitVertex();\n"
6603 													"    gs_fs_result = result;\n"
6604 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
6605 													"    EmitVertex();\n"
6606 													"    gs_fs_result = result;\n"
6607 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
6608 													"    EmitVertex();\n"
6609 													"}\n"
6610 													"\n";
6611 
6612 	static const GLchar* tess_ctrl_shader_template =
6613 		"VERSION\n"
6614 		"#extension GL_ARB_explicit_uniform_location : enable\n"
6615 		"\n"
6616 		"layout(vertices = 1) out;\n"
6617 		"\n"
6618 		"in  vec4 vs_tcs_result[];\n"
6619 		"out vec4 tcs_tes_result[];\n"
6620 		"\n"
6621 		"VARIABLE_DECLARATION;\n"
6622 		"\n"
6623 		"void main()\n"
6624 		"{\n"
6625 		"    vec4 result = vec4(0, 1, 0, 1);\n"
6626 		"\n"
6627 		"VERIFICATION"
6628 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6629 		"    {\n"
6630 		"         result = vec4(1, 0, 0, 1);\n"
6631 		"    }\n"
6632 		"\n"
6633 		"    tcs_tes_result[gl_InvocationID] = result;\n"
6634 		"\n"
6635 		"    gl_TessLevelOuter[0] = 1.0;\n"
6636 		"    gl_TessLevelOuter[1] = 1.0;\n"
6637 		"    gl_TessLevelOuter[2] = 1.0;\n"
6638 		"    gl_TessLevelOuter[3] = 1.0;\n"
6639 		"    gl_TessLevelInner[0] = 1.0;\n"
6640 		"    gl_TessLevelInner[1] = 1.0;\n"
6641 		"}\n"
6642 		"\n";
6643 
6644 	static const GLchar* tess_eval_shader_template = "VERSION\n"
6645 													 "#extension GL_ARB_explicit_uniform_location : enable\n"
6646 													 "\n"
6647 													 "layout(isolines, point_mode) in;\n"
6648 													 "\n"
6649 													 "in  vec4 tcs_tes_result[];\n"
6650 													 "out vec4 tes_gs_result;\n"
6651 													 "\n"
6652 													 "VARIABLE_DECLARATION;\n"
6653 													 "\n"
6654 													 "void main()\n"
6655 													 "{\n"
6656 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
6657 													 "\n"
6658 													 "VERIFICATION"
6659 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6660 													 "    {\n"
6661 													 "         result = vec4(1, 0, 0, 1);\n"
6662 													 "    }\n"
6663 													 "\n"
6664 													 "    tes_gs_result = result;\n"
6665 													 "}\n"
6666 													 "\n";
6667 
6668 	static const GLchar* vertex_shader_template = "VERSION\n"
6669 												  "#extension GL_ARB_explicit_uniform_location : enable\n"
6670 												  "\n"
6671 												  "out vec4 vs_tcs_result;\n"
6672 												  "\n"
6673 												  "VARIABLE_DECLARATION;\n"
6674 												  "\n"
6675 												  "void main()\n"
6676 												  "{\n"
6677 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
6678 												  "\n"
6679 												  "VERIFICATION"
6680 												  "\n"
6681 												  "    vs_tcs_result = result;\n"
6682 												  "}\n"
6683 												  "\n";
6684 
6685 	const GLchar* shader_template = 0;
6686 	const GLchar* location_string = 0;
6687 
6688 	switch (in_stage)
6689 	{
6690 	case Utils::COMPUTE_SHADER:
6691 		return;
6692 		break;
6693 	case Utils::FRAGMENT_SHADER:
6694 		shader_template = fragment_shader_template;
6695 		location_string = "0";
6696 		break;
6697 	case Utils::GEOMETRY_SHADER:
6698 		shader_template = geometry_shader_template;
6699 		location_string = "1";
6700 		break;
6701 	case Utils::TESS_CTRL_SHADER:
6702 		shader_template = tess_ctrl_shader_template;
6703 		location_string = "4";
6704 		break;
6705 	case Utils::TESS_EVAL_SHADER:
6706 		shader_template = tess_eval_shader_template;
6707 		location_string = "3";
6708 		break;
6709 	case Utils::VERTEX_SHADER:
6710 		shader_template = vertex_shader_template;
6711 		location_string = "2";
6712 		break;
6713 	default:
6714 		TCU_FAIL("Invalid enum");
6715 		break;
6716 	}
6717 
6718 	const Utils::qualifierSet& test_case = getCurrentTestCase();
6719 
6720 	std::string uni_declaration;
6721 	std::string uni_reference;
6722 	Utils::prepareVariableStrings(in_stage, Utils::UNIFORM, test_case, "vec4", "test", uni_declaration, uni_reference);
6723 
6724 	out_source.m_parts[0].m_code = shader_template;
6725 
6726 	size_t position = 0;
6727 
6728 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6729 						out_source.m_parts[0].m_code);
6730 
6731 	Utils::replaceToken("VARIABLE_DECLARATION", position, uni_declaration.c_str(), out_source.m_parts[0].m_code);
6732 
6733 	position -= strlen(variable_declaration);
6734 
6735 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6736 
6737 	Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
6738 
6739 	Utils::replaceAllTokens("LOC_VALUE", location_string, out_source.m_parts[0].m_code);
6740 }
6741 
6742 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
6743  *
6744  * @param program Current program
6745  **/
prepareUniforms(Utils::program & program)6746 void QualifierOrderUniformTest::prepareUniforms(Utils::program& program)
6747 {
6748 	static const GLfloat float_data[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
6749 
6750 	program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6751 	program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6752 	program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6753 	program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6754 	program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6755 }
6756 
6757 /** Prepare test cases
6758  *
6759  * @return false if ARB_explicit_uniform_location is not supported, true otherwise
6760  **/
testInit()6761 bool QualifierOrderUniformTest::testInit()
6762 {
6763 	if (false == m_is_explicit_uniform_location)
6764 	{
6765 		return false;
6766 	}
6767 
6768 	m_test_cases.resize(4);
6769 
6770 	m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6771 	m_test_cases[0].push_back(Utils::QUAL_UNIFORM);
6772 	m_test_cases[0].push_back(Utils::QUAL_LOCATION);
6773 
6774 	m_test_cases[1].push_back(Utils::QUAL_LOWP);
6775 	m_test_cases[1].push_back(Utils::QUAL_UNIFORM);
6776 	m_test_cases[1].push_back(Utils::QUAL_LOCATION);
6777 
6778 	m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6779 	m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6780 	m_test_cases[2].push_back(Utils::QUAL_UNIFORM);
6781 	m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6782 
6783 	m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6784 	m_test_cases[3].push_back(Utils::QUAL_LOWP);
6785 	m_test_cases[3].push_back(Utils::QUAL_UNIFORM);
6786 	m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6787 
6788 	return true;
6789 }
6790 
6791 /** Returns reference to current test case
6792  *
6793  * @return Reference to testCase
6794  **/
getCurrentTestCase()6795 const Utils::qualifierSet& QualifierOrderUniformTest::getCurrentTestCase()
6796 {
6797 	if ((glw::GLuint)-1 == m_current_test_case_index)
6798 	{
6799 		return m_test_cases[0];
6800 	}
6801 	else
6802 	{
6803 		return m_test_cases[m_current_test_case_index];
6804 	}
6805 }
6806 
6807 /** Constructor
6808  *
6809  * @param context Test context
6810  **/
QualifierOrderFunctionInoutTest(deqp::Context & context)6811 QualifierOrderFunctionInoutTest::QualifierOrderFunctionInoutTest(deqp::Context& context)
6812 	: GLSLTestBase(context, "qualifier_order_function_inout", "Verify order of qualifiers of inout function parameters")
6813 {
6814 	/* Nothing to be done here */
6815 }
6816 
6817 /** Set up next test case
6818  *
6819  * @param test_case_index Index of next test case
6820  *
6821  * @return false if there is no more test cases, true otherwise
6822  **/
prepareNextTestCase(glw::GLuint test_case_index)6823 bool QualifierOrderFunctionInoutTest::prepareNextTestCase(glw::GLuint test_case_index)
6824 {
6825 	m_current_test_case_index = test_case_index;
6826 
6827 	if ((glw::GLuint)-1 == test_case_index)
6828 	{
6829 		/* Nothing to be done here */;
6830 	}
6831 	else if (m_test_cases.size() <= test_case_index)
6832 	{
6833 		return false;
6834 	}
6835 
6836 	const Utils::qualifierSet& set = getCurrentTestCase();
6837 
6838 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6839 
6840 	for (GLuint i = 0; i < set.size(); ++i)
6841 	{
6842 		message << Utils::getQualifierString(set[i]) << " ";
6843 	}
6844 
6845 	message << tcu::TestLog::EndMessage;
6846 
6847 	return true;
6848 }
6849 
6850 /** Prepare source for given shader stage
6851  *
6852  * @param in_stage           Shader stage, compute shader will use 430
6853  * @param in_use_version_400 Select if 400 or 420 should be used
6854  * @param out_source         Prepared shader source instance
6855  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6856 void QualifierOrderFunctionInoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6857 														  Utils::shaderSource& out_source)
6858 {
6859 	static const GLchar* verification_snippet =
6860 		"    vec4 temp = VARIABLE_NAME;\n"
6861 		"\n"
6862 		"    function(temp);\n"
6863 		"\n"
6864 		"    vec4 diff = temp - vec4(0, 0, 1, 1);\n"
6865 		"    if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6866 		"    {\n"
6867 		"        result = VARIABLE_NAME;\n"
6868 		"    }\n";
6869 
6870 	static const GLchar* function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
6871 												"{\n"
6872 												"    param = param.wzyx;\n"
6873 												"}\n";
6874 
6875 	static const GLchar* fragment_shader_template = "VERSION\n"
6876 													"\n"
6877 													"in  vec4 gs_fs_result;\n"
6878 													"out vec4 fs_out_result;\n"
6879 													"\n"
6880 													"uniform vec4 VARIABLE_NAME;\n"
6881 													"\n"
6882 													"FUNCTION_DECLARATION\n"
6883 													"\n"
6884 													"void main()\n"
6885 													"{\n"
6886 													"    vec4 result = vec4(0, 1, 0, 1);\n"
6887 													"\n"
6888 													"VERIFICATION"
6889 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6890 													"    {\n"
6891 													"         result = vec4(1, 0, 0, 1);\n"
6892 													"    }\n"
6893 													"\n"
6894 													"    fs_out_result = result;\n"
6895 													"}\n"
6896 													"\n";
6897 
6898 	static const GLchar* geometry_shader_template = "VERSION\n"
6899 													"\n"
6900 													"layout(points)                           in;\n"
6901 													"layout(triangle_strip, max_vertices = 4) out;\n"
6902 													"\n"
6903 													"in  vec4 tes_gs_result[];\n"
6904 													"out vec4 gs_fs_result;\n"
6905 													"\n"
6906 													"uniform vec4 VARIABLE_NAME;\n"
6907 													"\n"
6908 													"FUNCTION_DECLARATION\n"
6909 													"\n"
6910 													"void main()\n"
6911 													"{\n"
6912 													"    vec4 result = vec4(0, 1, 0, 1);\n"
6913 													"\n"
6914 													"VERIFICATION"
6915 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6916 													"    {\n"
6917 													"         result = vec4(1, 0, 0, 1);\n"
6918 													"    }\n"
6919 													"\n"
6920 													"    gs_fs_result = result;\n"
6921 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
6922 													"    EmitVertex();\n"
6923 													"    gs_fs_result = result;\n"
6924 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
6925 													"    EmitVertex();\n"
6926 													"    gs_fs_result = result;\n"
6927 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
6928 													"    EmitVertex();\n"
6929 													"    gs_fs_result = result;\n"
6930 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
6931 													"    EmitVertex();\n"
6932 													"}\n"
6933 													"\n";
6934 
6935 	static const GLchar* tess_ctrl_shader_template =
6936 		"VERSION\n"
6937 		"\n"
6938 		"layout(vertices = 1) out;\n"
6939 		"\n"
6940 		"in  vec4 vs_tcs_result[];\n"
6941 		"out vec4 tcs_tes_result[];\n"
6942 		"\n"
6943 		"uniform vec4 VARIABLE_NAME;\n"
6944 		"\n"
6945 		"FUNCTION_DECLARATION\n"
6946 		"\n"
6947 		"void main()\n"
6948 		"{\n"
6949 		"    vec4 result = vec4(0, 1, 0, 1);\n"
6950 		"\n"
6951 		"VERIFICATION"
6952 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6953 		"    {\n"
6954 		"         result = vec4(1, 0, 0, 1);\n"
6955 		"    }\n"
6956 		"\n"
6957 		"    tcs_tes_result[gl_InvocationID] = result;\n"
6958 		"\n"
6959 		"    gl_TessLevelOuter[0] = 1.0;\n"
6960 		"    gl_TessLevelOuter[1] = 1.0;\n"
6961 		"    gl_TessLevelOuter[2] = 1.0;\n"
6962 		"    gl_TessLevelOuter[3] = 1.0;\n"
6963 		"    gl_TessLevelInner[0] = 1.0;\n"
6964 		"    gl_TessLevelInner[1] = 1.0;\n"
6965 		"}\n"
6966 		"\n";
6967 
6968 	static const GLchar* tess_eval_shader_template = "VERSION\n"
6969 													 "\n"
6970 													 "layout(isolines, point_mode) in;\n"
6971 													 "\n"
6972 													 "in  vec4 tcs_tes_result[];\n"
6973 													 "out vec4 tes_gs_result;\n"
6974 													 "\n"
6975 													 "uniform vec4 VARIABLE_NAME;\n"
6976 													 "\n"
6977 													 "FUNCTION_DECLARATION\n"
6978 													 "\n"
6979 													 "void main()\n"
6980 													 "{\n"
6981 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
6982 													 "\n"
6983 													 "VERIFICATION"
6984 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6985 													 "    {\n"
6986 													 "         result = vec4(1, 0, 0, 1);\n"
6987 													 "    }\n"
6988 													 "\n"
6989 													 "    tes_gs_result = result;\n"
6990 													 "}\n"
6991 													 "\n";
6992 
6993 	static const GLchar* vertex_shader_template = "VERSION\n"
6994 												  "\n"
6995 												  "out vec4 vs_tcs_result;\n"
6996 												  "\n"
6997 												  "uniform vec4 VARIABLE_NAME;\n"
6998 												  "\n"
6999 												  "FUNCTION_DECLARATION\n"
7000 												  "\n"
7001 												  "void main()\n"
7002 												  "{\n"
7003 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
7004 												  "\n"
7005 												  "VERIFICATION"
7006 												  "\n"
7007 												  "    vs_tcs_result = result;\n"
7008 												  "}\n"
7009 												  "\n";
7010 
7011 	const GLchar* shader_template = 0;
7012 
7013 	switch (in_stage)
7014 	{
7015 	case Utils::COMPUTE_SHADER:
7016 		return;
7017 		break;
7018 	case Utils::FRAGMENT_SHADER:
7019 		shader_template = fragment_shader_template;
7020 		break;
7021 	case Utils::GEOMETRY_SHADER:
7022 		shader_template = geometry_shader_template;
7023 		break;
7024 	case Utils::TESS_CTRL_SHADER:
7025 		shader_template = tess_ctrl_shader_template;
7026 		break;
7027 	case Utils::TESS_EVAL_SHADER:
7028 		shader_template = tess_eval_shader_template;
7029 		break;
7030 	case Utils::VERTEX_SHADER:
7031 		shader_template = vertex_shader_template;
7032 		break;
7033 	default:
7034 		TCU_FAIL("Invalid enum");
7035 		break;
7036 	}
7037 
7038 	const std::string& uni_reference  = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7039 	const std::string& qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7040 
7041 	out_source.m_parts[0].m_code = shader_template;
7042 
7043 	size_t position = 0;
7044 
7045 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7046 						out_source.m_parts[0].m_code);
7047 
7048 	Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7049 
7050 	position -= strlen(function_declaration);
7051 
7052 	Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7053 
7054 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7055 
7056 	Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7057 }
7058 
7059 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7060  *
7061  * @param program Current program
7062  **/
prepareUniforms(Utils::program & program)7063 void QualifierOrderFunctionInoutTest::prepareUniforms(Utils::program& program)
7064 {
7065 	static const GLfloat float_data[4] = { 1.0f, 1.0f, 0.0f, 0.0f };
7066 
7067 	program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7068 	program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7069 	program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7070 	program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7071 	program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7072 }
7073 
7074 /** Prepare test cases
7075  *
7076  * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7077  **/
testInit()7078 bool QualifierOrderFunctionInoutTest::testInit()
7079 {
7080 	m_test_cases.resize(6);
7081 
7082 	m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7083 	m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7084 	m_test_cases[0].push_back(Utils::QUAL_INOUT);
7085 
7086 	m_test_cases[1].push_back(Utils::QUAL_INOUT);
7087 	m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7088 	m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7089 
7090 	m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7091 	m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7092 	m_test_cases[2].push_back(Utils::QUAL_INOUT);
7093 
7094 	m_test_cases[3].push_back(Utils::QUAL_INOUT);
7095 	m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7096 	m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7097 
7098 	m_test_cases[4].push_back(Utils::QUAL_LOWP);
7099 	m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7100 	m_test_cases[4].push_back(Utils::QUAL_INOUT);
7101 
7102 	m_test_cases[5].push_back(Utils::QUAL_INOUT);
7103 	m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7104 	m_test_cases[5].push_back(Utils::QUAL_LOWP);
7105 
7106 	return true;
7107 }
7108 
7109 /** Returns reference to current test case
7110  *
7111  * @return Reference to testCase
7112  **/
getCurrentTestCase()7113 const Utils::qualifierSet& QualifierOrderFunctionInoutTest::getCurrentTestCase()
7114 {
7115 	if ((glw::GLuint)-1 == m_current_test_case_index)
7116 	{
7117 		return m_test_cases[0];
7118 	}
7119 	else
7120 	{
7121 		return m_test_cases[m_current_test_case_index];
7122 	}
7123 }
7124 
7125 /** Constructor
7126  *
7127  * @param context Test context
7128  **/
QualifierOrderFunctionInputTest(deqp::Context & context)7129 QualifierOrderFunctionInputTest::QualifierOrderFunctionInputTest(deqp::Context& context)
7130 	: GLSLTestBase(context, "qualifier_order_function_input", "Verify order of qualifiers of function input parameters")
7131 {
7132 	/* Nothing to be done here */
7133 }
7134 
7135 /** Set up next test case
7136  *
7137  * @param test_case_index Index of next test case
7138  *
7139  * @return false if there is no more test cases, true otherwise
7140  **/
prepareNextTestCase(glw::GLuint test_case_index)7141 bool QualifierOrderFunctionInputTest::prepareNextTestCase(glw::GLuint test_case_index)
7142 {
7143 	m_current_test_case_index = test_case_index;
7144 
7145 	if ((glw::GLuint)-1 == test_case_index)
7146 	{
7147 		/* Nothing to be done here */;
7148 	}
7149 	else if (m_test_cases.size() <= test_case_index)
7150 	{
7151 		return false;
7152 	}
7153 
7154 	const Utils::qualifierSet& set = getCurrentTestCase();
7155 
7156 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7157 
7158 	for (GLuint i = 0; i < set.size(); ++i)
7159 	{
7160 		message << Utils::getQualifierString(set[i]) << " ";
7161 	}
7162 
7163 	message << tcu::TestLog::EndMessage;
7164 
7165 	return true;
7166 }
7167 
7168 /** Prepare source for given shader stage
7169  *
7170  * @param in_stage           Shader stage, compute shader will use 430
7171  * @param in_use_version_400 Select if 400 or 420 should be used
7172  * @param out_source         Prepared shader source instance
7173  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7174 void QualifierOrderFunctionInputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7175 														  Utils::shaderSource& out_source)
7176 {
7177 	static const GLchar* verification_snippet =
7178 		"    vec4 temp = function(VARIABLE_NAME);\n"
7179 		"\n"
7180 		"    vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7181 		"    if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7182 		"    {\n"
7183 		"        result = VARIABLE_NAME;\n"
7184 		"    }\n";
7185 
7186 	static const GLchar* function_declaration = "vec4 function(QUALIFIERS_LIST vec4 param)\n"
7187 												"{\n"
7188 												"    return param.wzyx;\n"
7189 												"}\n";
7190 
7191 	static const GLchar* fragment_shader_template = "VERSION\n"
7192 													"\n"
7193 													"in  vec4 gs_fs_result;\n"
7194 													"out vec4 fs_out_result;\n"
7195 													"\n"
7196 													"uniform vec4 VARIABLE_NAME;\n"
7197 													"\n"
7198 													"FUNCTION_DECLARATION\n"
7199 													"\n"
7200 													"void main()\n"
7201 													"{\n"
7202 													"    vec4 result = vec4(0, 1, 0, 1);\n"
7203 													"\n"
7204 													"VERIFICATION"
7205 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7206 													"    {\n"
7207 													"         result = vec4(1, 0, 0, 1);\n"
7208 													"    }\n"
7209 													"\n"
7210 													"    fs_out_result = result;\n"
7211 													"}\n"
7212 													"\n";
7213 
7214 	static const GLchar* geometry_shader_template = "VERSION\n"
7215 													"\n"
7216 													"layout(points)                           in;\n"
7217 													"layout(triangle_strip, max_vertices = 4) out;\n"
7218 													"\n"
7219 													"in  vec4 tes_gs_result[];\n"
7220 													"out vec4 gs_fs_result;\n"
7221 													"\n"
7222 													"uniform vec4 VARIABLE_NAME;\n"
7223 													"\n"
7224 													"FUNCTION_DECLARATION\n"
7225 													"\n"
7226 													"void main()\n"
7227 													"{\n"
7228 													"    vec4 result = vec4(0, 1, 0, 1);\n"
7229 													"\n"
7230 													"VERIFICATION"
7231 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7232 													"    {\n"
7233 													"         result = vec4(1, 0, 0, 1);\n"
7234 													"    }\n"
7235 													"\n"
7236 													"    gs_fs_result = result;\n"
7237 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
7238 													"    EmitVertex();\n"
7239 													"    gs_fs_result = result;\n"
7240 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
7241 													"    EmitVertex();\n"
7242 													"    gs_fs_result = result;\n"
7243 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
7244 													"    EmitVertex();\n"
7245 													"    gs_fs_result = result;\n"
7246 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
7247 													"    EmitVertex();\n"
7248 													"}\n"
7249 													"\n";
7250 
7251 	static const GLchar* tess_ctrl_shader_template =
7252 		"VERSION\n"
7253 		"\n"
7254 		"layout(vertices = 1) out;\n"
7255 		"\n"
7256 		"in  vec4 vs_tcs_result[];\n"
7257 		"out vec4 tcs_tes_result[];\n"
7258 		"\n"
7259 		"uniform vec4 VARIABLE_NAME;\n"
7260 		"\n"
7261 		"FUNCTION_DECLARATION\n"
7262 		"\n"
7263 		"void main()\n"
7264 		"{\n"
7265 		"    vec4 result = vec4(0, 1, 0, 1);\n"
7266 		"\n"
7267 		"VERIFICATION"
7268 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7269 		"    {\n"
7270 		"         result = vec4(1, 0, 0, 1);\n"
7271 		"    }\n"
7272 		"\n"
7273 		"    tcs_tes_result[gl_InvocationID] = result;\n"
7274 		"\n"
7275 		"    gl_TessLevelOuter[0] = 1.0;\n"
7276 		"    gl_TessLevelOuter[1] = 1.0;\n"
7277 		"    gl_TessLevelOuter[2] = 1.0;\n"
7278 		"    gl_TessLevelOuter[3] = 1.0;\n"
7279 		"    gl_TessLevelInner[0] = 1.0;\n"
7280 		"    gl_TessLevelInner[1] = 1.0;\n"
7281 		"}\n"
7282 		"\n";
7283 
7284 	static const GLchar* tess_eval_shader_template = "VERSION\n"
7285 													 "\n"
7286 													 "layout(isolines, point_mode) in;\n"
7287 													 "\n"
7288 													 "in  vec4 tcs_tes_result[];\n"
7289 													 "out vec4 tes_gs_result;\n"
7290 													 "\n"
7291 													 "uniform vec4 VARIABLE_NAME;\n"
7292 													 "\n"
7293 													 "FUNCTION_DECLARATION\n"
7294 													 "\n"
7295 													 "void main()\n"
7296 													 "{\n"
7297 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
7298 													 "\n"
7299 													 "VERIFICATION"
7300 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7301 													 "    {\n"
7302 													 "         result = vec4(1, 0, 0, 1);\n"
7303 													 "    }\n"
7304 													 "\n"
7305 													 "    tes_gs_result = result;\n"
7306 													 "}\n"
7307 													 "\n";
7308 
7309 	static const GLchar* vertex_shader_template = "VERSION\n"
7310 												  "\n"
7311 												  "out vec4 vs_tcs_result;\n"
7312 												  "\n"
7313 												  "uniform vec4 VARIABLE_NAME;\n"
7314 												  "\n"
7315 												  "FUNCTION_DECLARATION\n"
7316 												  "\n"
7317 												  "void main()\n"
7318 												  "{\n"
7319 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
7320 												  "\n"
7321 												  "VERIFICATION"
7322 												  "\n"
7323 												  "    vs_tcs_result = result;\n"
7324 												  "}\n"
7325 												  "\n";
7326 
7327 	const GLchar* shader_template = 0;
7328 
7329 	switch (in_stage)
7330 	{
7331 	case Utils::COMPUTE_SHADER:
7332 		return;
7333 		break;
7334 	case Utils::FRAGMENT_SHADER:
7335 		shader_template = fragment_shader_template;
7336 		break;
7337 	case Utils::GEOMETRY_SHADER:
7338 		shader_template = geometry_shader_template;
7339 		break;
7340 	case Utils::TESS_CTRL_SHADER:
7341 		shader_template = tess_ctrl_shader_template;
7342 		break;
7343 	case Utils::TESS_EVAL_SHADER:
7344 		shader_template = tess_eval_shader_template;
7345 		break;
7346 	case Utils::VERTEX_SHADER:
7347 		shader_template = vertex_shader_template;
7348 		break;
7349 	default:
7350 		TCU_FAIL("Invalid enum");
7351 		break;
7352 	}
7353 
7354 	const std::string& uni_reference  = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7355 	const std::string& qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7356 
7357 	out_source.m_parts[0].m_code = shader_template;
7358 
7359 	size_t position = 0;
7360 
7361 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7362 						out_source.m_parts[0].m_code);
7363 
7364 	Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7365 
7366 	position -= strlen(function_declaration);
7367 
7368 	Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7369 
7370 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7371 
7372 	Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7373 }
7374 
7375 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7376  *
7377  * @param program Current program
7378  **/
prepareUniforms(Utils::program & program)7379 void QualifierOrderFunctionInputTest::prepareUniforms(Utils::program& program)
7380 {
7381 	static const GLfloat float_data[4] = { 1.0f, 1.0f, 0.0f, 0.0f };
7382 
7383 	program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7384 	program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7385 	program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7386 	program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7387 	program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7388 }
7389 
7390 /** Prepare test cases
7391  *
7392  * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7393  **/
testInit()7394 bool QualifierOrderFunctionInputTest::testInit()
7395 {
7396 	m_test_cases.resize(6);
7397 
7398 	m_test_cases[0].push_back(Utils::QUAL_CONST);
7399 	m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7400 	m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7401 	m_test_cases[0].push_back(Utils::QUAL_IN);
7402 
7403 	m_test_cases[1].push_back(Utils::QUAL_IN);
7404 	m_test_cases[1].push_back(Utils::QUAL_CONST);
7405 	m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7406 	m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7407 
7408 	m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7409 	m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7410 	m_test_cases[2].push_back(Utils::QUAL_CONST);
7411 	m_test_cases[2].push_back(Utils::QUAL_IN);
7412 
7413 	m_test_cases[3].push_back(Utils::QUAL_IN);
7414 	m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7415 	m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7416 	m_test_cases[3].push_back(Utils::QUAL_CONST);
7417 
7418 	m_test_cases[4].push_back(Utils::QUAL_LOWP);
7419 	m_test_cases[4].push_back(Utils::QUAL_CONST);
7420 	m_test_cases[4].push_back(Utils::QUAL_IN);
7421 	m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7422 
7423 	m_test_cases[5].push_back(Utils::QUAL_IN);
7424 	m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7425 	m_test_cases[5].push_back(Utils::QUAL_CONST);
7426 	m_test_cases[5].push_back(Utils::QUAL_LOWP);
7427 
7428 	return true;
7429 }
7430 
7431 /** Returns reference to current test case
7432  *
7433  * @return Reference to testCase
7434  **/
getCurrentTestCase()7435 const Utils::qualifierSet& QualifierOrderFunctionInputTest::getCurrentTestCase()
7436 {
7437 	if ((glw::GLuint)-1 == m_current_test_case_index)
7438 	{
7439 		return m_test_cases[0];
7440 	}
7441 	else
7442 	{
7443 		return m_test_cases[m_current_test_case_index];
7444 	}
7445 }
7446 
7447 /** Constructor
7448  *
7449  * @param context Test context
7450  **/
QualifierOrderFunctionOutputTest(deqp::Context & context)7451 QualifierOrderFunctionOutputTest::QualifierOrderFunctionOutputTest(deqp::Context& context)
7452 	: GLSLTestBase(context, "qualifier_order_function_output",
7453 				   "Verify order of qualifiers of output function parameters")
7454 {
7455 	/* Nothing to be done here */
7456 }
7457 
7458 /** Set up next test case
7459  *
7460  * @param test_case_index Index of next test case
7461  *
7462  * @return false if there is no more test cases, true otherwise
7463  **/
prepareNextTestCase(glw::GLuint test_case_index)7464 bool QualifierOrderFunctionOutputTest::prepareNextTestCase(glw::GLuint test_case_index)
7465 {
7466 	m_current_test_case_index = test_case_index;
7467 
7468 	if ((glw::GLuint)-1 == test_case_index)
7469 	{
7470 		/* Nothing to be done here */;
7471 	}
7472 	else if (m_test_cases.size() <= test_case_index)
7473 	{
7474 		return false;
7475 	}
7476 
7477 	const Utils::qualifierSet& set = getCurrentTestCase();
7478 
7479 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7480 
7481 	for (GLuint i = 0; i < set.size(); ++i)
7482 	{
7483 		message << Utils::getQualifierString(set[i]) << " ";
7484 	}
7485 
7486 	message << tcu::TestLog::EndMessage;
7487 
7488 	return true;
7489 }
7490 
7491 /** Prepare source for given shader stage
7492  *
7493  * @param in_stage           Shader stage, compute shader will use 430
7494  * @param in_use_version_400 Select if 400 or 420 should be used
7495  * @param out_source         Prepared shader source instance
7496  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7497 void QualifierOrderFunctionOutputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7498 														   Utils::shaderSource& out_source)
7499 {
7500 	static const GLchar* verification_snippet =
7501 		"    vec4 temp;\n"
7502 		"\n"
7503 		"    function(temp);\n"
7504 		"\n"
7505 		"    vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7506 		"    if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7507 		"    {\n"
7508 		"        result = VARIABLE_NAME;\n"
7509 		"    }\n";
7510 
7511 	static const GLchar* function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
7512 												"{\n"
7513 												"    param = VARIABLE_NAME.wzyx;\n"
7514 												"}\n";
7515 
7516 	static const GLchar* fragment_shader_template = "VERSION\n"
7517 													"\n"
7518 													"in  vec4 gs_fs_result;\n"
7519 													"out vec4 fs_out_result;\n"
7520 													"\n"
7521 													"uniform vec4 VARIABLE_NAME;\n"
7522 													"\n"
7523 													"FUNCTION_DECLARATION\n"
7524 													"\n"
7525 													"void main()\n"
7526 													"{\n"
7527 													"    vec4 result = vec4(0, 1, 0, 1);\n"
7528 													"\n"
7529 													"VERIFICATION"
7530 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7531 													"    {\n"
7532 													"         result = vec4(1, 0, 0, 1);\n"
7533 													"    }\n"
7534 													"\n"
7535 													"    fs_out_result = result;\n"
7536 													"}\n"
7537 													"\n";
7538 
7539 	static const GLchar* geometry_shader_template = "VERSION\n"
7540 													"\n"
7541 													"layout(points)                           in;\n"
7542 													"layout(triangle_strip, max_vertices = 4) out;\n"
7543 													"\n"
7544 													"in  vec4 tes_gs_result[];\n"
7545 													"out vec4 gs_fs_result;\n"
7546 													"\n"
7547 													"uniform vec4 VARIABLE_NAME;\n"
7548 													"\n"
7549 													"FUNCTION_DECLARATION\n"
7550 													"\n"
7551 													"void main()\n"
7552 													"{\n"
7553 													"    vec4 result = vec4(0, 1, 0, 1);\n"
7554 													"\n"
7555 													"VERIFICATION"
7556 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7557 													"    {\n"
7558 													"         result = vec4(1, 0, 0, 1);\n"
7559 													"    }\n"
7560 													"\n"
7561 													"    gs_fs_result = result;\n"
7562 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
7563 													"    EmitVertex();\n"
7564 													"    gs_fs_result = result;\n"
7565 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
7566 													"    EmitVertex();\n"
7567 													"    gs_fs_result = result;\n"
7568 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
7569 													"    EmitVertex();\n"
7570 													"    gs_fs_result = result;\n"
7571 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
7572 													"    EmitVertex();\n"
7573 													"}\n"
7574 													"\n";
7575 
7576 	static const GLchar* tess_ctrl_shader_template =
7577 		"VERSION\n"
7578 		"\n"
7579 		"layout(vertices = 1) out;\n"
7580 		"\n"
7581 		"in  vec4 vs_tcs_result[];\n"
7582 		"out vec4 tcs_tes_result[];\n"
7583 		"\n"
7584 		"uniform vec4 VARIABLE_NAME;\n"
7585 		"\n"
7586 		"FUNCTION_DECLARATION\n"
7587 		"\n"
7588 		"void main()\n"
7589 		"{\n"
7590 		"    vec4 result = vec4(0, 1, 0, 1);\n"
7591 		"\n"
7592 		"VERIFICATION"
7593 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7594 		"    {\n"
7595 		"         result = vec4(1, 0, 0, 1);\n"
7596 		"    }\n"
7597 		"\n"
7598 		"    tcs_tes_result[gl_InvocationID] = result;\n"
7599 		"\n"
7600 		"    gl_TessLevelOuter[0] = 1.0;\n"
7601 		"    gl_TessLevelOuter[1] = 1.0;\n"
7602 		"    gl_TessLevelOuter[2] = 1.0;\n"
7603 		"    gl_TessLevelOuter[3] = 1.0;\n"
7604 		"    gl_TessLevelInner[0] = 1.0;\n"
7605 		"    gl_TessLevelInner[1] = 1.0;\n"
7606 		"}\n"
7607 		"\n";
7608 
7609 	static const GLchar* tess_eval_shader_template = "VERSION\n"
7610 													 "\n"
7611 													 "layout(isolines, point_mode) in;\n"
7612 													 "\n"
7613 													 "in  vec4 tcs_tes_result[];\n"
7614 													 "out vec4 tes_gs_result;\n"
7615 													 "\n"
7616 													 "uniform vec4 VARIABLE_NAME;\n"
7617 													 "\n"
7618 													 "FUNCTION_DECLARATION\n"
7619 													 "\n"
7620 													 "void main()\n"
7621 													 "{\n"
7622 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
7623 													 "\n"
7624 													 "VERIFICATION"
7625 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7626 													 "    {\n"
7627 													 "         result = vec4(1, 0, 0, 1);\n"
7628 													 "    }\n"
7629 													 "\n"
7630 													 "    tes_gs_result = result;\n"
7631 													 "}\n"
7632 													 "\n";
7633 
7634 	static const GLchar* vertex_shader_template = "VERSION\n"
7635 												  "\n"
7636 												  "out vec4 vs_tcs_result;\n"
7637 												  "\n"
7638 												  "uniform vec4 VARIABLE_NAME;\n"
7639 												  "\n"
7640 												  "FUNCTION_DECLARATION\n"
7641 												  "\n"
7642 												  "void main()\n"
7643 												  "{\n"
7644 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
7645 												  "\n"
7646 												  "VERIFICATION"
7647 												  "\n"
7648 												  "    vs_tcs_result = result;\n"
7649 												  "}\n"
7650 												  "\n";
7651 
7652 	const GLchar* shader_template = 0;
7653 
7654 	switch (in_stage)
7655 	{
7656 	case Utils::COMPUTE_SHADER:
7657 		return;
7658 		break;
7659 	case Utils::FRAGMENT_SHADER:
7660 		shader_template = fragment_shader_template;
7661 		break;
7662 	case Utils::GEOMETRY_SHADER:
7663 		shader_template = geometry_shader_template;
7664 		break;
7665 	case Utils::TESS_CTRL_SHADER:
7666 		shader_template = tess_ctrl_shader_template;
7667 		break;
7668 	case Utils::TESS_EVAL_SHADER:
7669 		shader_template = tess_eval_shader_template;
7670 		break;
7671 	case Utils::VERTEX_SHADER:
7672 		shader_template = vertex_shader_template;
7673 		break;
7674 	default:
7675 		TCU_FAIL("Invalid enum");
7676 		break;
7677 	}
7678 
7679 	const std::string& uni_reference  = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7680 	const std::string& qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7681 
7682 	out_source.m_parts[0].m_code = shader_template;
7683 
7684 	size_t position = 0;
7685 
7686 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7687 						out_source.m_parts[0].m_code);
7688 
7689 	Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7690 
7691 	position -= strlen(function_declaration);
7692 
7693 	Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7694 
7695 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7696 
7697 	Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7698 }
7699 
7700 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7701  *
7702  * @param program Current program
7703  **/
prepareUniforms(Utils::program & program)7704 void QualifierOrderFunctionOutputTest::prepareUniforms(Utils::program& program)
7705 {
7706 	static const GLfloat float_data[4] = { 1.0f, 1.0f, 0.0f, 0.0f };
7707 
7708 	program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7709 	program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7710 	program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7711 	program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7712 	program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7713 }
7714 
7715 /** Prepare test cases
7716  *
7717  * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7718  **/
testInit()7719 bool QualifierOrderFunctionOutputTest::testInit()
7720 {
7721 	m_test_cases.resize(6);
7722 
7723 	m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7724 	m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7725 	m_test_cases[0].push_back(Utils::QUAL_OUT);
7726 
7727 	m_test_cases[1].push_back(Utils::QUAL_OUT);
7728 	m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7729 	m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7730 
7731 	m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7732 	m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7733 	m_test_cases[2].push_back(Utils::QUAL_OUT);
7734 
7735 	m_test_cases[3].push_back(Utils::QUAL_OUT);
7736 	m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7737 	m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7738 
7739 	m_test_cases[4].push_back(Utils::QUAL_LOWP);
7740 	m_test_cases[4].push_back(Utils::QUAL_OUT);
7741 	m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7742 
7743 	m_test_cases[5].push_back(Utils::QUAL_OUT);
7744 	m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7745 	m_test_cases[5].push_back(Utils::QUAL_LOWP);
7746 
7747 	return true;
7748 }
7749 
7750 /** Returns reference to current test case
7751  *
7752  * @return Reference to testCase
7753  **/
getCurrentTestCase()7754 const Utils::qualifierSet& QualifierOrderFunctionOutputTest::getCurrentTestCase()
7755 {
7756 	if ((glw::GLuint)-1 == m_current_test_case_index)
7757 	{
7758 		return m_test_cases[0];
7759 	}
7760 	else
7761 	{
7762 		return m_test_cases[m_current_test_case_index];
7763 	}
7764 }
7765 
7766 /** Constructor
7767  *
7768  * @param context Test context
7769  **/
QualifierOverrideLayoutTest(deqp::Context & context)7770 QualifierOverrideLayoutTest::QualifierOverrideLayoutTest(deqp::Context& context)
7771 	: GLSLTestBase(context, "qualifier_override_layout", "Verifies overriding layout qualifiers")
7772 {
7773 	/* Nothing to be done here */
7774 }
7775 
7776 /** Prepare source for given shader stage
7777  *
7778  * @param in_stage           Shader stage, compute shader will use 430
7779  * @param in_use_version_400 Select if 400 or 420 should be used
7780  * @param out_source         Prepared shader source instance
7781  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7782 void QualifierOverrideLayoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7783 													  Utils::shaderSource& out_source)
7784 {
7785 	static const GLchar* fragment_shader_template = "VERSION\n"
7786 													"\n"
7787 													"in  layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7788 													"out vec4 fs_out_result;\n"
7789 													"\n"
7790 													"void main()\n"
7791 													"{\n"
7792 													"    vec4 result = vec4(0, 1, 0, 1);\n"
7793 													"\n"
7794 													"    if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7795 													"    {\n"
7796 													"         result = vec4(1, 0, 0, 1);\n"
7797 													"    }\n"
7798 													"\n"
7799 													"    fs_out_result = result;\n"
7800 													"}\n"
7801 													"\n";
7802 
7803 	static const GLchar* geometry_shader_template =
7804 		"VERSION\n"
7805 		"\n"
7806 		"layout(points)                                                    in;\n"
7807 		"layout(triangle_strip, max_vertices = 2) layout(max_vertices = 4) out;\n"
7808 		"\n"
7809 		"in  layout(location = 3) layout(location = 2) vec4 tes_gs_result[];\n"
7810 		"out layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7811 		"\n"
7812 		"void main()\n"
7813 		"{\n"
7814 		"    vec4 result = vec4(0, 1, 0, 1);\n"
7815 		"\n"
7816 		"    if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7817 		"    {\n"
7818 		"         result = vec4(1, 0, 0, 1);\n"
7819 		"    }\n"
7820 		"\n"
7821 		"    gs_fs_result = result;\n"
7822 		"    gl_Position  = vec4(-1, -1, 0, 1);\n"
7823 		"    EmitVertex();\n"
7824 		"    gs_fs_result = result;\n"
7825 		"    gl_Position  = vec4(-1, 1, 0, 1);\n"
7826 		"    EmitVertex();\n"
7827 		"    gs_fs_result = result;\n"
7828 		"    gl_Position  = vec4(1, -1, 0, 1);\n"
7829 		"    EmitVertex();\n"
7830 		"    gs_fs_result = result;\n"
7831 		"    gl_Position  = vec4(1, 1, 0, 1);\n"
7832 		"    EmitVertex();\n"
7833 		"}\n"
7834 		"\n";
7835 
7836 	static const GLchar* tess_ctrl_shader_template =
7837 		"VERSION\n"
7838 		"\n"
7839 		"layout(vertices = 4) layout(vertices = 1) out;\n"
7840 		"\n"
7841 		"in  layout(location = 3) layout(location = 2) vec4 vs_tcs_result[];\n"
7842 		"out layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7843 		"\n"
7844 		"void main()\n"
7845 		"{\n"
7846 		"    vec4 result = vec4(0, 1, 0, 1);\n"
7847 		"\n"
7848 		"    if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7849 		"    {\n"
7850 		"         result = vec4(1, 0, 0, 1);\n"
7851 		"    }\n"
7852 		"\n"
7853 		"    tcs_tes_result[gl_InvocationID] = result;\n"
7854 		"\n"
7855 		"    gl_TessLevelOuter[0] = 1.0;\n"
7856 		"    gl_TessLevelOuter[1] = 1.0;\n"
7857 		"    gl_TessLevelOuter[2] = 1.0;\n"
7858 		"    gl_TessLevelOuter[3] = 1.0;\n"
7859 		"    gl_TessLevelInner[0] = 1.0;\n"
7860 		"    gl_TessLevelInner[1] = 1.0;\n"
7861 		"}\n"
7862 		"\n";
7863 
7864 	static const GLchar* tess_eval_shader_template =
7865 		"VERSION\n"
7866 		"\n"
7867 		"layout(isolines, point_mode) in;\n"
7868 		"\n"
7869 		"in  layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7870 		"out layout(location = 3) layout(location = 2) vec4 tes_gs_result;\n"
7871 		"\n"
7872 		"void main()\n"
7873 		"{\n"
7874 		"    vec4 result = vec4(0, 1, 0, 1);\n"
7875 		"\n"
7876 		"    if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7877 		"    {\n"
7878 		"         result = vec4(1, 0, 0, 1);\n"
7879 		"    }\n"
7880 		"\n"
7881 		"    tes_gs_result = result;\n"
7882 		"}\n"
7883 		"\n";
7884 
7885 	static const GLchar* vertex_shader_template = "VERSION\n"
7886 												  "\n"
7887 												  "in  layout(location = 3) layout(location = 2) vec4 in_vs_test;\n"
7888 												  "out layout(location = 3) layout(location = 2) vec4 vs_tcs_result;\n"
7889 												  "\n"
7890 												  "void main()\n"
7891 												  "{\n"
7892 												  "    vec4 result = in_vs_test;\n"
7893 												  "\n"
7894 												  "    vs_tcs_result = result;\n"
7895 												  "}\n"
7896 												  "\n";
7897 
7898 	const GLchar* shader_template = 0;
7899 
7900 	switch (in_stage)
7901 	{
7902 	case Utils::COMPUTE_SHADER:
7903 		return;
7904 		break;
7905 	case Utils::FRAGMENT_SHADER:
7906 		shader_template = fragment_shader_template;
7907 		break;
7908 	case Utils::GEOMETRY_SHADER:
7909 		shader_template = geometry_shader_template;
7910 		break;
7911 	case Utils::TESS_CTRL_SHADER:
7912 		shader_template = tess_ctrl_shader_template;
7913 		break;
7914 	case Utils::TESS_EVAL_SHADER:
7915 		shader_template = tess_eval_shader_template;
7916 		break;
7917 	case Utils::VERTEX_SHADER:
7918 		shader_template = vertex_shader_template;
7919 		break;
7920 	default:
7921 		TCU_FAIL("Invalid enum");
7922 		break;
7923 	}
7924 
7925 	out_source.m_parts[0].m_code = shader_template;
7926 
7927 	size_t position = 0;
7928 
7929 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7930 						out_source.m_parts[0].m_code);
7931 }
7932 
7933 /**Prepare vertex buffer and vertex array object.
7934  *
7935  * @param program Program instance
7936  * @param buffer  Buffer instance
7937  * @param vao     VertexArray instance
7938  *
7939  * @return 0
7940  **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)7941 void QualifierOverrideLayoutTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
7942 													  Utils::vertexArray& vao)
7943 {
7944 	static const GLint expected_location = 2;
7945 
7946 	std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
7947 	GLint		test_loc  = program.getAttribLocation(test_name.c_str());
7948 
7949 	if (expected_location != test_loc)
7950 	{
7951 		TCU_FAIL("Vertex attribute location is invalid");
7952 	}
7953 
7954 	vao.generate();
7955 	vao.bind();
7956 
7957 	buffer.generate(GL_ARRAY_BUFFER);
7958 
7959 	GLfloat	data[]	= { 0.0f, 1.0f, 0.0f, 1.0f };
7960 	GLsizeiptr data_size = sizeof(data);
7961 
7962 	buffer.update(data_size, data, GL_STATIC_DRAW);
7963 
7964 	/* GL entry points */
7965 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7966 
7967 	/* Set up vao */
7968 	gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
7969 						   0 /* offset */);
7970 	GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
7971 
7972 	/* Enable attribute */
7973 	gl.enableVertexAttribArray(test_loc);
7974 	GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
7975 }
7976 
7977 /** Constructor
7978  *
7979  * @param context Test context
7980  **/
BindingUniformBlocksTest(deqp::Context & context)7981 BindingUniformBlocksTest::BindingUniformBlocksTest(deqp::Context& context)
7982 	: GLSLTestBase(context, "binding_uniform_blocks", "Test verifies uniform block binding")
7983 	, m_goku_buffer(context)
7984 	, m_vegeta_buffer(context)
7985 	, m_children_buffer(context)
7986 {
7987 	/* Nothing to be done here */
7988 }
7989 
7990 /** Prepare source for given shader stage
7991  *
7992  * @param in_stage           Shader stage, compute shader will use 430
7993  * @param in_use_version_400 Select if 400 or 420 should be used
7994  * @param out_source         Prepared shader source instance
7995  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7996 void BindingUniformBlocksTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7997 												   Utils::shaderSource& out_source)
7998 {
7999 	static const GLchar* uni_goku = "layout(std140, binding = 0) uniform GOKU {\n"
8000 									"    vec4 chichi;\n"
8001 									"} goku;\n";
8002 
8003 	static const GLchar* uni_vegeta = "layout(std140, binding = 1) uniform VEGETA {\n"
8004 									  "    vec3 bulma;\n"
8005 									  "} vegeta;\n";
8006 
8007 	static const GLchar* uni_children = "layout(std140, binding = 3) uniform CHILDREN {\n"
8008 										"    vec4 gohan;\n"
8009 										"    vec4 trunks;\n"
8010 										"} children;\n\n";
8011 
8012 	static const GLchar* verification_snippet = "    if ((vec4(1, 0, 0, 0) != goku.chichi)    ||\n"
8013 												"        (vec3(0, 1, 0)    != vegeta.bulma)   ||\n"
8014 												"        (vec4(0, 0, 1, 0) != children.gohan) ||\n"
8015 												"        (vec4(0, 0, 0, 1) != children.trunks) )\n"
8016 												"    {\n"
8017 												"        result = vec4(1, 0, 0, 1);\n"
8018 												"    }\n";
8019 
8020 	static const GLchar* compute_shader_template =
8021 		"VERSION\n"
8022 		"\n"
8023 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8024 		"\n"
8025 		"writeonly uniform image2D uni_image;\n"
8026 		"\n"
8027 		"UNI_GOKU\n"
8028 		"UNI_VEGETA\n"
8029 		"UNI_CHILDREN\n"
8030 		"\n"
8031 		"void main()\n"
8032 		"{\n"
8033 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8034 		"\n"
8035 		"VERIFICATION"
8036 		"\n"
8037 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8038 		"}\n"
8039 		"\n";
8040 
8041 	static const GLchar* fragment_shader_template = "VERSION\n"
8042 													"\n"
8043 													"in  vec4 gs_fs_result;\n"
8044 													"out vec4 fs_out_result;\n"
8045 													"\n"
8046 													"UNI_GOKU\n"
8047 													"UNI_VEGETA\n"
8048 													"UNI_CHILDREN\n"
8049 													"\n"
8050 													"void main()\n"
8051 													"{\n"
8052 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8053 													"\n"
8054 													"VERIFICATION"
8055 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8056 													"    {\n"
8057 													"         result = vec4(1, 0, 0, 1);\n"
8058 													"    }\n"
8059 													"\n"
8060 													"    fs_out_result = result;\n"
8061 													"}\n"
8062 													"\n";
8063 
8064 	static const GLchar* geometry_shader_template = "VERSION\n"
8065 													"\n"
8066 													"layout(points)                           in;\n"
8067 													"layout(triangle_strip, max_vertices = 4) out;\n"
8068 													"\n"
8069 													"in  vec4 tes_gs_result[];\n"
8070 													"out vec4 gs_fs_result;\n"
8071 													"\n"
8072 													"UNI_CHILDREN\n"
8073 													"UNI_GOKU\n"
8074 													"UNI_VEGETA\n"
8075 													"\n"
8076 													"void main()\n"
8077 													"{\n"
8078 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8079 													"\n"
8080 													"VERIFICATION"
8081 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8082 													"    {\n"
8083 													"         result = vec4(1, 0, 0, 1);\n"
8084 													"    }\n"
8085 													"\n"
8086 													"    gs_fs_result = result;\n"
8087 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
8088 													"    EmitVertex();\n"
8089 													"    gs_fs_result = result;\n"
8090 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
8091 													"    EmitVertex();\n"
8092 													"    gs_fs_result = result;\n"
8093 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
8094 													"    EmitVertex();\n"
8095 													"    gs_fs_result = result;\n"
8096 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
8097 													"    EmitVertex();\n"
8098 													"}\n"
8099 													"\n";
8100 
8101 	static const GLchar* tess_ctrl_shader_template =
8102 		"VERSION\n"
8103 		"\n"
8104 		"layout(vertices = 1) out;\n"
8105 		"\n"
8106 		"in  vec4 vs_tcs_result[];\n"
8107 		"out vec4 tcs_tes_result[];\n"
8108 		"\n"
8109 		"UNI_VEGETA\n"
8110 		"UNI_CHILDREN\n"
8111 		"UNI_GOKU\n"
8112 		"\n"
8113 		"void main()\n"
8114 		"{\n"
8115 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8116 		"\n"
8117 		"VERIFICATION"
8118 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8119 		"    {\n"
8120 		"         result = vec4(1, 0, 0, 1);\n"
8121 		"    }\n"
8122 		"\n"
8123 		"    tcs_tes_result[gl_InvocationID] = result;\n"
8124 		"\n"
8125 		"    gl_TessLevelOuter[0] = 1.0;\n"
8126 		"    gl_TessLevelOuter[1] = 1.0;\n"
8127 		"    gl_TessLevelOuter[2] = 1.0;\n"
8128 		"    gl_TessLevelOuter[3] = 1.0;\n"
8129 		"    gl_TessLevelInner[0] = 1.0;\n"
8130 		"    gl_TessLevelInner[1] = 1.0;\n"
8131 		"}\n"
8132 		"\n";
8133 
8134 	static const GLchar* tess_eval_shader_template = "VERSION\n"
8135 													 "\n"
8136 													 "layout(isolines, point_mode) in;\n"
8137 													 "\n"
8138 													 "in  vec4 tcs_tes_result[];\n"
8139 													 "out vec4 tes_gs_result;\n"
8140 													 "\n"
8141 													 "UNI_GOKU\n"
8142 													 "UNI_CHILDREN\n"
8143 													 "UNI_VEGETA\n"
8144 													 "\n"
8145 													 "void main()\n"
8146 													 "{\n"
8147 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
8148 													 "\n"
8149 													 "VERIFICATION"
8150 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8151 													 "    {\n"
8152 													 "         result = vec4(1, 0, 0, 1);\n"
8153 													 "    }\n"
8154 													 "\n"
8155 													 "    tes_gs_result = result;\n"
8156 													 "}\n"
8157 													 "\n";
8158 
8159 	static const GLchar* vertex_shader_template = "VERSION\n"
8160 												  "\n"
8161 												  "out vec4 vs_tcs_result;\n"
8162 												  "\n"
8163 												  "UNI_CHILDREN\n"
8164 												  "UNI_VEGETA\n"
8165 												  "UNI_GOKU\n"
8166 												  "\n"
8167 												  "void main()\n"
8168 												  "{\n"
8169 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
8170 												  "\n"
8171 												  "VERIFICATION"
8172 												  "\n"
8173 												  "    vs_tcs_result = result;\n"
8174 												  "}\n"
8175 												  "\n";
8176 
8177 	const GLchar* shader_template = 0;
8178 
8179 	switch (in_stage)
8180 	{
8181 	case Utils::COMPUTE_SHADER:
8182 		shader_template = compute_shader_template;
8183 		break;
8184 	case Utils::FRAGMENT_SHADER:
8185 		shader_template = fragment_shader_template;
8186 		break;
8187 	case Utils::GEOMETRY_SHADER:
8188 		shader_template = geometry_shader_template;
8189 		break;
8190 	case Utils::TESS_CTRL_SHADER:
8191 		shader_template = tess_ctrl_shader_template;
8192 		break;
8193 	case Utils::TESS_EVAL_SHADER:
8194 		shader_template = tess_eval_shader_template;
8195 		break;
8196 	case Utils::VERTEX_SHADER:
8197 		shader_template = vertex_shader_template;
8198 		break;
8199 	default:
8200 		TCU_FAIL("Invalid enum");
8201 		break;
8202 	}
8203 
8204 	out_source.m_parts[0].m_code = shader_template;
8205 
8206 	size_t position = 0;
8207 
8208 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8209 						out_source.m_parts[0].m_code);
8210 
8211 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8212 
8213 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8214 
8215 	Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
8216 
8217 	Utils::replaceAllTokens("UNI_CHILDREN", uni_children, out_source.m_parts[0].m_code);
8218 }
8219 
8220 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8221  *
8222  * @param program Current program
8223  **/
prepareUniforms(Utils::program & program)8224 void BindingUniformBlocksTest::prepareUniforms(Utils::program& program)
8225 {
8226 	(void)program;
8227 	static const GLfloat goku_data[4]	 = { 1.0f, 0.0f, 0.0f, 0.0f };
8228 	static const GLfloat vegeta_data[3]   = { 0.0f, 1.0f, 0.0f };
8229 	static const GLfloat children_data[8] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
8230 
8231 	m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8232 	m_vegeta_buffer.generate(GL_UNIFORM_BUFFER);
8233 	m_children_buffer.generate(GL_UNIFORM_BUFFER);
8234 
8235 	m_goku_buffer.update(sizeof(goku_data), (GLvoid*)goku_data, GL_STATIC_DRAW);
8236 	m_vegeta_buffer.update(sizeof(vegeta_data), (GLvoid*)vegeta_data, GL_STATIC_DRAW);
8237 	m_children_buffer.update(sizeof(children_data), (GLvoid*)children_data, GL_STATIC_DRAW);
8238 
8239 	m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8240 	m_vegeta_buffer.bindRange(1 /* index */, 0 /* offset */, sizeof(vegeta_data));
8241 	m_children_buffer.bindRange(3 /* index */, 0 /* offset */, sizeof(children_data));
8242 }
8243 
8244 /** Overwrite of releaseResource method, release extra uniform buffer
8245  *
8246  * @param ignored
8247  **/
releaseResource()8248 void BindingUniformBlocksTest::releaseResource()
8249 {
8250 	m_goku_buffer.release();
8251 	m_vegeta_buffer.release();
8252 	m_children_buffer.release();
8253 }
8254 
8255 /** Constructor
8256  *
8257  * @param context Test context
8258  **/
BindingUniformSingleBlockTest(deqp::Context & context)8259 BindingUniformSingleBlockTest::BindingUniformSingleBlockTest(deqp::Context& context)
8260 	: GLSLTestBase(context, "binding_uniform_single_block", "Test verifies uniform block binding")
8261 	, m_goku_buffer(context)
8262 {
8263 	/* Nothing to be done here */
8264 }
8265 
8266 /** Set up next test case
8267  *
8268  * @param test_case_index Index of next test case
8269  *
8270  * @return false if there is no more test cases, true otherwise
8271  **/
prepareNextTestCase(glw::GLuint test_case_index)8272 bool BindingUniformSingleBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
8273 {
8274 	switch (test_case_index)
8275 	{
8276 	case (glw::GLuint)-1:
8277 	case 0:
8278 		m_test_stage = Utils::VERTEX_SHADER;
8279 		break;
8280 	case 1:
8281 		m_test_stage = Utils::TESS_CTRL_SHADER;
8282 		break;
8283 	case 2:
8284 		m_test_stage = Utils::TESS_EVAL_SHADER;
8285 		break;
8286 	case 3:
8287 		m_test_stage = Utils::GEOMETRY_SHADER;
8288 		break;
8289 	case 4:
8290 		m_test_stage = Utils::FRAGMENT_SHADER;
8291 		break;
8292 	default:
8293 		return false;
8294 		break;
8295 	}
8296 
8297 	m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
8298 										<< Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
8299 										<< tcu::TestLog::EndMessage;
8300 
8301 	return true;
8302 }
8303 
8304 /** Prepare source for given shader stage
8305  *
8306  * @param in_stage           Shader stage, compute shader will use 430
8307  * @param in_use_version_400 Select if 400 or 420 should be used
8308  * @param out_source         Prepared shader source instance
8309  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8310 void BindingUniformSingleBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8311 														Utils::shaderSource& out_source)
8312 {
8313 	static const GLchar* uni_goku_with_binding = "layout(std140, binding = 0) uniform GOKU {\n"
8314 												 "    vec4 gohan;\n"
8315 												 "    vec4 goten;\n"
8316 												 "} goku;\n";
8317 
8318 	static const GLchar* uni_goku_no_binding = "layout(std140) uniform GOKU {\n"
8319 											   "    vec4 gohan;\n"
8320 											   "    vec4 goten;\n"
8321 											   "} goku;\n";
8322 
8323 	static const GLchar* verification_snippet = "    if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
8324 												"        (vec4(0, 1, 0, 0) != goku.goten) )\n"
8325 												"    {\n"
8326 												"        result = vec4(1, 0, 0, 1);\n"
8327 												"    }\n";
8328 
8329 	static const GLchar* compute_shader_template =
8330 		"VERSION\n"
8331 		"\n"
8332 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8333 		"\n"
8334 		"writeonly uniform image2D uni_image;\n"
8335 		"\n"
8336 		"UNI_GOKU\n"
8337 		"\n"
8338 		"void main()\n"
8339 		"{\n"
8340 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8341 		"\n"
8342 		"VERIFICATION"
8343 		"\n"
8344 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8345 		"}\n"
8346 		"\n";
8347 
8348 	static const GLchar* fragment_shader_template = "VERSION\n"
8349 													"\n"
8350 													"in  vec4 gs_fs_result;\n"
8351 													"out vec4 fs_out_result;\n"
8352 													"\n"
8353 													"UNI_GOKU\n"
8354 													"\n"
8355 													"void main()\n"
8356 													"{\n"
8357 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8358 													"\n"
8359 													"VERIFICATION"
8360 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8361 													"    {\n"
8362 													"         result = vec4(1, 0, 0, 1);\n"
8363 													"    }\n"
8364 													"\n"
8365 													"    fs_out_result = result;\n"
8366 													"}\n"
8367 													"\n";
8368 
8369 	static const GLchar* geometry_shader_template = "VERSION\n"
8370 													"\n"
8371 													"layout(points)                           in;\n"
8372 													"layout(triangle_strip, max_vertices = 4) out;\n"
8373 													"\n"
8374 													"in  vec4 tes_gs_result[];\n"
8375 													"out vec4 gs_fs_result;\n"
8376 													"\n"
8377 													"UNI_GOKU\n"
8378 													"\n"
8379 													"void main()\n"
8380 													"{\n"
8381 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8382 													"\n"
8383 													"VERIFICATION"
8384 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8385 													"    {\n"
8386 													"         result = vec4(1, 0, 0, 1);\n"
8387 													"    }\n"
8388 													"\n"
8389 													"    gs_fs_result = result;\n"
8390 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
8391 													"    EmitVertex();\n"
8392 													"    gs_fs_result = result;\n"
8393 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
8394 													"    EmitVertex();\n"
8395 													"    gs_fs_result = result;\n"
8396 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
8397 													"    EmitVertex();\n"
8398 													"    gs_fs_result = result;\n"
8399 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
8400 													"    EmitVertex();\n"
8401 													"}\n"
8402 													"\n";
8403 
8404 	static const GLchar* tess_ctrl_shader_template =
8405 		"VERSION\n"
8406 		"\n"
8407 		"layout(vertices = 1) out;\n"
8408 		"\n"
8409 		"in  vec4 vs_tcs_result[];\n"
8410 		"out vec4 tcs_tes_result[];\n"
8411 		"\n"
8412 		"UNI_GOKU\n"
8413 		"\n"
8414 		"void main()\n"
8415 		"{\n"
8416 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8417 		"\n"
8418 		"VERIFICATION"
8419 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8420 		"    {\n"
8421 		"         result = vec4(1, 0, 0, 1);\n"
8422 		"    }\n"
8423 		"\n"
8424 		"    tcs_tes_result[gl_InvocationID] = result;\n"
8425 		"\n"
8426 		"    gl_TessLevelOuter[0] = 1.0;\n"
8427 		"    gl_TessLevelOuter[1] = 1.0;\n"
8428 		"    gl_TessLevelOuter[2] = 1.0;\n"
8429 		"    gl_TessLevelOuter[3] = 1.0;\n"
8430 		"    gl_TessLevelInner[0] = 1.0;\n"
8431 		"    gl_TessLevelInner[1] = 1.0;\n"
8432 		"}\n"
8433 		"\n";
8434 
8435 	static const GLchar* tess_eval_shader_template = "VERSION\n"
8436 													 "\n"
8437 													 "layout(isolines, point_mode) in;\n"
8438 													 "\n"
8439 													 "in  vec4 tcs_tes_result[];\n"
8440 													 "out vec4 tes_gs_result;\n"
8441 													 "\n"
8442 													 "UNI_GOKU\n"
8443 													 "\n"
8444 													 "void main()\n"
8445 													 "{\n"
8446 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
8447 													 "\n"
8448 													 "VERIFICATION"
8449 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8450 													 "    {\n"
8451 													 "         result = vec4(1, 0, 0, 1);\n"
8452 													 "    }\n"
8453 													 "\n"
8454 													 "    tes_gs_result = result;\n"
8455 													 "}\n"
8456 													 "\n";
8457 
8458 	static const GLchar* vertex_shader_template = "VERSION\n"
8459 												  "\n"
8460 												  "out vec4 vs_tcs_result;\n"
8461 												  "\n"
8462 												  "UNI_GOKU\n"
8463 												  "\n"
8464 												  "void main()\n"
8465 												  "{\n"
8466 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
8467 												  "\n"
8468 												  "VERIFICATION"
8469 												  "\n"
8470 												  "    vs_tcs_result = result;\n"
8471 												  "}\n"
8472 												  "\n";
8473 
8474 	const GLchar* shader_template	= 0;
8475 	const GLchar* uniform_definition = uni_goku_no_binding;
8476 
8477 	switch (in_stage)
8478 	{
8479 	case Utils::COMPUTE_SHADER:
8480 		shader_template	= compute_shader_template;
8481 		uniform_definition = uni_goku_with_binding;
8482 		break;
8483 	case Utils::FRAGMENT_SHADER:
8484 		shader_template = fragment_shader_template;
8485 		break;
8486 	case Utils::GEOMETRY_SHADER:
8487 		shader_template = geometry_shader_template;
8488 		break;
8489 	case Utils::TESS_CTRL_SHADER:
8490 		shader_template = tess_ctrl_shader_template;
8491 		break;
8492 	case Utils::TESS_EVAL_SHADER:
8493 		shader_template = tess_eval_shader_template;
8494 		break;
8495 	case Utils::VERTEX_SHADER:
8496 		shader_template = vertex_shader_template;
8497 		break;
8498 	default:
8499 		TCU_FAIL("Invalid enum");
8500 		break;
8501 	}
8502 
8503 	if (in_stage == m_test_stage)
8504 	{
8505 		uniform_definition = uni_goku_with_binding;
8506 	}
8507 
8508 	out_source.m_parts[0].m_code = shader_template;
8509 
8510 	size_t position = 0;
8511 
8512 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8513 						out_source.m_parts[0].m_code);
8514 
8515 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8516 
8517 	Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
8518 }
8519 
8520 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8521  *
8522  * @param program Current program
8523  **/
prepareUniforms(Utils::program & program)8524 void BindingUniformSingleBlockTest::prepareUniforms(Utils::program& program)
8525 {
8526 	(void)program;
8527 	static const GLfloat goku_data[8] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
8528 
8529 	m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8530 
8531 	m_goku_buffer.update(sizeof(goku_data), (GLvoid*)goku_data, GL_STATIC_DRAW);
8532 
8533 	m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8534 }
8535 
8536 /** Overwrite of releaseResource method, release extra uniform buffer
8537  *
8538  * @param ignored
8539  **/
releaseResource()8540 void BindingUniformSingleBlockTest::releaseResource()
8541 {
8542 	m_goku_buffer.release();
8543 }
8544 
8545 /** Constructor
8546  *
8547  * @param context Test context
8548  **/
BindingUniformBlockArrayTest(deqp::Context & context)8549 BindingUniformBlockArrayTest::BindingUniformBlockArrayTest(deqp::Context& context)
8550 	: GLSLTestBase(context, "binding_uniform_block_array", "Test verifies binding of uniform block arrays")
8551 	, m_goku_00_buffer(context)
8552 	, m_goku_01_buffer(context)
8553 	, m_goku_02_buffer(context)
8554 	, m_goku_03_buffer(context)
8555 	, m_goku_04_buffer(context)
8556 	, m_goku_05_buffer(context)
8557 	, m_goku_06_buffer(context)
8558 	, m_goku_07_buffer(context)
8559 	, m_goku_08_buffer(context)
8560 	, m_goku_09_buffer(context)
8561 	, m_goku_10_buffer(context)
8562 	, m_goku_11_buffer(context)
8563 	, m_goku_12_buffer(context)
8564 	, m_goku_13_buffer(context)
8565 {
8566 	/* Nothing to be done here */
8567 }
8568 
8569 /** Prepare source for given shader stage
8570  *
8571  * @param in_stage           Shader stage, compute shader will use 430
8572  * @param in_use_version_400 Select if 400 or 420 should be used
8573  * @param out_source         Prepared shader source instance
8574  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8575 void BindingUniformBlockArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8576 													   Utils::shaderSource& out_source)
8577 {
8578 	static const GLchar* uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
8579 									"    vec4 gohan;\n"
8580 									"    vec4 goten;\n"
8581 									"} goku[14];\n";
8582 
8583 	static const GLchar* verification_snippet = "    if ((vec4(0, 0, 0, 0) != goku[0].gohan)  ||\n"
8584 												"        (vec4(0, 0, 0, 1) != goku[0].goten)  ||\n"
8585 												"        (vec4(0, 0, 1, 0) != goku[1].gohan)  ||\n"
8586 												"        (vec4(0, 0, 1, 1) != goku[1].goten)  ||\n"
8587 												"        (vec4(0, 1, 0, 0) != goku[2].gohan)  ||\n"
8588 												"        (vec4(0, 1, 0, 1) != goku[2].goten)  ||\n"
8589 												"        (vec4(0, 1, 1, 0) != goku[3].gohan)  ||\n"
8590 												"        (vec4(0, 1, 1, 1) != goku[3].goten)  ||\n"
8591 												"        (vec4(1, 0, 0, 0) != goku[4].gohan)  ||\n"
8592 												"        (vec4(1, 0, 0, 1) != goku[4].goten)  ||\n"
8593 												"        (vec4(1, 0, 1, 0) != goku[5].gohan)  ||\n"
8594 												"        (vec4(1, 0, 1, 1) != goku[5].goten)  ||\n"
8595 												"        (vec4(1, 1, 0, 0) != goku[6].gohan)  ||\n"
8596 												"        (vec4(1, 1, 0, 1) != goku[6].goten)  ||\n"
8597 												"        (vec4(1, 1, 1, 0) != goku[7].gohan)  ||\n"
8598 												"        (vec4(1, 1, 1, 1) != goku[7].goten)  ||\n"
8599 												"        (vec4(0, 0, 0, 0) != goku[8].gohan)  ||\n"
8600 												"        (vec4(0, 0, 0, 1) != goku[8].goten)  ||\n"
8601 												"        (vec4(0, 0, 1, 0) != goku[9].gohan)  ||\n"
8602 												"        (vec4(0, 0, 1, 1) != goku[9].goten)  ||\n"
8603 												"        (vec4(0, 1, 0, 0) != goku[10].gohan) ||\n"
8604 												"        (vec4(0, 1, 0, 1) != goku[10].goten) ||\n"
8605 												"        (vec4(0, 1, 1, 0) != goku[11].gohan) ||\n"
8606 												"        (vec4(0, 1, 1, 1) != goku[11].goten) ||\n"
8607 												"        (vec4(1, 0, 0, 0) != goku[12].gohan) ||\n"
8608 												"        (vec4(1, 0, 0, 1) != goku[12].goten) ||\n"
8609 												"        (vec4(1, 0, 1, 0) != goku[13].gohan) ||\n"
8610 												"        (vec4(1, 0, 1, 1) != goku[13].goten) )\n"
8611 												"    {\n"
8612 												"        result = vec4(1, 0, 0, 1);\n"
8613 												"    }\n";
8614 
8615 	static const GLchar* compute_shader_template =
8616 		"VERSION\n"
8617 		"\n"
8618 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8619 		"\n"
8620 		"writeonly uniform image2D uni_image;\n"
8621 		"\n"
8622 		"UNI_GOKU\n"
8623 		"\n"
8624 		"void main()\n"
8625 		"{\n"
8626 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8627 		"\n"
8628 		"VERIFICATION"
8629 		"\n"
8630 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8631 		"}\n"
8632 		"\n";
8633 
8634 	static const GLchar* fragment_shader_template = "VERSION\n"
8635 													"\n"
8636 													"in  vec4 gs_fs_result;\n"
8637 													"out vec4 fs_out_result;\n"
8638 													"\n"
8639 													"UNI_GOKU\n"
8640 													"\n"
8641 													"void main()\n"
8642 													"{\n"
8643 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8644 													"\n"
8645 													"VERIFICATION"
8646 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8647 													"    {\n"
8648 													"         result = vec4(1, 0, 0, 1);\n"
8649 													"    }\n"
8650 													"\n"
8651 													"    fs_out_result = result;\n"
8652 													"}\n"
8653 													"\n";
8654 
8655 	static const GLchar* geometry_shader_template = "VERSION\n"
8656 													"\n"
8657 													"layout(points)                           in;\n"
8658 													"layout(triangle_strip, max_vertices = 4) out;\n"
8659 													"\n"
8660 													"in  vec4 tes_gs_result[];\n"
8661 													"out vec4 gs_fs_result;\n"
8662 													"\n"
8663 													"UNI_GOKU\n"
8664 													"\n"
8665 													"void main()\n"
8666 													"{\n"
8667 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8668 													"\n"
8669 													"VERIFICATION"
8670 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8671 													"    {\n"
8672 													"         result = vec4(1, 0, 0, 1);\n"
8673 													"    }\n"
8674 													"\n"
8675 													"    gs_fs_result = result;\n"
8676 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
8677 													"    EmitVertex();\n"
8678 													"    gs_fs_result = result;\n"
8679 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
8680 													"    EmitVertex();\n"
8681 													"    gs_fs_result = result;\n"
8682 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
8683 													"    EmitVertex();\n"
8684 													"    gs_fs_result = result;\n"
8685 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
8686 													"    EmitVertex();\n"
8687 													"}\n"
8688 													"\n";
8689 
8690 	static const GLchar* tess_ctrl_shader_template =
8691 		"VERSION\n"
8692 		"\n"
8693 		"layout(vertices = 1) out;\n"
8694 		"\n"
8695 		"in  vec4 vs_tcs_result[];\n"
8696 		"out vec4 tcs_tes_result[];\n"
8697 		"\n"
8698 		"UNI_GOKU\n"
8699 		"\n"
8700 		"void main()\n"
8701 		"{\n"
8702 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8703 		"\n"
8704 		"VERIFICATION"
8705 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8706 		"    {\n"
8707 		"         result = vec4(1, 0, 0, 1);\n"
8708 		"    }\n"
8709 		"\n"
8710 		"    tcs_tes_result[gl_InvocationID] = result;\n"
8711 		"\n"
8712 		"    gl_TessLevelOuter[0] = 1.0;\n"
8713 		"    gl_TessLevelOuter[1] = 1.0;\n"
8714 		"    gl_TessLevelOuter[2] = 1.0;\n"
8715 		"    gl_TessLevelOuter[3] = 1.0;\n"
8716 		"    gl_TessLevelInner[0] = 1.0;\n"
8717 		"    gl_TessLevelInner[1] = 1.0;\n"
8718 		"}\n"
8719 		"\n";
8720 
8721 	static const GLchar* tess_eval_shader_template = "VERSION\n"
8722 													 "\n"
8723 													 "layout(isolines, point_mode) in;\n"
8724 													 "\n"
8725 													 "in  vec4 tcs_tes_result[];\n"
8726 													 "out vec4 tes_gs_result;\n"
8727 													 "\n"
8728 													 "UNI_GOKU\n"
8729 													 "\n"
8730 													 "void main()\n"
8731 													 "{\n"
8732 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
8733 													 "\n"
8734 													 "VERIFICATION"
8735 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8736 													 "    {\n"
8737 													 "         result = vec4(1, 0, 0, 1);\n"
8738 													 "    }\n"
8739 													 "\n"
8740 													 "    tes_gs_result = result;\n"
8741 													 "}\n"
8742 													 "\n";
8743 
8744 	static const GLchar* vertex_shader_template = "VERSION\n"
8745 												  "\n"
8746 												  "out vec4 vs_tcs_result;\n"
8747 												  "\n"
8748 												  "UNI_GOKU\n"
8749 												  "\n"
8750 												  "void main()\n"
8751 												  "{\n"
8752 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
8753 												  "\n"
8754 												  "VERIFICATION"
8755 												  "\n"
8756 												  "    vs_tcs_result = result;\n"
8757 												  "}\n"
8758 												  "\n";
8759 
8760 	const GLchar* shader_template = 0;
8761 
8762 	switch (in_stage)
8763 	{
8764 	case Utils::COMPUTE_SHADER:
8765 		shader_template = compute_shader_template;
8766 		break;
8767 	case Utils::FRAGMENT_SHADER:
8768 		shader_template = fragment_shader_template;
8769 		break;
8770 	case Utils::GEOMETRY_SHADER:
8771 		shader_template = geometry_shader_template;
8772 		break;
8773 	case Utils::TESS_CTRL_SHADER:
8774 		shader_template = tess_ctrl_shader_template;
8775 		break;
8776 	case Utils::TESS_EVAL_SHADER:
8777 		shader_template = tess_eval_shader_template;
8778 		break;
8779 	case Utils::VERTEX_SHADER:
8780 		shader_template = vertex_shader_template;
8781 		break;
8782 	default:
8783 		TCU_FAIL("Invalid enum");
8784 		break;
8785 	}
8786 
8787 	out_source.m_parts[0].m_code = shader_template;
8788 
8789 	size_t position = 0;
8790 
8791 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8792 						out_source.m_parts[0].m_code);
8793 
8794 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8795 
8796 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8797 }
8798 
8799 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8800  *
8801  * @param program Current program
8802  **/
prepareUniforms(Utils::program & program)8803 void BindingUniformBlockArrayTest::prepareUniforms(Utils::program& program)
8804 {
8805 	static const GLfloat goku_data[][8] = {
8806 		{ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f },
8807 		{ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
8808 		{ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
8809 		{ 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f },
8810 		{ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f },
8811 		{ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
8812 		{ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f }
8813 	};
8814 
8815 	Utils::buffer* buffers[14] = { &m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8816 								   &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8817 								   &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8818 								   &m_goku_12_buffer, &m_goku_13_buffer };
8819 
8820 	for (GLuint i = 0; i < 14; ++i)
8821 	{
8822 		checkBinding(program, i, i + 2);
8823 
8824 		buffers[i]->generate(GL_UNIFORM_BUFFER);
8825 		buffers[i]->update(sizeof(GLfloat) * 8, (GLvoid*)goku_data[i], GL_STATIC_DRAW);
8826 		buffers[i]->bindRange(i + 2 /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
8827 	}
8828 }
8829 
8830 /** Overwrite of releaseResource method, release extra uniform buffer
8831  *
8832  * @param ignored
8833  **/
releaseResource()8834 void BindingUniformBlockArrayTest::releaseResource()
8835 {
8836 	Utils::buffer* buffers[14] = { &m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8837 								   &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8838 								   &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8839 								   &m_goku_12_buffer, &m_goku_13_buffer };
8840 
8841 	for (GLuint i = 0; i < 14; ++i)
8842 	{
8843 		buffers[i]->release();
8844 	}
8845 }
8846 
8847 /** Verifies that API reports correct uniform binding
8848  *
8849  * @param program          Program
8850  * @param index            Index of array element
8851  * @param expected_binding Expected binding
8852  **/
checkBinding(Utils::program & program,glw::GLuint index,glw::GLint expected_binding)8853 void BindingUniformBlockArrayTest::checkBinding(Utils::program& program, glw::GLuint index, glw::GLint expected_binding)
8854 {
8855 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8856 
8857 	GLchar buffer[64];
8858 	sprintf(buffer, "GOKU[%d]", index);
8859 
8860 	const GLuint uniform_index = gl.getUniformBlockIndex(program.m_program_object_id, buffer);
8861 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8862 	if (GL_INVALID_INDEX == uniform_index)
8863 	{
8864 		TCU_FAIL("Uniform block is inactive");
8865 	}
8866 
8867 	GLint binding = -1;
8868 
8869 	gl.getActiveUniformBlockiv(program.m_program_object_id, uniform_index, GL_UNIFORM_BLOCK_BINDING, &binding);
8870 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8871 
8872 	if (expected_binding != binding)
8873 	{
8874 		TCU_FAIL("Wrong binding reported by API");
8875 	}
8876 }
8877 
8878 /** Constructor
8879  *
8880  * @param context Test context
8881  **/
BindingUniformDefaultTest(deqp::Context & context)8882 BindingUniformDefaultTest::BindingUniformDefaultTest(deqp::Context& context)
8883 	: APITestBase(context, "binding_uniform_default", "Test verifies default binding of uniform block")
8884 {
8885 	/* Nothing to be done here */
8886 }
8887 
8888 /** Execute API call and verifies results
8889  *
8890  * @return true when results are positive, false otherwise
8891  **/
checkResults(Utils::program & program)8892 bool BindingUniformDefaultTest::checkResults(Utils::program& program)
8893 {
8894 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8895 
8896 	const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
8897 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8898 	if (GL_INVALID_INDEX == index)
8899 	{
8900 		TCU_FAIL("Uniform block is inactive");
8901 		return false;
8902 	}
8903 
8904 	GLint binding = -1;
8905 
8906 	gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
8907 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8908 
8909 	if (0 != binding)
8910 	{
8911 		return false;
8912 	}
8913 
8914 	return true;
8915 }
8916 
8917 /** Prepare source for given shader stage
8918  *
8919  * @param in_stage           Shader stage, compute shader will use 430
8920  * @param in_use_version_400 Select if 400 or 420 should be used
8921  * @param out_source         Prepared shader source instance
8922  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8923 void BindingUniformDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8924 													Utils::shaderSource& out_source)
8925 {
8926 	static const GLchar* uni_goku = "layout(std140) uniform GOKU {\n"
8927 									"    vec4 gohan;\n"
8928 									"    vec4 goten;\n"
8929 									"} goku;\n";
8930 
8931 	static const GLchar* verification_snippet = "    if ((vec4(0, 0, 0, 0) != goku.gohan) ||\n"
8932 												"        (vec4(0, 0, 0, 1) != goku.goten) )\n"
8933 												"    {\n"
8934 												"        result = vec4(1, 0, 0, 1);\n"
8935 												"    }\n";
8936 
8937 	static const GLchar* compute_shader_template =
8938 		"VERSION\n"
8939 		"\n"
8940 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8941 		"\n"
8942 		"writeonly uniform image2D uni_image;\n"
8943 		"\n"
8944 		"UNI_GOKU\n"
8945 		"\n"
8946 		"void main()\n"
8947 		"{\n"
8948 		"    vec4 result = vec4(0, 1, 0, 1);\n"
8949 		"\n"
8950 		"VERIFICATION"
8951 		"\n"
8952 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8953 		"}\n"
8954 		"\n";
8955 
8956 	static const GLchar* fragment_shader_template = "VERSION\n"
8957 													"\n"
8958 													"in  vec4 gs_fs_result;\n"
8959 													"out vec4 fs_out_result;\n"
8960 													"\n"
8961 													"UNI_GOKU\n"
8962 													"\n"
8963 													"void main()\n"
8964 													"{\n"
8965 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8966 													"\n"
8967 													"VERIFICATION"
8968 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8969 													"    {\n"
8970 													"         result = vec4(1, 0, 0, 1);\n"
8971 													"    }\n"
8972 													"\n"
8973 													"    fs_out_result = result;\n"
8974 													"}\n"
8975 													"\n";
8976 
8977 	static const GLchar* geometry_shader_template = "VERSION\n"
8978 													"\n"
8979 													"layout(points)                           in;\n"
8980 													"layout(triangle_strip, max_vertices = 4) out;\n"
8981 													"\n"
8982 													"in  vec4 tes_gs_result[];\n"
8983 													"out vec4 gs_fs_result;\n"
8984 													"\n"
8985 													"UNI_GOKU\n"
8986 													"\n"
8987 													"void main()\n"
8988 													"{\n"
8989 													"    vec4 result = vec4(0, 1, 0, 1);\n"
8990 													"\n"
8991 													"VERIFICATION"
8992 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8993 													"    {\n"
8994 													"         result = vec4(1, 0, 0, 1);\n"
8995 													"    }\n"
8996 													"\n"
8997 													"    gs_fs_result = result;\n"
8998 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
8999 													"    EmitVertex();\n"
9000 													"    gs_fs_result = result;\n"
9001 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
9002 													"    EmitVertex();\n"
9003 													"    gs_fs_result = result;\n"
9004 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
9005 													"    EmitVertex();\n"
9006 													"    gs_fs_result = result;\n"
9007 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
9008 													"    EmitVertex();\n"
9009 													"}\n"
9010 													"\n";
9011 
9012 	static const GLchar* tess_ctrl_shader_template =
9013 		"VERSION\n"
9014 		"\n"
9015 		"layout(vertices = 1) out;\n"
9016 		"\n"
9017 		"in  vec4 vs_tcs_result[];\n"
9018 		"out vec4 tcs_tes_result[];\n"
9019 		"\n"
9020 		"UNI_GOKU\n"
9021 		"\n"
9022 		"void main()\n"
9023 		"{\n"
9024 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9025 		"\n"
9026 		"VERIFICATION"
9027 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9028 		"    {\n"
9029 		"         result = vec4(1, 0, 0, 1);\n"
9030 		"    }\n"
9031 		"\n"
9032 		"    tcs_tes_result[gl_InvocationID] = result;\n"
9033 		"\n"
9034 		"    gl_TessLevelOuter[0] = 1.0;\n"
9035 		"    gl_TessLevelOuter[1] = 1.0;\n"
9036 		"    gl_TessLevelOuter[2] = 1.0;\n"
9037 		"    gl_TessLevelOuter[3] = 1.0;\n"
9038 		"    gl_TessLevelInner[0] = 1.0;\n"
9039 		"    gl_TessLevelInner[1] = 1.0;\n"
9040 		"}\n"
9041 		"\n";
9042 
9043 	static const GLchar* tess_eval_shader_template = "VERSION\n"
9044 													 "\n"
9045 													 "layout(isolines, point_mode) in;\n"
9046 													 "\n"
9047 													 "in  vec4 tcs_tes_result[];\n"
9048 													 "out vec4 tes_gs_result;\n"
9049 													 "\n"
9050 													 "UNI_GOKU\n"
9051 													 "\n"
9052 													 "void main()\n"
9053 													 "{\n"
9054 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
9055 													 "\n"
9056 													 "VERIFICATION"
9057 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9058 													 "    {\n"
9059 													 "         result = vec4(1, 0, 0, 1);\n"
9060 													 "    }\n"
9061 													 "\n"
9062 													 "    tes_gs_result = result;\n"
9063 													 "}\n"
9064 													 "\n";
9065 
9066 	static const GLchar* vertex_shader_template = "VERSION\n"
9067 												  "\n"
9068 												  "out vec4 vs_tcs_result;\n"
9069 												  "\n"
9070 												  "UNI_GOKU\n"
9071 												  "\n"
9072 												  "void main()\n"
9073 												  "{\n"
9074 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
9075 												  "\n"
9076 												  "VERIFICATION"
9077 												  "\n"
9078 												  "    vs_tcs_result = result;\n"
9079 												  "}\n"
9080 												  "\n";
9081 
9082 	const GLchar* shader_template = 0;
9083 
9084 	switch (in_stage)
9085 	{
9086 	case Utils::COMPUTE_SHADER:
9087 		shader_template = compute_shader_template;
9088 		break;
9089 	case Utils::FRAGMENT_SHADER:
9090 		shader_template = fragment_shader_template;
9091 		break;
9092 	case Utils::GEOMETRY_SHADER:
9093 		shader_template = geometry_shader_template;
9094 		break;
9095 	case Utils::TESS_CTRL_SHADER:
9096 		shader_template = tess_ctrl_shader_template;
9097 		break;
9098 	case Utils::TESS_EVAL_SHADER:
9099 		shader_template = tess_eval_shader_template;
9100 		break;
9101 	case Utils::VERTEX_SHADER:
9102 		shader_template = vertex_shader_template;
9103 		break;
9104 	default:
9105 		TCU_FAIL("Invalid enum");
9106 		break;
9107 	}
9108 
9109 	out_source.m_parts[0].m_code = shader_template;
9110 
9111 	size_t position = 0;
9112 
9113 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9114 						out_source.m_parts[0].m_code);
9115 
9116 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9117 
9118 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9119 }
9120 
9121 /** Constructor
9122  *
9123  * @param context Test context
9124  **/
BindingUniformAPIOverirdeTest(deqp::Context & context)9125 BindingUniformAPIOverirdeTest::BindingUniformAPIOverirdeTest(deqp::Context& context)
9126 	: GLSLTestBase(context, "binding_uniform_api_overirde", "Test verifies if binding can be overriden with API")
9127 	, m_goku_buffer(context)
9128 {
9129 	/* Nothing to be done here */
9130 }
9131 
9132 /** Prepare source for given shader stage
9133  *
9134  * @param in_stage           Shader stage, compute shader will use 430
9135  * @param in_use_version_400 Select if 400 or 420 should be used
9136  * @param out_source         Prepared shader source instance
9137  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9138 void BindingUniformAPIOverirdeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9139 														Utils::shaderSource& out_source)
9140 {
9141 	static const GLchar* uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
9142 									"    vec4 gohan;\n"
9143 									"    vec4 goten;\n"
9144 									"} goku;\n";
9145 
9146 	static const GLchar* verification_snippet = "    if ((vec4(1, 0, 0, 0) != goku.gohan)  ||\n"
9147 												"        (vec4(0, 1, 0, 0) != goku.goten)  )\n"
9148 												"    {\n"
9149 												"        result = vec4(1, 0, 0, 1);\n"
9150 												"    }\n";
9151 
9152 	static const GLchar* compute_shader_template =
9153 		"VERSION\n"
9154 		"\n"
9155 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9156 		"\n"
9157 		"writeonly uniform image2D uni_image;\n"
9158 		"\n"
9159 		"UNI_GOKU\n"
9160 		"\n"
9161 		"void main()\n"
9162 		"{\n"
9163 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9164 		"\n"
9165 		"VERIFICATION"
9166 		"\n"
9167 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9168 		"}\n"
9169 		"\n";
9170 
9171 	static const GLchar* fragment_shader_template = "VERSION\n"
9172 													"\n"
9173 													"in  vec4 gs_fs_result;\n"
9174 													"out vec4 fs_out_result;\n"
9175 													"\n"
9176 													"UNI_GOKU\n"
9177 													"\n"
9178 													"void main()\n"
9179 													"{\n"
9180 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9181 													"\n"
9182 													"VERIFICATION"
9183 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9184 													"    {\n"
9185 													"         result = vec4(1, 0, 0, 1);\n"
9186 													"    }\n"
9187 													"\n"
9188 													"    fs_out_result = result;\n"
9189 													"}\n"
9190 													"\n";
9191 
9192 	static const GLchar* geometry_shader_template = "VERSION\n"
9193 													"\n"
9194 													"layout(points)                           in;\n"
9195 													"layout(triangle_strip, max_vertices = 4) out;\n"
9196 													"\n"
9197 													"in  vec4 tes_gs_result[];\n"
9198 													"out vec4 gs_fs_result;\n"
9199 													"\n"
9200 													"UNI_GOKU\n"
9201 													"\n"
9202 													"void main()\n"
9203 													"{\n"
9204 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9205 													"\n"
9206 													"VERIFICATION"
9207 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9208 													"    {\n"
9209 													"         result = vec4(1, 0, 0, 1);\n"
9210 													"    }\n"
9211 													"\n"
9212 													"    gs_fs_result = result;\n"
9213 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
9214 													"    EmitVertex();\n"
9215 													"    gs_fs_result = result;\n"
9216 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
9217 													"    EmitVertex();\n"
9218 													"    gs_fs_result = result;\n"
9219 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
9220 													"    EmitVertex();\n"
9221 													"    gs_fs_result = result;\n"
9222 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
9223 													"    EmitVertex();\n"
9224 													"}\n"
9225 													"\n";
9226 
9227 	static const GLchar* tess_ctrl_shader_template =
9228 		"VERSION\n"
9229 		"\n"
9230 		"layout(vertices = 1) out;\n"
9231 		"\n"
9232 		"in  vec4 vs_tcs_result[];\n"
9233 		"out vec4 tcs_tes_result[];\n"
9234 		"\n"
9235 		"UNI_GOKU\n"
9236 		"\n"
9237 		"void main()\n"
9238 		"{\n"
9239 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9240 		"\n"
9241 		"VERIFICATION"
9242 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9243 		"    {\n"
9244 		"         result = vec4(1, 0, 0, 1);\n"
9245 		"    }\n"
9246 		"\n"
9247 		"    tcs_tes_result[gl_InvocationID] = result;\n"
9248 		"\n"
9249 		"    gl_TessLevelOuter[0] = 1.0;\n"
9250 		"    gl_TessLevelOuter[1] = 1.0;\n"
9251 		"    gl_TessLevelOuter[2] = 1.0;\n"
9252 		"    gl_TessLevelOuter[3] = 1.0;\n"
9253 		"    gl_TessLevelInner[0] = 1.0;\n"
9254 		"    gl_TessLevelInner[1] = 1.0;\n"
9255 		"}\n"
9256 		"\n";
9257 
9258 	static const GLchar* tess_eval_shader_template = "VERSION\n"
9259 													 "\n"
9260 													 "layout(isolines, point_mode) in;\n"
9261 													 "\n"
9262 													 "in  vec4 tcs_tes_result[];\n"
9263 													 "out vec4 tes_gs_result;\n"
9264 													 "\n"
9265 													 "UNI_GOKU\n"
9266 													 "\n"
9267 													 "void main()\n"
9268 													 "{\n"
9269 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
9270 													 "\n"
9271 													 "VERIFICATION"
9272 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9273 													 "    {\n"
9274 													 "         result = vec4(1, 0, 0, 1);\n"
9275 													 "    }\n"
9276 													 "\n"
9277 													 "    tes_gs_result = result;\n"
9278 													 "}\n"
9279 													 "\n";
9280 
9281 	static const GLchar* vertex_shader_template = "VERSION\n"
9282 												  "\n"
9283 												  "out vec4 vs_tcs_result;\n"
9284 												  "\n"
9285 												  "UNI_GOKU\n"
9286 												  "\n"
9287 												  "void main()\n"
9288 												  "{\n"
9289 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
9290 												  "\n"
9291 												  "VERIFICATION"
9292 												  "\n"
9293 												  "    vs_tcs_result = result;\n"
9294 												  "}\n"
9295 												  "\n";
9296 
9297 	const GLchar* shader_template = 0;
9298 
9299 	switch (in_stage)
9300 	{
9301 	case Utils::COMPUTE_SHADER:
9302 		shader_template = compute_shader_template;
9303 		break;
9304 	case Utils::FRAGMENT_SHADER:
9305 		shader_template = fragment_shader_template;
9306 		break;
9307 	case Utils::GEOMETRY_SHADER:
9308 		shader_template = geometry_shader_template;
9309 		break;
9310 	case Utils::TESS_CTRL_SHADER:
9311 		shader_template = tess_ctrl_shader_template;
9312 		break;
9313 	case Utils::TESS_EVAL_SHADER:
9314 		shader_template = tess_eval_shader_template;
9315 		break;
9316 	case Utils::VERTEX_SHADER:
9317 		shader_template = vertex_shader_template;
9318 		break;
9319 	default:
9320 		TCU_FAIL("Invalid enum");
9321 		break;
9322 	}
9323 
9324 	out_source.m_parts[0].m_code = shader_template;
9325 
9326 	size_t position = 0;
9327 
9328 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9329 						out_source.m_parts[0].m_code);
9330 
9331 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9332 
9333 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9334 }
9335 
9336 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
9337  *
9338  * @param program Current program
9339  **/
prepareUniforms(Utils::program & program)9340 void BindingUniformAPIOverirdeTest::prepareUniforms(Utils::program& program)
9341 {
9342 	static const GLfloat goku_data[8] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
9343 
9344 	static const GLuint new_binding = 11;
9345 
9346 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9347 
9348 	const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
9349 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
9350 	if (GL_INVALID_INDEX == index)
9351 	{
9352 		TCU_FAIL("Uniform block is inactive");
9353 		return;
9354 	}
9355 
9356 	gl.uniformBlockBinding(program.m_program_object_id, index, new_binding);
9357 	GLU_EXPECT_NO_ERROR(gl.getError(), "UniformBlockBinding");
9358 
9359 	GLint binding = -1;
9360 
9361 	gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
9362 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
9363 
9364 	if (new_binding != binding)
9365 	{
9366 		TCU_FAIL("GetActiveUniformBlockiv returned wrong binding");
9367 		return;
9368 	}
9369 
9370 	m_goku_buffer.generate(GL_UNIFORM_BUFFER);
9371 	m_goku_buffer.update(sizeof(GLfloat) * 8, (GLvoid*)goku_data, GL_STATIC_DRAW);
9372 	m_goku_buffer.bindRange(new_binding /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
9373 }
9374 
9375 /** Overwrite of releaseResource method, release extra uniform buffer
9376  *
9377  * @param ignored
9378  **/
releaseResource()9379 void BindingUniformAPIOverirdeTest::releaseResource()
9380 {
9381 	m_goku_buffer.release();
9382 }
9383 
9384 /** Constructor
9385  *
9386  * @param context Test context
9387  **/
BindingUniformGlobalBlockTest(deqp::Context & context)9388 BindingUniformGlobalBlockTest::BindingUniformGlobalBlockTest(deqp::Context& context)
9389 	: NegativeTestBase(context, "binding_uniform_global_block",
9390 					   "Test verifies that global uniform cannot be qualified with binding")
9391 {
9392 	/* Nothing to be done here */
9393 }
9394 
9395 /** Prepare source for given shader stage
9396  *
9397  * @param in_stage           Shader stage, compute shader will use 430
9398  * @param in_use_version_400 Select if 400 or 420 should be used
9399  * @param out_source         Prepared shader source instance
9400  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9401 void BindingUniformGlobalBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9402 														Utils::shaderSource& out_source)
9403 {
9404 	static const GLchar* verification_snippet = "    if (vec4(0, 0, 1, 1) != uni_test)\n"
9405 												"    {\n"
9406 												"        result = vec4(1, 0, 0, 1);\n"
9407 												"    }\n";
9408 
9409 	static const GLchar* uniform_definition = "layout(binding = 0) uniform vec4 uni_test;\n";
9410 
9411 	static const GLchar* compute_shader_template =
9412 		"VERSION\n"
9413 		"\n"
9414 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9415 		"\n"
9416 		"writeonly uniform image2D uni_image;\n"
9417 		"\n"
9418 		"UNIFORM_DEFINITION\n"
9419 		"\n"
9420 		"void main()\n"
9421 		"{\n"
9422 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9423 		"\n"
9424 		"VERIFICATION"
9425 		"\n"
9426 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9427 		"}\n"
9428 		"\n";
9429 
9430 	static const GLchar* fragment_shader_template = "VERSION\n"
9431 													"\n"
9432 													"in  vec4 gs_fs_result;\n"
9433 													"out vec4 fs_out_result;\n"
9434 													"\n"
9435 													"UNIFORM_DEFINITION\n"
9436 													"\n"
9437 													"void main()\n"
9438 													"{\n"
9439 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9440 													"\n"
9441 													"VERIFICATION"
9442 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9443 													"    {\n"
9444 													"         result = vec4(1, 0, 0, 1);\n"
9445 													"    }\n"
9446 													"\n"
9447 													"    fs_out_result = result;\n"
9448 													"}\n"
9449 													"\n";
9450 
9451 	static const GLchar* geometry_shader_template = "VERSION\n"
9452 													"\n"
9453 													"layout(points)                           in;\n"
9454 													"layout(triangle_strip, max_vertices = 4) out;\n"
9455 													"\n"
9456 													"in  vec4 tes_gs_result[];\n"
9457 													"out vec4 gs_fs_result;\n"
9458 													"\n"
9459 													"UNIFORM_DEFINITION\n"
9460 													"\n"
9461 													"void main()\n"
9462 													"{\n"
9463 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9464 													"\n"
9465 													"VERIFICATION"
9466 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9467 													"    {\n"
9468 													"         result = vec4(1, 0, 0, 1);\n"
9469 													"    }\n"
9470 													"\n"
9471 													"    gs_fs_result = result;\n"
9472 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
9473 													"    EmitVertex();\n"
9474 													"    gs_fs_result = result;\n"
9475 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
9476 													"    EmitVertex();\n"
9477 													"    gs_fs_result = result;\n"
9478 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
9479 													"    EmitVertex();\n"
9480 													"    gs_fs_result = result;\n"
9481 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
9482 													"    EmitVertex();\n"
9483 													"}\n"
9484 													"\n";
9485 
9486 	static const GLchar* tess_ctrl_shader_template =
9487 		"VERSION\n"
9488 		"\n"
9489 		"layout(vertices = 1) out;\n"
9490 		"\n"
9491 		"in  vec4 vs_tcs_result[];\n"
9492 		"out vec4 tcs_tes_result[];\n"
9493 		"\n"
9494 		"UNIFORM_DEFINITION\n"
9495 		"\n"
9496 		"void main()\n"
9497 		"{\n"
9498 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9499 		"\n"
9500 		"VERIFICATION"
9501 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9502 		"    {\n"
9503 		"         result = vec4(1, 0, 0, 1);\n"
9504 		"    }\n"
9505 		"\n"
9506 		"    tcs_tes_result[gl_InvocationID] = result;\n"
9507 		"\n"
9508 		"    gl_TessLevelOuter[0] = 1.0;\n"
9509 		"    gl_TessLevelOuter[1] = 1.0;\n"
9510 		"    gl_TessLevelOuter[2] = 1.0;\n"
9511 		"    gl_TessLevelOuter[3] = 1.0;\n"
9512 		"    gl_TessLevelInner[0] = 1.0;\n"
9513 		"    gl_TessLevelInner[1] = 1.0;\n"
9514 		"}\n"
9515 		"\n";
9516 
9517 	static const GLchar* tess_eval_shader_template = "VERSION\n"
9518 													 "\n"
9519 													 "layout(isolines, point_mode) in;\n"
9520 													 "\n"
9521 													 "in  vec4 tcs_tes_result[];\n"
9522 													 "out vec4 tes_gs_result;\n"
9523 													 "\n"
9524 													 "UNIFORM_DEFINITION\n"
9525 													 "\n"
9526 													 "void main()\n"
9527 													 "{\n"
9528 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
9529 													 "\n"
9530 													 "VERIFICATION"
9531 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9532 													 "    {\n"
9533 													 "         result = vec4(1, 0, 0, 1);\n"
9534 													 "    }\n"
9535 													 "\n"
9536 													 "    tes_gs_result = result;\n"
9537 													 "}\n"
9538 													 "\n";
9539 
9540 	static const GLchar* vertex_shader_template = "VERSION\n"
9541 												  "\n"
9542 												  "out vec4 vs_tcs_result;\n"
9543 												  "\n"
9544 												  "UNIFORM_DEFINITION\n"
9545 												  "\n"
9546 												  "void main()\n"
9547 												  "{\n"
9548 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
9549 												  "\n"
9550 												  "VERIFICATION"
9551 												  "\n"
9552 												  "    vs_tcs_result = result;\n"
9553 												  "}\n"
9554 												  "\n";
9555 
9556 	const GLchar* shader_template = 0;
9557 
9558 	switch (in_stage)
9559 	{
9560 	case Utils::COMPUTE_SHADER:
9561 		shader_template = compute_shader_template;
9562 		break;
9563 	case Utils::FRAGMENT_SHADER:
9564 		shader_template = fragment_shader_template;
9565 		break;
9566 	case Utils::GEOMETRY_SHADER:
9567 		shader_template = geometry_shader_template;
9568 		break;
9569 	case Utils::TESS_CTRL_SHADER:
9570 		shader_template = tess_ctrl_shader_template;
9571 		break;
9572 	case Utils::TESS_EVAL_SHADER:
9573 		shader_template = tess_eval_shader_template;
9574 		break;
9575 	case Utils::VERTEX_SHADER:
9576 		shader_template = vertex_shader_template;
9577 		break;
9578 	default:
9579 		TCU_FAIL("Invalid enum");
9580 		break;
9581 	}
9582 
9583 	out_source.m_parts[0].m_code = shader_template;
9584 
9585 	size_t position = 0;
9586 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9587 						out_source.m_parts[0].m_code);
9588 
9589 	Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9590 
9591 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9592 }
9593 
9594 /** Constructor
9595  *
9596  * @param context Test context
9597  **/
BindingUniformInvalidTest(deqp::Context & context)9598 BindingUniformInvalidTest::BindingUniformInvalidTest(deqp::Context& context)
9599 	: NegativeTestBase(context, "binding_uniform_invalid", "Test verifies invalid binding values")
9600 {
9601 	/* Nothing to be done here */
9602 }
9603 
9604 /** Set up next test case
9605  *
9606  * @param test_case_index Index of next test case
9607  *
9608  * @return false if there is no more test cases, true otherwise
9609  **/
prepareNextTestCase(glw::GLuint test_case_index)9610 bool BindingUniformInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
9611 {
9612 	switch (test_case_index)
9613 	{
9614 	case (glw::GLuint)-1:
9615 		m_case = TEST_CASES_MAX;
9616 		break;
9617 	case NEGATIVE_VALUE:
9618 	case VARIABLE_NAME:
9619 	case STD140:
9620 	case MISSING:
9621 		m_case = (TESTCASES)test_case_index;
9622 		break;
9623 	default:
9624 		return false;
9625 	}
9626 
9627 	return true;
9628 }
9629 
9630 /** Prepare source for given shader stage
9631  *
9632  * @param in_stage           Shader stage, compute shader will use 430
9633  * @param in_use_version_400 Select if 400 or 420 should be used
9634  * @param out_source         Prepared shader source instance
9635  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9636 void BindingUniformInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9637 													Utils::shaderSource& out_source)
9638 {
9639 	static const GLchar* verification_snippet = "    if (vec4(0, 0, 1, 1) != goku.gohan)\n"
9640 												"    {\n"
9641 												"        result = vec4(1, 0, 0, 1);\n"
9642 												"    }\n";
9643 
9644 	static const GLchar* uniform_definition = "layout(std140, binding BINDING) uniform GOKU {\n"
9645 											  "    vec4 gohan;\n"
9646 											  "    vec4 goten;\n"
9647 											  "} goku;\n";
9648 
9649 	static const GLchar* compute_shader_template =
9650 		"VERSION\n"
9651 		"\n"
9652 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9653 		"\n"
9654 		"writeonly uniform image2D uni_image;\n"
9655 		"\n"
9656 		"UNIFORM_DEFINITION\n"
9657 		"\n"
9658 		"void main()\n"
9659 		"{\n"
9660 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9661 		"\n"
9662 		"VERIFICATION"
9663 		"\n"
9664 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9665 		"}\n"
9666 		"\n";
9667 
9668 	static const GLchar* fragment_shader_template = "VERSION\n"
9669 													"\n"
9670 													"in  vec4 gs_fs_result;\n"
9671 													"out vec4 fs_out_result;\n"
9672 													"\n"
9673 													"UNIFORM_DEFINITION\n"
9674 													"\n"
9675 													"void main()\n"
9676 													"{\n"
9677 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9678 													"\n"
9679 													"VERIFICATION"
9680 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9681 													"    {\n"
9682 													"         result = vec4(1, 0, 0, 1);\n"
9683 													"    }\n"
9684 													"\n"
9685 													"    fs_out_result = result;\n"
9686 													"}\n"
9687 													"\n";
9688 
9689 	static const GLchar* geometry_shader_template = "VERSION\n"
9690 													"\n"
9691 													"layout(points)                           in;\n"
9692 													"layout(triangle_strip, max_vertices = 4) out;\n"
9693 													"\n"
9694 													"in  vec4 tes_gs_result[];\n"
9695 													"out vec4 gs_fs_result;\n"
9696 													"\n"
9697 													"UNIFORM_DEFINITION\n"
9698 													"\n"
9699 													"void main()\n"
9700 													"{\n"
9701 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9702 													"\n"
9703 													"VERIFICATION"
9704 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9705 													"    {\n"
9706 													"         result = vec4(1, 0, 0, 1);\n"
9707 													"    }\n"
9708 													"\n"
9709 													"    gs_fs_result = result;\n"
9710 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
9711 													"    EmitVertex();\n"
9712 													"    gs_fs_result = result;\n"
9713 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
9714 													"    EmitVertex();\n"
9715 													"    gs_fs_result = result;\n"
9716 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
9717 													"    EmitVertex();\n"
9718 													"    gs_fs_result = result;\n"
9719 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
9720 													"    EmitVertex();\n"
9721 													"}\n"
9722 													"\n";
9723 
9724 	static const GLchar* tess_ctrl_shader_template =
9725 		"VERSION\n"
9726 		"\n"
9727 		"layout(vertices = 1) out;\n"
9728 		"\n"
9729 		"in  vec4 vs_tcs_result[];\n"
9730 		"out vec4 tcs_tes_result[];\n"
9731 		"\n"
9732 		"UNIFORM_DEFINITION\n"
9733 		"\n"
9734 		"void main()\n"
9735 		"{\n"
9736 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9737 		"\n"
9738 		"VERIFICATION"
9739 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9740 		"    {\n"
9741 		"         result = vec4(1, 0, 0, 1);\n"
9742 		"    }\n"
9743 		"\n"
9744 		"    tcs_tes_result[gl_InvocationID] = result;\n"
9745 		"\n"
9746 		"    gl_TessLevelOuter[0] = 1.0;\n"
9747 		"    gl_TessLevelOuter[1] = 1.0;\n"
9748 		"    gl_TessLevelOuter[2] = 1.0;\n"
9749 		"    gl_TessLevelOuter[3] = 1.0;\n"
9750 		"    gl_TessLevelInner[0] = 1.0;\n"
9751 		"    gl_TessLevelInner[1] = 1.0;\n"
9752 		"}\n"
9753 		"\n";
9754 
9755 	static const GLchar* tess_eval_shader_template = "VERSION\n"
9756 													 "\n"
9757 													 "layout(isolines, point_mode) in;\n"
9758 													 "\n"
9759 													 "in  vec4 tcs_tes_result[];\n"
9760 													 "out vec4 tes_gs_result;\n"
9761 													 "\n"
9762 													 "UNIFORM_DEFINITION\n"
9763 													 "\n"
9764 													 "void main()\n"
9765 													 "{\n"
9766 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
9767 													 "\n"
9768 													 "VERIFICATION"
9769 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9770 													 "    {\n"
9771 													 "         result = vec4(1, 0, 0, 1);\n"
9772 													 "    }\n"
9773 													 "\n"
9774 													 "    tes_gs_result = result;\n"
9775 													 "}\n"
9776 													 "\n";
9777 
9778 	static const GLchar* vertex_shader_template = "VERSION\n"
9779 												  "\n"
9780 												  "out vec4 vs_tcs_result;\n"
9781 												  "\n"
9782 												  "UNIFORM_DEFINITION\n"
9783 												  "\n"
9784 												  "void main()\n"
9785 												  "{\n"
9786 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
9787 												  "\n"
9788 												  "VERIFICATION"
9789 												  "\n"
9790 												  "    vs_tcs_result = result;\n"
9791 												  "}\n"
9792 												  "\n";
9793 
9794 	const GLchar* shader_template = 0;
9795 
9796 	switch (in_stage)
9797 	{
9798 	case Utils::COMPUTE_SHADER:
9799 		shader_template = compute_shader_template;
9800 		break;
9801 	case Utils::FRAGMENT_SHADER:
9802 		shader_template = fragment_shader_template;
9803 		break;
9804 	case Utils::GEOMETRY_SHADER:
9805 		shader_template = geometry_shader_template;
9806 		break;
9807 	case Utils::TESS_CTRL_SHADER:
9808 		shader_template = tess_ctrl_shader_template;
9809 		break;
9810 	case Utils::TESS_EVAL_SHADER:
9811 		shader_template = tess_eval_shader_template;
9812 		break;
9813 	case Utils::VERTEX_SHADER:
9814 		shader_template = vertex_shader_template;
9815 		break;
9816 	default:
9817 		TCU_FAIL("Invalid enum");
9818 		break;
9819 	}
9820 
9821 	out_source.m_parts[0].m_code = shader_template;
9822 
9823 	size_t position = 0;
9824 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9825 						out_source.m_parts[0].m_code);
9826 
9827 	Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9828 
9829 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9830 
9831 	Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
9832 }
9833 
getCaseString(TESTCASES test_case)9834 const GLchar* BindingUniformInvalidTest::getCaseString(TESTCASES test_case)
9835 {
9836 	(void)test_case;
9837 	const GLchar* binding = 0;
9838 
9839 	switch (m_case)
9840 	{
9841 	case NEGATIVE_VALUE:
9842 		binding = "= -1";
9843 		break;
9844 	case VARIABLE_NAME:
9845 		binding = "= goku";
9846 		break;
9847 	case STD140:
9848 		binding = "= std140";
9849 		break;
9850 	case MISSING:
9851 		binding = "";
9852 		break;
9853 	case TEST_CASES_MAX:
9854 		binding = "= 0";
9855 		break;
9856 	default:
9857 		TCU_FAIL("Invalid enum");
9858 	}
9859 
9860 	return binding;
9861 }
9862 
9863 /** Constructor
9864  *
9865  * @param context Test context
9866  **/
BindingSamplersTest(deqp::Context & context)9867 BindingSamplersTest::BindingSamplersTest(deqp::Context& context)
9868 	: GLSLTestBase(context, "binding_samplers", "Test verifies smaplers binding")
9869 	, m_goku_texture(context)
9870 	, m_vegeta_texture(context)
9871 	, m_trunks_texture(context)
9872 	, m_buffer(context)
9873 {
9874 	/* Nothing to be done here */
9875 }
9876 
9877 /** Set up next test case
9878  *
9879  * @param test_case_index Index of next test case
9880  *
9881  * @return false if there is no more test cases, true otherwise
9882  **/
prepareNextTestCase(glw::GLuint test_case_index)9883 bool BindingSamplersTest::prepareNextTestCase(glw::GLuint test_case_index)
9884 {
9885 	switch (test_case_index)
9886 	{
9887 	case (glw::GLuint)-1:
9888 	case 0:
9889 		m_test_case = Utils::TEX_2D;
9890 		break;
9891 	case 1:
9892 		m_test_case = Utils::TEX_BUFFER;
9893 		break;
9894 	case 2:
9895 		m_test_case = Utils::TEX_2D_RECT;
9896 		break;
9897 	case 3:
9898 		m_test_case = Utils::TEX_2D_ARRAY;
9899 		break;
9900 	case 4:
9901 		m_test_case = Utils::TEX_3D;
9902 		break;
9903 	case 5:
9904 		m_test_case = Utils::TEX_CUBE;
9905 		break;
9906 	case 6:
9907 		m_test_case = Utils::TEX_1D;
9908 		break;
9909 	case 7:
9910 		m_test_case = Utils::TEX_1D_ARRAY;
9911 		break;
9912 	default:
9913 		return false;
9914 		break;
9915 	}
9916 
9917 	m_context.getTestContext().getLog() << tcu::TestLog::Message
9918 										<< "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
9919 										<< tcu::TestLog::EndMessage;
9920 
9921 	return true;
9922 }
9923 
9924 /** Prepare source for given shader stage
9925  *
9926  * @param in_stage           Shader stage, compute shader will use 430
9927  * @param in_use_version_400 Select if 400 or 420 should be used
9928  * @param out_source         Prepared shader source instance
9929  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9930 void BindingSamplersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9931 											  Utils::shaderSource& out_source)
9932 {
9933 	static const GLchar* uni_goku = "layout(binding = 0) uniform TYPE goku;\n";
9934 
9935 	static const GLchar* uni_vegeta = "layout(binding = 1) uniform TYPE vegeta;\n";
9936 
9937 	static const GLchar* uni_trunks = "layout(binding = 3) uniform TYPE trunks;\n\n";
9938 
9939 	static const GLchar* verification_snippet = "    TEX_COORD_TYPE tex_coord = TEX_COORD_TYPE(COORDINATES);\n"
9940 												"    vec4 goku_color   = SAMPLING_FUNCTION(goku,   tex_coord);\n"
9941 												"    vec4 vegeta_color = SAMPLING_FUNCTION(vegeta, tex_coord);\n"
9942 												"    vec4 trunks_color = SAMPLING_FUNCTION(trunks, tex_coord);\n"
9943 												"\n"
9944 												"    if ((vec4(1, 0, 0, 0) != goku_color)   ||\n"
9945 												"        (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
9946 												"        (vec4(0, 0, 1, 0) != trunks_color)  )\n"
9947 												"    {\n"
9948 												"        result = vec4(1, 0, 0, 1);\n"
9949 												"    }\n";
9950 
9951 	static const GLchar* compute_shader_template =
9952 		"VERSION\n"
9953 		"\n"
9954 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9955 		"\n"
9956 		"writeonly uniform image2D uni_image;\n"
9957 		"\n"
9958 		"UNI_GOKU\n"
9959 		"UNI_VEGETA\n"
9960 		"UNI_TRUNKS\n"
9961 		"\n"
9962 		"void main()\n"
9963 		"{\n"
9964 		"    vec4 result = vec4(0, 1, 0, 1);\n"
9965 		"\n"
9966 		"VERIFICATION"
9967 		"\n"
9968 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9969 		"}\n"
9970 		"\n";
9971 
9972 	static const GLchar* fragment_shader_template = "VERSION\n"
9973 													"\n"
9974 													"in  vec4 gs_fs_result;\n"
9975 													"out vec4 fs_out_result;\n"
9976 													"\n"
9977 													"UNI_GOKU\n"
9978 													"UNI_VEGETA\n"
9979 													"UNI_TRUNKS\n"
9980 													"\n"
9981 													"void main()\n"
9982 													"{\n"
9983 													"    vec4 result = vec4(0, 1, 0, 1);\n"
9984 													"\n"
9985 													"VERIFICATION"
9986 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9987 													"    {\n"
9988 													"         result = vec4(1, 0, 0, 1);\n"
9989 													"    }\n"
9990 													"\n"
9991 													"    fs_out_result = result;\n"
9992 													"}\n"
9993 													"\n";
9994 
9995 	static const GLchar* geometry_shader_template = "VERSION\n"
9996 													"\n"
9997 													"layout(points)                           in;\n"
9998 													"layout(triangle_strip, max_vertices = 4) out;\n"
9999 													"\n"
10000 													"in  vec4 tes_gs_result[];\n"
10001 													"out vec4 gs_fs_result;\n"
10002 													"\n"
10003 													"UNI_TRUNKS\n"
10004 													"UNI_GOKU\n"
10005 													"UNI_VEGETA\n"
10006 													"\n"
10007 													"void main()\n"
10008 													"{\n"
10009 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10010 													"\n"
10011 													"VERIFICATION"
10012 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10013 													"    {\n"
10014 													"         result = vec4(1, 0, 0, 1);\n"
10015 													"    }\n"
10016 													"\n"
10017 													"    gs_fs_result = result;\n"
10018 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
10019 													"    EmitVertex();\n"
10020 													"    gs_fs_result = result;\n"
10021 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
10022 													"    EmitVertex();\n"
10023 													"    gs_fs_result = result;\n"
10024 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
10025 													"    EmitVertex();\n"
10026 													"    gs_fs_result = result;\n"
10027 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
10028 													"    EmitVertex();\n"
10029 													"}\n"
10030 													"\n";
10031 
10032 	static const GLchar* tess_ctrl_shader_template =
10033 		"VERSION\n"
10034 		"\n"
10035 		"layout(vertices = 1) out;\n"
10036 		"\n"
10037 		"in  vec4 vs_tcs_result[];\n"
10038 		"out vec4 tcs_tes_result[];\n"
10039 		"\n"
10040 		"UNI_VEGETA\n"
10041 		"UNI_TRUNKS\n"
10042 		"UNI_GOKU\n"
10043 		"\n"
10044 		"void main()\n"
10045 		"{\n"
10046 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10047 		"\n"
10048 		"VERIFICATION"
10049 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10050 		"    {\n"
10051 		"         result = vec4(1, 0, 0, 1);\n"
10052 		"    }\n"
10053 		"\n"
10054 		"    tcs_tes_result[gl_InvocationID] = result;\n"
10055 		"\n"
10056 		"    gl_TessLevelOuter[0] = 1.0;\n"
10057 		"    gl_TessLevelOuter[1] = 1.0;\n"
10058 		"    gl_TessLevelOuter[2] = 1.0;\n"
10059 		"    gl_TessLevelOuter[3] = 1.0;\n"
10060 		"    gl_TessLevelInner[0] = 1.0;\n"
10061 		"    gl_TessLevelInner[1] = 1.0;\n"
10062 		"}\n"
10063 		"\n";
10064 
10065 	static const GLchar* tess_eval_shader_template = "VERSION\n"
10066 													 "\n"
10067 													 "layout(isolines, point_mode) in;\n"
10068 													 "\n"
10069 													 "in  vec4 tcs_tes_result[];\n"
10070 													 "out vec4 tes_gs_result;\n"
10071 													 "\n"
10072 													 "UNI_GOKU\n"
10073 													 "UNI_TRUNKS\n"
10074 													 "UNI_VEGETA\n"
10075 													 "\n"
10076 													 "void main()\n"
10077 													 "{\n"
10078 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
10079 													 "\n"
10080 													 "VERIFICATION"
10081 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10082 													 "    {\n"
10083 													 "         result = vec4(1, 0, 0, 1);\n"
10084 													 "    }\n"
10085 													 "\n"
10086 													 "    tes_gs_result = result;\n"
10087 													 "}\n"
10088 													 "\n";
10089 
10090 	static const GLchar* vertex_shader_template = "VERSION\n"
10091 												  "\n"
10092 												  "out vec4 vs_tcs_result;\n"
10093 												  "\n"
10094 												  "UNI_TRUNKS\n"
10095 												  "UNI_VEGETA\n"
10096 												  "UNI_GOKU\n"
10097 												  "\n"
10098 												  "void main()\n"
10099 												  "{\n"
10100 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
10101 												  "\n"
10102 												  "VERIFICATION"
10103 												  "\n"
10104 												  "    vs_tcs_result = result;\n"
10105 												  "}\n"
10106 												  "\n";
10107 
10108 	const Utils::TYPES base_tex_coord_type = (Utils::TEX_BUFFER == m_test_case) ? Utils::INT : Utils::FLOAT;
10109 	const GLchar*	  coordinates		   = 0;
10110 	GLuint			   n_coordinates	   = Utils::getNumberOfCoordinates(m_test_case);
10111 	const GLchar*	  shader_template	 = 0;
10112 	const GLchar*	  sampler_type		   = Utils::getSamplerType(m_test_case);
10113 	const GLchar*	  sampling_function   = (Utils::TEX_BUFFER == m_test_case) ? "texelFetch" : "texture";
10114 	const GLchar*	  tex_coord_type	  = Utils::getTypeName(base_tex_coord_type, 1 /* n_columns */, n_coordinates);
10115 
10116 	switch (in_stage)
10117 	{
10118 	case Utils::COMPUTE_SHADER:
10119 		shader_template = compute_shader_template;
10120 		break;
10121 	case Utils::FRAGMENT_SHADER:
10122 		shader_template = fragment_shader_template;
10123 		break;
10124 	case Utils::GEOMETRY_SHADER:
10125 		shader_template = geometry_shader_template;
10126 		break;
10127 	case Utils::TESS_CTRL_SHADER:
10128 		shader_template = tess_ctrl_shader_template;
10129 		break;
10130 	case Utils::TESS_EVAL_SHADER:
10131 		shader_template = tess_eval_shader_template;
10132 		break;
10133 	case Utils::VERTEX_SHADER:
10134 		shader_template = vertex_shader_template;
10135 		break;
10136 	default:
10137 		TCU_FAIL("Invalid enum");
10138 		break;
10139 	}
10140 
10141 	switch (n_coordinates)
10142 	{
10143 	case 1:
10144 		coordinates = "0";
10145 		break;
10146 	case 2:
10147 		coordinates = "0, 0";
10148 		break;
10149 	case 3:
10150 		coordinates = "0, 0, 0";
10151 		break;
10152 	case 4:
10153 		coordinates = "0, 0, 0, 0";
10154 		break;
10155 	}
10156 
10157 	out_source.m_parts[0].m_code = shader_template;
10158 
10159 	size_t position = 0;
10160 
10161 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10162 						out_source.m_parts[0].m_code);
10163 
10164 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10165 
10166 	position -= strlen(verification_snippet);
10167 
10168 	Utils::replaceToken("COORDINATES", position, coordinates, out_source.m_parts[0].m_code);
10169 
10170 	Utils::replaceAllTokens("SAMPLING_FUNCTION", sampling_function, out_source.m_parts[0].m_code);
10171 
10172 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10173 
10174 	Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
10175 
10176 	Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
10177 
10178 	Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
10179 
10180 	Utils::replaceAllTokens("TYPE", sampler_type, out_source.m_parts[0].m_code);
10181 }
10182 
10183 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10184  *
10185  * @param program Current program
10186  **/
prepareUniforms(Utils::program & program)10187 void BindingSamplersTest::prepareUniforms(Utils::program& program)
10188 {
10189 	(void)program;
10190 	static const GLuint goku_data   = 0x000000ff;
10191 	static const GLuint vegeta_data = 0x0000ff00;
10192 	static const GLuint trunks_data = 0x00ff0000;
10193 
10194 	prepareTexture(m_goku_texture, m_test_case, goku_data);
10195 	prepareTexture(m_vegeta_texture, m_test_case, vegeta_data);
10196 	prepareTexture(m_trunks_texture, m_test_case, trunks_data);
10197 
10198 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10199 
10200 	gl.activeTexture(GL_TEXTURE0);
10201 	GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10202 
10203 	m_goku_texture.bind();
10204 
10205 	gl.activeTexture(GL_TEXTURE1);
10206 	GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10207 
10208 	m_vegeta_texture.bind();
10209 
10210 	gl.activeTexture(GL_TEXTURE3);
10211 	GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10212 
10213 	m_trunks_texture.bind();
10214 }
10215 
10216 /** Overwrite of releaseResource method, release extra buffer and texture
10217  *
10218  * @param ignored
10219  **/
releaseResource()10220 void BindingSamplersTest::releaseResource()
10221 {
10222 	m_goku_texture.release();
10223 	m_vegeta_texture.release();
10224 	m_trunks_texture.release();
10225 	m_buffer.release();
10226 }
10227 
10228 /** Prepare texture of given type filled with given color
10229  *
10230  * @param texture      Texture
10231  * @param texture_type Type of texture
10232  * @param color        Color
10233  **/
prepareTexture(Utils::texture & texture,Utils::TEXTURE_TYPES texture_type,glw::GLuint color)10234 void BindingSamplersTest::prepareTexture(Utils::texture& texture, Utils::TEXTURE_TYPES texture_type, glw::GLuint color)
10235 {
10236 	(void)texture_type;
10237 	static const GLuint width  = 16;
10238 	static const GLuint height = 16;
10239 	static const GLuint depth  = 1;
10240 
10241 	std::vector<GLuint> texture_data;
10242 	texture_data.resize(width * height);
10243 
10244 	for (GLuint i = 0; i < texture_data.size(); ++i)
10245 	{
10246 		texture_data[i] = color;
10247 	}
10248 
10249 	if (Utils::TEX_BUFFER != m_test_case)
10250 	{
10251 		texture.create(width, height, depth, GL_RGBA8, m_test_case);
10252 
10253 		texture.update(width, height, depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10254 	}
10255 	else
10256 	{
10257 		m_buffer.generate(GL_TEXTURE_BUFFER);
10258 		m_buffer.update(texture_data.size(), &texture_data[0], GL_STATIC_DRAW);
10259 
10260 		texture.createBuffer(GL_RGBA8, m_buffer.m_id);
10261 	}
10262 }
10263 
10264 /** Constructor
10265  *
10266  * @param context Test context
10267  **/
BindingSamplerSingleTest(deqp::Context & context)10268 BindingSamplerSingleTest::BindingSamplerSingleTest(deqp::Context& context)
10269 	: GLSLTestBase(context, "binding_sampler_single", "Test verifies sampler binding"), m_goku_texture(context)
10270 {
10271 	/* Nothing to be done here */
10272 }
10273 
10274 /** Set up next test case
10275  *
10276  * @param test_case_index Index of next test case
10277  *
10278  * @return false if there is no more test cases, true otherwise
10279  **/
prepareNextTestCase(glw::GLuint test_case_index)10280 bool BindingSamplerSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
10281 {
10282 	switch (test_case_index)
10283 	{
10284 	case (glw::GLuint)-1:
10285 	case 0:
10286 		m_test_stage = Utils::VERTEX_SHADER;
10287 		break;
10288 	case 1:
10289 		m_test_stage = Utils::TESS_CTRL_SHADER;
10290 		break;
10291 	case 2:
10292 		m_test_stage = Utils::TESS_EVAL_SHADER;
10293 		break;
10294 	case 3:
10295 		m_test_stage = Utils::GEOMETRY_SHADER;
10296 		break;
10297 	case 4:
10298 		m_test_stage = Utils::FRAGMENT_SHADER;
10299 		break;
10300 	default:
10301 		return false;
10302 		break;
10303 	}
10304 
10305 	m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
10306 										<< Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
10307 										<< tcu::TestLog::EndMessage;
10308 
10309 	return true;
10310 }
10311 
10312 /** Prepare source for given shader stage
10313  *
10314  * @param in_stage           Shader stage, compute shader will use 430
10315  * @param in_use_version_400 Select if 400 or 420 should be used
10316  * @param out_source         Prepared shader source instance
10317  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10318 void BindingSamplerSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10319 												   Utils::shaderSource& out_source)
10320 {
10321 	static const GLchar* uni_goku_with_binding = "layout(binding = 2) uniform sampler2D goku;\n";
10322 
10323 	static const GLchar* uni_goku_no_binding = "uniform sampler2D goku;\n";
10324 
10325 	static const GLchar* verification_snippet = "    vec4 goku_color = texture(goku, vec2(0,0));\n"
10326 												"\n"
10327 												"    if (vec4(1, 0, 0, 0) != goku_color)\n"
10328 												"    {\n"
10329 												"        result = vec4(1, 0, 0, 1);\n"
10330 												"    }\n";
10331 
10332 	static const GLchar* compute_shader_template =
10333 		"VERSION\n"
10334 		"\n"
10335 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10336 		"\n"
10337 		"writeonly uniform image2D uni_image;\n"
10338 		"\n"
10339 		"UNI_GOKU\n"
10340 		"\n"
10341 		"void main()\n"
10342 		"{\n"
10343 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10344 		"\n"
10345 		"VERIFICATION"
10346 		"\n"
10347 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10348 		"}\n"
10349 		"\n";
10350 
10351 	static const GLchar* fragment_shader_template = "VERSION\n"
10352 													"\n"
10353 													"in  vec4 gs_fs_result;\n"
10354 													"out vec4 fs_out_result;\n"
10355 													"\n"
10356 													"UNI_GOKU\n"
10357 													"\n"
10358 													"void main()\n"
10359 													"{\n"
10360 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10361 													"\n"
10362 													"VERIFICATION"
10363 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10364 													"    {\n"
10365 													"         result = vec4(1, 0, 0, 1);\n"
10366 													"    }\n"
10367 													"\n"
10368 													"    fs_out_result = result;\n"
10369 													"}\n"
10370 													"\n";
10371 
10372 	static const GLchar* geometry_shader_template = "VERSION\n"
10373 													"\n"
10374 													"layout(points)                           in;\n"
10375 													"layout(triangle_strip, max_vertices = 4) out;\n"
10376 													"\n"
10377 													"in  vec4 tes_gs_result[];\n"
10378 													"out vec4 gs_fs_result;\n"
10379 													"\n"
10380 													"UNI_GOKU\n"
10381 													"\n"
10382 													"void main()\n"
10383 													"{\n"
10384 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10385 													"\n"
10386 													"VERIFICATION"
10387 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10388 													"    {\n"
10389 													"         result = vec4(1, 0, 0, 1);\n"
10390 													"    }\n"
10391 													"\n"
10392 													"    gs_fs_result = result;\n"
10393 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
10394 													"    EmitVertex();\n"
10395 													"    gs_fs_result = result;\n"
10396 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
10397 													"    EmitVertex();\n"
10398 													"    gs_fs_result = result;\n"
10399 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
10400 													"    EmitVertex();\n"
10401 													"    gs_fs_result = result;\n"
10402 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
10403 													"    EmitVertex();\n"
10404 													"}\n"
10405 													"\n";
10406 
10407 	static const GLchar* tess_ctrl_shader_template =
10408 		"VERSION\n"
10409 		"\n"
10410 		"layout(vertices = 1) out;\n"
10411 		"\n"
10412 		"in  vec4 vs_tcs_result[];\n"
10413 		"out vec4 tcs_tes_result[];\n"
10414 		"\n"
10415 		"UNI_GOKU\n"
10416 		"\n"
10417 		"void main()\n"
10418 		"{\n"
10419 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10420 		"\n"
10421 		"VERIFICATION"
10422 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10423 		"    {\n"
10424 		"         result = vec4(1, 0, 0, 1);\n"
10425 		"    }\n"
10426 		"\n"
10427 		"    tcs_tes_result[gl_InvocationID] = result;\n"
10428 		"\n"
10429 		"    gl_TessLevelOuter[0] = 1.0;\n"
10430 		"    gl_TessLevelOuter[1] = 1.0;\n"
10431 		"    gl_TessLevelOuter[2] = 1.0;\n"
10432 		"    gl_TessLevelOuter[3] = 1.0;\n"
10433 		"    gl_TessLevelInner[0] = 1.0;\n"
10434 		"    gl_TessLevelInner[1] = 1.0;\n"
10435 		"}\n"
10436 		"\n";
10437 
10438 	static const GLchar* tess_eval_shader_template = "VERSION\n"
10439 													 "\n"
10440 													 "layout(isolines, point_mode) in;\n"
10441 													 "\n"
10442 													 "in  vec4 tcs_tes_result[];\n"
10443 													 "out vec4 tes_gs_result;\n"
10444 													 "\n"
10445 													 "UNI_GOKU\n"
10446 													 "\n"
10447 													 "void main()\n"
10448 													 "{\n"
10449 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
10450 													 "\n"
10451 													 "VERIFICATION"
10452 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10453 													 "    {\n"
10454 													 "         result = vec4(1, 0, 0, 1);\n"
10455 													 "    }\n"
10456 													 "\n"
10457 													 "    tes_gs_result = result;\n"
10458 													 "}\n"
10459 													 "\n";
10460 
10461 	static const GLchar* vertex_shader_template = "VERSION\n"
10462 												  "\n"
10463 												  "out vec4 vs_tcs_result;\n"
10464 												  "\n"
10465 												  "UNI_GOKU\n"
10466 												  "\n"
10467 												  "void main()\n"
10468 												  "{\n"
10469 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
10470 												  "\n"
10471 												  "VERIFICATION"
10472 												  "\n"
10473 												  "    vs_tcs_result = result;\n"
10474 												  "}\n"
10475 												  "\n";
10476 
10477 	const GLchar* shader_template	= 0;
10478 	const GLchar* uniform_definition = uni_goku_no_binding;
10479 
10480 	switch (in_stage)
10481 	{
10482 	case Utils::COMPUTE_SHADER:
10483 		shader_template	= compute_shader_template;
10484 		uniform_definition = uni_goku_with_binding;
10485 		break;
10486 	case Utils::FRAGMENT_SHADER:
10487 		shader_template = fragment_shader_template;
10488 		break;
10489 	case Utils::GEOMETRY_SHADER:
10490 		shader_template = geometry_shader_template;
10491 		break;
10492 	case Utils::TESS_CTRL_SHADER:
10493 		shader_template = tess_ctrl_shader_template;
10494 		break;
10495 	case Utils::TESS_EVAL_SHADER:
10496 		shader_template = tess_eval_shader_template;
10497 		break;
10498 	case Utils::VERTEX_SHADER:
10499 		shader_template = vertex_shader_template;
10500 		break;
10501 	default:
10502 		TCU_FAIL("Invalid enum");
10503 		break;
10504 	}
10505 
10506 	if (in_stage == m_test_stage)
10507 	{
10508 		uniform_definition = uni_goku_with_binding;
10509 	}
10510 
10511 	out_source.m_parts[0].m_code = shader_template;
10512 
10513 	size_t position = 0;
10514 
10515 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10516 						out_source.m_parts[0].m_code);
10517 
10518 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10519 
10520 	Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
10521 }
10522 
10523 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10524  *
10525  * @param program Current program
10526  **/
prepareUniforms(Utils::program & program)10527 void BindingSamplerSingleTest::prepareUniforms(Utils::program& program)
10528 {
10529 	(void)program;
10530 	static const GLuint goku_data = 0x000000ff;
10531 
10532 	m_goku_texture.create(16, 16, GL_RGBA8);
10533 
10534 	std::vector<GLuint> texture_data;
10535 	texture_data.resize(16 * 16);
10536 
10537 	for (GLuint i = 0; i < texture_data.size(); ++i)
10538 	{
10539 		texture_data[i] = goku_data;
10540 	}
10541 
10542 	m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10543 
10544 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10545 
10546 	gl.activeTexture(GL_TEXTURE2);
10547 	GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10548 
10549 	m_goku_texture.bind();
10550 }
10551 
10552 /** Overwrite of releaseResource method, release extra texture
10553  *
10554  * @param ignored
10555  **/
releaseResource()10556 void BindingSamplerSingleTest::releaseResource()
10557 {
10558 	m_goku_texture.release();
10559 }
10560 
10561 /** Constructor
10562  *
10563  * @param context Test context
10564  **/
BindingSamplerArrayTest(deqp::Context & context)10565 BindingSamplerArrayTest::BindingSamplerArrayTest(deqp::Context& context)
10566 	: GLSLTestBase(context, "binding_sampler_array", "Test verifies binding of sampler arrays")
10567 	, m_goku_00_texture(context)
10568 	, m_goku_01_texture(context)
10569 	, m_goku_02_texture(context)
10570 	, m_goku_03_texture(context)
10571 	, m_goku_04_texture(context)
10572 	, m_goku_05_texture(context)
10573 	, m_goku_06_texture(context)
10574 {
10575 	/* Nothing to be done here */
10576 }
10577 
10578 /** Prepare source for given shader stage
10579  *
10580  * @param in_stage           Shader stage, compute shader will use 430
10581  * @param in_use_version_400 Select if 400 or 420 should be used
10582  * @param out_source         Prepared shader source instance
10583  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10584 void BindingSamplerArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10585 												  Utils::shaderSource& out_source)
10586 {
10587 	static const GLchar* uni_goku = "layout(binding = 1) uniform sampler2D goku[7];\n";
10588 
10589 	static const GLchar* verification_snippet = "    vec4 color[7];\n"
10590 												"\n"
10591 												"    for (uint i = 0u; i < 7; ++i)\n"
10592 												"    {\n"
10593 												"        color[i] = texture(goku[i], vec2(0, 0));\n"
10594 												"    }\n"
10595 												"\n"
10596 												"    if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
10597 												"        (vec4(0, 0, 0, 1) != color[1]) ||\n"
10598 												"        (vec4(0, 0, 1, 0) != color[2]) ||\n"
10599 												"        (vec4(0, 0, 1, 1) != color[3]) ||\n"
10600 												"        (vec4(0, 1, 0, 0) != color[4]) ||\n"
10601 												"        (vec4(0, 1, 0, 1) != color[5]) ||\n"
10602 												"        (vec4(0, 1, 1, 0) != color[6]) )\n"
10603 												"    {\n"
10604 												"        result = vec4(1, 0, 0, 1);\n"
10605 												"    }\n";
10606 
10607 	static const GLchar* compute_shader_template =
10608 		"VERSION\n"
10609 		"\n"
10610 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10611 		"\n"
10612 		"writeonly uniform image2D uni_image;\n"
10613 		"\n"
10614 		"UNI_GOKU\n"
10615 		"\n"
10616 		"void main()\n"
10617 		"{\n"
10618 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10619 		"\n"
10620 		"VERIFICATION"
10621 		"\n"
10622 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10623 		"}\n"
10624 		"\n";
10625 
10626 	static const GLchar* fragment_shader_template = "VERSION\n"
10627 													"\n"
10628 													"in  vec4 gs_fs_result;\n"
10629 													"out vec4 fs_out_result;\n"
10630 													"\n"
10631 													"UNI_GOKU\n"
10632 													"\n"
10633 													"void main()\n"
10634 													"{\n"
10635 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10636 													"\n"
10637 													"VERIFICATION"
10638 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10639 													"    {\n"
10640 													"         result = vec4(1, 0, 0, 1);\n"
10641 													"    }\n"
10642 													"\n"
10643 													"    fs_out_result = result;\n"
10644 													"}\n"
10645 													"\n";
10646 
10647 	static const GLchar* geometry_shader_template = "VERSION\n"
10648 													"\n"
10649 													"layout(points)                           in;\n"
10650 													"layout(triangle_strip, max_vertices = 4) out;\n"
10651 													"\n"
10652 													"in  vec4 tes_gs_result[];\n"
10653 													"out vec4 gs_fs_result;\n"
10654 													"\n"
10655 													"UNI_GOKU\n"
10656 													"\n"
10657 													"void main()\n"
10658 													"{\n"
10659 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10660 													"\n"
10661 													"VERIFICATION"
10662 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10663 													"    {\n"
10664 													"         result = vec4(1, 0, 0, 1);\n"
10665 													"    }\n"
10666 													"\n"
10667 													"    gs_fs_result = result;\n"
10668 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
10669 													"    EmitVertex();\n"
10670 													"    gs_fs_result = result;\n"
10671 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
10672 													"    EmitVertex();\n"
10673 													"    gs_fs_result = result;\n"
10674 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
10675 													"    EmitVertex();\n"
10676 													"    gs_fs_result = result;\n"
10677 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
10678 													"    EmitVertex();\n"
10679 													"}\n"
10680 													"\n";
10681 
10682 	static const GLchar* tess_ctrl_shader_template =
10683 		"VERSION\n"
10684 		"\n"
10685 		"layout(vertices = 1) out;\n"
10686 		"\n"
10687 		"in  vec4 vs_tcs_result[];\n"
10688 		"out vec4 tcs_tes_result[];\n"
10689 		"\n"
10690 		"UNI_GOKU\n"
10691 		"\n"
10692 		"void main()\n"
10693 		"{\n"
10694 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10695 		"\n"
10696 		"VERIFICATION"
10697 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10698 		"    {\n"
10699 		"         result = vec4(1, 0, 0, 1);\n"
10700 		"    }\n"
10701 		"\n"
10702 		"    tcs_tes_result[gl_InvocationID] = result;\n"
10703 		"\n"
10704 		"    gl_TessLevelOuter[0] = 1.0;\n"
10705 		"    gl_TessLevelOuter[1] = 1.0;\n"
10706 		"    gl_TessLevelOuter[2] = 1.0;\n"
10707 		"    gl_TessLevelOuter[3] = 1.0;\n"
10708 		"    gl_TessLevelInner[0] = 1.0;\n"
10709 		"    gl_TessLevelInner[1] = 1.0;\n"
10710 		"}\n"
10711 		"\n";
10712 
10713 	static const GLchar* tess_eval_shader_template = "VERSION\n"
10714 													 "\n"
10715 													 "layout(isolines, point_mode) in;\n"
10716 													 "\n"
10717 													 "in  vec4 tcs_tes_result[];\n"
10718 													 "out vec4 tes_gs_result;\n"
10719 													 "\n"
10720 													 "UNI_GOKU\n"
10721 													 "\n"
10722 													 "void main()\n"
10723 													 "{\n"
10724 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
10725 													 "\n"
10726 													 "VERIFICATION"
10727 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10728 													 "    {\n"
10729 													 "         result = vec4(1, 0, 0, 1);\n"
10730 													 "    }\n"
10731 													 "\n"
10732 													 "    tes_gs_result = result;\n"
10733 													 "}\n"
10734 													 "\n";
10735 
10736 	static const GLchar* vertex_shader_template = "VERSION\n"
10737 												  "\n"
10738 												  "out vec4 vs_tcs_result;\n"
10739 												  "\n"
10740 												  "UNI_GOKU\n"
10741 												  "\n"
10742 												  "void main()\n"
10743 												  "{\n"
10744 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
10745 												  "\n"
10746 												  "VERIFICATION"
10747 												  "\n"
10748 												  "    vs_tcs_result = result;\n"
10749 												  "}\n"
10750 												  "\n";
10751 
10752 	const GLchar* shader_template = 0;
10753 
10754 	switch (in_stage)
10755 	{
10756 	case Utils::COMPUTE_SHADER:
10757 		shader_template = compute_shader_template;
10758 		break;
10759 	case Utils::FRAGMENT_SHADER:
10760 		shader_template = fragment_shader_template;
10761 		break;
10762 	case Utils::GEOMETRY_SHADER:
10763 		shader_template = geometry_shader_template;
10764 		break;
10765 	case Utils::TESS_CTRL_SHADER:
10766 		shader_template = tess_ctrl_shader_template;
10767 		break;
10768 	case Utils::TESS_EVAL_SHADER:
10769 		shader_template = tess_eval_shader_template;
10770 		break;
10771 	case Utils::VERTEX_SHADER:
10772 		shader_template = vertex_shader_template;
10773 		break;
10774 	default:
10775 		TCU_FAIL("Invalid enum");
10776 		break;
10777 	}
10778 
10779 	out_source.m_parts[0].m_code = shader_template;
10780 
10781 	size_t position = 0;
10782 
10783 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10784 						out_source.m_parts[0].m_code);
10785 
10786 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10787 
10788 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10789 }
10790 
10791 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10792  *
10793  * @param program Current program
10794  **/
prepareUniforms(Utils::program & program)10795 void BindingSamplerArrayTest::prepareUniforms(Utils::program& program)
10796 {
10797 	static const GLuint goku_data[7] = {
10798 		0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
10799 	};
10800 
10801 	static const GLuint binding_offset = 1;
10802 
10803 	Utils::texture* textures[7] = {
10804 		&m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10805 		&m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10806 	};
10807 
10808 	std::vector<GLuint> texture_data;
10809 	texture_data.resize(16 * 16);
10810 
10811 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10812 
10813 	for (GLuint i = 0; i < 7; ++i)
10814 	{
10815 		GLint expected_binding = i + binding_offset;
10816 
10817 		checkBinding(program, i, expected_binding);
10818 
10819 		gl.activeTexture(GL_TEXTURE0 + expected_binding);
10820 		GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10821 
10822 		textures[i]->create(16, 16, GL_RGBA8);
10823 
10824 		for (GLuint j = 0; j < texture_data.size(); ++j)
10825 		{
10826 			texture_data[j] = goku_data[i];
10827 		}
10828 
10829 		textures[i]->update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10830 	}
10831 }
10832 
10833 /** Overwrite of releaseResource method, release extra textures
10834  *
10835  * @param ignored
10836  **/
releaseResource()10837 void BindingSamplerArrayTest::releaseResource()
10838 {
10839 	Utils::texture* textures[7] = {
10840 		&m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10841 		&m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10842 	};
10843 
10844 	for (GLuint i = 0; i < 7; ++i)
10845 	{
10846 		textures[i]->release();
10847 	}
10848 }
10849 
10850 /** Verifies that API reports correct uniform binding
10851  *
10852  * @param program          Program
10853  * @param index            Index of array element
10854  * @param expected_binding Expected binding
10855  **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)10856 void BindingSamplerArrayTest::checkBinding(Utils::program& program, GLuint index, GLint expected_binding)
10857 {
10858 	if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
10859 	{
10860 		TCU_FAIL("Wrong binding reported by API");
10861 	}
10862 }
10863 
10864 /** Constructor
10865  *
10866  * @param context Test context
10867  **/
BindingSamplerDefaultTest(deqp::Context & context)10868 BindingSamplerDefaultTest::BindingSamplerDefaultTest(deqp::Context& context)
10869 	: APITestBase(context, "binding_sampler_default", "Test verifies default sampler binding")
10870 {
10871 	/* Nothing to be done here */
10872 }
10873 
10874 /** Execute API call and verifies results
10875  *
10876  * @return true when results are positive, false otherwise
10877  **/
checkResults(Utils::program & program)10878 bool BindingSamplerDefaultTest::checkResults(Utils::program& program)
10879 {
10880 	return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
10881 }
10882 
10883 /** Prepare source for given shader stage
10884  *
10885  * @param in_stage           Shader stage, compute shader will use 430
10886  * @param in_use_version_400 Select if 400 or 420 should be used
10887  * @param out_source         Prepared shader source instance
10888  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10889 void BindingSamplerDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10890 													Utils::shaderSource& out_source)
10891 {
10892 	static const GLchar* uni_goku = "uniform sampler2D goku;\n";
10893 
10894 	static const GLchar* verification_snippet = "    vec4 color = texture(goku, vec2(0,0));\n"
10895 												"    if (vec4(1, 0, 0, 0) != color)\n"
10896 												"    {\n"
10897 												"        result = vec4(1, 0, 0, 1);\n"
10898 												"    }\n";
10899 
10900 	static const GLchar* compute_shader_template =
10901 		"VERSION\n"
10902 		"\n"
10903 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10904 		"\n"
10905 		"writeonly uniform image2D uni_image;\n"
10906 		"\n"
10907 		"UNI_GOKU\n"
10908 		"\n"
10909 		"void main()\n"
10910 		"{\n"
10911 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10912 		"\n"
10913 		"VERIFICATION"
10914 		"\n"
10915 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10916 		"}\n"
10917 		"\n";
10918 
10919 	static const GLchar* fragment_shader_template = "VERSION\n"
10920 													"\n"
10921 													"in  vec4 gs_fs_result;\n"
10922 													"out vec4 fs_out_result;\n"
10923 													"\n"
10924 													"UNI_GOKU\n"
10925 													"\n"
10926 													"void main()\n"
10927 													"{\n"
10928 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10929 													"\n"
10930 													"VERIFICATION"
10931 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10932 													"    {\n"
10933 													"         result = vec4(1, 0, 0, 1);\n"
10934 													"    }\n"
10935 													"\n"
10936 													"    fs_out_result = result;\n"
10937 													"}\n"
10938 													"\n";
10939 
10940 	static const GLchar* geometry_shader_template = "VERSION\n"
10941 													"\n"
10942 													"layout(points)                           in;\n"
10943 													"layout(triangle_strip, max_vertices = 4) out;\n"
10944 													"\n"
10945 													"in  vec4 tes_gs_result[];\n"
10946 													"out vec4 gs_fs_result;\n"
10947 													"\n"
10948 													"UNI_GOKU\n"
10949 													"\n"
10950 													"void main()\n"
10951 													"{\n"
10952 													"    vec4 result = vec4(0, 1, 0, 1);\n"
10953 													"\n"
10954 													"VERIFICATION"
10955 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10956 													"    {\n"
10957 													"         result = vec4(1, 0, 0, 1);\n"
10958 													"    }\n"
10959 													"\n"
10960 													"    gs_fs_result = result;\n"
10961 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
10962 													"    EmitVertex();\n"
10963 													"    gs_fs_result = result;\n"
10964 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
10965 													"    EmitVertex();\n"
10966 													"    gs_fs_result = result;\n"
10967 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
10968 													"    EmitVertex();\n"
10969 													"    gs_fs_result = result;\n"
10970 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
10971 													"    EmitVertex();\n"
10972 													"}\n"
10973 													"\n";
10974 
10975 	static const GLchar* tess_ctrl_shader_template =
10976 		"VERSION\n"
10977 		"\n"
10978 		"layout(vertices = 1) out;\n"
10979 		"\n"
10980 		"in  vec4 vs_tcs_result[];\n"
10981 		"out vec4 tcs_tes_result[];\n"
10982 		"\n"
10983 		"UNI_GOKU\n"
10984 		"\n"
10985 		"void main()\n"
10986 		"{\n"
10987 		"    vec4 result = vec4(0, 1, 0, 1);\n"
10988 		"\n"
10989 		"VERIFICATION"
10990 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10991 		"    {\n"
10992 		"         result = vec4(1, 0, 0, 1);\n"
10993 		"    }\n"
10994 		"\n"
10995 		"    tcs_tes_result[gl_InvocationID] = result;\n"
10996 		"\n"
10997 		"    gl_TessLevelOuter[0] = 1.0;\n"
10998 		"    gl_TessLevelOuter[1] = 1.0;\n"
10999 		"    gl_TessLevelOuter[2] = 1.0;\n"
11000 		"    gl_TessLevelOuter[3] = 1.0;\n"
11001 		"    gl_TessLevelInner[0] = 1.0;\n"
11002 		"    gl_TessLevelInner[1] = 1.0;\n"
11003 		"}\n"
11004 		"\n";
11005 
11006 	static const GLchar* tess_eval_shader_template = "VERSION\n"
11007 													 "\n"
11008 													 "layout(isolines, point_mode) in;\n"
11009 													 "\n"
11010 													 "in  vec4 tcs_tes_result[];\n"
11011 													 "out vec4 tes_gs_result;\n"
11012 													 "\n"
11013 													 "UNI_GOKU\n"
11014 													 "\n"
11015 													 "void main()\n"
11016 													 "{\n"
11017 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
11018 													 "\n"
11019 													 "VERIFICATION"
11020 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11021 													 "    {\n"
11022 													 "         result = vec4(1, 0, 0, 1);\n"
11023 													 "    }\n"
11024 													 "\n"
11025 													 "    tes_gs_result = result;\n"
11026 													 "}\n"
11027 													 "\n";
11028 
11029 	static const GLchar* vertex_shader_template = "VERSION\n"
11030 												  "\n"
11031 												  "out vec4 vs_tcs_result;\n"
11032 												  "\n"
11033 												  "UNI_GOKU\n"
11034 												  "\n"
11035 												  "void main()\n"
11036 												  "{\n"
11037 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
11038 												  "\n"
11039 												  "VERIFICATION"
11040 												  "\n"
11041 												  "    vs_tcs_result = result;\n"
11042 												  "}\n"
11043 												  "\n";
11044 
11045 	const GLchar* shader_template = 0;
11046 
11047 	switch (in_stage)
11048 	{
11049 	case Utils::COMPUTE_SHADER:
11050 		shader_template = compute_shader_template;
11051 		break;
11052 	case Utils::FRAGMENT_SHADER:
11053 		shader_template = fragment_shader_template;
11054 		break;
11055 	case Utils::GEOMETRY_SHADER:
11056 		shader_template = geometry_shader_template;
11057 		break;
11058 	case Utils::TESS_CTRL_SHADER:
11059 		shader_template = tess_ctrl_shader_template;
11060 		break;
11061 	case Utils::TESS_EVAL_SHADER:
11062 		shader_template = tess_eval_shader_template;
11063 		break;
11064 	case Utils::VERTEX_SHADER:
11065 		shader_template = vertex_shader_template;
11066 		break;
11067 	default:
11068 		TCU_FAIL("Invalid enum");
11069 		break;
11070 	}
11071 
11072 	out_source.m_parts[0].m_code = shader_template;
11073 
11074 	size_t position = 0;
11075 
11076 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11077 						out_source.m_parts[0].m_code);
11078 
11079 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11080 
11081 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11082 }
11083 
11084 /** Constructor
11085  *
11086  * @param context Test context
11087  **/
BindingSamplerAPIOverrideTest(deqp::Context & context)11088 BindingSamplerAPIOverrideTest::BindingSamplerAPIOverrideTest(deqp::Context& context)
11089 	: GLSLTestBase(context, "binding_sampler_api_override", "Verifies that API can override sampler binding")
11090 	, m_goku_texture(context)
11091 {
11092 	/* Nothing to be done here */
11093 }
11094 
11095 /** Prepare source for given shader stage
11096  *
11097  * @param in_stage           Shader stage, compute shader will use 430
11098  * @param in_use_version_400 Select if 400 or 420 should be used
11099  * @param out_source         Prepared shader source instance
11100  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11101 void BindingSamplerAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11102 														Utils::shaderSource& out_source)
11103 {
11104 	static const GLchar* uni_goku = "layout(binding = 2) uniform sampler2D goku;\n";
11105 
11106 	static const GLchar* verification_snippet = "    vec4 color = texture(goku, vec2(0,0));\n"
11107 												"    if (vec4(1, 0, 0, 0) != color)\n"
11108 												"    {\n"
11109 												"        result = vec4(1, 0, 0, 1);\n"
11110 												"    }\n";
11111 
11112 	static const GLchar* compute_shader_template =
11113 		"VERSION\n"
11114 		"\n"
11115 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11116 		"\n"
11117 		"writeonly uniform image2D uni_image;\n"
11118 		"\n"
11119 		"UNI_GOKU\n"
11120 		"\n"
11121 		"void main()\n"
11122 		"{\n"
11123 		"    vec4 result = vec4(0, 1, 0, 1);\n"
11124 		"\n"
11125 		"VERIFICATION"
11126 		"\n"
11127 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11128 		"}\n"
11129 		"\n";
11130 
11131 	static const GLchar* fragment_shader_template = "VERSION\n"
11132 													"\n"
11133 													"in  vec4 gs_fs_result;\n"
11134 													"out vec4 fs_out_result;\n"
11135 													"\n"
11136 													"UNI_GOKU\n"
11137 													"\n"
11138 													"void main()\n"
11139 													"{\n"
11140 													"    vec4 result = vec4(0, 1, 0, 1);\n"
11141 													"\n"
11142 													"VERIFICATION"
11143 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11144 													"    {\n"
11145 													"         result = vec4(1, 0, 0, 1);\n"
11146 													"    }\n"
11147 													"\n"
11148 													"    fs_out_result = result;\n"
11149 													"}\n"
11150 													"\n";
11151 
11152 	static const GLchar* geometry_shader_template = "VERSION\n"
11153 													"\n"
11154 													"layout(points)                           in;\n"
11155 													"layout(triangle_strip, max_vertices = 4) out;\n"
11156 													"\n"
11157 													"in  vec4 tes_gs_result[];\n"
11158 													"out vec4 gs_fs_result;\n"
11159 													"\n"
11160 													"UNI_GOKU\n"
11161 													"\n"
11162 													"void main()\n"
11163 													"{\n"
11164 													"    vec4 result = vec4(0, 1, 0, 1);\n"
11165 													"\n"
11166 													"VERIFICATION"
11167 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11168 													"    {\n"
11169 													"         result = vec4(1, 0, 0, 1);\n"
11170 													"    }\n"
11171 													"\n"
11172 													"    gs_fs_result = result;\n"
11173 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
11174 													"    EmitVertex();\n"
11175 													"    gs_fs_result = result;\n"
11176 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
11177 													"    EmitVertex();\n"
11178 													"    gs_fs_result = result;\n"
11179 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
11180 													"    EmitVertex();\n"
11181 													"    gs_fs_result = result;\n"
11182 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
11183 													"    EmitVertex();\n"
11184 													"}\n"
11185 													"\n";
11186 
11187 	static const GLchar* tess_ctrl_shader_template =
11188 		"VERSION\n"
11189 		"\n"
11190 		"layout(vertices = 1) out;\n"
11191 		"\n"
11192 		"in  vec4 vs_tcs_result[];\n"
11193 		"out vec4 tcs_tes_result[];\n"
11194 		"\n"
11195 		"UNI_GOKU\n"
11196 		"\n"
11197 		"void main()\n"
11198 		"{\n"
11199 		"    vec4 result = vec4(0, 1, 0, 1);\n"
11200 		"\n"
11201 		"VERIFICATION"
11202 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11203 		"    {\n"
11204 		"         result = vec4(1, 0, 0, 1);\n"
11205 		"    }\n"
11206 		"\n"
11207 		"    tcs_tes_result[gl_InvocationID] = result;\n"
11208 		"\n"
11209 		"    gl_TessLevelOuter[0] = 1.0;\n"
11210 		"    gl_TessLevelOuter[1] = 1.0;\n"
11211 		"    gl_TessLevelOuter[2] = 1.0;\n"
11212 		"    gl_TessLevelOuter[3] = 1.0;\n"
11213 		"    gl_TessLevelInner[0] = 1.0;\n"
11214 		"    gl_TessLevelInner[1] = 1.0;\n"
11215 		"}\n"
11216 		"\n";
11217 
11218 	static const GLchar* tess_eval_shader_template = "VERSION\n"
11219 													 "\n"
11220 													 "layout(isolines, point_mode) in;\n"
11221 													 "\n"
11222 													 "in  vec4 tcs_tes_result[];\n"
11223 													 "out vec4 tes_gs_result;\n"
11224 													 "\n"
11225 													 "UNI_GOKU\n"
11226 													 "\n"
11227 													 "void main()\n"
11228 													 "{\n"
11229 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
11230 													 "\n"
11231 													 "VERIFICATION"
11232 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11233 													 "    {\n"
11234 													 "         result = vec4(1, 0, 0, 1);\n"
11235 													 "    }\n"
11236 													 "\n"
11237 													 "    tes_gs_result = result;\n"
11238 													 "}\n"
11239 													 "\n";
11240 
11241 	static const GLchar* vertex_shader_template = "VERSION\n"
11242 												  "\n"
11243 												  "out vec4 vs_tcs_result;\n"
11244 												  "\n"
11245 												  "UNI_GOKU\n"
11246 												  "\n"
11247 												  "void main()\n"
11248 												  "{\n"
11249 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
11250 												  "\n"
11251 												  "VERIFICATION"
11252 												  "\n"
11253 												  "    vs_tcs_result = result;\n"
11254 												  "}\n"
11255 												  "\n";
11256 
11257 	const GLchar* shader_template = 0;
11258 
11259 	switch (in_stage)
11260 	{
11261 	case Utils::COMPUTE_SHADER:
11262 		shader_template = compute_shader_template;
11263 		break;
11264 	case Utils::FRAGMENT_SHADER:
11265 		shader_template = fragment_shader_template;
11266 		break;
11267 	case Utils::GEOMETRY_SHADER:
11268 		shader_template = geometry_shader_template;
11269 		break;
11270 	case Utils::TESS_CTRL_SHADER:
11271 		shader_template = tess_ctrl_shader_template;
11272 		break;
11273 	case Utils::TESS_EVAL_SHADER:
11274 		shader_template = tess_eval_shader_template;
11275 		break;
11276 	case Utils::VERTEX_SHADER:
11277 		shader_template = vertex_shader_template;
11278 		break;
11279 	default:
11280 		TCU_FAIL("Invalid enum");
11281 		break;
11282 	}
11283 
11284 	out_source.m_parts[0].m_code = shader_template;
11285 
11286 	size_t position = 0;
11287 
11288 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11289 						out_source.m_parts[0].m_code);
11290 
11291 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11292 
11293 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11294 }
11295 
11296 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11297  *
11298  * @param program Current program
11299  **/
prepareUniforms(Utils::program & program)11300 void BindingSamplerAPIOverrideTest::prepareUniforms(Utils::program& program)
11301 {
11302 	static const GLuint goku_data   = 0x000000ff;
11303 	static const GLint  new_binding = 11;
11304 
11305 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11306 
11307 	const GLint uniform_location = program.getUniformLocation("goku");
11308 	if (-1 == uniform_location)
11309 	{
11310 		TCU_FAIL("Uniform is inactive");
11311 	}
11312 
11313 	gl.uniform1i(uniform_location, new_binding);
11314 
11315 	GLint binding = -1;
11316 
11317 	gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
11318 	GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
11319 
11320 	if (new_binding != binding)
11321 	{
11322 		TCU_FAIL("Wrong binding value");
11323 		return;
11324 	}
11325 
11326 	m_goku_texture.create(16, 16, GL_RGBA8);
11327 
11328 	std::vector<GLuint> texture_data;
11329 	texture_data.resize(16 * 16);
11330 
11331 	for (GLuint i = 0; i < texture_data.size(); ++i)
11332 	{
11333 		texture_data[i] = goku_data;
11334 	}
11335 
11336 	m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
11337 
11338 	gl.activeTexture(GL_TEXTURE11);
11339 	GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
11340 
11341 	m_goku_texture.bind();
11342 }
11343 
11344 /** Overwrite of releaseResource method, release extra texture
11345  *
11346  * @param ignored
11347  **/
releaseResource()11348 void BindingSamplerAPIOverrideTest::releaseResource()
11349 {
11350 	m_goku_texture.release();
11351 }
11352 
11353 /** Constructor
11354  *
11355  * @param context Test context
11356  **/
BindingSamplerInvalidTest(deqp::Context & context)11357 BindingSamplerInvalidTest::BindingSamplerInvalidTest(deqp::Context& context)
11358 	: NegativeTestBase(context, "binding_sampler_invalid", "Test verifies invalid binding values")
11359 {
11360 	/* Nothing to be done here */
11361 }
11362 
11363 /** Set up next test case
11364  *
11365  * @param test_case_index Index of next test case
11366  *
11367  * @return false if there is no more test cases, true otherwise
11368  **/
prepareNextTestCase(glw::GLuint test_case_index)11369 bool BindingSamplerInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
11370 {
11371 	switch (test_case_index)
11372 	{
11373 	case (glw::GLuint)-1:
11374 		m_case = TEST_CASES_MAX;
11375 		break;
11376 	case NEGATIVE_VALUE:
11377 	case VARIABLE_NAME:
11378 	case STD140:
11379 	case MISSING:
11380 		m_case = (TESTCASES)test_case_index;
11381 		break;
11382 	default:
11383 		return false;
11384 	}
11385 
11386 	return true;
11387 }
11388 
11389 /** Prepare source for given shader stage
11390  *
11391  * @param in_stage           Shader stage, compute shader will use 430
11392  * @param in_use_version_400 Select if 400 or 420 should be used
11393  * @param out_source         Prepared shader source instance
11394  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11395 void BindingSamplerInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11396 													Utils::shaderSource& out_source)
11397 {
11398 	static const GLchar* uni_goku = "layout(binding BINDING) uniform sampler2D goku;\n";
11399 
11400 	static const GLchar* verification_snippet = "    vec4 color = texture(goku, vec2(0,0));\n"
11401 												"    if (vec4(1, 0, 0, 0) != color)\n"
11402 												"    {\n"
11403 												"        result = vec4(1, 0, 0, 1);\n"
11404 												"    }\n";
11405 
11406 	static const GLchar* compute_shader_template =
11407 		"VERSION\n"
11408 		"\n"
11409 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11410 		"\n"
11411 		"writeonly uniform image2D uni_image;\n"
11412 		"\n"
11413 		"UNI_GOKU\n"
11414 		"\n"
11415 		"void main()\n"
11416 		"{\n"
11417 		"    vec4 result = vec4(0, 1, 0, 1);\n"
11418 		"\n"
11419 		"VERIFICATION"
11420 		"\n"
11421 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11422 		"}\n"
11423 		"\n";
11424 
11425 	static const GLchar* fragment_shader_template = "VERSION\n"
11426 													"\n"
11427 													"in  vec4 gs_fs_result;\n"
11428 													"out vec4 fs_out_result;\n"
11429 													"\n"
11430 													"UNI_GOKU\n"
11431 													"\n"
11432 													"void main()\n"
11433 													"{\n"
11434 													"    vec4 result = vec4(0, 1, 0, 1);\n"
11435 													"\n"
11436 													"VERIFICATION"
11437 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11438 													"    {\n"
11439 													"         result = vec4(1, 0, 0, 1);\n"
11440 													"    }\n"
11441 													"\n"
11442 													"    fs_out_result = result;\n"
11443 													"}\n"
11444 													"\n";
11445 
11446 	static const GLchar* geometry_shader_template = "VERSION\n"
11447 													"\n"
11448 													"layout(points)                           in;\n"
11449 													"layout(triangle_strip, max_vertices = 4) out;\n"
11450 													"\n"
11451 													"in  vec4 tes_gs_result[];\n"
11452 													"out vec4 gs_fs_result;\n"
11453 													"\n"
11454 													"UNI_GOKU\n"
11455 													"\n"
11456 													"void main()\n"
11457 													"{\n"
11458 													"    vec4 result = vec4(0, 1, 0, 1);\n"
11459 													"\n"
11460 													"VERIFICATION"
11461 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11462 													"    {\n"
11463 													"         result = vec4(1, 0, 0, 1);\n"
11464 													"    }\n"
11465 													"\n"
11466 													"    gs_fs_result = result;\n"
11467 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
11468 													"    EmitVertex();\n"
11469 													"    gs_fs_result = result;\n"
11470 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
11471 													"    EmitVertex();\n"
11472 													"    gs_fs_result = result;\n"
11473 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
11474 													"    EmitVertex();\n"
11475 													"    gs_fs_result = result;\n"
11476 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
11477 													"    EmitVertex();\n"
11478 													"}\n"
11479 													"\n";
11480 
11481 	static const GLchar* tess_ctrl_shader_template =
11482 		"VERSION\n"
11483 		"\n"
11484 		"layout(vertices = 1) out;\n"
11485 		"\n"
11486 		"in  vec4 vs_tcs_result[];\n"
11487 		"out vec4 tcs_tes_result[];\n"
11488 		"\n"
11489 		"UNI_GOKU\n"
11490 		"\n"
11491 		"void main()\n"
11492 		"{\n"
11493 		"    vec4 result = vec4(0, 1, 0, 1);\n"
11494 		"\n"
11495 		"VERIFICATION"
11496 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11497 		"    {\n"
11498 		"         result = vec4(1, 0, 0, 1);\n"
11499 		"    }\n"
11500 		"\n"
11501 		"    tcs_tes_result[gl_InvocationID] = result;\n"
11502 		"\n"
11503 		"    gl_TessLevelOuter[0] = 1.0;\n"
11504 		"    gl_TessLevelOuter[1] = 1.0;\n"
11505 		"    gl_TessLevelOuter[2] = 1.0;\n"
11506 		"    gl_TessLevelOuter[3] = 1.0;\n"
11507 		"    gl_TessLevelInner[0] = 1.0;\n"
11508 		"    gl_TessLevelInner[1] = 1.0;\n"
11509 		"}\n"
11510 		"\n";
11511 
11512 	static const GLchar* tess_eval_shader_template = "VERSION\n"
11513 													 "\n"
11514 													 "layout(isolines, point_mode) in;\n"
11515 													 "\n"
11516 													 "in  vec4 tcs_tes_result[];\n"
11517 													 "out vec4 tes_gs_result;\n"
11518 													 "\n"
11519 													 "UNI_GOKU\n"
11520 													 "\n"
11521 													 "void main()\n"
11522 													 "{\n"
11523 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
11524 													 "\n"
11525 													 "VERIFICATION"
11526 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11527 													 "    {\n"
11528 													 "         result = vec4(1, 0, 0, 1);\n"
11529 													 "    }\n"
11530 													 "\n"
11531 													 "    tes_gs_result = result;\n"
11532 													 "}\n"
11533 													 "\n";
11534 
11535 	static const GLchar* vertex_shader_template = "VERSION\n"
11536 												  "\n"
11537 												  "out vec4 vs_tcs_result;\n"
11538 												  "\n"
11539 												  "UNI_GOKU\n"
11540 												  "\n"
11541 												  "void main()\n"
11542 												  "{\n"
11543 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
11544 												  "\n"
11545 												  "VERIFICATION"
11546 												  "\n"
11547 												  "    vs_tcs_result = result;\n"
11548 												  "}\n"
11549 												  "\n";
11550 
11551 	const GLchar* shader_template = 0;
11552 
11553 	switch (in_stage)
11554 	{
11555 	case Utils::COMPUTE_SHADER:
11556 		shader_template = compute_shader_template;
11557 		break;
11558 	case Utils::FRAGMENT_SHADER:
11559 		shader_template = fragment_shader_template;
11560 		break;
11561 	case Utils::GEOMETRY_SHADER:
11562 		shader_template = geometry_shader_template;
11563 		break;
11564 	case Utils::TESS_CTRL_SHADER:
11565 		shader_template = tess_ctrl_shader_template;
11566 		break;
11567 	case Utils::TESS_EVAL_SHADER:
11568 		shader_template = tess_eval_shader_template;
11569 		break;
11570 	case Utils::VERTEX_SHADER:
11571 		shader_template = vertex_shader_template;
11572 		break;
11573 	default:
11574 		TCU_FAIL("Invalid enum");
11575 		break;
11576 	}
11577 
11578 	out_source.m_parts[0].m_code = shader_template;
11579 
11580 	size_t position = 0;
11581 
11582 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11583 						out_source.m_parts[0].m_code);
11584 
11585 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11586 
11587 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11588 
11589 	Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
11590 }
11591 
getCaseString(TESTCASES test_case)11592 const GLchar* BindingSamplerInvalidTest::getCaseString(TESTCASES test_case)
11593 {
11594 	(void)test_case;
11595 	const GLchar* binding = 0;
11596 
11597 	switch (m_case)
11598 	{
11599 	case NEGATIVE_VALUE:
11600 		binding = "= -1";
11601 		break;
11602 	case VARIABLE_NAME:
11603 		binding = "= goku";
11604 		break;
11605 	case STD140:
11606 		binding = "= std140";
11607 		break;
11608 	case MISSING:
11609 		binding = "";
11610 		break;
11611 	case TEST_CASES_MAX:
11612 		binding = "= 0";
11613 		break;
11614 	default:
11615 		TCU_FAIL("Invalid enum");
11616 	}
11617 
11618 	return binding;
11619 }
11620 
11621 /* Constants used by BindingImagesTest */
11622 const GLuint BindingImagesTest::m_goku_data   = 0x000000ff;
11623 const GLuint BindingImagesTest::m_vegeta_data = 0x0000ff00;
11624 const GLuint BindingImagesTest::m_trunks_data = 0x00ff0000;
11625 
11626 /** Constructor
11627  *
11628  * @param context Test context
11629  **/
BindingImagesTest(deqp::Context & context)11630 BindingImagesTest::BindingImagesTest(deqp::Context& context)
11631 	: BindingImageTest(context, "binding_images", "Test verifies binding of images")
11632 	, m_goku_texture(context)
11633 	, m_vegeta_texture(context)
11634 	, m_trunks_texture(context)
11635 	, m_goku_buffer(context)
11636 	, m_vegeta_buffer(context)
11637 	, m_trunks_buffer(context)
11638 {
11639 	/* Nothing to be done here */
11640 }
11641 
11642 /** Set up next test case
11643  *
11644  * @param test_case_index Index of next test case
11645  *
11646  * @return false if there is no more test cases, true otherwise
11647  **/
prepareNextTestCase(glw::GLuint test_case_index)11648 bool BindingImagesTest::prepareNextTestCase(glw::GLuint test_case_index)
11649 {
11650 	switch (test_case_index)
11651 	{
11652 	case (glw::GLuint)-1:
11653 	case 0:
11654 		m_test_case = Utils::TEX_2D;
11655 		break;
11656 	case 1:
11657 		m_test_case = Utils::TEX_BUFFER;
11658 		break;
11659 	case 2:
11660 		m_test_case = Utils::TEX_2D_RECT;
11661 		break;
11662 	case 3:
11663 		m_test_case = Utils::TEX_2D_ARRAY;
11664 		break;
11665 	case 4:
11666 		m_test_case = Utils::TEX_3D;
11667 		break;
11668 	case 5:
11669 		m_test_case = Utils::TEX_CUBE;
11670 		break;
11671 	case 6:
11672 		m_test_case = Utils::TEX_1D;
11673 		break;
11674 	case 7:
11675 		m_test_case = Utils::TEX_1D_ARRAY;
11676 		break;
11677 	default:
11678 		return false;
11679 		break;
11680 	}
11681 
11682 	m_context.getTestContext().getLog() << tcu::TestLog::Message
11683 										<< "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
11684 										<< tcu::TestLog::EndMessage;
11685 
11686 	return true;
11687 }
11688 
11689 /** Prepare source for given shader stage
11690  *
11691  * @param in_stage           Shader stage, compute shader will use 430
11692  * @param in_use_version_400 Select if 400 or 420 should be used
11693  * @param out_source         Prepared shader source instance
11694  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11695 void BindingImagesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11696 											Utils::shaderSource& out_source)
11697 {
11698 	static const GLchar* uni_goku = "layout(binding = 1, rgba8) uniform TYPE goku;\n";
11699 
11700 	static const GLchar* uni_vegeta = "layout(binding = 2, rgba8) uniform TYPE vegeta;\n";
11701 
11702 	static const GLchar* uni_trunks = "layout(binding = 4, rgba8) uniform TYPE trunks;\n\n";
11703 
11704 	static const GLchar* verification_snippet = "    TEX_COORD_TYPE tex_coord_read  = TEX_COORD_TYPE(COORDINATES);\n"
11705 												"    TEX_COORD_TYPE tex_coord_write = TEX_COORD_TYPE(COORDINATES);\n"
11706 												"    vec4 goku_color   = imageLoad(goku,   tex_coord_read);\n"
11707 												"    vec4 vegeta_color = imageLoad(vegeta, tex_coord_read);\n"
11708 												"    vec4 trunks_color = imageLoad(trunks, tex_coord_read);\n"
11709 												"\n"
11710 												"    imageStore(goku,   tex_coord_write, vec4(0, 1, 0, 1));\n"
11711 												"    imageStore(vegeta, tex_coord_write, vec4(0, 1, 0, 1));\n"
11712 												"    imageStore(trunks, tex_coord_write, vec4(0, 1, 0, 1));\n"
11713 												"\n"
11714 												"    if ((vec4(1, 0, 0, 0) != goku_color)   ||\n"
11715 												"        (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
11716 												"        (vec4(0, 0, 1, 0) != trunks_color)  )\n"
11717 												"    {\n"
11718 												"        result = goku_color;\n"
11719 												"        //result = vec4(1, 0, 0, 1);\n"
11720 												"    }\n";
11721 
11722 	static const GLchar* compute_shader_template =
11723 		"VERSION\n"
11724 		"#extension GL_ARB_shader_image_load_store : enable\n"
11725 		"\n"
11726 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11727 		"\n"
11728 		"writeonly uniform image2D uni_image;\n"
11729 		"\n"
11730 		"UNI_GOKU\n"
11731 		"UNI_VEGETA\n"
11732 		"UNI_TRUNKS\n"
11733 		"\n"
11734 		"void main()\n"
11735 		"{\n"
11736 		"    vec4 result = vec4(0, 1, 0, 1);\n"
11737 		"\n"
11738 		"    if(gl_GlobalInvocationID.xy == vec2(0, 0)) {\n"
11739 		"VERIFICATION"
11740 		"    }\n"
11741 		"\n"
11742 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11743 		"}\n"
11744 		"\n";
11745 
11746 	static const GLchar* fragment_shader_template = "VERSION\n"
11747 													"#extension GL_ARB_shader_image_load_store : enable\n"
11748 													"\n"
11749 													"in  vec4 gs_fs_result;\n"
11750 													"out vec4 fs_out_result;\n"
11751 													"\n"
11752 													"UNI_GOKU\n"
11753 													"UNI_VEGETA\n"
11754 													"UNI_TRUNKS\n"
11755 													"\n"
11756 													"void main()\n"
11757 													"{\n"
11758 													"    vec4 result = vec4(0, 1, 0, 1);\n"
11759 													"\n"
11760 													"VERIFICATION"
11761 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11762 													"    {\n"
11763 													"         result = vec4(1, 0, 0, 1);\n"
11764 													"    }\n"
11765 													"\n"
11766 													"    fs_out_result = result;\n"
11767 													"}\n"
11768 													"\n";
11769 
11770 	static const GLchar* geometry_shader_template = "VERSION\n"
11771 													"#extension GL_ARB_shader_image_load_store : enable\n"
11772 													"\n"
11773 													"layout(points)                           in;\n"
11774 													"layout(triangle_strip, max_vertices = 4) out;\n"
11775 													"\n"
11776 													"in  vec4 tes_gs_result[];\n"
11777 													"out vec4 gs_fs_result;\n"
11778 													"\n"
11779 													"#if IMAGES\n"
11780 													"UNI_TRUNKS\n"
11781 													"UNI_GOKU\n"
11782 													"UNI_VEGETA\n"
11783 													"#endif\n"
11784 													"\n"
11785 													"void main()\n"
11786 													"{\n"
11787 													"    vec4 result = vec4(0, 1, 0, 1);\n"
11788 													"\n"
11789 													"#if IMAGES\n"
11790 													"VERIFICATION else\n"
11791 													"#endif\n"
11792 													"    if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11793 													"    {\n"
11794 													"         result = vec4(1, 0, 0, 1);\n"
11795 													"    }\n"
11796 													"\n"
11797 													"    gs_fs_result = result;\n"
11798 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
11799 													"    EmitVertex();\n"
11800 													"    gs_fs_result = result;\n"
11801 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
11802 													"    EmitVertex();\n"
11803 													"    gs_fs_result = result;\n"
11804 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
11805 													"    EmitVertex();\n"
11806 													"    gs_fs_result = result;\n"
11807 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
11808 													"    EmitVertex();\n"
11809 													"}\n"
11810 													"\n";
11811 
11812 	static const GLchar* tess_ctrl_shader_template =
11813 		"VERSION\n"
11814 		"#extension GL_ARB_shader_image_load_store : enable\n"
11815 		"\n"
11816 		"layout(vertices = 1) out;\n"
11817 		"\n"
11818 		"in  vec4 vs_tcs_result[];\n"
11819 		"out vec4 tcs_tes_result[];\n"
11820 		"\n"
11821 		"#if IMAGES\n"
11822 		"UNI_VEGETA\n"
11823 		"UNI_TRUNKS\n"
11824 		"UNI_GOKU\n"
11825 		"#endif\n"
11826 		"\n"
11827 		"void main()\n"
11828 		"{\n"
11829 		"    vec4 result = vec4(0, 1, 0, 1);\n"
11830 		"\n"
11831 		"#if IMAGES\n"
11832 		"VERIFICATION else\n"
11833 		"#endif\n"
11834 		"    if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11835 		"    {\n"
11836 		"         result = vec4(1, 0, 0, 1);\n"
11837 		"    }\n"
11838 		"\n"
11839 		"    tcs_tes_result[gl_InvocationID] = result;\n"
11840 		"\n"
11841 		"    gl_TessLevelOuter[0] = 1.0;\n"
11842 		"    gl_TessLevelOuter[1] = 1.0;\n"
11843 		"    gl_TessLevelOuter[2] = 1.0;\n"
11844 		"    gl_TessLevelOuter[3] = 1.0;\n"
11845 		"    gl_TessLevelInner[0] = 1.0;\n"
11846 		"    gl_TessLevelInner[1] = 1.0;\n"
11847 		"}\n"
11848 		"\n";
11849 
11850 	static const GLchar* tess_eval_shader_template = "VERSION\n"
11851 													 "#extension GL_ARB_shader_image_load_store : enable\n"
11852 													 "\n"
11853 													 "layout(isolines, point_mode) in;\n"
11854 													 "\n"
11855 													 "in  vec4 tcs_tes_result[];\n"
11856 													 "out vec4 tes_gs_result;\n"
11857 													 "\n"
11858 													 "#if IMAGES\n"
11859 													 "UNI_GOKU\n"
11860 													 "UNI_TRUNKS\n"
11861 													 "UNI_VEGETA\n"
11862 													 "#endif\n"
11863 													 "\n"
11864 													 "void main()\n"
11865 													 "{\n"
11866 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
11867 													 "\n"
11868 													 "#if IMAGES\n"
11869 													 "VERIFICATION else\n"
11870 													 "#endif\n"
11871 													 "    if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11872 													 "    {\n"
11873 													 "         result = vec4(1, 0, 0, 1);\n"
11874 													 "    }\n"
11875 													 "\n"
11876 													 "    tes_gs_result = result;\n"
11877 													 "}\n"
11878 													 "\n";
11879 
11880 	static const GLchar* vertex_shader_template = "VERSION\n"
11881 												  "#extension GL_ARB_shader_image_load_store : enable\n"
11882 												  "\n"
11883 												  "out vec4 vs_tcs_result;\n"
11884 												  "\n"
11885 												  "#if IMAGES\n"
11886 												  "UNI_TRUNKS\n"
11887 												  "UNI_VEGETA\n"
11888 												  "UNI_GOKU\n"
11889 												  "#endif\n"
11890 												  "\n"
11891 												  "void main()\n"
11892 												  "{\n"
11893 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
11894 												  "\n"
11895 												  "#if IMAGES\n"
11896 												  "VERIFICATION"
11897 												  "#endif\n"
11898 												  "\n"
11899 												  "    vs_tcs_result = result;\n"
11900 												  "}\n"
11901 												  "\n";
11902 
11903 	const GLchar* coordinates_read  = 0;
11904 	const GLchar* coordinates_write = 0;
11905 	const GLchar* image_type		= Utils::getImageType(m_test_case);
11906 	GLuint		  n_coordinates		= Utils::getNumberOfCoordinates(m_test_case);
11907 	const GLchar* shader_template   = 0;
11908 	const GLchar* tex_coord_type	= Utils::getTypeName(Utils::INT, 1 /* n_columns */, n_coordinates);
11909 
11910 	switch (in_stage)
11911 	{
11912 	case Utils::COMPUTE_SHADER:
11913 		shader_template = compute_shader_template;
11914 		break;
11915 	case Utils::FRAGMENT_SHADER:
11916 		shader_template = fragment_shader_template;
11917 		break;
11918 	case Utils::GEOMETRY_SHADER:
11919 		shader_template = geometry_shader_template;
11920 		break;
11921 	case Utils::TESS_CTRL_SHADER:
11922 		shader_template = tess_ctrl_shader_template;
11923 		break;
11924 	case Utils::TESS_EVAL_SHADER:
11925 		shader_template = tess_eval_shader_template;
11926 		break;
11927 	case Utils::VERTEX_SHADER:
11928 		shader_template = vertex_shader_template;
11929 		break;
11930 	default:
11931 		TCU_FAIL("Invalid enum");
11932 		break;
11933 	}
11934 
11935 	switch (n_coordinates)
11936 	{
11937 	case 1:
11938 		coordinates_read  = "1";
11939 		coordinates_write = "0";
11940 		break;
11941 	case 2:
11942 		coordinates_read  = "1, 0";
11943 		coordinates_write = "0, 0";
11944 		break;
11945 	case 3:
11946 		coordinates_read  = "1, 0, 0";
11947 		coordinates_write = "0, 0, 0";
11948 		break;
11949 	case 4:
11950 		coordinates_read  = "1, 0, 0, 0";
11951 		coordinates_write = "0, 0, 0, 0";
11952 		break;
11953 	}
11954 
11955 	out_source.m_parts[0].m_code = shader_template;
11956 
11957 	size_t position = 0;
11958 
11959 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11960 						out_source.m_parts[0].m_code);
11961 
11962 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11963 
11964 	position -= strlen(verification_snippet);
11965 
11966 	Utils::replaceToken("COORDINATES", position, coordinates_read, out_source.m_parts[0].m_code);
11967 
11968 	Utils::replaceToken("COORDINATES", position, coordinates_write, out_source.m_parts[0].m_code);
11969 
11970 	Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
11971 							out_source.m_parts[0].m_code);
11972 
11973 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11974 
11975 	Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
11976 
11977 	Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
11978 
11979 	Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
11980 
11981 	Utils::replaceAllTokens("TYPE", image_type, out_source.m_parts[0].m_code);
11982 }
11983 
11984 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11985  *
11986  * @param program Current program
11987  **/
prepareUniforms(Utils::program & program)11988 void BindingImagesTest::prepareUniforms(Utils::program& program)
11989 {
11990 	(void)program;
11991 	prepareBuffer(m_goku_buffer, m_goku_data);
11992 	prepareBuffer(m_vegeta_buffer, m_vegeta_data);
11993 	prepareBuffer(m_trunks_buffer, m_trunks_data);
11994 
11995 	prepareTexture(m_goku_texture, m_goku_buffer, m_test_case, m_goku_data, 1);
11996 	prepareTexture(m_vegeta_texture, m_vegeta_buffer, m_test_case, m_vegeta_data, 2);
11997 	prepareTexture(m_trunks_texture, m_trunks_buffer, m_test_case, m_trunks_data, 4);
11998 }
11999 
12000 /** Overwrite of releaseResource method, release extra buffers and textures
12001  *
12002  * @param ignored
12003  **/
releaseResource()12004 void BindingImagesTest::releaseResource()
12005 {
12006 	m_goku_texture.release();
12007 	m_vegeta_texture.release();
12008 	m_trunks_texture.release();
12009 	if (m_test_case != Utils::TEX_BUFFER)
12010 	{
12011 		m_goku_buffer.release();
12012 		m_vegeta_buffer.release();
12013 		m_trunks_buffer.release();
12014 	}
12015 }
12016 
12017 /** Verify that all images have green texel at [0,0,0,0]
12018  *
12019  * @return true texel is green, false otherwise
12020  **/
verifyAdditionalResults() const12021 bool BindingImagesTest::verifyAdditionalResults() const
12022 {
12023 	if (Utils::TEX_BUFFER != m_test_case)
12024 	{
12025 		return (verifyTexture(m_goku_texture) && verifyTexture(m_vegeta_texture) && verifyTexture(m_trunks_texture));
12026 	}
12027 	else
12028 	{
12029 		return (verifyBuffer(m_goku_buffer) && verifyBuffer(m_vegeta_buffer) && verifyBuffer(m_trunks_buffer));
12030 	}
12031 }
12032 
12033 /** Constructor
12034  *
12035  * @param context Test context
12036  **/
BindingImageSingleTest(deqp::Context & context)12037 BindingImageSingleTest::BindingImageSingleTest(deqp::Context& context)
12038 	: BindingImageTest(context, "binding_image_single", "Test verifies single binding of image used in multiple stages")
12039 	, m_goku_texture(context)
12040 {
12041 	/* Nothing to be done here */
12042 }
12043 
12044 /** Set up next test case
12045  *
12046  * @param test_case_index Index of next test case
12047  *
12048  * @return false if there is no more test cases, true otherwise
12049  **/
prepareNextTestCase(glw::GLuint test_case_index)12050 bool BindingImageSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
12051 {
12052 	switch (test_case_index)
12053 	{
12054 	case (glw::GLuint)-1:
12055 	case 0:
12056 		m_test_stage = Utils::VERTEX_SHADER;
12057 		break;
12058 	case 1:
12059 		m_test_stage = Utils::TESS_CTRL_SHADER;
12060 		break;
12061 	case 2:
12062 		m_test_stage = Utils::TESS_EVAL_SHADER;
12063 		break;
12064 	case 3:
12065 		m_test_stage = Utils::GEOMETRY_SHADER;
12066 		break;
12067 	case 4:
12068 		m_test_stage = Utils::FRAGMENT_SHADER;
12069 		break;
12070 	default:
12071 		return false;
12072 		break;
12073 	}
12074 
12075 	m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
12076 										<< Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
12077 										<< tcu::TestLog::EndMessage;
12078 
12079 	return true;
12080 }
12081 
12082 /** Prepare source for given shader stage
12083  *
12084  * @param in_stage           Shader stage, compute shader will use 430
12085  * @param in_use_version_400 Select if 400 or 420 should be used
12086  * @param out_source         Prepared shader source instance
12087  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12088 void BindingImageSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12089 												 Utils::shaderSource& out_source)
12090 {
12091 	static const GLchar* uni_goku_with_binding = "layout(binding = 2, rgba8) uniform image2D goku;\n";
12092 
12093 	static const GLchar* uni_goku_no_binding = "layout(rgba8) uniform image2D goku;\n";
12094 
12095 	static const GLchar* verification_snippet = "    vec4 goku_color = imageLoad(goku, ivec2(0,1));\n"
12096 												"\n"
12097 												"    imageStore(goku, ivec2(0,0), vec4(0, 1, 0, 1));\n"
12098 												"\n"
12099 												"    if (vec4(1, 0, 0, 0) != goku_color)\n"
12100 												"    {\n"
12101 												"        result = vec4(1, 0, 0, 1);\n"
12102 												"    }\n";
12103 
12104 	static const GLchar* compute_shader_template =
12105 		"VERSION\n"
12106 		"#extension GL_ARB_shader_image_load_store : enable\n"
12107 		"\n"
12108 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12109 		"\n"
12110 		"writeonly uniform image2D uni_image;\n"
12111 		"\n"
12112 		"UNI_GOKU\n"
12113 		"\n"
12114 		"void main()\n"
12115 		"{\n"
12116 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12117 		"\n"
12118 		"VERIFICATION"
12119 		"\n"
12120 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12121 		"}\n"
12122 		"\n";
12123 
12124 	static const GLchar* fragment_shader_template = "VERSION\n"
12125 													"#extension GL_ARB_shader_image_load_store : enable\n"
12126 													"\n"
12127 													"in  vec4 gs_fs_result;\n"
12128 													"out vec4 fs_out_result;\n"
12129 													"\n"
12130 													"UNI_GOKU\n"
12131 													"\n"
12132 													"void main()\n"
12133 													"{\n"
12134 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12135 													"\n"
12136 													"VERIFICATION"
12137 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12138 													"    {\n"
12139 													"         result = vec4(1, 0, 0, 1);\n"
12140 													"    }\n"
12141 													"\n"
12142 													"    fs_out_result = result;\n"
12143 													"}\n"
12144 													"\n";
12145 
12146 	static const GLchar* geometry_shader_template = "VERSION\n"
12147 													"#extension GL_ARB_shader_image_load_store : enable\n"
12148 													"\n"
12149 													"layout(points)                           in;\n"
12150 													"layout(triangle_strip, max_vertices = 4) out;\n"
12151 													"\n"
12152 													"in  vec4 tes_gs_result[];\n"
12153 													"out vec4 gs_fs_result;\n"
12154 													"\n"
12155 													"#if IMAGES\n"
12156 													"UNI_GOKU\n"
12157 													"#endif\n"
12158 													"\n"
12159 													"void main()\n"
12160 													"{\n"
12161 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12162 													"\n"
12163 													"#if IMAGES\n"
12164 													"VERIFICATION else\n"
12165 													"#endif\n"
12166 													"    if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12167 													"    {\n"
12168 													"         result = vec4(1, 0, 0, 1);\n"
12169 													"    }\n"
12170 													"\n"
12171 													"    gs_fs_result = result;\n"
12172 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
12173 													"    EmitVertex();\n"
12174 													"    gs_fs_result = result;\n"
12175 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
12176 													"    EmitVertex();\n"
12177 													"    gs_fs_result = result;\n"
12178 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
12179 													"    EmitVertex();\n"
12180 													"    gs_fs_result = result;\n"
12181 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
12182 													"    EmitVertex();\n"
12183 													"}\n"
12184 													"\n";
12185 
12186 	static const GLchar* tess_ctrl_shader_template =
12187 		"VERSION\n"
12188 		"#extension GL_ARB_shader_image_load_store : enable\n"
12189 		"\n"
12190 		"layout(vertices = 1) out;\n"
12191 		"\n"
12192 		"in  vec4 vs_tcs_result[];\n"
12193 		"out vec4 tcs_tes_result[];\n"
12194 		"\n"
12195 		"#if IMAGES\n"
12196 		"UNI_GOKU\n"
12197 		"#endif\n"
12198 		"\n"
12199 		"void main()\n"
12200 		"{\n"
12201 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12202 		"\n"
12203 		"#if IMAGES\n"
12204 		"VERIFICATION else\n"
12205 		"#endif\n"
12206 		"    if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12207 		"    {\n"
12208 		"         result = vec4(1, 0, 0, 1);\n"
12209 		"    }\n"
12210 		"\n"
12211 		"    tcs_tes_result[gl_InvocationID] = result;\n"
12212 		"\n"
12213 		"    gl_TessLevelOuter[0] = 1.0;\n"
12214 		"    gl_TessLevelOuter[1] = 1.0;\n"
12215 		"    gl_TessLevelOuter[2] = 1.0;\n"
12216 		"    gl_TessLevelOuter[3] = 1.0;\n"
12217 		"    gl_TessLevelInner[0] = 1.0;\n"
12218 		"    gl_TessLevelInner[1] = 1.0;\n"
12219 		"}\n"
12220 		"\n";
12221 
12222 	static const GLchar* tess_eval_shader_template = "VERSION\n"
12223 													 "#extension GL_ARB_shader_image_load_store : enable\n"
12224 													 "\n"
12225 													 "layout(isolines, point_mode) in;\n"
12226 													 "\n"
12227 													 "in  vec4 tcs_tes_result[];\n"
12228 													 "out vec4 tes_gs_result;\n"
12229 													 "\n"
12230 													 "#if IMAGES\n"
12231 													 "UNI_GOKU\n"
12232 													 "#endif\n"
12233 													 "\n"
12234 													 "void main()\n"
12235 													 "{\n"
12236 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
12237 													 "\n"
12238 													 "#if IMAGES\n"
12239 													 "VERIFICATION else\n"
12240 													 "#endif\n"
12241 													 "    if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12242 													 "    {\n"
12243 													 "         result = vec4(1, 0, 0, 1);\n"
12244 													 "    }\n"
12245 													 "\n"
12246 													 "    tes_gs_result = result;\n"
12247 													 "}\n"
12248 													 "\n";
12249 
12250 	static const GLchar* vertex_shader_template = "VERSION\n"
12251 												  "#extension GL_ARB_shader_image_load_store : enable\n"
12252 												  "\n"
12253 												  "out vec4 vs_tcs_result;\n"
12254 												  "\n"
12255 												  "#if IMAGES\n"
12256 												  "UNI_GOKU\n"
12257 												  "#endif\n"
12258 												  "\n"
12259 												  "void main()\n"
12260 												  "{\n"
12261 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
12262 												  "\n"
12263 												  "#if IMAGES\n"
12264 												  "VERIFICATION"
12265 												  "#endif\n"
12266 												  "\n"
12267 												  "    vs_tcs_result = result;\n"
12268 												  "}\n"
12269 												  "\n";
12270 
12271 	const GLchar* shader_template	= 0;
12272 	const GLchar* uniform_definition = uni_goku_no_binding;
12273 
12274 	switch (in_stage)
12275 	{
12276 	case Utils::COMPUTE_SHADER:
12277 		shader_template	= compute_shader_template;
12278 		uniform_definition = uni_goku_with_binding;
12279 		break;
12280 	case Utils::FRAGMENT_SHADER:
12281 		shader_template = fragment_shader_template;
12282 		/* We can't rely on the binding qualifier being present in m_test_stage
12283 		 * if images are unsupported in that stage.
12284 		 */
12285 		if (maxImageUniforms(m_test_stage) == 0)
12286 			uniform_definition = uni_goku_with_binding;
12287 		break;
12288 	case Utils::GEOMETRY_SHADER:
12289 		shader_template = geometry_shader_template;
12290 		break;
12291 	case Utils::TESS_CTRL_SHADER:
12292 		shader_template = tess_ctrl_shader_template;
12293 		break;
12294 	case Utils::TESS_EVAL_SHADER:
12295 		shader_template = tess_eval_shader_template;
12296 		break;
12297 	case Utils::VERTEX_SHADER:
12298 		shader_template = vertex_shader_template;
12299 		break;
12300 	default:
12301 		TCU_FAIL("Invalid enum");
12302 		break;
12303 	}
12304 
12305 	if (in_stage == m_test_stage)
12306 	{
12307 		uniform_definition = uni_goku_with_binding;
12308 	}
12309 
12310 	out_source.m_parts[0].m_code = shader_template;
12311 
12312 	size_t position = 0;
12313 
12314 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12315 						out_source.m_parts[0].m_code);
12316 
12317 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12318 
12319 	Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
12320 							out_source.m_parts[0].m_code);
12321 
12322 	Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
12323 }
12324 
12325 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12326  *
12327  * @param program Current program
12328  **/
prepareUniforms(Utils::program & program)12329 void BindingImageSingleTest::prepareUniforms(Utils::program& program)
12330 {
12331 	(void)program;
12332 	static const GLuint goku_data = 0x000000ff;
12333 
12334 	prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, 2 /* unit */);
12335 }
12336 
12337 /** Overwrite of releaseResource method, release extra texture
12338  *
12339  * @param ignored
12340  **/
releaseResource()12341 void BindingImageSingleTest::releaseResource()
12342 {
12343 	m_goku_texture.release();
12344 }
12345 
12346 /** Verify that all images have green texel at [0,0,0,0]
12347  *
12348  * @return true texel is green, false otherwise
12349  **/
verifyAdditionalResults() const12350 bool BindingImageSingleTest::verifyAdditionalResults() const
12351 {
12352 	return verifyTexture(m_goku_texture);
12353 }
12354 
12355 /** Constructor
12356  *
12357  * @param context Test context
12358  **/
BindingImageArrayTest(deqp::Context & context)12359 BindingImageArrayTest::BindingImageArrayTest(deqp::Context& context)
12360 	: BindingImageTest(context, "binding_image_array", "Test verifies binding of image array")
12361 	, m_goku_00_texture(context)
12362 	, m_goku_01_texture(context)
12363 	, m_goku_02_texture(context)
12364 	, m_goku_03_texture(context)
12365 	, m_goku_04_texture(context)
12366 	, m_goku_05_texture(context)
12367 	, m_goku_06_texture(context)
12368 {
12369 	/* Nothing to be done here */
12370 }
12371 
12372 /** Prepare source for given shader stage
12373  *
12374  * @param in_stage           Shader stage, compute shader will use 430
12375  * @param in_use_version_400 Select if 400 or 420 should be used
12376  * @param out_source         Prepared shader source instance
12377  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12378 void BindingImageArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12379 												Utils::shaderSource& out_source)
12380 {
12381 	static const GLchar* uni_goku = "layout(binding = 1, rgba8) uniform image2D goku[7];\n";
12382 
12383 	static const GLchar* verification_snippet = "    vec4 color[7];\n"
12384 												"\n"
12385 												"    for (uint i = 0u; i < 7; ++i)\n"
12386 												"    {\n"
12387 												"        color[i] = imageLoad(goku[i], ivec2(0,0));\n"
12388 												"    }\n"
12389 												"\n"
12390 												"    if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
12391 												"        (vec4(0, 0, 0, 1) != color[1]) ||\n"
12392 												"        (vec4(0, 0, 1, 0) != color[2]) ||\n"
12393 												"        (vec4(0, 0, 1, 1) != color[3]) ||\n"
12394 												"        (vec4(0, 1, 0, 0) != color[4]) ||\n"
12395 												"        (vec4(0, 1, 0, 1) != color[5]) ||\n"
12396 												"        (vec4(0, 1, 1, 0) != color[6]) )\n"
12397 												"    {\n"
12398 												"        result = vec4(1, 0, 0, 1);\n"
12399 												"    }\n";
12400 
12401 	static const GLchar* compute_shader_template =
12402 		"VERSION\n"
12403 		"#extension GL_ARB_shader_image_load_store : enable\n"
12404 		"\n"
12405 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12406 		"\n"
12407 		"writeonly uniform image2D uni_image;\n"
12408 		"\n"
12409 		"UNI_GOKU\n"
12410 		"\n"
12411 		"void main()\n"
12412 		"{\n"
12413 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12414 		"\n"
12415 		"VERIFICATION"
12416 		"\n"
12417 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12418 		"}\n"
12419 		"\n";
12420 
12421 	static const GLchar* fragment_shader_template = "VERSION\n"
12422 													"#extension GL_ARB_shader_image_load_store : enable\n"
12423 													"\n"
12424 													"in  vec4 gs_fs_result;\n"
12425 													"out vec4 fs_out_result;\n"
12426 													"\n"
12427 													"UNI_GOKU\n"
12428 													"\n"
12429 													"void main()\n"
12430 													"{\n"
12431 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12432 													"\n"
12433 													"VERIFICATION"
12434 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12435 													"    {\n"
12436 													"         result = vec4(1, 0, 0, 1);\n"
12437 													"    }\n"
12438 													"\n"
12439 													"    fs_out_result = result;\n"
12440 													"}\n"
12441 													"\n";
12442 
12443 	static const GLchar* geometry_shader_template = "VERSION\n"
12444 													"#extension GL_ARB_shader_image_load_store : enable\n"
12445 													"\n"
12446 													"layout(points)                           in;\n"
12447 													"layout(triangle_strip, max_vertices = 4) out;\n"
12448 													"\n"
12449 													"in  vec4 tes_gs_result[];\n"
12450 													"out vec4 gs_fs_result;\n"
12451 													"\n"
12452 													"#if IMAGES\n"
12453 													"UNI_GOKU\n"
12454 													"#endif\n"
12455 													"\n"
12456 													"void main()\n"
12457 													"{\n"
12458 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12459 													"\n"
12460 													"#if IMAGES\n"
12461 													"VERIFICATION else\n"
12462 													"#endif\n"
12463 													"    if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12464 													"    {\n"
12465 													"         result = vec4(1, 0, 0, 1);\n"
12466 													"    }\n"
12467 													"\n"
12468 													"    gs_fs_result = result;\n"
12469 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
12470 													"    EmitVertex();\n"
12471 													"    gs_fs_result = result;\n"
12472 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
12473 													"    EmitVertex();\n"
12474 													"    gs_fs_result = result;\n"
12475 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
12476 													"    EmitVertex();\n"
12477 													"    gs_fs_result = result;\n"
12478 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
12479 													"    EmitVertex();\n"
12480 													"}\n"
12481 													"\n";
12482 
12483 	static const GLchar* tess_ctrl_shader_template =
12484 		"VERSION\n"
12485 		"#extension GL_ARB_shader_image_load_store : enable\n"
12486 		"\n"
12487 		"layout(vertices = 1) out;\n"
12488 		"\n"
12489 		"in  vec4 vs_tcs_result[];\n"
12490 		"out vec4 tcs_tes_result[];\n"
12491 		"\n"
12492 		"#if IMAGES\n"
12493 		"UNI_GOKU\n"
12494 		"#endif\n"
12495 		"\n"
12496 		"void main()\n"
12497 		"{\n"
12498 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12499 		"\n"
12500 		"#if IMAGES\n"
12501 		"VERIFICATION else\n"
12502 		"#endif\n"
12503 		"    if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12504 		"    {\n"
12505 		"         result = vec4(1, 0, 0, 1);\n"
12506 		"    }\n"
12507 		"\n"
12508 		"    tcs_tes_result[gl_InvocationID] = result;\n"
12509 		"\n"
12510 		"    gl_TessLevelOuter[0] = 1.0;\n"
12511 		"    gl_TessLevelOuter[1] = 1.0;\n"
12512 		"    gl_TessLevelOuter[2] = 1.0;\n"
12513 		"    gl_TessLevelOuter[3] = 1.0;\n"
12514 		"    gl_TessLevelInner[0] = 1.0;\n"
12515 		"    gl_TessLevelInner[1] = 1.0;\n"
12516 		"}\n"
12517 		"\n";
12518 
12519 	static const GLchar* tess_eval_shader_template = "VERSION\n"
12520 													 "#extension GL_ARB_shader_image_load_store : enable\n"
12521 													 "\n"
12522 													 "layout(isolines, point_mode) in;\n"
12523 													 "\n"
12524 													 "in  vec4 tcs_tes_result[];\n"
12525 													 "out vec4 tes_gs_result;\n"
12526 													 "\n"
12527 													 "#if IMAGES\n"
12528 													 "UNI_GOKU\n"
12529 													 "#endif\n"
12530 													 "\n"
12531 													 "void main()\n"
12532 													 "{\n"
12533 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
12534 													 "\n"
12535 													 "#if IMAGES\n"
12536 													 "VERIFICATION else\n"
12537 													 "#endif\n"
12538 													 "    if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12539 													 "    {\n"
12540 													 "         result = vec4(1, 0, 0, 1);\n"
12541 													 "    }\n"
12542 													 "\n"
12543 													 "    tes_gs_result = result;\n"
12544 													 "}\n"
12545 													 "\n";
12546 
12547 	static const GLchar* vertex_shader_template = "VERSION\n"
12548 												  "#extension GL_ARB_shader_image_load_store : enable\n"
12549 												  "\n"
12550 												  "out vec4 vs_tcs_result;\n"
12551 												  "\n"
12552 												  "#if IMAGES\n"
12553 												  "UNI_GOKU\n"
12554 												  "#endif\n"
12555 												  "\n"
12556 												  "void main()\n"
12557 												  "{\n"
12558 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
12559 												  "\n"
12560 												  "#if IMAGES\n"
12561 												  "VERIFICATION"
12562 												  "#endif\n"
12563 												  "\n"
12564 												  "    vs_tcs_result = result;\n"
12565 												  "}\n"
12566 												  "\n";
12567 
12568 	const GLchar* shader_template = 0;
12569 
12570 	switch (in_stage)
12571 	{
12572 	case Utils::COMPUTE_SHADER:
12573 		shader_template = compute_shader_template;
12574 		break;
12575 	case Utils::FRAGMENT_SHADER:
12576 		shader_template = fragment_shader_template;
12577 		break;
12578 	case Utils::GEOMETRY_SHADER:
12579 		shader_template = geometry_shader_template;
12580 		break;
12581 	case Utils::TESS_CTRL_SHADER:
12582 		shader_template = tess_ctrl_shader_template;
12583 		break;
12584 	case Utils::TESS_EVAL_SHADER:
12585 		shader_template = tess_eval_shader_template;
12586 		break;
12587 	case Utils::VERTEX_SHADER:
12588 		shader_template = vertex_shader_template;
12589 		break;
12590 	default:
12591 		TCU_FAIL("Invalid enum");
12592 		break;
12593 	}
12594 
12595 	out_source.m_parts[0].m_code = shader_template;
12596 
12597 	size_t position = 0;
12598 
12599 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12600 						out_source.m_parts[0].m_code);
12601 
12602 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12603 
12604 	Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
12605 							out_source.m_parts[0].m_code);
12606 
12607 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12608 }
12609 
12610 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12611  *
12612  * @param program Current program
12613  **/
prepareUniforms(Utils::program & program)12614 void BindingImageArrayTest::prepareUniforms(Utils::program& program)
12615 {
12616 	static const GLuint goku_data[7] = {
12617 		0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
12618 	};
12619 
12620 	Utils::texture* textures[7] = {
12621 		&m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12622 		&m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12623 	};
12624 
12625 	for (GLuint i = 0; i < 7; ++i)
12626 	{
12627 		GLint expected_binding = i + 1;
12628 
12629 		checkBinding(program, i, expected_binding);
12630 
12631 		prepareTexture(*textures[i], Utils::buffer(m_context), Utils::TEX_2D, goku_data[i], expected_binding);
12632 	}
12633 }
12634 
12635 /** Overwrite of releaseResource method, release extra textures
12636  *
12637  * @param ignored
12638  **/
releaseResource()12639 void BindingImageArrayTest::releaseResource()
12640 {
12641 	Utils::texture* textures[7] = {
12642 		&m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12643 		&m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12644 	};
12645 
12646 	for (GLuint i = 0; i < 7; ++i)
12647 	{
12648 		textures[i]->release();
12649 	}
12650 }
12651 
12652 /** Verifies that API reports correct uniform binding
12653  *
12654  * @param program          Program
12655  * @param index            Index of array element
12656  * @param expected_binding Expected binding
12657  **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)12658 void BindingImageArrayTest::checkBinding(Utils::program& program, GLuint index, GLint expected_binding)
12659 {
12660 	if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
12661 	{
12662 		TCU_FAIL("Wrong binding reported by API");
12663 	}
12664 }
12665 
12666 /** Constructor
12667  *
12668  * @param context Test context
12669  **/
BindingImageDefaultTest(deqp::Context & context)12670 BindingImageDefaultTest::BindingImageDefaultTest(deqp::Context& context)
12671 	: APITestBase(context, "binding_image_default", "Test verifies default image binding")
12672 {
12673 	/* Nothing to be done here */
12674 }
12675 
12676 /** Execute API call and verifies results
12677  *
12678  * @return true when results are positive, false otherwise
12679  **/
checkResults(Utils::program & program)12680 bool BindingImageDefaultTest::checkResults(Utils::program& program)
12681 {
12682 	return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
12683 }
12684 
12685 /** Prepare source for given shader stage
12686  *
12687  * @param in_stage           Shader stage, compute shader will use 430
12688  * @param in_use_version_400 Select if 400 or 420 should be used
12689  * @param out_source         Prepared shader source instance
12690  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12691 void BindingImageDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12692 												  Utils::shaderSource& out_source)
12693 {
12694 	static const GLchar* uni_goku = "layout(rgba8) uniform image2D goku;\n";
12695 
12696 	static const GLchar* verification_snippet = "    vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12697 												"\n"
12698 												"    if (vec4(1, 0, 0, 0) != goku_color)\n"
12699 												"    {\n"
12700 												"        result = vec4(1, 0, 0, 1);\n"
12701 												"    }\n";
12702 
12703 	static const GLchar* compute_shader_template =
12704 		"VERSION\n"
12705 		"#extension GL_ARB_shader_image_load_store : enable\n"
12706 		"\n"
12707 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12708 		"\n"
12709 		"writeonly uniform image2D uni_image;\n"
12710 		"\n"
12711 		"UNI_GOKU\n"
12712 		"\n"
12713 		"void main()\n"
12714 		"{\n"
12715 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12716 		"\n"
12717 		"VERIFICATION"
12718 		"\n"
12719 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12720 		"}\n"
12721 		"\n";
12722 
12723 	static const GLchar* fragment_shader_template = "VERSION\n"
12724 													"#extension GL_ARB_shader_image_load_store : enable\n"
12725 													"\n"
12726 													"in  vec4 gs_fs_result;\n"
12727 													"out vec4 fs_out_result;\n"
12728 													"\n"
12729 													"UNI_GOKU\n"
12730 													"\n"
12731 													"void main()\n"
12732 													"{\n"
12733 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12734 													"\n"
12735 													"VERIFICATION"
12736 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12737 													"    {\n"
12738 													"         result = vec4(1, 0, 0, 1);\n"
12739 													"    }\n"
12740 													"\n"
12741 													"    fs_out_result = result;\n"
12742 													"}\n"
12743 													"\n";
12744 
12745 	static const GLchar* geometry_shader_template = "VERSION\n"
12746 													"#extension GL_ARB_shader_image_load_store : enable\n"
12747 													"\n"
12748 													"layout(points)                           in;\n"
12749 													"layout(triangle_strip, max_vertices = 4) out;\n"
12750 													"\n"
12751 													"in  vec4 tes_gs_result[];\n"
12752 													"out vec4 gs_fs_result;\n"
12753 													"\n"
12754 													"#if IMAGES\n"
12755 													"UNI_GOKU\n"
12756 													"#endif\n"
12757 													"\n"
12758 													"void main()\n"
12759 													"{\n"
12760 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12761 													"\n"
12762 													"#if IMAGES\n"
12763 													"VERIFICATION else\n"
12764 													"#endif\n"
12765 													"    if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12766 													"    {\n"
12767 													"         result = vec4(1, 0, 0, 1);\n"
12768 													"    }\n"
12769 													"\n"
12770 													"    gs_fs_result = result;\n"
12771 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
12772 													"    EmitVertex();\n"
12773 													"    gs_fs_result = result;\n"
12774 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
12775 													"    EmitVertex();\n"
12776 													"    gs_fs_result = result;\n"
12777 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
12778 													"    EmitVertex();\n"
12779 													"    gs_fs_result = result;\n"
12780 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
12781 													"    EmitVertex();\n"
12782 													"}\n"
12783 													"\n";
12784 
12785 	static const GLchar* tess_ctrl_shader_template =
12786 		"VERSION\n"
12787 		"#extension GL_ARB_shader_image_load_store : enable\n"
12788 		"\n"
12789 		"layout(vertices = 1) out;\n"
12790 		"\n"
12791 		"in  vec4 vs_tcs_result[];\n"
12792 		"out vec4 tcs_tes_result[];\n"
12793 		"\n"
12794 		"#if IMAGES\n"
12795 		"UNI_GOKU\n"
12796 		"#endif\n"
12797 		"\n"
12798 		"void main()\n"
12799 		"{\n"
12800 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12801 		"\n"
12802 		"#if IMAGES\n"
12803 		"VERIFICATION else\n"
12804 		"#endif\n"
12805 		"    if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12806 		"    {\n"
12807 		"         result = vec4(1, 0, 0, 1);\n"
12808 		"    }\n"
12809 		"\n"
12810 		"    tcs_tes_result[gl_InvocationID] = result;\n"
12811 		"\n"
12812 		"    gl_TessLevelOuter[0] = 1.0;\n"
12813 		"    gl_TessLevelOuter[1] = 1.0;\n"
12814 		"    gl_TessLevelOuter[2] = 1.0;\n"
12815 		"    gl_TessLevelOuter[3] = 1.0;\n"
12816 		"    gl_TessLevelInner[0] = 1.0;\n"
12817 		"    gl_TessLevelInner[1] = 1.0;\n"
12818 		"}\n"
12819 		"\n";
12820 
12821 	static const GLchar* tess_eval_shader_template = "VERSION\n"
12822 													 "#extension GL_ARB_shader_image_load_store : enable\n"
12823 													 "\n"
12824 													 "layout(isolines, point_mode) in;\n"
12825 													 "\n"
12826 													 "in  vec4 tcs_tes_result[];\n"
12827 													 "out vec4 tes_gs_result;\n"
12828 													 "\n"
12829 													 "#if IMAGES\n"
12830 													 "UNI_GOKU\n"
12831 													 "#endif\n"
12832 													 "\n"
12833 													 "void main()\n"
12834 													 "{\n"
12835 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
12836 													 "\n"
12837 													 "#if IMAGES\n"
12838 													 "VERIFICATION else\n"
12839 													 "#endif\n"
12840 													 "    if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12841 													 "    {\n"
12842 													 "         result = vec4(1, 0, 0, 1);\n"
12843 													 "    }\n"
12844 													 "\n"
12845 													 "    tes_gs_result = result;\n"
12846 													 "}\n"
12847 													 "\n";
12848 
12849 	static const GLchar* vertex_shader_template = "VERSION\n"
12850 												  "#extension GL_ARB_shader_image_load_store : enable\n"
12851 												  "\n"
12852 												  "out vec4 vs_tcs_result;\n"
12853 												  "\n"
12854 												  "#if IMAGES\n"
12855 												  "UNI_GOKU\n"
12856 												  "#endif\n"
12857 												  "\n"
12858 												  "void main()\n"
12859 												  "{\n"
12860 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
12861 												  "\n"
12862 												  "#if IMAGES\n"
12863 												  "VERIFICATION"
12864 												  "#endif\n"
12865 												  "\n"
12866 												  "    vs_tcs_result = result;\n"
12867 												  "}\n"
12868 												  "\n";
12869 
12870 	const GLchar* shader_template = 0;
12871 
12872 	switch (in_stage)
12873 	{
12874 	case Utils::COMPUTE_SHADER:
12875 		shader_template = compute_shader_template;
12876 		break;
12877 	case Utils::FRAGMENT_SHADER:
12878 		shader_template = fragment_shader_template;
12879 		break;
12880 	case Utils::GEOMETRY_SHADER:
12881 		shader_template = geometry_shader_template;
12882 		break;
12883 	case Utils::TESS_CTRL_SHADER:
12884 		shader_template = tess_ctrl_shader_template;
12885 		break;
12886 	case Utils::TESS_EVAL_SHADER:
12887 		shader_template = tess_eval_shader_template;
12888 		break;
12889 	case Utils::VERTEX_SHADER:
12890 		shader_template = vertex_shader_template;
12891 		break;
12892 	default:
12893 		TCU_FAIL("Invalid enum");
12894 		break;
12895 	}
12896 
12897 	out_source.m_parts[0].m_code = shader_template;
12898 
12899 	size_t position = 0;
12900 
12901 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12902 						out_source.m_parts[0].m_code);
12903 
12904 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12905 
12906 	Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
12907 							out_source.m_parts[0].m_code);
12908 
12909 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12910 }
12911 
12912 /** Constructor
12913  *
12914  * @param context Test context
12915  **/
BindingImageAPIOverrideTest(deqp::Context & context)12916 BindingImageAPIOverrideTest::BindingImageAPIOverrideTest(deqp::Context& context)
12917 	: BindingImageTest(context, "binding_image_api_override", "Verifies that API can override image binding")
12918 	, m_goku_texture(context)
12919 {
12920 	/* Nothing to be done here */
12921 }
12922 
12923 /** Prepare source for given shader stage
12924  *
12925  * @param in_stage           Shader stage, compute shader will use 430
12926  * @param in_use_version_400 Select if 400 or 420 should be used
12927  * @param out_source         Prepared shader source instance
12928  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12929 void BindingImageAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12930 													  Utils::shaderSource& out_source)
12931 {
12932 	static const GLchar* uni_goku = "layout(binding = 3, rgba8) uniform image2D goku;\n";
12933 
12934 	static const GLchar* verification_snippet = "    vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12935 												"\n"
12936 												"    if (vec4(1, 0, 0, 0) != goku_color)\n"
12937 												"    {\n"
12938 												"        result = vec4(1, 0, 0, 1);\n"
12939 												"    }\n";
12940 
12941 	static const GLchar* compute_shader_template =
12942 		"VERSION\n"
12943 		"#extension GL_ARB_shader_image_load_store : enable\n"
12944 		"\n"
12945 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12946 		"\n"
12947 		"writeonly uniform image2D uni_image;\n"
12948 		"\n"
12949 		"UNI_GOKU\n"
12950 		"\n"
12951 		"void main()\n"
12952 		"{\n"
12953 		"    vec4 result = vec4(0, 1, 0, 1);\n"
12954 		"\n"
12955 		"VERIFICATION"
12956 		"\n"
12957 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12958 		"}\n"
12959 		"\n";
12960 
12961 	static const GLchar* fragment_shader_template = "VERSION\n"
12962 													"#extension GL_ARB_shader_image_load_store : enable\n"
12963 													"\n"
12964 													"in  vec4 gs_fs_result;\n"
12965 													"out vec4 fs_out_result;\n"
12966 													"\n"
12967 													"UNI_GOKU\n"
12968 													"\n"
12969 													"void main()\n"
12970 													"{\n"
12971 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12972 													"\n"
12973 													"VERIFICATION"
12974 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12975 													"    {\n"
12976 													"         result = vec4(1, 0, 0, 1);\n"
12977 													"    }\n"
12978 													"\n"
12979 													"    fs_out_result = result;\n"
12980 													"}\n"
12981 													"\n";
12982 
12983 	static const GLchar* geometry_shader_template = "VERSION\n"
12984 													"#extension GL_ARB_shader_image_load_store : enable\n"
12985 													"\n"
12986 													"layout(points)                           in;\n"
12987 													"layout(triangle_strip, max_vertices = 4) out;\n"
12988 													"\n"
12989 													"in  vec4 tes_gs_result[];\n"
12990 													"out vec4 gs_fs_result;\n"
12991 													"\n"
12992 													"#if IMAGES\n"
12993 													"UNI_GOKU\n"
12994 													"#endif\n"
12995 													"\n"
12996 													"void main()\n"
12997 													"{\n"
12998 													"    vec4 result = vec4(0, 1, 0, 1);\n"
12999 													"\n"
13000 													"#if IMAGES\n"
13001 													"VERIFICATION else\n"
13002 													"#endif\n"
13003 													"    if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13004 													"    {\n"
13005 													"         result = vec4(1, 0, 0, 1);\n"
13006 													"    }\n"
13007 													"\n"
13008 													"    gs_fs_result = result;\n"
13009 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
13010 													"    EmitVertex();\n"
13011 													"    gs_fs_result = result;\n"
13012 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
13013 													"    EmitVertex();\n"
13014 													"    gs_fs_result = result;\n"
13015 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
13016 													"    EmitVertex();\n"
13017 													"    gs_fs_result = result;\n"
13018 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
13019 													"    EmitVertex();\n"
13020 													"}\n"
13021 													"\n";
13022 
13023 	static const GLchar* tess_ctrl_shader_template =
13024 		"VERSION\n"
13025 		"#extension GL_ARB_shader_image_load_store : enable\n"
13026 		"\n"
13027 		"layout(vertices = 1) out;\n"
13028 		"\n"
13029 		"in  vec4 vs_tcs_result[];\n"
13030 		"out vec4 tcs_tes_result[];\n"
13031 		"\n"
13032 		"#if IMAGES\n"
13033 		"UNI_GOKU\n"
13034 		"#endif\n"
13035 		"\n"
13036 		"void main()\n"
13037 		"{\n"
13038 		"    vec4 result = vec4(0, 1, 0, 1);\n"
13039 		"\n"
13040 		"#if IMAGES\n"
13041 		"VERIFICATION else\n"
13042 		"#endif\n"
13043 		"    if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13044 		"    {\n"
13045 		"         result = vec4(1, 0, 0, 1);\n"
13046 		"    }\n"
13047 		"\n"
13048 		"    tcs_tes_result[gl_InvocationID] = result;\n"
13049 		"\n"
13050 		"    gl_TessLevelOuter[0] = 1.0;\n"
13051 		"    gl_TessLevelOuter[1] = 1.0;\n"
13052 		"    gl_TessLevelOuter[2] = 1.0;\n"
13053 		"    gl_TessLevelOuter[3] = 1.0;\n"
13054 		"    gl_TessLevelInner[0] = 1.0;\n"
13055 		"    gl_TessLevelInner[1] = 1.0;\n"
13056 		"}\n"
13057 		"\n";
13058 
13059 	static const GLchar* tess_eval_shader_template = "VERSION\n"
13060 													 "#extension GL_ARB_shader_image_load_store : enable\n"
13061 													 "\n"
13062 													 "layout(isolines, point_mode) in;\n"
13063 													 "\n"
13064 													 "in  vec4 tcs_tes_result[];\n"
13065 													 "out vec4 tes_gs_result;\n"
13066 													 "\n"
13067 													 "#if IMAGES\n"
13068 													 "UNI_GOKU\n"
13069 													 "#endif\n"
13070 													 "\n"
13071 													 "void main()\n"
13072 													 "{\n"
13073 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
13074 													 "\n"
13075 													 "#if IMAGES\n"
13076 													 "VERIFICATION else\n"
13077 													 "#endif\n"
13078 													 "    if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13079 													 "    {\n"
13080 													 "         result = vec4(1, 0, 0, 1);\n"
13081 													 "    }\n"
13082 													 "\n"
13083 													 "    tes_gs_result = result;\n"
13084 													 "}\n"
13085 													 "\n";
13086 
13087 	static const GLchar* vertex_shader_template = "VERSION\n"
13088 												  "#extension GL_ARB_shader_image_load_store : enable\n"
13089 												  "\n"
13090 												  "out vec4 vs_tcs_result;\n"
13091 												  "\n"
13092 												  "#if IMAGES\n"
13093 												  "UNI_GOKU\n"
13094 												  "#endif\n"
13095 												  "\n"
13096 												  "void main()\n"
13097 												  "{\n"
13098 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
13099 												  "\n"
13100 												  "#if IMAGES\n"
13101 												  "VERIFICATION"
13102 												  "#endif\n"
13103 												  "\n"
13104 												  "    vs_tcs_result = result;\n"
13105 												  "}\n"
13106 												  "\n";
13107 
13108 	const GLchar* shader_template = 0;
13109 
13110 	switch (in_stage)
13111 	{
13112 	case Utils::COMPUTE_SHADER:
13113 		shader_template = compute_shader_template;
13114 		break;
13115 	case Utils::FRAGMENT_SHADER:
13116 		shader_template = fragment_shader_template;
13117 		break;
13118 	case Utils::GEOMETRY_SHADER:
13119 		shader_template = geometry_shader_template;
13120 		break;
13121 	case Utils::TESS_CTRL_SHADER:
13122 		shader_template = tess_ctrl_shader_template;
13123 		break;
13124 	case Utils::TESS_EVAL_SHADER:
13125 		shader_template = tess_eval_shader_template;
13126 		break;
13127 	case Utils::VERTEX_SHADER:
13128 		shader_template = vertex_shader_template;
13129 		break;
13130 	default:
13131 		TCU_FAIL("Invalid enum");
13132 		break;
13133 	}
13134 
13135 	out_source.m_parts[0].m_code = shader_template;
13136 
13137 	size_t position = 0;
13138 
13139 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13140 						out_source.m_parts[0].m_code);
13141 
13142 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13143 
13144 	Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
13145 							out_source.m_parts[0].m_code);
13146 
13147 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13148 }
13149 
13150 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
13151  *
13152  * @param program Current program
13153  **/
prepareUniforms(Utils::program & program)13154 void BindingImageAPIOverrideTest::prepareUniforms(Utils::program& program)
13155 {
13156 	static const GLuint goku_data   = 0x000000ff;
13157 	static const GLint  new_binding = 7;
13158 
13159 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
13160 
13161 	const GLint uniform_location = program.getUniformLocation("goku");
13162 	if (-1 == uniform_location)
13163 	{
13164 		TCU_FAIL("Uniform is inactive");
13165 	}
13166 
13167 	gl.uniform1i(uniform_location, new_binding);
13168 
13169 	GLint binding = -1;
13170 
13171 	gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
13172 	GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
13173 
13174 	if (new_binding != binding)
13175 	{
13176 		TCU_FAIL("Wrong binding value");
13177 		return;
13178 	}
13179 
13180 	prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, new_binding);
13181 }
13182 
13183 /** Overwrite of releaseResource method, release extra texture
13184  *
13185  * @param ignored
13186  **/
releaseResource()13187 void BindingImageAPIOverrideTest::releaseResource()
13188 {
13189 	m_goku_texture.release();
13190 }
13191 
13192 /** Constructor
13193  *
13194  * @param context Test context
13195  **/
BindingImageInvalidTest(deqp::Context & context)13196 BindingImageInvalidTest::BindingImageInvalidTest(deqp::Context& context)
13197 	: NegativeTestBase(context, "binding_image_invalid", "Test verifies invalid binding values")
13198 {
13199 	/* Nothing to be done here */
13200 }
13201 
13202 /** Set up next test case
13203  *
13204  * @param test_case_index Index of next test case
13205  *
13206  * @return false if there is no more test cases, true otherwise
13207  **/
prepareNextTestCase(glw::GLuint test_case_index)13208 bool BindingImageInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
13209 {
13210 	switch (test_case_index)
13211 	{
13212 	case (glw::GLuint)-1:
13213 		m_case = TEST_CASES_MAX;
13214 		break;
13215 	case NEGATIVE_VALUE:
13216 	case VARIABLE_NAME:
13217 	case STD140:
13218 	case MISSING:
13219 		m_case = (TESTCASES)test_case_index;
13220 		break;
13221 	default:
13222 		return false;
13223 	}
13224 
13225 	return true;
13226 }
13227 
13228 /** Prepare source for given shader stage
13229  *
13230  * @param in_stage           Shader stage, compute shader will use 430
13231  * @param in_use_version_400 Select if 400 or 420 should be used
13232  * @param out_source         Prepared shader source instance
13233  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13234 void BindingImageInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13235 												  Utils::shaderSource& out_source)
13236 {
13237 	static const GLchar* uni_goku = "layout(binding BINDING, rgba8) uniform image2D goku;\n";
13238 
13239 	static const GLchar* verification_snippet = "    vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
13240 												"\n"
13241 												"    if (vec4(1, 0, 0, 0) != goku_color)\n"
13242 												"    {\n"
13243 												"        result = vec4(1, 0, 0, 1);\n"
13244 												"    }\n";
13245 
13246 	static const GLchar* compute_shader_template =
13247 		"VERSION\n"
13248 		"#extension GL_ARB_shader_image_load_store : enable\n"
13249 		"\n"
13250 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13251 		"\n"
13252 		"writeonly uniform image2D uni_image;\n"
13253 		"\n"
13254 		"UNI_GOKU\n"
13255 		"\n"
13256 		"void main()\n"
13257 		"{\n"
13258 		"    vec4 result = vec4(0, 1, 0, 1);\n"
13259 		"\n"
13260 		"VERIFICATION"
13261 		"\n"
13262 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13263 		"}\n"
13264 		"\n";
13265 
13266 	static const GLchar* fragment_shader_template = "VERSION\n"
13267 													"#extension GL_ARB_shader_image_load_store : enable\n"
13268 													"\n"
13269 													"in  vec4 gs_fs_result;\n"
13270 													"out vec4 fs_out_result;\n"
13271 													"\n"
13272 													"UNI_GOKU\n"
13273 													"\n"
13274 													"void main()\n"
13275 													"{\n"
13276 													"    vec4 result = vec4(0, 1, 0, 1);\n"
13277 													"\n"
13278 													"VERIFICATION"
13279 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13280 													"    {\n"
13281 													"         result = vec4(1, 0, 0, 1);\n"
13282 													"    }\n"
13283 													"\n"
13284 													"    fs_out_result = result;\n"
13285 													"}\n"
13286 													"\n";
13287 
13288 	static const GLchar* geometry_shader_template = "VERSION\n"
13289 													"#extension GL_ARB_shader_image_load_store : enable\n"
13290 													"\n"
13291 													"layout(points)                           in;\n"
13292 													"layout(triangle_strip, max_vertices = 4) out;\n"
13293 													"\n"
13294 													"in  vec4 tes_gs_result[];\n"
13295 													"out vec4 gs_fs_result;\n"
13296 													"\n"
13297 													"UNI_GOKU\n"
13298 													"\n"
13299 													"void main()\n"
13300 													"{\n"
13301 													"    vec4 result = vec4(0, 1, 0, 1);\n"
13302 													"\n"
13303 													"VERIFICATION"
13304 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13305 													"    {\n"
13306 													"         result = vec4(1, 0, 0, 1);\n"
13307 													"    }\n"
13308 													"\n"
13309 													"    gs_fs_result = result;\n"
13310 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
13311 													"    EmitVertex();\n"
13312 													"    gs_fs_result = result;\n"
13313 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
13314 													"    EmitVertex();\n"
13315 													"    gs_fs_result = result;\n"
13316 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
13317 													"    EmitVertex();\n"
13318 													"    gs_fs_result = result;\n"
13319 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
13320 													"    EmitVertex();\n"
13321 													"}\n"
13322 													"\n";
13323 
13324 	static const GLchar* tess_ctrl_shader_template =
13325 		"VERSION\n"
13326 		"#extension GL_ARB_shader_image_load_store : enable\n"
13327 		"\n"
13328 		"layout(vertices = 1) out;\n"
13329 		"\n"
13330 		"in  vec4 vs_tcs_result[];\n"
13331 		"out vec4 tcs_tes_result[];\n"
13332 		"\n"
13333 		"UNI_GOKU\n"
13334 		"\n"
13335 		"void main()\n"
13336 		"{\n"
13337 		"    vec4 result = vec4(0, 1, 0, 1);\n"
13338 		"\n"
13339 		"VERIFICATION"
13340 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13341 		"    {\n"
13342 		"         result = vec4(1, 0, 0, 1);\n"
13343 		"    }\n"
13344 		"\n"
13345 		"    tcs_tes_result[gl_InvocationID] = result;\n"
13346 		"\n"
13347 		"    gl_TessLevelOuter[0] = 1.0;\n"
13348 		"    gl_TessLevelOuter[1] = 1.0;\n"
13349 		"    gl_TessLevelOuter[2] = 1.0;\n"
13350 		"    gl_TessLevelOuter[3] = 1.0;\n"
13351 		"    gl_TessLevelInner[0] = 1.0;\n"
13352 		"    gl_TessLevelInner[1] = 1.0;\n"
13353 		"}\n"
13354 		"\n";
13355 
13356 	static const GLchar* tess_eval_shader_template = "VERSION\n"
13357 													 "#extension GL_ARB_shader_image_load_store : enable\n"
13358 													 "\n"
13359 													 "layout(isolines, point_mode) in;\n"
13360 													 "\n"
13361 													 "in  vec4 tcs_tes_result[];\n"
13362 													 "out vec4 tes_gs_result;\n"
13363 													 "\n"
13364 													 "UNI_GOKU\n"
13365 													 "\n"
13366 													 "void main()\n"
13367 													 "{\n"
13368 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
13369 													 "\n"
13370 													 "VERIFICATION"
13371 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13372 													 "    {\n"
13373 													 "         result = vec4(1, 0, 0, 1);\n"
13374 													 "    }\n"
13375 													 "\n"
13376 													 "    tes_gs_result = result;\n"
13377 													 "}\n"
13378 													 "\n";
13379 
13380 	static const GLchar* vertex_shader_template = "VERSION\n"
13381 												  "#extension GL_ARB_shader_image_load_store : enable\n"
13382 												  "\n"
13383 												  "out vec4 vs_tcs_result;\n"
13384 												  "\n"
13385 												  "UNI_GOKU\n"
13386 												  "\n"
13387 												  "void main()\n"
13388 												  "{\n"
13389 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
13390 												  "\n"
13391 												  "VERIFICATION"
13392 												  "\n"
13393 												  "    vs_tcs_result = result;\n"
13394 												  "}\n"
13395 												  "\n";
13396 
13397 	const GLchar* shader_template = 0;
13398 
13399 	switch (in_stage)
13400 	{
13401 	case Utils::COMPUTE_SHADER:
13402 		shader_template = compute_shader_template;
13403 		break;
13404 	case Utils::FRAGMENT_SHADER:
13405 		shader_template = fragment_shader_template;
13406 		break;
13407 	case Utils::GEOMETRY_SHADER:
13408 		shader_template = geometry_shader_template;
13409 		break;
13410 	case Utils::TESS_CTRL_SHADER:
13411 		shader_template = tess_ctrl_shader_template;
13412 		break;
13413 	case Utils::TESS_EVAL_SHADER:
13414 		shader_template = tess_eval_shader_template;
13415 		break;
13416 	case Utils::VERTEX_SHADER:
13417 		shader_template = vertex_shader_template;
13418 		break;
13419 	default:
13420 		TCU_FAIL("Invalid enum");
13421 		break;
13422 	}
13423 
13424 	out_source.m_parts[0].m_code = shader_template;
13425 
13426 	size_t position = 0;
13427 
13428 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13429 						out_source.m_parts[0].m_code);
13430 
13431 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13432 
13433 	Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13434 
13435 	Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
13436 }
13437 
getCaseString(TESTCASES test_case)13438 const GLchar* BindingImageInvalidTest::getCaseString(TESTCASES test_case)
13439 {
13440 	(void)test_case;
13441 	const GLchar* binding = 0;
13442 
13443 	switch (m_case)
13444 	{
13445 	case NEGATIVE_VALUE:
13446 		binding = "= -1";
13447 		break;
13448 	case VARIABLE_NAME:
13449 		binding = "= goku";
13450 		break;
13451 	case STD140:
13452 		binding = "= std140";
13453 		break;
13454 	case MISSING:
13455 		binding = "";
13456 		break;
13457 	case TEST_CASES_MAX:
13458 		binding = "= 0";
13459 		break;
13460 	default:
13461 		TCU_FAIL("Invalid enum");
13462 	}
13463 
13464 	return binding;
13465 }
13466 
13467 /* Constants used by InitializerListTest */
13468 const GLfloat InitializerListTest::m_value = 0.0625f;
13469 
13470 /** Constructor
13471  *
13472  * @param context Test context
13473  **/
InitializerListTest(deqp::Context & context)13474 InitializerListTest::InitializerListTest(deqp::Context& context)
13475 	: GLSLTestBase(context, "initializer_list", "Test verifies initializer lists")
13476 {
13477 	/* Nothing to be done here */
13478 }
13479 
13480 /** Set up next test case
13481  *
13482  * @param test_case_index Index of next test case
13483  *
13484  * @return false if there is no more test cases, true otherwise
13485  **/
prepareNextTestCase(glw::GLuint test_case_index)13486 bool InitializerListTest::prepareNextTestCase(glw::GLuint test_case_index)
13487 {
13488 	m_current_test_case_index = test_case_index;
13489 
13490 	if ((glw::GLuint)-1 == test_case_index)
13491 	{
13492 		m_current_test_case_index = 0;
13493 		return true;
13494 	}
13495 	else if (m_test_cases.size() <= test_case_index)
13496 	{
13497 		return false;
13498 	}
13499 
13500 	logTestCaseName();
13501 
13502 	return true;
13503 }
13504 
13505 /** Overwritte of prepareUniforms method
13506  *
13507  * @param program Current program
13508  **/
prepareUniforms(Utils::program & program)13509 void InitializerListTest::prepareUniforms(Utils::program& program)
13510 {
13511 	static const GLfloat float_data[16] = { m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value,
13512 											m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value };
13513 
13514 	program.uniform("uni_matrix", Utils::FLOAT, 4, 4, float_data);
13515 }
13516 
13517 /** Prepare source for given shader stage
13518  *
13519  * @param in_stage           Shader stage, compute shader will use 430
13520  * @param in_use_version_400 Select if 400 or 420 should be used
13521  * @param out_source         Prepared shader source instance
13522  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13523 void InitializerListTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13524 											  Utils::shaderSource& out_source)
13525 {
13526 	static const GLchar* verification_snippet = "    TYPE_NAME variableARRAY_DEFINITION = INITIALIZATION;\n"
13527 												"\n"
13528 												"    float sum = SUM;\n"
13529 												"\n"
13530 												"    if (EXPECTED_VALUE != sum)\n"
13531 												"    {\n"
13532 												"        result = vec4(1, 0, 0, 1);\n"
13533 												"    }\n";
13534 
13535 	static const GLchar* compute_shader_template =
13536 		"VERSION\n"
13537 		"\n"
13538 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13539 		"\n"
13540 		"writeonly uniform image2D uni_image;\n"
13541 		"          uniform mat4    uni_matrix;\n"
13542 		"\n"
13543 		"TYPE_DEFINITION\n"
13544 		"\n"
13545 		"void main()\n"
13546 		"{\n"
13547 		"    vec4 result = vec4(0, 1, 0, 1);\n"
13548 		"\n"
13549 		"VERIFICATION"
13550 		"\n"
13551 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13552 		"}\n"
13553 		"\n";
13554 
13555 	static const GLchar* fragment_shader_template = "VERSION\n"
13556 													"\n"
13557 													"in  vec4 gs_fs_result;\n"
13558 													"out vec4 fs_out_result;\n"
13559 													"\n"
13560 													"uniform mat4 uni_matrix;\n"
13561 													"\n"
13562 													"TYPE_DEFINITION\n"
13563 													"\n"
13564 													"void main()\n"
13565 													"{\n"
13566 													"    vec4 result = vec4(0, 1, 0, 1);\n"
13567 													"\n"
13568 													"VERIFICATION"
13569 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13570 													"    {\n"
13571 													"         result = vec4(1, 0, 0, 1);\n"
13572 													"    }\n"
13573 													"\n"
13574 													"    fs_out_result = result;\n"
13575 													"}\n"
13576 													"\n";
13577 
13578 	static const GLchar* geometry_shader_template = "VERSION\n"
13579 													"\n"
13580 													"layout(points)                           in;\n"
13581 													"layout(triangle_strip, max_vertices = 4) out;\n"
13582 													"\n"
13583 													"in  vec4 tes_gs_result[];\n"
13584 													"out vec4 gs_fs_result;\n"
13585 													"\n"
13586 													"uniform mat4 uni_matrix;\n"
13587 													"\n"
13588 													"TYPE_DEFINITION\n"
13589 													"\n"
13590 													"void main()\n"
13591 													"{\n"
13592 													"    vec4 result = vec4(0, 1, 0, 1);\n"
13593 													"\n"
13594 													"VERIFICATION"
13595 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13596 													"    {\n"
13597 													"         result = vec4(1, 0, 0, 1);\n"
13598 													"    }\n"
13599 													"\n"
13600 													"    gs_fs_result = result;\n"
13601 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
13602 													"    EmitVertex();\n"
13603 													"    gs_fs_result = result;\n"
13604 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
13605 													"    EmitVertex();\n"
13606 													"    gs_fs_result = result;\n"
13607 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
13608 													"    EmitVertex();\n"
13609 													"    gs_fs_result = result;\n"
13610 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
13611 													"    EmitVertex();\n"
13612 													"}\n"
13613 													"\n";
13614 
13615 	static const GLchar* tess_ctrl_shader_template =
13616 		"VERSION\n"
13617 		"\n"
13618 		"layout(vertices = 1) out;\n"
13619 		"\n"
13620 		"in  vec4 vs_tcs_result[];\n"
13621 		"out vec4 tcs_tes_result[];\n"
13622 		"\n"
13623 		"uniform mat4 uni_matrix;\n"
13624 		"\n"
13625 		"TYPE_DEFINITION\n"
13626 		"\n"
13627 		"void main()\n"
13628 		"{\n"
13629 		"    vec4 result = vec4(0, 1, 0, 1);\n"
13630 		"\n"
13631 		"VERIFICATION"
13632 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13633 		"    {\n"
13634 		"         result = vec4(1, 0, 0, 1);\n"
13635 		"    }\n"
13636 		"\n"
13637 		"    tcs_tes_result[gl_InvocationID] = result;\n"
13638 		"\n"
13639 		"    gl_TessLevelOuter[0] = 1.0;\n"
13640 		"    gl_TessLevelOuter[1] = 1.0;\n"
13641 		"    gl_TessLevelOuter[2] = 1.0;\n"
13642 		"    gl_TessLevelOuter[3] = 1.0;\n"
13643 		"    gl_TessLevelInner[0] = 1.0;\n"
13644 		"    gl_TessLevelInner[1] = 1.0;\n"
13645 		"}\n"
13646 		"\n";
13647 
13648 	static const GLchar* tess_eval_shader_template = "VERSION\n"
13649 													 "\n"
13650 													 "layout(isolines, point_mode) in;\n"
13651 													 "\n"
13652 													 "in  vec4 tcs_tes_result[];\n"
13653 													 "out vec4 tes_gs_result;\n"
13654 													 "\n"
13655 													 "uniform mat4 uni_matrix;\n"
13656 													 "\n"
13657 													 "TYPE_DEFINITION\n"
13658 													 "\n"
13659 													 "void main()\n"
13660 													 "{\n"
13661 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
13662 													 "\n"
13663 													 "VERIFICATION"
13664 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13665 													 "    {\n"
13666 													 "         result = vec4(1, 0, 0, 1);\n"
13667 													 "    }\n"
13668 													 "\n"
13669 													 "    tes_gs_result = result;\n"
13670 													 "}\n"
13671 													 "\n";
13672 
13673 	static const GLchar* vertex_shader_template = "VERSION\n"
13674 												  "\n"
13675 												  "out vec4 vs_tcs_result;\n"
13676 												  "\n"
13677 												  "uniform mat4 uni_matrix;\n"
13678 												  "\n"
13679 												  "TYPE_DEFINITION\n"
13680 												  "\n"
13681 												  "void main()\n"
13682 												  "{\n"
13683 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
13684 												  "\n"
13685 												  "VERIFICATION"
13686 												  "\n"
13687 												  "    vs_tcs_result = result;\n"
13688 												  "}\n"
13689 												  "\n";
13690 
13691 	const std::string& array_definition = getArrayDefinition();
13692 	const std::string& expected_value   = getExpectedValue();
13693 	const std::string& initialization   = getInitialization();
13694 	const GLchar*	  shader_template  = 0;
13695 	const std::string& sum				= getSum();
13696 	const std::string& type_definition  = getTypeDefinition();
13697 	const std::string& type_name		= getTypeName();
13698 
13699 	switch (in_stage)
13700 	{
13701 	case Utils::COMPUTE_SHADER:
13702 		shader_template = compute_shader_template;
13703 		break;
13704 	case Utils::FRAGMENT_SHADER:
13705 		shader_template = fragment_shader_template;
13706 		break;
13707 	case Utils::GEOMETRY_SHADER:
13708 		shader_template = geometry_shader_template;
13709 		break;
13710 	case Utils::TESS_CTRL_SHADER:
13711 		shader_template = tess_ctrl_shader_template;
13712 		break;
13713 	case Utils::TESS_EVAL_SHADER:
13714 		shader_template = tess_eval_shader_template;
13715 		break;
13716 	case Utils::VERTEX_SHADER:
13717 		shader_template = vertex_shader_template;
13718 		break;
13719 	default:
13720 		TCU_FAIL("Invalid enum");
13721 		break;
13722 	}
13723 
13724 	out_source.m_parts[0].m_code = shader_template;
13725 
13726 	size_t position = 0;
13727 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13728 						out_source.m_parts[0].m_code);
13729 
13730 	Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
13731 
13732 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13733 
13734 	position -= strlen(verification_snippet);
13735 
13736 	Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
13737 
13738 	Utils::replaceToken("ARRAY_DEFINITION", position, array_definition.c_str(), out_source.m_parts[0].m_code);
13739 
13740 	Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
13741 
13742 	Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
13743 
13744 	Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
13745 }
13746 
13747 /** Prepare test cases
13748  *
13749  * @return true
13750  **/
testInit()13751 bool InitializerListTest::testInit()
13752 {
13753 	for (GLuint i = 0; i < TESTED_INITIALIZERS_MAX; ++i)
13754 	{
13755 		const TESTED_INITIALIZERS l_init = (TESTED_INITIALIZERS)i;
13756 
13757 		testCase test_case = { l_init, 1, 1 };
13758 
13759 		switch (l_init)
13760 		{
13761 		case VECTOR:
13762 		case ARRAY_VECTOR_CTR:
13763 		case ARRAY_VECTOR_LIST:
13764 		case UNSIZED_ARRAY_VECTOR:
13765 			for (GLuint row = 2; row <= 4; ++row)
13766 			{
13767 				test_case.m_n_rows = row;
13768 
13769 				m_test_cases.push_back(test_case);
13770 			}
13771 
13772 			break;
13773 
13774 		case MATRIX:
13775 		case MATRIX_ROWS:
13776 		case ARRAY_MATRIX_CTR:
13777 		case ARRAY_MATRIX_LIST:
13778 		case UNSIZED_ARRAY_MATRIX:
13779 			for (GLuint col = 2; col <= 4; ++col)
13780 			{
13781 				for (GLuint row = 2; row <= 4; ++row)
13782 				{
13783 					test_case.m_n_cols = col;
13784 					test_case.m_n_rows = row;
13785 
13786 					m_test_cases.push_back(test_case);
13787 				}
13788 			}
13789 
13790 			break;
13791 
13792 		case ARRAY_SCALAR:
13793 		case UNSIZED_ARRAY_SCALAR:
13794 			m_test_cases.push_back(test_case);
13795 
13796 			break;
13797 
13798 		case STRUCT:
13799 		case ARRAY_STRUCT:
13800 		case NESTED_STRUCT_CTR:
13801 		case NESTED_STRUCT_LIST:
13802 		case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13803 		case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13804 		case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13805 		case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13806 		case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13807 		case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13808 		case UNSIZED_ARRAY_STRUCT:
13809 			test_case.m_n_rows = 4;
13810 			m_test_cases.push_back(test_case);
13811 
13812 			break;
13813 		default:
13814 			DE_ASSERT(0);
13815 			break;
13816 		}
13817 	}
13818 
13819 	return true;
13820 }
13821 
13822 /** Get string representing "[SIZE]" for current test case
13823  *
13824  * @return String
13825  **/
getArrayDefinition()13826 std::string InitializerListTest::getArrayDefinition()
13827 {
13828 	const testCase& test_case = m_test_cases[m_current_test_case_index];
13829 
13830 	std::string array_definition;
13831 
13832 	switch (test_case.m_initializer)
13833 	{
13834 	case VECTOR:
13835 	case MATRIX:
13836 	case MATRIX_ROWS:
13837 	case STRUCT:
13838 	case NESTED_STRUCT_CTR:
13839 	case NESTED_STRUCT_LIST:
13840 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13841 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13842 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13843 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13844 		array_definition = "";
13845 		break;
13846 	case ARRAY_SCALAR:
13847 	case ARRAY_VECTOR_CTR:
13848 	case ARRAY_VECTOR_LIST:
13849 	case ARRAY_MATRIX_CTR:
13850 	case ARRAY_MATRIX_LIST:
13851 	case ARRAY_STRUCT:
13852 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13853 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13854 		array_definition = "[4]";
13855 		break;
13856 	case UNSIZED_ARRAY_SCALAR:
13857 	case UNSIZED_ARRAY_VECTOR:
13858 	case UNSIZED_ARRAY_MATRIX:
13859 	case UNSIZED_ARRAY_STRUCT:
13860 		array_definition = "[]";
13861 		break;
13862 	default:
13863 		TCU_FAIL("Invalid enum");
13864 		break;
13865 	}
13866 
13867 	return array_definition;
13868 }
13869 
13870 /** Get string representing expected value of sum for current test case
13871  *
13872  * @return String
13873  **/
getExpectedValue()13874 std::string InitializerListTest::getExpectedValue()
13875 {
13876 	const testCase& test_case = m_test_cases[m_current_test_case_index];
13877 
13878 	GLfloat value = 0.0f;
13879 
13880 	switch (test_case.m_initializer)
13881 	{
13882 	case VECTOR:
13883 	case MATRIX:
13884 	case MATRIX_ROWS:
13885 		value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows);
13886 		break;
13887 	case ARRAY_VECTOR_CTR:
13888 	case ARRAY_VECTOR_LIST:
13889 	case ARRAY_MATRIX_CTR:
13890 	case ARRAY_MATRIX_LIST:
13891 	case UNSIZED_ARRAY_VECTOR:
13892 	case UNSIZED_ARRAY_MATRIX:
13893 		value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows) * 4.0f;
13894 		break;
13895 	case ARRAY_SCALAR:
13896 	case UNSIZED_ARRAY_SCALAR:
13897 		value = 4.0f;
13898 		break;
13899 	case STRUCT:
13900 		value = 8.0f;
13901 		break;
13902 	case NESTED_STRUCT_CTR:
13903 	case NESTED_STRUCT_LIST:
13904 		value = 12.0f;
13905 		break;
13906 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13907 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13908 		value = 16.0f;
13909 		break;
13910 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13911 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13912 		value = 28.0f;
13913 		break;
13914 	case ARRAY_STRUCT:
13915 	case UNSIZED_ARRAY_STRUCT:
13916 		value = 32.0f;
13917 		break;
13918 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13919 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13920 		value = 48.0f;
13921 		break;
13922 	default:
13923 		TCU_FAIL("Invalid enum");
13924 		break;
13925 	}
13926 
13927 	value *= m_value;
13928 
13929 	std::string expected_value;
13930 	expected_value.resize(64, 0);
13931 
13932 	sprintf(&expected_value[0], "%f", value);
13933 
13934 	return expected_value;
13935 }
13936 
13937 /** Get string representing initialization list for current test case
13938  *
13939  * @return String
13940  **/
getInitialization()13941 std::string InitializerListTest::getInitialization()
13942 {
13943 	const testCase& test_case = m_test_cases[m_current_test_case_index];
13944 
13945 	std::string initialization;
13946 
13947 	switch (test_case.m_initializer)
13948 	{
13949 	case VECTOR:
13950 		initialization.append(getVectorInitializer(0 /*column*/, test_case.m_n_rows));
13951 
13952 		break;
13953 
13954 	case MATRIX:
13955 		initialization = "{ ";
13956 		initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13957 		initialization.append(" }");
13958 
13959 		break;
13960 
13961 	case MATRIX_ROWS:
13962 	{
13963 		initialization = "{ ";
13964 		initialization.append(getVectorArrayCtr(test_case.m_n_cols, test_case.m_n_rows));
13965 		initialization.append(" }");
13966 	}
13967 	break;
13968 
13969 	case STRUCT:
13970 		initialization = "{ ";
13971 		initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
13972 		initialization.append(", ");
13973 		initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
13974 		initialization.append(" }");
13975 
13976 		break;
13977 
13978 	case ARRAY_SCALAR:
13979 	case UNSIZED_ARRAY_SCALAR:
13980 		initialization = "{ ";
13981 		initialization.append(getVectorValues(0 /* column */, 4 /* size */));
13982 		initialization.append(" }");
13983 
13984 		break;
13985 
13986 	case ARRAY_VECTOR_LIST:
13987 	case UNSIZED_ARRAY_VECTOR:
13988 		initialization = "{ ";
13989 		initialization.append(getVectorArrayList(4 /* columns */, test_case.m_n_rows));
13990 		initialization.append(" }");
13991 
13992 		break;
13993 
13994 	case ARRAY_VECTOR_CTR:
13995 		initialization = "{ ";
13996 		initialization.append(getVectorArrayCtr(4 /* columns */, test_case.m_n_rows));
13997 		initialization.append(" }");
13998 
13999 		break;
14000 
14001 	case ARRAY_MATRIX_LIST:
14002 	case UNSIZED_ARRAY_MATRIX:
14003 		initialization = "{ ";
14004 
14005 		for (GLuint i = 0; i < 4; ++i)
14006 		{
14007 			initialization.append("{ ");
14008 			initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
14009 			initialization.append(" }");
14010 
14011 			if (i + 1 < 4)
14012 			{
14013 				initialization.append(", ");
14014 			}
14015 		}
14016 
14017 		initialization.append(" }");
14018 
14019 		break;
14020 
14021 	case ARRAY_MATRIX_CTR:
14022 	{
14023 		const std::string& type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
14024 
14025 		initialization = "{ ";
14026 
14027 		for (GLuint i = 0; i < 4; ++i)
14028 		{
14029 			initialization.append(type_name);
14030 			initialization.append("(");
14031 			for (GLuint col = 0; col < test_case.m_n_cols; ++col)
14032 			{
14033 				initialization.append(getVectorValues(col, test_case.m_n_rows));
14034 
14035 				if (col + 1 < test_case.m_n_cols)
14036 				{
14037 					initialization.append(", ");
14038 				}
14039 			}
14040 			initialization.append(")");
14041 
14042 			if (i + 1 < 4)
14043 			{
14044 				initialization.append(", ");
14045 			}
14046 		}
14047 
14048 		initialization.append(" }");
14049 	}
14050 	break;
14051 
14052 	case ARRAY_STRUCT:
14053 	case UNSIZED_ARRAY_STRUCT:
14054 		initialization = "{ ";
14055 
14056 		for (GLuint i = 0; i < 4; ++i)
14057 		{
14058 			initialization.append("{ ");
14059 			initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
14060 			initialization.append(", ");
14061 			initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
14062 			initialization.append(" }");
14063 
14064 			if (i + 1 < 4)
14065 			{
14066 				initialization.append(", ");
14067 			}
14068 		}
14069 
14070 		initialization.append(" }");
14071 
14072 		break;
14073 
14074 	case NESTED_STRUCT_CTR:
14075 		initialization = "StructureWithStructure(BasicStructure(";
14076 		initialization.append(getVectorConstructor(0 /* column */, 4));
14077 		initialization.append(", ");
14078 		initialization.append(getVectorConstructor(2 /* column */, 4));
14079 		initialization.append("), ");
14080 		initialization.append(getVectorConstructor(3 /* column */, 4));
14081 		initialization.append(")");
14082 
14083 		break;
14084 
14085 	case NESTED_STRUCT_LIST:
14086 		initialization = "{ { ";
14087 		initialization.append(getVectorInitializer(0 /* column */, 4));
14088 		initialization.append(", ");
14089 		initialization.append(getVectorInitializer(2 /* column */, 4));
14090 		initialization.append(" }, ");
14091 		initialization.append(getVectorInitializer(3 /* column */, 4));
14092 		initialization.append(" }");
14093 
14094 		break;
14095 
14096 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14097 		initialization = "{ ";
14098 		initialization.append(getVectorInitializer(0 /* column */, 4));
14099 		initialization.append(", { ");
14100 
14101 		for (GLuint i = 0; i < 3; ++i)
14102 		{
14103 			initialization.append("{ ");
14104 			initialization.append(getVectorInitializer(2 /* column */, 4));
14105 			initialization.append(", ");
14106 			initialization.append(getVectorInitializer(3 /* column */, 4));
14107 			initialization.append(" }");
14108 
14109 			if (i + 1 < 3)
14110 			{
14111 				initialization.append(", ");
14112 			}
14113 		}
14114 
14115 		initialization.append(" } }");
14116 
14117 		break;
14118 
14119 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14120 		initialization = "{ ";
14121 		initialization.append(getVectorConstructor(0 /* column */, 4));
14122 		initialization.append(", { ");
14123 
14124 		for (GLuint i = 0; i < 3; ++i)
14125 		{
14126 			initialization.append("{ ");
14127 			initialization.append(getVectorInitializer(2 /* column */, 4));
14128 			initialization.append(", ");
14129 			initialization.append(getVectorConstructor(3 /* column */, 4));
14130 			initialization.append(" }");
14131 
14132 			if (i + 1 < 3)
14133 			{
14134 				initialization.append(", ");
14135 			}
14136 		}
14137 
14138 		initialization.append(" } }");
14139 
14140 		break;
14141 
14142 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14143 		initialization = "{ ";
14144 
14145 		for (GLuint i = 0; i < 4; ++i)
14146 		{
14147 			initialization.append("{ { ");
14148 
14149 			initialization.append(getVectorInitializer(0 /* column */, 4));
14150 			initialization.append(", ");
14151 			initialization.append(getVectorInitializer(1 /* column */, 4));
14152 
14153 			initialization.append(" }, ");
14154 
14155 			initialization.append(getVectorInitializer(2 /* column */, 4));
14156 
14157 			initialization.append(" }");
14158 
14159 			if (i + 1 < 4)
14160 			{
14161 				initialization.append(", ");
14162 			}
14163 		}
14164 
14165 		initialization.append(" }");
14166 
14167 		break;
14168 
14169 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14170 		initialization = "{\n";
14171 
14172 		for (GLuint i = 0; i < 2; ++i)
14173 		{
14174 			initialization.append("StructureWithStructure(\n");
14175 			initialization.append("BasicStructure(");
14176 
14177 			initialization.append(getVectorConstructor(0 /* column */, 4));
14178 			initialization.append(" , ");
14179 			initialization.append(getVectorConstructor(1 /* column */, 4));
14180 
14181 			initialization.append("), ");
14182 
14183 			initialization.append(getVectorConstructor(2 /* column */, 4));
14184 
14185 			initialization.append(")");
14186 
14187 			initialization.append(" , ");
14188 
14189 			initialization.append("{ { ");
14190 
14191 			initialization.append(getVectorInitializer(0 /* column */, 4));
14192 			initialization.append(", ");
14193 			initialization.append(getVectorInitializer(1 /* column */, 4));
14194 
14195 			initialization.append(" }, ");
14196 
14197 			initialization.append(getVectorInitializer(2 /* column */, 4));
14198 
14199 			initialization.append(" }");
14200 
14201 			if (i + 1 < 2)
14202 			{
14203 				initialization.append(" , ");
14204 			}
14205 		}
14206 
14207 		initialization.append(" }");
14208 
14209 		break;
14210 
14211 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14212 		initialization = "{ ";
14213 		initialization.append("{ ");
14214 		initialization.append(getVectorInitializer(0 /* column */, 4));
14215 		initialization.append(", ");
14216 		initialization.append("{ ");
14217 		initialization.append(getVectorInitializer(1 /* column */, 4));
14218 		initialization.append(", ");
14219 		initialization.append(getVectorInitializer(2 /* column */, 4));
14220 		initialization.append(" }");
14221 		initialization.append(" }");
14222 		initialization.append(", ");
14223 		initialization.append(getVectorInitializer(3 /* column */, 4));
14224 		initialization.append(" }");
14225 
14226 		break;
14227 
14228 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14229 		initialization = "StructureWithStructureWithArray(";
14230 		initialization.append("StructureWithArray(");
14231 		initialization.append(getVectorConstructor(0 /* column */, 4));
14232 		initialization.append(" , vec4[2]( ");
14233 		initialization.append(getVectorConstructor(1 /* column */, 4));
14234 		initialization.append(" , ");
14235 		initialization.append(getVectorConstructor(2 /* column */, 4));
14236 		initialization.append(" )");
14237 		initialization.append(")");
14238 		initialization.append(" , ");
14239 		initialization.append(getVectorConstructor(3 /* column */, 4));
14240 		initialization.append(")");
14241 
14242 		break;
14243 
14244 	default:
14245 		TCU_FAIL("Invalid enum");
14246 		break;
14247 	}
14248 
14249 	return initialization;
14250 }
14251 
14252 /** Logs description of current test case
14253  *
14254  **/
logTestCaseName()14255 void InitializerListTest::logTestCaseName()
14256 {
14257 	const testCase& test_case = m_test_cases[m_current_test_case_index];
14258 
14259 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
14260 
14261 	switch (test_case.m_initializer)
14262 	{
14263 	case VECTOR:
14264 		message << "List. Single vec" << test_case.m_n_rows;
14265 		break;
14266 	case MATRIX:
14267 		message << "List. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14268 		break;
14269 	case MATRIX_ROWS:
14270 		message << "Ctr. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14271 		break;
14272 	case STRUCT:
14273 		message << "List. Structure";
14274 		break;
14275 	case NESTED_STRUCT_CTR:
14276 		message << "Ctr. Nested structure";
14277 		break;
14278 	case NESTED_STRUCT_LIST:
14279 		message << "List. Nested structure";
14280 		break;
14281 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14282 		message << "List. Structure with structure array";
14283 		break;
14284 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14285 		message << "Mix. Structure with structure array";
14286 		break;
14287 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14288 		message << "List. Structure with structure with array";
14289 		break;
14290 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14291 		message << "Mix. Structure with structure with array";
14292 		break;
14293 	case ARRAY_SCALAR:
14294 		message << "List. Array of scalars";
14295 		break;
14296 	case ARRAY_VECTOR_CTR:
14297 		message << "Ctr. Array of vec" << test_case.m_n_rows;
14298 		break;
14299 	case ARRAY_VECTOR_LIST:
14300 		message << "List. Array of vec" << test_case.m_n_rows;
14301 		break;
14302 	case ARRAY_MATRIX_CTR:
14303 		message << "Ctr. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14304 		break;
14305 	case ARRAY_MATRIX_LIST:
14306 		message << "List. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14307 		break;
14308 	case ARRAY_STRUCT:
14309 		message << "List. Array of structures";
14310 		break;
14311 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14312 		message << "List. Array of structures with structures";
14313 		break;
14314 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14315 		message << "Mix. Array of structures with structures";
14316 		break;
14317 	case UNSIZED_ARRAY_SCALAR:
14318 		message << "List. Unsized array of scalars";
14319 		break;
14320 	case UNSIZED_ARRAY_VECTOR:
14321 		message << "List. Unsized array of vec" << test_case.m_n_rows;
14322 		break;
14323 	case UNSIZED_ARRAY_MATRIX:
14324 		message << "List. Unsized array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14325 		break;
14326 	case UNSIZED_ARRAY_STRUCT:
14327 		message << "List. Unsized array of structures";
14328 		break;
14329 	default:
14330 		TCU_FAIL("Invalid enum");
14331 		break;
14332 	}
14333 
14334 	message << tcu::TestLog::EndMessage;
14335 }
14336 
14337 /** Get string representing sum for current test case
14338  *
14339  * @return String
14340  **/
getSum()14341 std::string InitializerListTest::getSum()
14342 {
14343 	static const GLchar* var = "variable";
14344 
14345 	const testCase& test_case = m_test_cases[m_current_test_case_index];
14346 
14347 	std::string sum;
14348 
14349 	switch (test_case.m_initializer)
14350 	{
14351 	case VECTOR:
14352 		sum = getVectorSum(var, test_case.m_n_rows);
14353 
14354 		break;
14355 
14356 	case MATRIX:
14357 	case MATRIX_ROWS:
14358 		sum = getVectorArraySum("variable[INDEX]", test_case.m_n_cols, test_case.m_n_rows);
14359 
14360 		break;
14361 
14362 	case STRUCT:
14363 		sum = getVectorSum("variable.member_a", test_case.m_n_rows);
14364 		sum.append(" + ");
14365 		sum.append(getVectorSum("variable.member_b", test_case.m_n_rows));
14366 
14367 		break;
14368 
14369 	case ARRAY_SCALAR:
14370 	case UNSIZED_ARRAY_SCALAR:
14371 		sum = "variable[0] + variable[1] + variable[2] + variable[3]";
14372 
14373 		break;
14374 
14375 	case ARRAY_VECTOR_LIST:
14376 	case ARRAY_VECTOR_CTR:
14377 	case UNSIZED_ARRAY_VECTOR:
14378 		sum = getVectorArraySum("variable[INDEX]", 4 /* columns */, test_case.m_n_rows);
14379 
14380 		break;
14381 
14382 	case ARRAY_MATRIX_LIST:
14383 	case ARRAY_MATRIX_CTR:
14384 	case UNSIZED_ARRAY_MATRIX:
14385 		sum.append(getVectorArraySum("variable[0][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14386 		sum.append(" + ");
14387 		sum.append(getVectorArraySum("variable[1][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14388 		sum.append(" + ");
14389 		sum.append(getVectorArraySum("variable[2][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14390 		sum.append(" + ");
14391 		sum.append(getVectorArraySum("variable[3][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14392 
14393 		break;
14394 
14395 	case ARRAY_STRUCT:
14396 	case UNSIZED_ARRAY_STRUCT:
14397 		sum.append(getVectorArraySum("variable[INDEX].member_a", 4, test_case.m_n_rows));
14398 		sum.append(" + ");
14399 		sum.append(getVectorArraySum("variable[INDEX].member_b", 4, test_case.m_n_rows));
14400 
14401 		break;
14402 
14403 	case NESTED_STRUCT_CTR:
14404 	case NESTED_STRUCT_LIST:
14405 		sum.append(getVectorSum("variable.member_a.member_a", 4));
14406 		sum.append(" + ");
14407 		sum.append(getVectorSum("variable.member_a.member_b", 4));
14408 		sum.append(" + ");
14409 		sum.append(getVectorSum("variable.member_b", 4));
14410 
14411 		break;
14412 
14413 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14414 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14415 		sum.append(getVectorSum("variable.member_a", 4));
14416 		sum.append(" + ");
14417 		sum.append(getVectorArraySum("variable.member_b[INDEX].member_a", 3, 4));
14418 		sum.append(" + ");
14419 		sum.append(getVectorArraySum("variable.member_b[INDEX].member_b", 3, 4));
14420 
14421 		break;
14422 
14423 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14424 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14425 		sum.append(getVectorArraySum("variable[INDEX].member_a.member_a", 4, 4));
14426 		sum.append(" + ");
14427 		sum.append(getVectorArraySum("variable[INDEX].member_a.member_b", 4, 4));
14428 		sum.append(" + ");
14429 		sum.append(getVectorArraySum("variable[INDEX].member_b", 4, 4));
14430 
14431 		break;
14432 
14433 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14434 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14435 		sum.append(getVectorSum("variable.member_a.member_a", 4));
14436 		sum.append(" + ");
14437 		sum.append(getVectorArraySum("variable.member_a.member_b[INDEX]", 2, 4));
14438 		sum.append(" + ");
14439 		sum.append(getVectorSum("variable.member_b", 4));
14440 
14441 		break;
14442 
14443 	default:
14444 		TCU_FAIL("Invalid enum");
14445 		break;
14446 	}
14447 
14448 	return sum;
14449 }
14450 
14451 /** Get string representing types definition for current test case
14452  *
14453  * @return String
14454  **/
getTypeDefinition()14455 std::string InitializerListTest::getTypeDefinition()
14456 {
14457 	const testCase& test_case = m_test_cases[m_current_test_case_index];
14458 
14459 	static const GLchar* basic_struct = "struct BasicStructure {\n"
14460 										"    vec4 member_a;\n"
14461 										"    vec4 member_b;\n"
14462 										"};\n";
14463 
14464 	static const GLchar* struct_with_array = "struct StructureWithArray {\n"
14465 											 "    vec4 member_a;\n"
14466 											 "    vec4 member_b[2];\n"
14467 											 "};\n";
14468 
14469 	static const GLchar* struct_with_struct = "struct StructureWithStructure {\n"
14470 											  "    BasicStructure member_a;\n"
14471 											  "    vec4           member_b;\n"
14472 											  "};\n";
14473 
14474 	static const GLchar* struct_with_struct_array = "struct StructureWithStructArray {\n"
14475 													"    vec4           member_a;\n"
14476 													"    BasicStructure member_b[3];\n"
14477 													"};\n";
14478 
14479 	static const GLchar* struct_with_struct_with_array = "struct StructureWithStructureWithArray {\n"
14480 														 "    StructureWithArray member_a;\n"
14481 														 "    vec4               member_b;\n"
14482 														 "};\n";
14483 
14484 	std::string type_definition;
14485 
14486 	switch (test_case.m_initializer)
14487 	{
14488 	case VECTOR:
14489 	case MATRIX:
14490 	case MATRIX_ROWS:
14491 	case ARRAY_SCALAR:
14492 	case ARRAY_VECTOR_CTR:
14493 	case ARRAY_VECTOR_LIST:
14494 	case ARRAY_MATRIX_CTR:
14495 	case ARRAY_MATRIX_LIST:
14496 	case UNSIZED_ARRAY_SCALAR:
14497 	case UNSIZED_ARRAY_VECTOR:
14498 	case UNSIZED_ARRAY_MATRIX:
14499 		type_definition = "";
14500 		break;
14501 	case STRUCT:
14502 	case ARRAY_STRUCT:
14503 	case UNSIZED_ARRAY_STRUCT:
14504 		type_definition = basic_struct;
14505 		break;
14506 	case NESTED_STRUCT_CTR:
14507 	case NESTED_STRUCT_LIST:
14508 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14509 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14510 		type_definition = basic_struct;
14511 		type_definition.append(struct_with_struct);
14512 		break;
14513 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14514 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14515 		type_definition = basic_struct;
14516 		type_definition.append(struct_with_struct_array);
14517 		break;
14518 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14519 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14520 		type_definition = struct_with_array;
14521 		type_definition.append(struct_with_struct_with_array);
14522 		break;
14523 	default:
14524 		TCU_FAIL("Invalid enum");
14525 		break;
14526 	}
14527 
14528 	return type_definition;
14529 }
14530 
14531 /** Get string representing name of variable's type for current test case
14532  *
14533  * @return String
14534  **/
getTypeName()14535 std::string InitializerListTest::getTypeName()
14536 {
14537 	const testCase& test_case = m_test_cases[m_current_test_case_index];
14538 
14539 	static const GLchar* basic_struct = "BasicStructure";
14540 
14541 	static const GLchar* struct_with_struct = "StructureWithStructure";
14542 
14543 	static const GLchar* struct_with_struct_array = "StructureWithStructArray";
14544 
14545 	static const GLchar* struct_with_struct_with_array = "StructureWithStructureWithArray";
14546 
14547 	std::string type_name;
14548 
14549 	switch (test_case.m_initializer)
14550 	{
14551 	case VECTOR:
14552 	case MATRIX:
14553 	case MATRIX_ROWS:
14554 	case ARRAY_VECTOR_CTR:
14555 	case ARRAY_VECTOR_LIST:
14556 	case ARRAY_MATRIX_CTR:
14557 	case ARRAY_MATRIX_LIST:
14558 	case UNSIZED_ARRAY_VECTOR:
14559 	case UNSIZED_ARRAY_MATRIX:
14560 		type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
14561 		break;
14562 	case STRUCT:
14563 	case ARRAY_STRUCT:
14564 	case UNSIZED_ARRAY_STRUCT:
14565 		type_name = basic_struct;
14566 		break;
14567 	case NESTED_STRUCT_CTR:
14568 	case NESTED_STRUCT_LIST:
14569 	case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14570 	case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14571 		type_name = struct_with_struct;
14572 		break;
14573 	case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14574 	case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14575 		type_name = struct_with_struct_array;
14576 		break;
14577 	case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14578 	case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14579 		type_name = struct_with_struct_with_array;
14580 		break;
14581 	case ARRAY_SCALAR:
14582 	case UNSIZED_ARRAY_SCALAR:
14583 		type_name = "float";
14584 		break;
14585 	default:
14586 		TCU_FAIL("Invalid enum");
14587 		break;
14588 	}
14589 
14590 	return type_name;
14591 }
14592 
14593 /** Get string representing array of vector constructors
14594  *
14595  * @param columns Number of columns
14596  * @param size    Size of vector
14597  *
14598  * @return String
14599  **/
getVectorArrayCtr(GLuint columns,GLuint size)14600 std::string InitializerListTest::getVectorArrayCtr(GLuint columns, GLuint size)
14601 {
14602 	std::string result;
14603 
14604 	for (GLuint col = 0; col < columns; ++col)
14605 	{
14606 		result.append(getVectorConstructor(col, size));
14607 
14608 		if (col + 1 < columns)
14609 		{
14610 			result.append(", ");
14611 		}
14612 	}
14613 
14614 	return result;
14615 }
14616 
14617 /** Get string representing array of vector initializers
14618  *
14619  * @param columns Number of columns
14620  * @param size    Size of vector
14621  *
14622  * @return String
14623  **/
getVectorArrayList(GLuint columns,GLuint size)14624 std::string InitializerListTest::getVectorArrayList(GLuint columns, GLuint size)
14625 {
14626 	std::string result;
14627 
14628 	for (GLuint col = 0; col < columns; ++col)
14629 	{
14630 		result.append(getVectorInitializer(col, size));
14631 
14632 		if (col + 1 < columns)
14633 		{
14634 			result.append(", ");
14635 		}
14636 	}
14637 
14638 	return result;
14639 }
14640 
14641 /** Get string representing vector constructor
14642  *
14643  * @param column Index of column of uni_matrix to use as data source
14644  * @param size   Size of vector
14645  *
14646  * @return String
14647  **/
getVectorConstructor(GLuint column,GLuint size)14648 std::string InitializerListTest::getVectorConstructor(GLuint column, GLuint size)
14649 {
14650 	const std::string& type_name = Utils::getTypeName(Utils::FLOAT, 1 /*n_cols*/, size);
14651 
14652 	std::string result;
14653 
14654 	result.append(type_name);
14655 	result.append("(");
14656 	result.append(getVectorValues(column, size));
14657 	result.append(")");
14658 
14659 	return result;
14660 }
14661 
14662 /** Get string representing vector initializer
14663  *
14664  * @param column Index of column of uni_matrix to use as data source
14665  * @param size   Size of vector
14666  *
14667  * @return String
14668  **/
getVectorInitializer(GLuint column,GLuint size)14669 std::string InitializerListTest::getVectorInitializer(GLuint column, GLuint size)
14670 {
14671 	std::string result;
14672 
14673 	result.append("{");
14674 	result.append(getVectorValues(column, size));
14675 	result.append("}");
14676 
14677 	return result;
14678 }
14679 
14680 /** Get string representing sum of vector array. Token INDEX in name will be replaced with element index.
14681  *
14682  * @param array_name Name of array variable
14683  * @param columns    Number of columns to sum
14684  * @param size       Size of vector
14685  *
14686  * @return String
14687  **/
getVectorArraySum(const GLchar * array_name,GLuint columns,GLuint size)14688 std::string InitializerListTest::getVectorArraySum(const GLchar* array_name, GLuint columns, GLuint size)
14689 {
14690 	static const GLchar* lut[] = { "0", "1", "2", "3" };
14691 
14692 	std::string sum;
14693 
14694 	for (GLuint i = 0; i < columns; ++i)
14695 	{
14696 		size_t		position = 0;
14697 		std::string name	 = array_name;
14698 
14699 		Utils::replaceToken("INDEX", position, lut[i], name);
14700 
14701 		sum.append(getVectorSum(name.c_str(), size));
14702 
14703 		if (i + 1 < columns)
14704 		{
14705 			sum.append(" + ");
14706 		}
14707 	}
14708 
14709 	return sum;
14710 }
14711 
14712 /** Get string representing sum of vectors' elements
14713  *
14714  * @param vector_name Name of vector variable
14715  * @param size        Size of vector
14716  *
14717  * @return String
14718  **/
getVectorSum(const GLchar * vector_name,GLuint size)14719 std::string InitializerListTest::getVectorSum(const GLchar* vector_name, GLuint size)
14720 {
14721 	static const GLchar* lut[] = {
14722 		".x", ".y", ".z", ".w",
14723 	};
14724 
14725 	std::string sum;
14726 
14727 	for (GLuint i = 0; i < size; ++i)
14728 	{
14729 		sum.append(vector_name);
14730 		sum.append(lut[i]);
14731 
14732 		if (i + 1 < size)
14733 		{
14734 			sum.append(" + ");
14735 		}
14736 	}
14737 
14738 	return sum;
14739 }
14740 
14741 /** Get string representing vector values
14742  *
14743  * @param column Index of column of uni_matrix to use as data source
14744  * @param size   Size of vector
14745  *
14746  * @return String
14747  **/
getVectorValues(GLuint column,GLuint size)14748 std::string InitializerListTest::getVectorValues(GLuint column, GLuint size)
14749 {
14750 	const GLchar* init_template = 0;
14751 	const GLchar* column_index  = 0;
14752 
14753 	switch (size)
14754 	{
14755 	case 2:
14756 		init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y";
14757 		break;
14758 	case 3:
14759 		init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z";
14760 		break;
14761 	case 4:
14762 		init_template = "uni_matrix[COLUMN].z, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z, uni_matrix[COLUMN].w";
14763 		break;
14764 	}
14765 
14766 	switch (column)
14767 	{
14768 	case 0:
14769 		column_index = "0";
14770 		break;
14771 	case 1:
14772 		column_index = "1";
14773 		break;
14774 	case 2:
14775 		column_index = "2";
14776 		break;
14777 	case 3:
14778 		column_index = "3";
14779 		break;
14780 	}
14781 
14782 	std::string initializer = init_template;
14783 
14784 	Utils::replaceAllTokens("COLUMN", column_index, initializer);
14785 
14786 	return initializer;
14787 }
14788 
14789 /** Constructor
14790  *
14791  * @param context Test context
14792  **/
InitializerListNegativeTest(deqp::Context & context)14793 InitializerListNegativeTest::InitializerListNegativeTest(deqp::Context& context)
14794 	: NegativeTestBase(context, "initializer_list_negative", "Verifies invalid initializers")
14795 {
14796 	/* Nothing to be done here */
14797 }
14798 
14799 /** Set up next test case
14800  *
14801  * @param test_case_index Index of next test case
14802  *
14803  * @return false if there is no more test cases, true otherwise
14804  **/
prepareNextTestCase(glw::GLuint test_case_index)14805 bool InitializerListNegativeTest::prepareNextTestCase(glw::GLuint test_case_index)
14806 {
14807 	m_current_test_case_index = test_case_index;
14808 
14809 	if ((glw::GLuint)-1 == test_case_index)
14810 	{
14811 		m_current_test_case_index = 0;
14812 		return true;
14813 	}
14814 	else if (m_test_cases.size() <= test_case_index)
14815 	{
14816 		return false;
14817 	}
14818 
14819 	logTestCaseName();
14820 
14821 	return true;
14822 }
14823 
14824 /** Prepare source for given shader stage
14825  *
14826  * @param in_stage           Shader stage, compute shader will use 430
14827  * @param in_use_version_400 Select if 400 or 420 should be used
14828  * @param out_source         Prepared shader source instance
14829  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)14830 void InitializerListNegativeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
14831 													  Utils::shaderSource& out_source)
14832 {
14833 	static const GLchar* verification_snippet = "    TYPE_NAME variable = INITIALIZATION;\n"
14834 												"\n"
14835 												"    float sum = SUM;\n"
14836 												"\n"
14837 												"    if (0 != sum)\n"
14838 												"    {\n"
14839 												"        result = vec4(1, 0, 0, 1);\n"
14840 												"    }\n";
14841 
14842 	static const GLchar* compute_shader_template =
14843 		"VERSION\n"
14844 		"\n"
14845 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
14846 		"\n"
14847 		"writeonly uniform image2D uni_image;\n"
14848 		"\n"
14849 		"TYPE_DEFINITION\n"
14850 		"\n"
14851 		"void main()\n"
14852 		"{\n"
14853 		"    vec4 result = vec4(0, 1, 0, 1);\n"
14854 		"\n"
14855 		"VERIFICATION"
14856 		"\n"
14857 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
14858 		"}\n"
14859 		"\n";
14860 
14861 	static const GLchar* fragment_shader_template = "VERSION\n"
14862 													"\n"
14863 													"in  vec4 gs_fs_result;\n"
14864 													"out vec4 fs_out_result;\n"
14865 													"\n"
14866 													"TYPE_DEFINITION\n"
14867 													"\n"
14868 													"void main()\n"
14869 													"{\n"
14870 													"    vec4 result = vec4(0, 1, 0, 1);\n"
14871 													"\n"
14872 													"VERIFICATION"
14873 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
14874 													"    {\n"
14875 													"         result = vec4(1, 0, 0, 1);\n"
14876 													"    }\n"
14877 													"\n"
14878 													"    fs_out_result = result;\n"
14879 													"}\n"
14880 													"\n";
14881 
14882 	static const GLchar* geometry_shader_template = "VERSION\n"
14883 													"\n"
14884 													"layout(points)                           in;\n"
14885 													"layout(triangle_strip, max_vertices = 4) out;\n"
14886 													"\n"
14887 													"in  vec4 tes_gs_result[];\n"
14888 													"out vec4 gs_fs_result;\n"
14889 													"\n"
14890 													"TYPE_DEFINITION\n"
14891 													"\n"
14892 													"void main()\n"
14893 													"{\n"
14894 													"    vec4 result = vec4(0, 1, 0, 1);\n"
14895 													"\n"
14896 													"VERIFICATION"
14897 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
14898 													"    {\n"
14899 													"         result = vec4(1, 0, 0, 1);\n"
14900 													"    }\n"
14901 													"\n"
14902 													"    gs_fs_result = result;\n"
14903 													"    gl_Position  = vec4(-1, -1, 0, 1);\n"
14904 													"    EmitVertex();\n"
14905 													"    gs_fs_result = result;\n"
14906 													"    gl_Position  = vec4(-1, 1, 0, 1);\n"
14907 													"    EmitVertex();\n"
14908 													"    gs_fs_result = result;\n"
14909 													"    gl_Position  = vec4(1, -1, 0, 1);\n"
14910 													"    EmitVertex();\n"
14911 													"    gs_fs_result = result;\n"
14912 													"    gl_Position  = vec4(1, 1, 0, 1);\n"
14913 													"    EmitVertex();\n"
14914 													"}\n"
14915 													"\n";
14916 
14917 	static const GLchar* tess_ctrl_shader_template =
14918 		"VERSION\n"
14919 		"\n"
14920 		"layout(vertices = 1) out;\n"
14921 		"\n"
14922 		"in  vec4 vs_tcs_result[];\n"
14923 		"out vec4 tcs_tes_result[];\n"
14924 		"\n"
14925 		"TYPE_DEFINITION\n"
14926 		"\n"
14927 		"void main()\n"
14928 		"{\n"
14929 		"    vec4 result = vec4(0, 1, 0, 1);\n"
14930 		"\n"
14931 		"VERIFICATION"
14932 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
14933 		"    {\n"
14934 		"         result = vec4(1, 0, 0, 1);\n"
14935 		"    }\n"
14936 		"\n"
14937 		"    tcs_tes_result[gl_InvocationID] = result;\n"
14938 		"\n"
14939 		"    gl_TessLevelOuter[0] = 1.0;\n"
14940 		"    gl_TessLevelOuter[1] = 1.0;\n"
14941 		"    gl_TessLevelOuter[2] = 1.0;\n"
14942 		"    gl_TessLevelOuter[3] = 1.0;\n"
14943 		"    gl_TessLevelInner[0] = 1.0;\n"
14944 		"    gl_TessLevelInner[1] = 1.0;\n"
14945 		"}\n"
14946 		"\n";
14947 
14948 	static const GLchar* tess_eval_shader_template = "VERSION\n"
14949 													 "\n"
14950 													 "layout(isolines, point_mode) in;\n"
14951 													 "\n"
14952 													 "in  vec4 tcs_tes_result[];\n"
14953 													 "out vec4 tes_gs_result;\n"
14954 													 "\n"
14955 													 "TYPE_DEFINITION\n"
14956 													 "\n"
14957 													 "void main()\n"
14958 													 "{\n"
14959 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
14960 													 "\n"
14961 													 "VERIFICATION"
14962 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
14963 													 "    {\n"
14964 													 "         result = vec4(1, 0, 0, 1);\n"
14965 													 "    }\n"
14966 													 "\n"
14967 													 "    tes_gs_result = result;\n"
14968 													 "}\n"
14969 													 "\n";
14970 
14971 	static const GLchar* vertex_shader_template = "VERSION\n"
14972 												  "\n"
14973 												  "out vec4 vs_tcs_result;\n"
14974 												  "\n"
14975 												  "TYPE_DEFINITION\n"
14976 												  "\n"
14977 												  "void main()\n"
14978 												  "{\n"
14979 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
14980 												  "\n"
14981 												  "VERIFICATION"
14982 												  "\n"
14983 												  "    vs_tcs_result = result;\n"
14984 												  "}\n"
14985 												  "\n";
14986 
14987 	const std::string& initialization  = getInitialization();
14988 	const GLchar*	  shader_template = 0;
14989 	const std::string& sum			   = getSum();
14990 	const std::string& type_definition = getTypeDefinition();
14991 	const std::string& type_name	   = getTypeName();
14992 
14993 	switch (in_stage)
14994 	{
14995 	case Utils::COMPUTE_SHADER:
14996 		shader_template = compute_shader_template;
14997 		break;
14998 	case Utils::FRAGMENT_SHADER:
14999 		shader_template = fragment_shader_template;
15000 		break;
15001 	case Utils::GEOMETRY_SHADER:
15002 		shader_template = geometry_shader_template;
15003 		break;
15004 	case Utils::TESS_CTRL_SHADER:
15005 		shader_template = tess_ctrl_shader_template;
15006 		break;
15007 	case Utils::TESS_EVAL_SHADER:
15008 		shader_template = tess_eval_shader_template;
15009 		break;
15010 	case Utils::VERTEX_SHADER:
15011 		shader_template = vertex_shader_template;
15012 		break;
15013 	default:
15014 		TCU_FAIL("Invalid enum");
15015 		break;
15016 	}
15017 
15018 	out_source.m_parts[0].m_code = shader_template;
15019 
15020 	size_t position = 0;
15021 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
15022 						out_source.m_parts[0].m_code);
15023 
15024 	Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
15025 
15026 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
15027 
15028 	position -= strlen(verification_snippet);
15029 
15030 	Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
15031 
15032 	Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
15033 
15034 	Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
15035 }
15036 
15037 /** Prepare test cases
15038  *
15039  * @return true
15040  **/
testInit()15041 bool InitializerListNegativeTest::testInit()
15042 {
15043 	for (GLuint i = 0; i < TESTED_ERRORS_MAX; ++i)
15044 	{
15045 		const TESTED_ERRORS error = (TESTED_ERRORS)i;
15046 
15047 		m_test_cases.push_back(error);
15048 	}
15049 
15050 	return true;
15051 }
15052 
15053 /** Get string representing initialization list for current test case
15054  *
15055  * @return String
15056  **/
getInitialization()15057 std::string InitializerListNegativeTest::getInitialization()
15058 {
15059 	const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15060 
15061 	std::string initialization;
15062 
15063 	switch (error)
15064 	{
15065 	case TYPE_UIVEC_BOOL:
15066 		initialization = "{ true, 0, 1, 2 }";
15067 
15068 		break;
15069 
15070 	case TYPE_IVEC_BOOL:
15071 		initialization = "{ true, 0, -1, 2 }";
15072 
15073 		break;
15074 
15075 	case TYPE_VEC_BOOL:
15076 		initialization = "{ true, 0.125, 0.25, 0.375 }";
15077 
15078 		break;
15079 
15080 	case TYPE_MAT_BOOL:
15081 		initialization = "{ {false, 0, 1, 1}, {0, 1, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15082 
15083 		break;
15084 
15085 	case COMPONENTS_VEC_LESS:
15086 	case COMPONENTS_VEC_MORE:
15087 		initialization = "{ 0, 0.25, 0.375 }";
15088 
15089 		break;
15090 
15091 	case COMPONENTS_MAT_LESS_ROWS:
15092 		initialization = "{ {0, 0, 1, 1}, {0, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15093 
15094 		break;
15095 
15096 	case COMPONENTS_MAT_MORE_ROWS:
15097 		initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1, 0}, {1, 0, 1} }";
15098 
15099 		break;
15100 
15101 	case COMPONENTS_MAT_LESS_COLUMNS:
15102 		initialization = "{ {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15103 
15104 		break;
15105 
15106 	case COMPONENTS_MAT_MORE_COLUMNS:
15107 		initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1}, {1, 0, 1} }";
15108 
15109 		break;
15110 
15111 	case LIST_IN_CONSTRUCTOR:
15112 		initialization = "Struct( { vec4(0, 1, 0, 1), vec3(0, 1, 0) }, vec4(1, 0, 1, 0) )";
15113 
15114 		break;
15115 
15116 	case STRUCT_LAYOUT_MEMBER_TYPE:
15117 		initialization = "{ { {0, 1, 0, 1}, vec4(0, 1, 0, 1) }, vec4(1, 0, 1, 0) }";
15118 
15119 		break;
15120 
15121 	case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15122 		initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } , vec4(1, 0, 1, 0), vec4(1, 0, 1, 0) }";
15123 
15124 		break;
15125 
15126 	case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15127 		initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } }";
15128 
15129 		break;
15130 
15131 	case STRUCT_LAYOUT_MEMBER_ORDER:
15132 		initialization = "{ vec4(1, 0, 1, 0), { vec3(0, 1, 0) , {0, 1, 0, 1} } }";
15133 
15134 		break;
15135 
15136 	default:
15137 		TCU_FAIL("Invalid enum");
15138 		break;
15139 	}
15140 
15141 	return initialization;
15142 }
15143 
15144 /** Logs description of current test case
15145  *
15146  **/
logTestCaseName()15147 void InitializerListNegativeTest::logTestCaseName()
15148 {
15149 	const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15150 
15151 	tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
15152 
15153 	switch (error)
15154 	{
15155 	case TYPE_UIVEC_BOOL:
15156 		message << "Wrong type in uvec initializer list";
15157 		break;
15158 	case TYPE_IVEC_BOOL:
15159 		message << "Wrong type in ivec initializer list";
15160 		break;
15161 	case TYPE_VEC_BOOL:
15162 		message << "Wrong type in vec initializer list";
15163 		break;
15164 	case TYPE_MAT_BOOL:
15165 		message << "Wrong type in mat initializer list";
15166 		break;
15167 	case COMPONENTS_VEC_LESS:
15168 		message << "Wrong number of componenets in vec initialize list - less";
15169 		break;
15170 	case COMPONENTS_VEC_MORE:
15171 		message << "Wrong number of componenets in vec initialize list - more";
15172 		break;
15173 	case COMPONENTS_MAT_LESS_ROWS:
15174 		message << "Wrong number of componenets in mat initialize list - less rows";
15175 		break;
15176 	case COMPONENTS_MAT_LESS_COLUMNS:
15177 		message << "Wrong number of componenets in mat initialize list - less columns";
15178 		break;
15179 	case COMPONENTS_MAT_MORE_ROWS:
15180 		message << "Wrong number of componenets in mat initialize list - more rows";
15181 		break;
15182 	case COMPONENTS_MAT_MORE_COLUMNS:
15183 		message << "Wrong number of componenets in mat initialize list - more columns";
15184 		break;
15185 	case LIST_IN_CONSTRUCTOR:
15186 		message << "Initializer list in constructor";
15187 		break;
15188 	case STRUCT_LAYOUT_MEMBER_TYPE:
15189 		message << "Wrong type of structure member";
15190 		break;
15191 	case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15192 		message << "Wrong number of structure members - more";
15193 		break;
15194 	case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15195 		message << "Wrong number of structure members - less";
15196 		break;
15197 	case STRUCT_LAYOUT_MEMBER_ORDER:
15198 		message << "Wrong order of structure members";
15199 		break;
15200 	default:
15201 		TCU_FAIL("Invalid enum");
15202 		break;
15203 	}
15204 
15205 	message << tcu::TestLog::EndMessage;
15206 }
15207 
15208 /** Get string representing sum for current test case
15209  *
15210  * @return String
15211  **/
getSum()15212 std::string InitializerListNegativeTest::getSum()
15213 {
15214 	const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15215 
15216 	std::string sum;
15217 
15218 	switch (error)
15219 	{
15220 	case TYPE_UIVEC_BOOL:
15221 	case TYPE_IVEC_BOOL:
15222 	case TYPE_VEC_BOOL:
15223 	case COMPONENTS_VEC_LESS:
15224 		sum = "variable.x + variable.y + variable.z + variable.w";
15225 		break;
15226 	case TYPE_MAT_BOOL:
15227 	case COMPONENTS_MAT_LESS_ROWS:
15228 	case COMPONENTS_MAT_LESS_COLUMNS:
15229 		sum = "variable[0].x + variable[0].y + variable[0].z + variable[0].w + "
15230 			  "variable[1].x + variable[1].y + variable[1].z + variable[1].w + "
15231 			  "variable[2].x + variable[2].y + variable[2].z + variable[2].w + "
15232 			  "variable[3].x + variable[3].y + variable[3].z + variable[3].w";
15233 		break;
15234 	case COMPONENTS_VEC_MORE:
15235 		sum = "variable.x + variable.y + variable.z";
15236 		break;
15237 	case COMPONENTS_MAT_MORE_ROWS:
15238 	case COMPONENTS_MAT_MORE_COLUMNS:
15239 		sum = "variable[0].x + variable[0].y + variable[0].z"
15240 			  "variable[1].x + variable[1].y + variable[1].z"
15241 			  "variable[2].x + variable[2].y + variable[2].z";
15242 		break;
15243 	case LIST_IN_CONSTRUCTOR:
15244 	case STRUCT_LAYOUT_MEMBER_TYPE:
15245 	case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15246 	case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15247 	case STRUCT_LAYOUT_MEMBER_ORDER:
15248 		sum = "variable.member_a.member_a.x + variable.member_a.member_a.y + variable.member_a.member_a.z + "
15249 			  "variable.member_a.member_a.w + "
15250 			  "variable.member_a.member_b.x + variable.member_a.member_b.y + variable.member_a.member_b.z + "
15251 			  "variable.member_b.x + variable.member_b.y + variable.member_b.z + variable.member_b.w";
15252 		break;
15253 	default:
15254 		TCU_FAIL("Invalid enum");
15255 		break;
15256 	}
15257 
15258 	return sum;
15259 }
15260 
15261 /** Get string representing types definition for current test case
15262  *
15263  * @return String
15264  **/
getTypeDefinition()15265 std::string InitializerListNegativeTest::getTypeDefinition()
15266 {
15267 	const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15268 
15269 	static const GLchar* struct_def = "struct BasicStructure {\n"
15270 									  "    vec4 member_a;\n"
15271 									  "    vec3 member_b;\n"
15272 									  "};\n"
15273 									  "\n"
15274 									  "struct StructureWithStructure {\n"
15275 									  "    BasicStructure member_a;\n"
15276 									  "    vec4           member_b;\n"
15277 									  "};\n";
15278 
15279 	std::string type_definition;
15280 
15281 	switch (error)
15282 	{
15283 	case TYPE_UIVEC_BOOL:
15284 	case TYPE_IVEC_BOOL:
15285 	case TYPE_VEC_BOOL:
15286 	case TYPE_MAT_BOOL:
15287 	case COMPONENTS_VEC_LESS:
15288 	case COMPONENTS_VEC_MORE:
15289 	case COMPONENTS_MAT_LESS_ROWS:
15290 	case COMPONENTS_MAT_LESS_COLUMNS:
15291 	case COMPONENTS_MAT_MORE_ROWS:
15292 	case COMPONENTS_MAT_MORE_COLUMNS:
15293 		type_definition = "";
15294 		break;
15295 	case LIST_IN_CONSTRUCTOR:
15296 	case STRUCT_LAYOUT_MEMBER_TYPE:
15297 	case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15298 	case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15299 	case STRUCT_LAYOUT_MEMBER_ORDER:
15300 		type_definition = struct_def;
15301 		break;
15302 	default:
15303 		TCU_FAIL("Invalid enum");
15304 		break;
15305 	}
15306 
15307 	return type_definition;
15308 }
15309 
15310 /** Get string representing name of variable's type for current test case
15311  *
15312  * @return String
15313  **/
getTypeName()15314 std::string InitializerListNegativeTest::getTypeName()
15315 {
15316 	const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15317 
15318 	static const GLchar* struct_with_struct = "StructureWithStructure";
15319 
15320 	std::string type_name;
15321 
15322 	switch (error)
15323 	{
15324 	case TYPE_UIVEC_BOOL:
15325 		type_name = "uvec4";
15326 		break;
15327 	case TYPE_IVEC_BOOL:
15328 		type_name = "ivec4";
15329 		break;
15330 	case TYPE_VEC_BOOL:
15331 	case COMPONENTS_VEC_LESS:
15332 		type_name = "vec4";
15333 		break;
15334 	case COMPONENTS_VEC_MORE:
15335 		type_name = "vec2";
15336 		break;
15337 	case TYPE_MAT_BOOL:
15338 	case COMPONENTS_MAT_LESS_ROWS:
15339 	case COMPONENTS_MAT_LESS_COLUMNS:
15340 		type_name = "mat4";
15341 		break;
15342 	case COMPONENTS_MAT_MORE_ROWS:
15343 	case COMPONENTS_MAT_MORE_COLUMNS:
15344 		type_name = "mat3";
15345 		break;
15346 		break;
15347 	case LIST_IN_CONSTRUCTOR:
15348 	case STRUCT_LAYOUT_MEMBER_TYPE:
15349 	case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15350 	case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15351 	case STRUCT_LAYOUT_MEMBER_ORDER:
15352 		type_name = struct_with_struct;
15353 		break;
15354 	default:
15355 		TCU_FAIL("Invalid enum");
15356 		break;
15357 	}
15358 
15359 	return type_name;
15360 }
15361 
15362 /** Constructor
15363  *
15364  * @param context Test context
15365  **/
LengthOfVectorAndMatrixTest(deqp::Context & context)15366 LengthOfVectorAndMatrixTest::LengthOfVectorAndMatrixTest(deqp::Context& context)
15367 	: GLSLTestBase(context, "length_of_vector_and_matrix", "Test verifies .length() for vectors and matrices")
15368 {
15369 	/* Nothing to be done here */
15370 }
15371 
15372 /** Set up next test case
15373  *
15374  * @param test_case_index Index of next test case
15375  *
15376  * @return false if there is no more test cases, true otherwise
15377  **/
prepareNextTestCase(glw::GLuint test_case_index)15378 bool LengthOfVectorAndMatrixTest::prepareNextTestCase(glw::GLuint test_case_index)
15379 {
15380 	m_current_test_case_index = test_case_index;
15381 
15382 	if ((glw::GLuint)-1 == test_case_index)
15383 	{
15384 		m_current_test_case_index = 0;
15385 		return true;
15386 	}
15387 	else if (m_test_cases.size() <= test_case_index)
15388 	{
15389 		return false;
15390 	}
15391 
15392 	const testCase& test_case = m_test_cases[m_current_test_case_index];
15393 
15394 	m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested type: "
15395 										<< Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows)
15396 										<< tcu::TestLog::EndMessage;
15397 
15398 	return true;
15399 }
15400 
15401 /** Prepare source for given shader stage
15402  *
15403  * @param in_stage           Shader stage, compute shader will use 430
15404  * @param in_use_version_400 Select if 400 or 420 should be used
15405  * @param out_source         Prepared shader source instance
15406  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15407 void LengthOfVectorAndMatrixTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15408 													  Utils::shaderSource& out_source)
15409 {
15410 	if (Utils::COMPUTE_SHADER == in_stage)
15411 	{
15412 		m_is_compute_program = true;
15413 		prepareComputeShaderSource(out_source);
15414 	}
15415 	else
15416 	{
15417 		m_is_compute_program = false;
15418 		prepareDrawShaderSource(in_stage, in_use_version_400, out_source);
15419 	}
15420 }
15421 
15422 /** Overwritte of prepareUniforms method
15423  *
15424  * @param program Current program
15425  **/
prepareUniforms(Utils::program & program)15426 void LengthOfVectorAndMatrixTest::prepareUniforms(Utils::program& program)
15427 {
15428 	static const GLfloat float_value = 0.125;
15429 	static const GLint   int_value   = -1;
15430 	static const GLuint  uint_value  = 1;
15431 
15432 	static const GLfloat float_data[16] = { float_value, float_value, float_value, float_value,
15433 											float_value, float_value, float_value, float_value,
15434 											float_value, float_value, float_value, float_value,
15435 											float_value, float_value, float_value, float_value };
15436 
15437 	static const GLint int_data[4] = { int_value, int_value, int_value, int_value };
15438 
15439 	static const GLuint uint_data[4] = { uint_value, uint_value, uint_value, uint_value };
15440 
15441 	if (false == m_is_compute_program)
15442 	{
15443 		return;
15444 	}
15445 
15446 	const testCase& test_case = m_test_cases[m_current_test_case_index];
15447 
15448 	switch (test_case.m_type)
15449 	{
15450 	case Utils::FLOAT:
15451 		program.uniform("uni_variable", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
15452 		break;
15453 	case Utils::INT:
15454 		program.uniform("uni_variable", Utils::INT, 1 /* columns */, test_case.m_n_rows, int_data);
15455 		break;
15456 	case Utils::UINT:
15457 		program.uniform("uni_variable", Utils::UINT, 1 /* columns */, test_case.m_n_rows, uint_data);
15458 		break;
15459 	default:
15460 		TCU_FAIL("Invalid enum");
15461 	}
15462 }
15463 
15464 /** Prepare vertex buffer
15465  *
15466  * @param program Program object
15467  * @param buffer  Vertex buffer
15468  * @param vao     Vertex array object
15469  *
15470  * @return 0
15471  **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)15472 void LengthOfVectorAndMatrixTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
15473 													  Utils::vertexArray& vao)
15474 {
15475 	static const GLfloat float_value = 0.125f;
15476 	static const GLint   int_value   = -1;
15477 	static const GLuint  uint_value  = 1;
15478 
15479 	static const GLfloat float_data[16] = { float_value, float_value, float_value, float_value,
15480 											float_value, float_value, float_value, float_value,
15481 											float_value, float_value, float_value, float_value,
15482 											float_value, float_value, float_value, float_value };
15483 
15484 	static const GLint int_data[4] = { int_value, int_value, int_value, int_value };
15485 
15486 	static const GLuint uint_data[4] = { uint_value, uint_value, uint_value, uint_value };
15487 
15488 	const testCase& test_case = m_test_cases[m_current_test_case_index];
15489 
15490 	std::string variable_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "variable");
15491 	GLint		variable_loc  = program.getAttribLocation(variable_name.c_str());
15492 
15493 	if (-1 == variable_loc)
15494 	{
15495 		TCU_FAIL("Vertex attribute location is invalid");
15496 	}
15497 
15498 	vao.generate();
15499 	vao.bind();
15500 
15501 	buffer.generate(GL_ARRAY_BUFFER);
15502 
15503 	GLvoid*	data_ptr  = 0;
15504 	GLsizeiptr data_size = 0;
15505 
15506 	switch (test_case.m_type)
15507 	{
15508 	case Utils::FLOAT:
15509 		data_ptr  = (GLvoid*)float_data;
15510 		data_size = sizeof(float_data);
15511 		break;
15512 	case Utils::INT:
15513 		data_ptr  = (GLvoid*)int_data;
15514 		data_size = sizeof(int_data);
15515 		break;
15516 	case Utils::UINT:
15517 		data_ptr  = (GLvoid*)uint_data;
15518 		data_size = sizeof(uint_data);
15519 		break;
15520 	default:
15521 		TCU_FAIL("Invalid enum");
15522 	}
15523 
15524 	buffer.update(data_size, data_ptr, GL_STATIC_DRAW);
15525 
15526 	/* GL entry points */
15527 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
15528 
15529 	/* Set up vao */
15530 	switch (test_case.m_type)
15531 	{
15532 	case Utils::FLOAT:
15533 		for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15534 		{
15535 			const GLuint  index  = variable_loc + col;
15536 			const GLint   size   = test_case.m_n_rows;
15537 			const GLvoid* offset = (const GLvoid*)(test_case.m_n_rows * sizeof(GLfloat) * col);
15538 
15539 			gl.vertexAttribPointer(index, size, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0, offset);
15540 			GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
15541 		}
15542 		break;
15543 	case Utils::INT:
15544 		gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_INT /* type */, 0 /* stride */,
15545 								0 /* offset */);
15546 		GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15547 		break;
15548 	case Utils::UINT:
15549 		gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_UNSIGNED_INT /* type */, 0 /* stride */,
15550 								0 /* offset */);
15551 		GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15552 		break;
15553 	default:
15554 		DE_ASSERT(0);
15555 		break;
15556 	}
15557 
15558 	/* Enable attribute */
15559 	for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15560 	{
15561 		gl.enableVertexAttribArray(variable_loc + col);
15562 		GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
15563 	}
15564 }
15565 
15566 /** Prepare test cases
15567  *
15568  * @return true
15569  **/
testInit()15570 bool LengthOfVectorAndMatrixTest::testInit()
15571 {
15572 	/* Vectors */
15573 	for (GLuint row = 2; row <= 4; ++row)
15574 	{
15575 		testCase test_case = { Utils::UINT, 1 /* n_cols */, row };
15576 
15577 		m_test_cases.push_back(test_case);
15578 	}
15579 
15580 	for (GLuint row = 2; row <= 4; ++row)
15581 	{
15582 		testCase test_case = { Utils::INT, 1 /* n_cols */, row };
15583 
15584 		m_test_cases.push_back(test_case);
15585 	}
15586 
15587 	for (GLuint row = 2; row <= 4; ++row)
15588 	{
15589 		testCase test_case = { Utils::FLOAT, 1 /* n_cols */, row };
15590 
15591 		m_test_cases.push_back(test_case);
15592 	}
15593 
15594 	/* Matrices */
15595 	for (GLuint col = 2; col <= 4; ++col)
15596 	{
15597 		for (GLuint row = 2; row <= 4; ++row)
15598 		{
15599 			testCase test_case = { Utils::FLOAT, col, row };
15600 
15601 			m_test_cases.push_back(test_case);
15602 		}
15603 	}
15604 
15605 	return true;
15606 }
15607 
15608 /** Get string representing value that should be placed at token EXPECTED_VALUE
15609  *
15610  * @param in_stage Shader stage
15611  *
15612  * @return String with value
15613  **/
getExpectedValue(Utils::SHADER_STAGES in_stage)15614 std::string LengthOfVectorAndMatrixTest::getExpectedValue(Utils::SHADER_STAGES in_stage)
15615 {
15616 	const testCase& test_case = m_test_cases[m_current_test_case_index];
15617 
15618 	GLuint count = 0;
15619 
15620 	switch (in_stage)
15621 	{
15622 	case Utils::FRAGMENT_SHADER:
15623 		count = 3;
15624 		break;
15625 	case Utils::COMPUTE_SHADER:
15626 		count = 2;
15627 		break;
15628 	default:
15629 		count = 4;
15630 	}
15631 
15632 	if (1 == test_case.m_n_cols)
15633 	{
15634 		count *= test_case.m_n_rows;
15635 	}
15636 	else
15637 	{
15638 		count *= test_case.m_n_cols;
15639 	}
15640 
15641 	std::string expected_value;
15642 	expected_value.resize(64, 0);
15643 
15644 	switch (test_case.m_type)
15645 	{
15646 	case Utils::FLOAT:
15647 	{
15648 		GLfloat value = 0.125f * (GLfloat)count;
15649 		sprintf(&expected_value[0], "%f", value);
15650 	}
15651 	break;
15652 	case Utils::INT:
15653 	{
15654 		GLint value = -1 * (GLint)count;
15655 		sprintf(&expected_value[0], "%d", value);
15656 	}
15657 	break;
15658 	case Utils::UINT:
15659 	{
15660 		GLuint value = 1 * (GLuint)count;
15661 		sprintf(&expected_value[0], "%d", value);
15662 	}
15663 	break;
15664 	default:
15665 		DE_ASSERT(0);
15666 		break;
15667 	}
15668 
15669 	return expected_value;
15670 }
15671 
15672 /** Get string reresenting initialization of local variables for current test case
15673  *
15674  * @return String with initialization
15675  **/
getInitialization()15676 std::string LengthOfVectorAndMatrixTest::getInitialization()
15677 {
15678 	const testCase& test_case = m_test_cases[m_current_test_case_index];
15679 
15680 	std::string initialization;
15681 
15682 	if (1 == test_case.m_n_cols)
15683 	{
15684 		initialization = getVectorInitializer(test_case.m_type, test_case.m_n_rows);
15685 	}
15686 	else
15687 	{
15688 		initialization = getMatrixInitializer(test_case.m_n_cols, test_case.m_n_rows);
15689 	}
15690 
15691 	return initialization;
15692 }
15693 
15694 /** Get string reresenting initialization of local matrix variables
15695  *
15696  * @param n_cols Number of columns
15697  * @param n_rows Number of rows
15698  *
15699  * @return String with initialization
15700  **/
getMatrixInitializer(GLuint n_cols,GLuint n_rows)15701 std::string LengthOfVectorAndMatrixTest::getMatrixInitializer(GLuint n_cols, GLuint n_rows)
15702 {
15703 	std::string result;
15704 
15705 	result.append("{ ");
15706 
15707 	for (GLuint col = 0; col < n_cols; ++col)
15708 	{
15709 		result.append(getVectorInitializer(Utils::FLOAT, n_rows));
15710 
15711 		if (col + 1 < n_cols)
15712 		{
15713 			result.append(", ");
15714 		}
15715 	}
15716 
15717 	result.append(" }");
15718 
15719 	return result;
15720 }
15721 
15722 /** Get string reresenting initialization of local vector variables
15723  *
15724  * @param type   Basic type of vector
15725  * @param n_rows Number of rows
15726  *
15727  * @return String with initialization
15728  **/
getVectorInitializer(Utils::TYPES type,glw::GLuint n_rows)15729 std::string LengthOfVectorAndMatrixTest::getVectorInitializer(Utils::TYPES type, glw::GLuint n_rows)
15730 {
15731 	std::string   result;
15732 	const GLchar* value = 0;
15733 
15734 	switch (type)
15735 	{
15736 	case Utils::FLOAT:
15737 		value = "0.125";
15738 		break;
15739 	case Utils::UINT:
15740 		value = "1";
15741 		break;
15742 	case Utils::INT:
15743 		value = "-1";
15744 		break;
15745 	default:
15746 		TCU_FAIL("Invalid enum");
15747 	}
15748 
15749 	result.append("{");
15750 
15751 	for (GLuint row = 0; row < n_rows; ++row)
15752 	{
15753 		result.append(value);
15754 
15755 		if (row + 1 < n_rows)
15756 		{
15757 			result.append(", ");
15758 		}
15759 	}
15760 
15761 	result.append("}");
15762 
15763 	return result;
15764 }
15765 
15766 /** Prepare source for given shader stage
15767  *
15768  * @param in_stage           Shader stage, compute shader will use 430
15769  * @param in_use_version_400 Select if 400 or 420 should be used
15770  * @param out_source         Prepared shader source instance
15771  **/
prepareDrawShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15772 void LengthOfVectorAndMatrixTest::prepareDrawShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15773 														  Utils::shaderSource& out_source)
15774 {
15775 	static const GLchar* verification_snippet =
15776 		"    VARIABLE_TYPE variable  = INITIALIZATION;\n"
15777 		"    Structure     structure = { { 0, 1, 0, 1 } , INITIALIZATION };\n"
15778 		"\n"
15779 		"    const uint variable_length           = variable.length();\n"
15780 		"    const uint structure_member_b_length = structure.member_b.length();\n"
15781 		"    const uint input_member_length       = INPUT_VARIABLE_NAME.length();\n"
15782 		"#ifndef FRAGMENT\n"
15783 		"    const uint output_member_length      = OUTPUT_VARIABLE_NAME.length();\n"
15784 		"#endif // FRAGMENT\n"
15785 		"\n"
15786 		"    BASE_TYPE array_var[variable.length()];\n"
15787 		"    BASE_TYPE array_str[structure.member_b.length()];\n"
15788 		"    BASE_TYPE array_in [INPUT_VARIABLE_NAME.length()];\n"
15789 		"#ifndef FRAGMENT\n"
15790 		"    BASE_TYPE array_out[OUTPUT_VARIABLE_NAME.length()];\n"
15791 		"#endif // FRAGMENT\n"
15792 		"\n"
15793 		"    BASE_TYPE sum = 0;\n"
15794 		"\n"
15795 		"    for (uint i = 0; i < variable_length; ++i)\n"
15796 		"    {\n"
15797 		"        array_var[i] = variableARRAY_INDEX.x;\n"
15798 		"    }\n"
15799 		"\n"
15800 		"    for (uint i = 0; i < structure_member_b_length; ++i)\n"
15801 		"    {\n"
15802 		"        array_str[i] = structure.member_bARRAY_INDEX.y;\n"
15803 		"    }\n"
15804 		"\n"
15805 		"    for (uint i = 0; i < input_member_length; ++i)\n"
15806 		"    {\n"
15807 		"        array_in[i]  = INPUT_VARIABLE_NAMEARRAY_INDEX.x;\n"
15808 		"    }\n"
15809 		"\n"
15810 		"#ifndef FRAGMENT\n"
15811 		"    for (uint i = 0; i < output_member_length; ++i)\n"
15812 		"    {\n"
15813 		"        array_out[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.y;\n"
15814 		"    }\n"
15815 		"#endif // FRAGMENT\n"
15816 		"\n"
15817 		"    for (uint i = 0; i < array_var.length(); ++i)\n"
15818 		"    {\n"
15819 		"         sum += array_var[i];\n"
15820 		"    }\n"
15821 		"\n"
15822 		"    for (uint i = 0; i < array_str.length(); ++i)\n"
15823 		"    {\n"
15824 		"         sum += array_str[i];\n"
15825 		"    }\n"
15826 		"\n"
15827 		"    for (uint i = 0; i < array_in.length(); ++i)\n"
15828 		"    {\n"
15829 		"         sum += array_in[i];\n"
15830 		"    }\n"
15831 		"\n"
15832 		"#ifndef FRAGMENT\n"
15833 		"    for (uint i = 0; i < array_out.length(); ++i)\n"
15834 		"    {\n"
15835 		"         sum += array_out[i];\n"
15836 		"    }\n"
15837 		"#endif // FRAGMENT\n"
15838 		"\n"
15839 		"    if (EXPECTED_VALUE != sum)\n"
15840 		"    {\n"
15841 		"        result = vec4(1, 0, 0, 1);\n"
15842 		"    }\n";
15843 
15844 	static const GLchar* fragment_shader_template = "VERSION\n"
15845 													"\n"
15846 													"#define FRAGMENT\n"
15847 													"\n"
15848 													"in  vec4 gs_fs_result;\n"
15849 													"out vec4 fs_out_result;\n"
15850 													"\n"
15851 													"in GSOutputBlock {\n"
15852 													"    VARIABLE_DECLARATION;\n"
15853 													"} input_block;\n"
15854 													"\n"
15855 													"struct Structure {\n"
15856 													"    vec4 member_a;\n"
15857 													"    TYPE_NAME member_b;\n"
15858 													"};\n"
15859 													"\n"
15860 													"void main()\n"
15861 													"{\n"
15862 													"    vec4 result = vec4(0, 1, 0, 1);\n"
15863 													"\n"
15864 													"VERIFICATION"
15865 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
15866 													"    {\n"
15867 													"         result = vec4(1, 0, 0, 1);\n"
15868 													"    }\n"
15869 													"\n"
15870 													"    fs_out_result = result;\n"
15871 													"}\n"
15872 													"\n";
15873 
15874 	static const GLchar* geometry_shader_template = "VERSION\n"
15875 													"\n"
15876 													"layout(points)                           in;\n"
15877 													"layout(triangle_strip, max_vertices = 4) out;\n"
15878 													"\n"
15879 													"in  vec4 tes_gs_result[];\n"
15880 													"out vec4 gs_fs_result;\n"
15881 													"\n"
15882 													"in TCSOutputBlock {\n"
15883 													"    VARIABLE_DECLARATION;\n"
15884 													"} input_block[];\n"
15885 													"out GSOutputBlock {\n"
15886 													"    VARIABLE_DECLARATION;\n"
15887 													"} output_block;\n"
15888 													"\n"
15889 													"struct Structure {\n"
15890 													"    vec4 member_a;\n"
15891 													"    TYPE_NAME member_b;\n"
15892 													"};\n"
15893 													"\n"
15894 													"void main()\n"
15895 													"{\n"
15896 													"    vec4 result = vec4(0, 1, 0, 1);\n"
15897 													"\n"
15898 													"VERIFICATION"
15899 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
15900 													"    {\n"
15901 													"         result = vec4(1, 0, 0, 1);\n"
15902 													"    }\n"
15903 													"\n"
15904 													"    gs_fs_result  = result;\n"
15905 													"    gl_Position   = vec4(-1, -1, 0, 1);\n"
15906 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15907 													"    EmitVertex();\n"
15908 													"    gs_fs_result  = result;\n"
15909 													"    gl_Position   = vec4(-1, 1, 0, 1);\n"
15910 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15911 													"    EmitVertex();\n"
15912 													"    gs_fs_result  = result;\n"
15913 													"    gl_Position   = vec4(1, -1, 0, 1);\n"
15914 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15915 													"    EmitVertex();\n"
15916 													"    gs_fs_result  = result;\n"
15917 													"    gl_Position   = vec4(1, 1, 0, 1);\n"
15918 													"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15919 													"    EmitVertex();\n"
15920 													"}\n"
15921 													"\n";
15922 
15923 	static const GLchar* tess_ctrl_shader_template =
15924 		"VERSION\n"
15925 		"\n"
15926 		"layout(vertices = 1) out;\n"
15927 		"\n"
15928 		"in  vec4 vs_tcs_result[];\n"
15929 		"out vec4 tcs_tes_result[];\n"
15930 		"\n"
15931 		"in VSOutputBlock {\n"
15932 		"    VARIABLE_DECLARATION;\n"
15933 		"} input_block[];\n"
15934 		"out TCSOutputBlock {\n"
15935 		"    VARIABLE_DECLARATION;\n"
15936 		"} output_block[];\n"
15937 		"\n"
15938 		"struct Structure {\n"
15939 		"    vec4 member_a;\n"
15940 		"    TYPE_NAME member_b;\n"
15941 		"};\n"
15942 		"\n"
15943 		"void main()\n"
15944 		"{\n"
15945 		"    vec4 result = vec4(0, 1, 0, 1);\n"
15946 		"\n"
15947 		"VERIFICATION"
15948 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
15949 		"    {\n"
15950 		"         result = vec4(1, 0, 0, 1);\n"
15951 		"    }\n"
15952 		"\n"
15953 		"    tcs_tes_result[gl_InvocationID] = result;\n"
15954 		"    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15955 		"\n"
15956 		"    gl_TessLevelOuter[0] = 1.0;\n"
15957 		"    gl_TessLevelOuter[1] = 1.0;\n"
15958 		"    gl_TessLevelOuter[2] = 1.0;\n"
15959 		"    gl_TessLevelOuter[3] = 1.0;\n"
15960 		"    gl_TessLevelInner[0] = 1.0;\n"
15961 		"    gl_TessLevelInner[1] = 1.0;\n"
15962 		"}\n"
15963 		"\n";
15964 
15965 	static const GLchar* tess_eval_shader_template = "VERSION\n"
15966 													 "\n"
15967 													 "layout(isolines, point_mode) in;\n"
15968 													 "\n"
15969 													 "in  vec4 tcs_tes_result[];\n"
15970 													 "out vec4 tes_gs_result;\n"
15971 													 "\n"
15972 													 "in TCSOutputBlock {\n"
15973 													 "    VARIABLE_DECLARATION;\n"
15974 													 "} input_block[];\n"
15975 													 "out TCSOutputBlock {\n"
15976 													 "    VARIABLE_DECLARATION;\n"
15977 													 "} output_block;\n"
15978 													 "\n"
15979 													 "struct Structure {\n"
15980 													 "    vec4 member_a;\n"
15981 													 "    TYPE_NAME member_b;\n"
15982 													 "};\n"
15983 													 "\n"
15984 													 "void main()\n"
15985 													 "{\n"
15986 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
15987 													 "\n"
15988 													 "VERIFICATION"
15989 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
15990 													 "    {\n"
15991 													 "         result = vec4(1, 0, 0, 1);\n"
15992 													 "    }\n"
15993 													 "\n"
15994 													 "    tes_gs_result = result;\n"
15995 													 "    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15996 													 "}\n"
15997 													 "\n";
15998 
15999 	static const GLchar* vertex_shader_template = "VERSION\n"
16000 												  "\n"
16001 												  "out vec4 vs_tcs_result;\n"
16002 												  "\n"
16003 												  "in VARIABLE_DECLARATION;\n"
16004 												  "out VSOutputBlock {\n"
16005 												  "    VARIABLE_DECLARATION;\n"
16006 												  "} output_block;\n"
16007 												  "\n"
16008 												  "struct Structure {\n"
16009 												  "    vec4 member_a;\n"
16010 												  "    TYPE_NAME member_b;\n"
16011 												  "};\n"
16012 												  "\n"
16013 												  "void main()\n"
16014 												  "{\n"
16015 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
16016 												  "\n"
16017 												  "VERIFICATION"
16018 												  "\n"
16019 												  "    vs_tcs_result = result;\n"
16020 												  "    OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
16021 												  "}\n"
16022 												  "\n";
16023 
16024 	const GLchar*   array_index		  = "";
16025 	const testCase& test_case		  = m_test_cases[m_current_test_case_index];
16026 	const GLchar*   shader_template   = 0;
16027 	const GLchar*   input_block_name  = "input_block";
16028 	const GLchar*   output_block_name = "output_block";
16029 
16030 	const std::string& base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
16031 	const std::string& expected_value = getExpectedValue(in_stage);
16032 	const std::string& initialization = getInitialization();
16033 	const std::string& type_name	  = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
16034 
16035 	std::string input_decl;
16036 	std::string input_ref;
16037 	std::string output_decl;
16038 	std::string output_ref;
16039 
16040 	Utils::qualifierSet in_qualifiers;
16041 	Utils::qualifierSet out_qualifiers;
16042 
16043 	if ((Utils::UINT == test_case.m_type) || (Utils::INT == test_case.m_type))
16044 	{
16045 		if (Utils::VERTEX_SHADER != in_stage)
16046 		{
16047 			in_qualifiers.push_back(Utils::QUAL_FLAT);
16048 		}
16049 
16050 		out_qualifiers.push_back(Utils::QUAL_FLAT);
16051 	}
16052 
16053 	switch (in_stage)
16054 	{
16055 	case Utils::COMPUTE_SHADER:
16056 		shader_template = 0;
16057 		break;
16058 	case Utils::FRAGMENT_SHADER:
16059 		shader_template = fragment_shader_template;
16060 		break;
16061 	case Utils::GEOMETRY_SHADER:
16062 		shader_template = geometry_shader_template;
16063 		break;
16064 	case Utils::TESS_CTRL_SHADER:
16065 		shader_template = tess_ctrl_shader_template;
16066 		break;
16067 	case Utils::TESS_EVAL_SHADER:
16068 		shader_template = tess_eval_shader_template;
16069 		break;
16070 	case Utils::VERTEX_SHADER:
16071 		shader_template = vertex_shader_template;
16072 		break;
16073 	default:
16074 		TCU_FAIL("Invalid enum");
16075 		break;
16076 	}
16077 
16078 	if (Utils::VERTEX_SHADER != in_stage)
16079 	{
16080 		Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable",
16081 										   input_block_name, input_decl, input_ref);
16082 	}
16083 	else
16084 	{
16085 		Utils::prepareVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable", input_decl,
16086 									  input_ref);
16087 	}
16088 	if (Utils::FRAGMENT_SHADER != in_stage)
16089 	{
16090 		Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
16091 										   output_block_name, output_decl, output_ref);
16092 	}
16093 	else
16094 	{
16095 		Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
16096 									  output_decl, output_ref);
16097 	}
16098 
16099 	if (1 != test_case.m_n_cols)
16100 	{
16101 		array_index = "[i]";
16102 	}
16103 
16104 	out_source.m_parts[0].m_code = shader_template;
16105 
16106 	size_t position = 0;
16107 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16108 						out_source.m_parts[0].m_code);
16109 
16110 	Utils::replaceToken("VARIABLE_DECLARATION", position, input_decl.c_str(), out_source.m_parts[0].m_code);
16111 
16112 	if (Utils::FRAGMENT_SHADER != in_stage)
16113 	{
16114 		Utils::replaceToken("VARIABLE_DECLARATION", position, output_decl.c_str(), out_source.m_parts[0].m_code);
16115 	}
16116 
16117 	Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16118 
16119 	size_t temp = position;
16120 
16121 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16122 
16123 	position = temp;
16124 
16125 	Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
16126 
16127 	Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
16128 
16129 	Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
16130 
16131 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16132 
16133 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16134 
16135 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16136 
16137 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16138 
16139 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16140 
16141 	Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
16142 
16143 	Utils::replaceAllTokens("INPUT_VARIABLE_NAME", input_ref.c_str(), out_source.m_parts[0].m_code);
16144 
16145 	Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", output_ref.c_str(), out_source.m_parts[0].m_code);
16146 
16147 	Utils::replaceAllTokens("ARRAY_INDEX", array_index, out_source.m_parts[0].m_code);
16148 }
16149 
16150 /** Prepare source for compute shader stage
16151  *
16152  * @param out_source Prepared shader source instance
16153  **/
prepareComputeShaderSource(Utils::shaderSource & out_source)16154 void LengthOfVectorAndMatrixTest::prepareComputeShaderSource(Utils::shaderSource& out_source)
16155 {
16156 	static const GLchar* verification_snippet =
16157 		"    VARIABLE_TYPE variable  = uni_variable;\n"
16158 		"    Structure     structure = { { 0, 1, 0, 1 } , uni_variable };\n"
16159 		"\n"
16160 		"    const uint variable_length           = variable.length();\n"
16161 		"    const uint structure_member_b_length = structure.member_b.length();\n"
16162 		"\n"
16163 		"    BASE_TYPE array_var[variable.length()];\n"
16164 		"    BASE_TYPE array_str[structure.member_b.length()];\n"
16165 		"\n"
16166 		"    BASE_TYPE sum = 0;\n"
16167 		"\n"
16168 		"    for (uint i = 0; i < variable_length; ++i)\n"
16169 		"    {\n"
16170 		"        array_var[i] = variableARRAY_INDEX.x;\n"
16171 		"    }\n"
16172 		"\n"
16173 		"    for (uint i = 0; i < structure_member_b_length; ++i)\n"
16174 		"    {\n"
16175 		"        array_str[i] = structure.member_bARRAY_INDEX.y;\n"
16176 		"    }\n"
16177 		"\n"
16178 		"    for (uint i = 0; i < array_var.length(); ++i)\n"
16179 		"    {\n"
16180 		"         sum += array_var[i];\n"
16181 		"    }\n"
16182 		"\n"
16183 		"    for (uint i = 0; i < array_str.length(); ++i)\n"
16184 		"    {\n"
16185 		"         sum += array_str[i];\n"
16186 		"    }\n"
16187 		"\n"
16188 		"    if (EXPECTED_VALUE != sum)\n"
16189 		"    {\n"
16190 		"        result = vec4(1, 0, 0, 1);\n"
16191 		"    }\n";
16192 
16193 	static const GLchar* compute_shader_template =
16194 		"VERSION\n"
16195 		"\n"
16196 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16197 		"\n"
16198 		"writeonly uniform image2D uni_image;\n"
16199 		"          uniform TYPE_NAME    uni_variable;\n"
16200 		"\n"
16201 		"struct Structure {\n"
16202 		"    vec4 member_a;\n"
16203 		"    TYPE_NAME member_b;\n"
16204 		"};\n"
16205 		"\n"
16206 		"void main()\n"
16207 		"{\n"
16208 		"    vec4 result = vec4(0, 1, 0, 1);\n"
16209 		"\n"
16210 		"VERIFICATION"
16211 		"\n"
16212 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16213 		"}\n"
16214 		"\n";
16215 
16216 	const testCase& test_case   = m_test_cases[m_current_test_case_index];
16217 	const GLchar*   array_index = "";
16218 
16219 	const std::string& base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
16220 	const std::string& expected_value = getExpectedValue(Utils::COMPUTE_SHADER);
16221 	const std::string& type_name	  = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
16222 
16223 	if (1 != test_case.m_n_cols)
16224 	{
16225 		array_index = "[i]";
16226 	}
16227 
16228 	out_source.m_parts[0].m_code = compute_shader_template;
16229 
16230 	size_t position = 0;
16231 	Utils::replaceToken("VERSION", position, getVersionString(Utils::COMPUTE_SHADER, false),
16232 						out_source.m_parts[0].m_code);
16233 
16234 	Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16235 
16236 	Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16237 
16238 	size_t temp = position;
16239 
16240 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16241 
16242 	position = temp;
16243 
16244 	Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
16245 
16246 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16247 
16248 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16249 
16250 	Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16251 
16252 	Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
16253 
16254 	Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
16255 
16256 	Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
16257 }
16258 
16259 /** Constructor
16260  *
16261  * @param context Test context
16262  **/
LengthOfComputeResultTest(deqp::Context & context)16263 LengthOfComputeResultTest::LengthOfComputeResultTest(deqp::Context& context)
16264 	: GLSLTestBase(context, "length_of_compute_result", "Test verifies .length() for results of computation")
16265 {
16266 	/* Nothing to be done here */
16267 }
16268 
16269 /** Prepare source for given shader stage
16270  *
16271  * @param in_stage           Shader stage, compute shader will use 430
16272  * @param in_use_version_400 Select if 400 or 420 should be used
16273  * @param out_source         Prepared shader source instance
16274  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16275 void LengthOfComputeResultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16276 													Utils::shaderSource& out_source)
16277 {
16278 	static const GLchar* uniforms = "uniform mat2x4 goten;\n"
16279 									"uniform uvec4  indices;\n"
16280 									"uniform uvec4  expected_lengths;\n"
16281 									"uniform mat4x3 gohan;\n"
16282 									"uniform vec3   vegeta;\n"
16283 									"uniform vec3   trunks;\n"
16284 									"uniform uint   variable;\n"
16285 									"uniform float  expected_sum;\n";
16286 
16287 	static const GLchar* verification_snippet =
16288 		"    uint lengths[4];\n"
16289 		"    float x[(gohan * goten).length()];\n"
16290 		"    float y[(gohan * goten)[variable - 1].length()];\n"
16291 		"\n"
16292 		"    lengths[indices.x] = gohan[variable].length();\n"
16293 		"    lengths[indices.y] = (gohan * goten).length();\n"
16294 		"    lengths[indices.z] = (gohan * goten)[variable].length();\n"
16295 		"    lengths[indices.w] = (vegeta * trunks).length();\n"
16296 		"\n"
16297 		"    float  dot_result = dot(vegeta, trunks);\n"
16298 		"    mat2x3 mul_result = gohan * goten;\n"
16299 		"\n"
16300 		"#ifdef TESS_CTRL\n"
16301 		"    const uint position_length        = gl_out[gl_InvocationID].gl_Position.length();\n"
16302 		"#endif\n"
16303 		"#ifndef COMPUTE\n"
16304 		"#ifndef FRAGMENT\n"
16305 		"#ifndef TESS_CTRL\n"
16306 		"    const uint position_length        = gl_Position.length();\n"
16307 		"#endif  /*TESS_CTRL */\n"
16308 		"#endif /* FRAGMENT */\n"
16309 		"#endif /* COMPUTE */\n"
16310 		"#ifdef FRAGMENT\n"
16311 		"    const uint point_coord_length     = gl_PointCoord.length();\n"
16312 		"    const uint sample_position_length = gl_SamplePosition.length();\n"
16313 		"#endif /* FRAGMENT */\n"
16314 		"    const uint outer_length           = outerProduct(vegeta, trunks).length();\n"
16315 		"\n"
16316 		"    for (uint i = 0; i < x.length(); ++i)\n"
16317 		"    {\n"
16318 		"        x[i] = mul_result[i].x;\n"
16319 		"    }\n"
16320 		"\n"
16321 		"    for (uint i = 0; i < y.length(); ++i)\n"
16322 		"    {\n"
16323 		"        y[i] = mul_result[0][i];\n"
16324 		"    }\n"
16325 		"\n"
16326 		"    if ( (expected_lengths.x != lengths[0])                   ||\n"
16327 		"         (expected_lengths.y != lengths[1])                   ||\n"
16328 		"         (expected_lengths.z != lengths[2])                   ||\n"
16329 		"         (expected_lengths.w != lengths[3])                   ||\n"
16330 		"#ifndef COMPUTE\n"
16331 		"#ifndef FRAGMENT\n"
16332 		"         (4 /* vec4 */       != position_length)              ||\n"
16333 		"#endif /* FRAGMENT */\n"
16334 		"#endif /* COMPUTE */\n"
16335 		"#ifdef FRAGMENT\n"
16336 		"         (2 /* vec2 */       != point_coord_length)           ||\n"
16337 		"         (2 /* vec2 */       != sample_position_length)       ||\n"
16338 		"#endif /* FRAGMENT */\n"
16339 		"         (0.5                != dot_result)                   ||\n"
16340 		"         (3 /* mat3 */       != outer_length)                 ||\n"
16341 		"         (expected_sum       != x[variable] + y[variable])    )\n"
16342 		"    {\n"
16343 		"        result = vec4(1, 0, 0, 1);\n"
16344 		"    }\n";
16345 
16346 	static const GLchar* compute_shader_template =
16347 		"VERSION\n"
16348 		"\n"
16349 		"#define COMPUTE\n"
16350 		"\n"
16351 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16352 		"\n"
16353 		"writeonly uniform image2D uni_image;\n"
16354 		"\n"
16355 		"UNIFORMS"
16356 		"\n"
16357 		"void main()\n"
16358 		"{\n"
16359 		"    vec4 result = vec4(0, 1, 0, 1);\n"
16360 		"\n"
16361 		"VERIFICATION"
16362 		"\n"
16363 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16364 		"}\n"
16365 		"\n";
16366 
16367 	static const GLchar* fragment_shader_template = "VERSION\n"
16368 													"\n"
16369 													"#define FRAGMENT\n"
16370 													"\n"
16371 													"in  vec4 gs_fs_result;\n"
16372 													"out vec4 fs_out_result;\n"
16373 													"\n"
16374 													"UNIFORMS"
16375 													"\n"
16376 													"void main()\n"
16377 													"{\n"
16378 													"    vec4 result = vec4(0, 1, 0, 1);\n"
16379 													"\n"
16380 													"VERIFICATION"
16381 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16382 													"    {\n"
16383 													"         result = vec4(1, 0, 0, 1);\n"
16384 													"    }\n"
16385 													"\n"
16386 													"    fs_out_result = result;\n"
16387 													"}\n"
16388 													"\n";
16389 
16390 	static const GLchar* geometry_shader_template = "VERSION\n"
16391 													"\n"
16392 													"layout(points)                           in;\n"
16393 													"layout(triangle_strip, max_vertices = 4) out;\n"
16394 													"\n"
16395 													"in  vec4 tes_gs_result[];\n"
16396 													"out vec4 gs_fs_result;\n"
16397 													"\n"
16398 													"UNIFORMS"
16399 													"\n"
16400 													"void main()\n"
16401 													"{\n"
16402 													"    vec4 result = vec4(0, 1, 0, 1);\n"
16403 													"\n"
16404 													"VERIFICATION"
16405 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16406 													"    {\n"
16407 													"         result = vec4(1, 0, 0, 1);\n"
16408 													"    }\n"
16409 													"\n"
16410 													"    gs_fs_result  = result;\n"
16411 													"    gl_Position   = vec4(-1, -1, 0, 1);\n"
16412 													"    EmitVertex();\n"
16413 													"    gs_fs_result  = result;\n"
16414 													"    gl_Position   = vec4(-1, 1, 0, 1);\n"
16415 													"    EmitVertex();\n"
16416 													"    gs_fs_result  = result;\n"
16417 													"    gl_Position   = vec4(1, -1, 0, 1);\n"
16418 													"    EmitVertex();\n"
16419 													"    gs_fs_result  = result;\n"
16420 													"    gl_Position   = vec4(1, 1, 0, 1);\n"
16421 													"    EmitVertex();\n"
16422 													"}\n"
16423 													"\n";
16424 
16425 	static const GLchar* tess_ctrl_shader_template =
16426 		"VERSION\n"
16427 		"#define TESS_CTRL\n"
16428 		"\n"
16429 		"layout(vertices = 1) out;\n"
16430 		"\n"
16431 		"in  vec4 vs_tcs_result[];\n"
16432 		"out vec4 tcs_tes_result[];\n"
16433 		"\n"
16434 		"UNIFORMS"
16435 		"\n"
16436 		"void main()\n"
16437 		"{\n"
16438 		"    vec4 result = vec4(0, 1, 0, 1);\n"
16439 		"\n"
16440 		"VERIFICATION"
16441 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16442 		"    {\n"
16443 		"         result = vec4(1, 0, 0, 1);\n"
16444 		"    }\n"
16445 		"\n"
16446 		"    tcs_tes_result[gl_InvocationID] = result;\n"
16447 		"\n"
16448 		"    gl_TessLevelOuter[0] = 1.0;\n"
16449 		"    gl_TessLevelOuter[1] = 1.0;\n"
16450 		"    gl_TessLevelOuter[2] = 1.0;\n"
16451 		"    gl_TessLevelOuter[3] = 1.0;\n"
16452 		"    gl_TessLevelInner[0] = 1.0;\n"
16453 		"    gl_TessLevelInner[1] = 1.0;\n"
16454 		"}\n"
16455 		"\n";
16456 
16457 	static const GLchar* tess_eval_shader_template = "VERSION\n"
16458 													 "\n"
16459 													 "layout(isolines, point_mode) in;\n"
16460 													 "\n"
16461 													 "in  vec4 tcs_tes_result[];\n"
16462 													 "out vec4 tes_gs_result;\n"
16463 													 "\n"
16464 													 "UNIFORMS"
16465 													 "\n"
16466 													 "void main()\n"
16467 													 "{\n"
16468 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
16469 													 "\n"
16470 													 "VERIFICATION"
16471 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16472 													 "    {\n"
16473 													 "         result = vec4(1, 0, 0, 1);\n"
16474 													 "    }\n"
16475 													 "\n"
16476 													 "    tes_gs_result = result;\n"
16477 													 "}\n"
16478 													 "\n";
16479 
16480 	static const GLchar* vertex_shader_template = "VERSION\n"
16481 												  "\n"
16482 												  "out vec4 vs_tcs_result;\n"
16483 												  "\n"
16484 												  "UNIFORMS"
16485 												  "\n"
16486 												  "void main()\n"
16487 												  "{\n"
16488 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
16489 												  "\n"
16490 												  "VERIFICATION"
16491 												  "\n"
16492 												  "    vs_tcs_result = result;\n"
16493 												  "}\n"
16494 												  "\n";
16495 
16496 	const GLchar* shader_template = 0;
16497 
16498 	switch (in_stage)
16499 	{
16500 	case Utils::COMPUTE_SHADER:
16501 		shader_template = compute_shader_template;
16502 		break;
16503 	case Utils::FRAGMENT_SHADER:
16504 		shader_template = fragment_shader_template;
16505 		break;
16506 	case Utils::GEOMETRY_SHADER:
16507 		shader_template = geometry_shader_template;
16508 		break;
16509 	case Utils::TESS_CTRL_SHADER:
16510 		shader_template = tess_ctrl_shader_template;
16511 		break;
16512 	case Utils::TESS_EVAL_SHADER:
16513 		shader_template = tess_eval_shader_template;
16514 		break;
16515 	case Utils::VERTEX_SHADER:
16516 		shader_template = vertex_shader_template;
16517 		break;
16518 	default:
16519 		TCU_FAIL("Invalid enum");
16520 		break;
16521 	}
16522 
16523 	out_source.m_parts[0].m_code = shader_template;
16524 
16525 	size_t position = 0;
16526 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16527 						out_source.m_parts[0].m_code);
16528 
16529 	Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16530 
16531 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16532 }
16533 
16534 /** Overwritte of prepareUniforms method
16535  *
16536  * @param program Current program
16537  **/
prepareUniforms(Utils::program & program)16538 void LengthOfComputeResultTest::prepareUniforms(Utils::program& program)
16539 {
16540 	static const GLfloat gohan_data[12] = { 0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f,
16541 											0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f };
16542 
16543 	static const GLfloat goten_data[8] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
16544 
16545 	static const GLfloat vegeta_data[3] = { 0.5f, 0.5f, 0.0f };
16546 
16547 	static const GLfloat trunks_data[3] = { 0.5f, 0.5f, 0.0f };
16548 
16549 	static const GLuint indices_data[4] = { 2, 1, 0, 3 };
16550 
16551 	static const GLuint variable_data[1] = { 1 };
16552 
16553 	static const GLuint expected_lengths_data[4] = { 3, 2, 3, 3 };
16554 
16555 	static const GLfloat expected_sum_data[1] = { 1.0f };
16556 
16557 	program.uniform("gohan", Utils::FLOAT, 4 /* n_cols */, 3 /* n_rows */, gohan_data);
16558 	program.uniform("goten", Utils::FLOAT, 2 /* n_cols */, 4 /* n_rows */, goten_data);
16559 	program.uniform("vegeta", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, vegeta_data);
16560 	program.uniform("trunks", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, trunks_data);
16561 	program.uniform("indices", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, indices_data);
16562 	program.uniform("variable", Utils::UINT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16563 	program.uniform("expected_lengths", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, expected_lengths_data);
16564 	program.uniform("expected_sum", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, expected_sum_data);
16565 }
16566 
16567 /** Constructor
16568  *
16569  * @param context Test context
16570  **/
ScalarSwizzlersTest(deqp::Context & context)16571 ScalarSwizzlersTest::ScalarSwizzlersTest(deqp::Context& context)
16572 	: GLSLTestBase(context, "scalar_swizzlers", "Verifies that swizzlers can be used on scalars")
16573 {
16574 	/* Nothing to be done here */
16575 }
16576 
16577 /** Prepare source for given shader stage
16578  *
16579  * @param in_stage           Shader stage, compute shader will use 430
16580  * @param in_use_version_400 Select if 400 or 420 should be used
16581  * @param out_source         Prepared shader source instance
16582  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16583 void ScalarSwizzlersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16584 											  Utils::shaderSource& out_source)
16585 {
16586 	static const GLchar* uniforms = "uniform float variable;\n"
16587 									"uniform vec3  expected_values;\n";
16588 
16589 	static const GLchar* literal = "#define LITERAL 0.375\n";
16590 
16591 	static const GLchar* structure = "struct Structure {\n"
16592 									 "    vec2 m_xx;\n"
16593 									 "    vec3 m_xxx;\n"
16594 									 "    vec4 m_xxxx;\n"
16595 									 "    vec2 m_nested_xx;\n"
16596 									 "    vec3 m_nested_xxx;\n"
16597 									 "    vec4 m_nested_xxxx;\n"
16598 									 "};\n";
16599 
16600 	static const GLchar* function = "bool check_values(in Structure structure, in float value)\n"
16601 									"{\n"
16602 									"    const vec2 xx   = vec2(value, value);\n"
16603 									"    const vec3 xxx  = vec3(value, value, value);\n"
16604 									"    const vec4 xxxx = vec4(value, value, value, value);\n"
16605 									"\n"
16606 									"    bool result = true;\n"
16607 									"\n"
16608 									"    if ((xx   != structure.m_xx)         ||\n"
16609 									"        (xxx  != structure.m_xxx)        ||\n"
16610 									"        (xxxx != structure.m_xxxx)       ||\n"
16611 									"        (xx   != structure.m_nested_xx)  ||\n"
16612 									"        (xxx  != structure.m_nested_xxx) ||\n"
16613 									"        (xxxx != structure.m_nested_xxxx) )\n"
16614 									"    {\n"
16615 									"        result = false;\n"
16616 									"    }\n"
16617 									"\n"
16618 									"    return result;\n"
16619 									"}\n";
16620 
16621 	static const GLchar* verification_snippet =
16622 		"    Structure literal_result;\n"
16623 		"    Structure constant_result;\n"
16624 		"    Structure variable_result;\n"
16625 		"\n"
16626 		"    literal_result.m_xx          = LITERAL.xx  ;\n"
16627 		"    literal_result.m_xxx         = LITERAL.xxx ;\n"
16628 		"    literal_result.m_xxxx        = LITERAL.xxxx;\n"
16629 		"    literal_result.m_nested_xx   = LITERAL.x.rr.sss.rr  ;\n"
16630 		"    literal_result.m_nested_xxx  = LITERAL.s.xx.rrr.xxx ;\n"
16631 		"    literal_result.m_nested_xxxx = LITERAL.r.ss.xxx.ssss;\n"
16632 		"\n"
16633 		"    const float constant = 0.125;\n"
16634 		"\n"
16635 		"    constant_result.m_xx          = constant.xx  ;\n"
16636 		"    constant_result.m_xxx         = constant.xxx ;\n"
16637 		"    constant_result.m_xxxx        = constant.xxxx;\n"
16638 		"    constant_result.m_nested_xx   = constant.x.rr.sss.rr  ;\n"
16639 		"    constant_result.m_nested_xxx  = constant.s.xx.rrr.xxx ;\n"
16640 		"    constant_result.m_nested_xxxx = constant.r.ss.xxx.ssss;\n"
16641 		"\n"
16642 		"    variable_result.m_xx          = variable.xx  ;\n"
16643 		"    variable_result.m_xxx         = variable.xxx ;\n"
16644 		"    variable_result.m_xxxx        = variable.xxxx;\n"
16645 		"    variable_result.m_nested_xx   = variable.x.rr.sss.rr  ;\n"
16646 		"    variable_result.m_nested_xxx  = variable.s.xx.rrr.xxx ;\n"
16647 		"    variable_result.m_nested_xxxx = variable.r.ss.xxx.ssss;\n"
16648 		"\n"
16649 		"    if ((false == check_values(literal_result,  expected_values.x)) ||\n"
16650 		"        (false == check_values(constant_result, expected_values.y)) ||\n"
16651 		"        (false == check_values(variable_result, expected_values.z)) )\n"
16652 		"    {\n"
16653 		"        result = vec4(1, 0, 0, 1);\n"
16654 		"    }\n";
16655 
16656 	static const GLchar* compute_shader_template =
16657 		"VERSION\n"
16658 		"\n"
16659 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16660 		"\n"
16661 		"writeonly uniform image2D uni_image;\n"
16662 		"\n"
16663 		"STRUCTURE"
16664 		"\n"
16665 		"UNIFORMS"
16666 		"\n"
16667 		"FUNCTION"
16668 		"\n"
16669 		"LITERAL"
16670 		"\n"
16671 		"void main()\n"
16672 		"{\n"
16673 		"    vec4 result = vec4(0, 1, 0, 1);\n"
16674 		"\n"
16675 		"VERIFICATION"
16676 		"\n"
16677 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16678 		"}\n"
16679 		"\n";
16680 
16681 	static const GLchar* fragment_shader_template = "VERSION\n"
16682 													"\n"
16683 													"#define FRAGMENT\n"
16684 													"\n"
16685 													"in  vec4 gs_fs_result;\n"
16686 													"out vec4 fs_out_result;\n"
16687 													"\n"
16688 													"STRUCTURE"
16689 													"\n"
16690 													"UNIFORMS"
16691 													"\n"
16692 													"FUNCTION"
16693 													"\n"
16694 													"LITERAL"
16695 													"\n"
16696 													"void main()\n"
16697 													"{\n"
16698 													"    vec4 result = vec4(0, 1, 0, 1);\n"
16699 													"\n"
16700 													"VERIFICATION"
16701 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16702 													"    {\n"
16703 													"         result = vec4(1, 0, 0, 1);\n"
16704 													"    }\n"
16705 													"\n"
16706 													"    fs_out_result = result;\n"
16707 													"}\n"
16708 													"\n";
16709 
16710 	static const GLchar* geometry_shader_template = "VERSION\n"
16711 													"\n"
16712 													"layout(points)                           in;\n"
16713 													"layout(triangle_strip, max_vertices = 4) out;\n"
16714 													"\n"
16715 													"in  vec4 tes_gs_result[];\n"
16716 													"out vec4 gs_fs_result;\n"
16717 													"\n"
16718 													"STRUCTURE"
16719 													"\n"
16720 													"UNIFORMS"
16721 													"\n"
16722 													"FUNCTION"
16723 													"\n"
16724 													"LITERAL"
16725 													"\n"
16726 													"void main()\n"
16727 													"{\n"
16728 													"    vec4 result = vec4(0, 1, 0, 1);\n"
16729 													"\n"
16730 													"VERIFICATION"
16731 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16732 													"    {\n"
16733 													"         result = vec4(1, 0, 0, 1);\n"
16734 													"    }\n"
16735 													"\n"
16736 													"    gs_fs_result  = result;\n"
16737 													"    gl_Position   = vec4(-1, -1, 0, 1);\n"
16738 													"    EmitVertex();\n"
16739 													"    gs_fs_result  = result;\n"
16740 													"    gl_Position   = vec4(-1, 1, 0, 1);\n"
16741 													"    EmitVertex();\n"
16742 													"    gs_fs_result  = result;\n"
16743 													"    gl_Position   = vec4(1, -1, 0, 1);\n"
16744 													"    EmitVertex();\n"
16745 													"    gs_fs_result  = result;\n"
16746 													"    gl_Position   = vec4(1, 1, 0, 1);\n"
16747 													"    EmitVertex();\n"
16748 													"}\n"
16749 													"\n";
16750 
16751 	static const GLchar* tess_ctrl_shader_template =
16752 		"VERSION\n"
16753 		"\n"
16754 		"layout(vertices = 1) out;\n"
16755 		"\n"
16756 		"in  vec4 vs_tcs_result[];\n"
16757 		"out vec4 tcs_tes_result[];\n"
16758 		"\n"
16759 		"STRUCTURE"
16760 		"\n"
16761 		"UNIFORMS"
16762 		"\n"
16763 		"FUNCTION"
16764 		"\n"
16765 		"LITERAL"
16766 		"\n"
16767 		"void main()\n"
16768 		"{\n"
16769 		"    vec4 result = vec4(0, 1, 0, 1);\n"
16770 		"\n"
16771 		"VERIFICATION"
16772 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16773 		"    {\n"
16774 		"         result = vec4(1, 0, 0, 1);\n"
16775 		"    }\n"
16776 		"\n"
16777 		"    tcs_tes_result[gl_InvocationID] = result;\n"
16778 		"\n"
16779 		"    gl_TessLevelOuter[0] = 1.0;\n"
16780 		"    gl_TessLevelOuter[1] = 1.0;\n"
16781 		"    gl_TessLevelOuter[2] = 1.0;\n"
16782 		"    gl_TessLevelOuter[3] = 1.0;\n"
16783 		"    gl_TessLevelInner[0] = 1.0;\n"
16784 		"    gl_TessLevelInner[1] = 1.0;\n"
16785 		"}\n"
16786 		"\n";
16787 
16788 	static const GLchar* tess_eval_shader_template = "VERSION\n"
16789 													 "\n"
16790 													 "layout(isolines, point_mode) in;\n"
16791 													 "\n"
16792 													 "in  vec4 tcs_tes_result[];\n"
16793 													 "out vec4 tes_gs_result;\n"
16794 													 "\n"
16795 													 "STRUCTURE"
16796 													 "\n"
16797 													 "UNIFORMS"
16798 													 "\n"
16799 													 "FUNCTION"
16800 													 "\n"
16801 													 "LITERAL"
16802 													 "\n"
16803 													 "void main()\n"
16804 													 "{\n"
16805 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
16806 													 "\n"
16807 													 "VERIFICATION"
16808 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16809 													 "    {\n"
16810 													 "         result = vec4(1, 0, 0, 1);\n"
16811 													 "    }\n"
16812 													 "\n"
16813 													 "    tes_gs_result = result;\n"
16814 													 "}\n"
16815 													 "\n";
16816 
16817 	static const GLchar* vertex_shader_template = "VERSION\n"
16818 												  "\n"
16819 												  "out vec4 vs_tcs_result;\n"
16820 												  "\n"
16821 												  "STRUCTURE"
16822 												  "\n"
16823 												  "UNIFORMS"
16824 												  "\n"
16825 												  "FUNCTION"
16826 												  "\n"
16827 												  "LITERAL"
16828 												  "\n"
16829 												  "void main()\n"
16830 												  "{\n"
16831 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
16832 												  "\n"
16833 												  "VERIFICATION"
16834 												  "\n"
16835 												  "    vs_tcs_result = result;\n"
16836 												  "}\n"
16837 												  "\n";
16838 
16839 	const GLchar* shader_template = 0;
16840 
16841 	switch (in_stage)
16842 	{
16843 	case Utils::COMPUTE_SHADER:
16844 		shader_template = compute_shader_template;
16845 		break;
16846 	case Utils::FRAGMENT_SHADER:
16847 		shader_template = fragment_shader_template;
16848 		break;
16849 	case Utils::GEOMETRY_SHADER:
16850 		shader_template = geometry_shader_template;
16851 		break;
16852 	case Utils::TESS_CTRL_SHADER:
16853 		shader_template = tess_ctrl_shader_template;
16854 		break;
16855 	case Utils::TESS_EVAL_SHADER:
16856 		shader_template = tess_eval_shader_template;
16857 		break;
16858 	case Utils::VERTEX_SHADER:
16859 		shader_template = vertex_shader_template;
16860 		break;
16861 	default:
16862 		TCU_FAIL("Invalid enum");
16863 		break;
16864 	}
16865 
16866 	out_source.m_parts[0].m_code = shader_template;
16867 
16868 	size_t position = 0;
16869 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16870 						out_source.m_parts[0].m_code);
16871 
16872 	Utils::replaceToken("STRUCTURE", position, structure, out_source.m_parts[0].m_code);
16873 
16874 	Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16875 
16876 	Utils::replaceToken("FUNCTION", position, function, out_source.m_parts[0].m_code);
16877 
16878 	Utils::replaceToken("LITERAL", position, literal, out_source.m_parts[0].m_code);
16879 
16880 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16881 }
16882 
16883 /** Overwritte of prepareUniforms method
16884  *
16885  * @param program Current program
16886  **/
prepareUniforms(Utils::program & program)16887 void ScalarSwizzlersTest::prepareUniforms(Utils::program& program)
16888 {
16889 	static const GLfloat variable_data[4]		 = { 0.75f };
16890 	static const GLfloat expected_values_data[3] = { 0.375f, 0.125f, 0.75f };
16891 
16892 	program.uniform("variable", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16893 	program.uniform("expected_values", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, expected_values_data);
16894 }
16895 
16896 /** Constructor
16897  *
16898  * @param context Test context
16899  **/
ScalarSwizzlersInvalidTest(deqp::Context & context)16900 ScalarSwizzlersInvalidTest::ScalarSwizzlersInvalidTest(deqp::Context& context)
16901 	: NegativeTestBase(context, "scalar_swizzlers_invalid",
16902 					   "Verifies if invalid use of swizzlers on scalars is reported as error")
16903 {
16904 	/* Nothing to be done here */
16905 }
16906 
16907 /** Set up next test case
16908  *
16909  * @param test_case_index Index of next test case
16910  *
16911  * @return false if there is no more test cases, true otherwise
16912  **/
prepareNextTestCase(glw::GLuint test_case_index)16913 bool ScalarSwizzlersInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
16914 {
16915 	switch (test_case_index)
16916 	{
16917 	case (glw::GLuint)-1:
16918 	case INVALID_Y:
16919 	case INVALID_B:
16920 	case INVALID_Q:
16921 	case INVALID_XY:
16922 	case INVALID_XRS:
16923 	case WRONG:
16924 	case MISSING_PARENTHESIS:
16925 		m_case = (TESTED_CASES)test_case_index;
16926 		break;
16927 	default:
16928 		return false;
16929 	}
16930 
16931 	return true;
16932 }
16933 
16934 /** Prepare source for given shader stage
16935  *
16936  * @param in_stage           Shader stage, compute shader will use 430
16937  * @param in_use_version_400 Select if 400 or 420 should be used
16938  * @param out_source         Prepared shader source instance
16939  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16940 void ScalarSwizzlersInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16941 													 Utils::shaderSource& out_source)
16942 {
16943 	static const GLchar* uniforms = "uniform float variable;\n";
16944 
16945 	static const GLchar* verification_invalid_y = "\n"
16946 												  "    if (0.125 != variable.y) )\n"
16947 												  "    {\n"
16948 												  "        result = vec4(1, 0, 0, 1);\n"
16949 												  "    }\n";
16950 
16951 	static const GLchar* verification_invalid_b = "\n"
16952 												  "    if (0.125 != variable.b) )\n"
16953 												  "    {\n"
16954 												  "        result = vec4(1, 0, 0, 1);\n"
16955 												  "    }\n";
16956 
16957 	static const GLchar* verification_invalid_q = "\n"
16958 												  "    if (0.125 != variable.q) )\n"
16959 												  "    {\n"
16960 												  "        result = vec4(1, 0, 0, 1);\n"
16961 												  "    }\n";
16962 
16963 	static const GLchar* verification_invalid_xy = "\n"
16964 												   "    if (vec2(0.125, 0.25) != variable.xy) )\n"
16965 												   "    {\n"
16966 												   "        result = vec4(1, 0, 0, 1);\n"
16967 												   "    }\n";
16968 
16969 	static const GLchar* verification_invalid_xrs = "\n"
16970 													"    if (vec3(0.125, 0.125, 0.25) != variable.xrs) )\n"
16971 													"    {\n"
16972 													"        result = vec4(1, 0, 0, 1);\n"
16973 													"    }\n";
16974 
16975 	static const GLchar* verification_wrong_u = "\n"
16976 												"    if (0.125 != variable.u) )\n"
16977 												"    {\n"
16978 												"        result = vec4(1, 0, 0, 1);\n"
16979 												"    }\n";
16980 
16981 	static const GLchar* verification_missing_parenthesis = "\n"
16982 															"    if (variable != 1.x) )\n"
16983 															"    {\n"
16984 															"        result = vec4(1, 0, 0, 1);\n"
16985 															"    }\n";
16986 
16987 	static const GLchar* compute_shader_template =
16988 		"VERSION\n"
16989 		"\n"
16990 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16991 		"\n"
16992 		"writeonly uniform image2D uni_image;\n"
16993 		"\n"
16994 		"UNIFORMS"
16995 		"\n"
16996 		"void main()\n"
16997 		"{\n"
16998 		"    vec4 result = vec4(0, 1, 0, 1);\n"
16999 		"\n"
17000 		"VERIFICATION"
17001 		"\n"
17002 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17003 		"}\n"
17004 		"\n";
17005 
17006 	static const GLchar* fragment_shader_template = "VERSION\n"
17007 													"\n"
17008 													"#define FRAGMENT\n"
17009 													"\n"
17010 													"in  vec4 gs_fs_result;\n"
17011 													"out vec4 fs_out_result;\n"
17012 													"\n"
17013 													"UNIFORMS"
17014 													"\n"
17015 													"void main()\n"
17016 													"{\n"
17017 													"    vec4 result = vec4(0, 1, 0, 1);\n"
17018 													"\n"
17019 													"VERIFICATION"
17020 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17021 													"    {\n"
17022 													"         result = vec4(1, 0, 0, 1);\n"
17023 													"    }\n"
17024 													"\n"
17025 													"    fs_out_result = result;\n"
17026 													"}\n"
17027 													"\n";
17028 
17029 	static const GLchar* geometry_shader_template = "VERSION\n"
17030 													"\n"
17031 													"layout(points)                           in;\n"
17032 													"layout(triangle_strip, max_vertices = 4) out;\n"
17033 													"\n"
17034 													"in  vec4 tes_gs_result[];\n"
17035 													"out vec4 gs_fs_result;\n"
17036 													"\n"
17037 													"UNIFORMS"
17038 													"\n"
17039 													"void main()\n"
17040 													"{\n"
17041 													"    vec4 result = vec4(0, 1, 0, 1);\n"
17042 													"\n"
17043 													"VERIFICATION"
17044 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17045 													"    {\n"
17046 													"         result = vec4(1, 0, 0, 1);\n"
17047 													"    }\n"
17048 													"\n"
17049 													"    gs_fs_result  = result;\n"
17050 													"    gl_Position   = vec4(-1, -1, 0, 1);\n"
17051 													"    EmitVertex();\n"
17052 													"    gs_fs_result  = result;\n"
17053 													"    gl_Position   = vec4(-1, 1, 0, 1);\n"
17054 													"    EmitVertex();\n"
17055 													"    gs_fs_result  = result;\n"
17056 													"    gl_Position   = vec4(1, -1, 0, 1);\n"
17057 													"    EmitVertex();\n"
17058 													"    gs_fs_result  = result;\n"
17059 													"    gl_Position   = vec4(1, 1, 0, 1);\n"
17060 													"    EmitVertex();\n"
17061 													"}\n"
17062 													"\n";
17063 
17064 	static const GLchar* tess_ctrl_shader_template =
17065 		"VERSION\n"
17066 		"\n"
17067 		"layout(vertices = 1) out;\n"
17068 		"\n"
17069 		"in  vec4 vs_tcs_result[];\n"
17070 		"out vec4 tcs_tes_result[];\n"
17071 		"\n"
17072 		"UNIFORMS"
17073 		"\n"
17074 		"void main()\n"
17075 		"{\n"
17076 		"    vec4 result = vec4(0, 1, 0, 1);\n"
17077 		"\n"
17078 		"VERIFICATION"
17079 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17080 		"    {\n"
17081 		"         result = vec4(1, 0, 0, 1);\n"
17082 		"    }\n"
17083 		"\n"
17084 		"    tcs_tes_result[gl_InvocationID] = result;\n"
17085 		"\n"
17086 		"    gl_TessLevelOuter[0] = 1.0;\n"
17087 		"    gl_TessLevelOuter[1] = 1.0;\n"
17088 		"    gl_TessLevelOuter[2] = 1.0;\n"
17089 		"    gl_TessLevelOuter[3] = 1.0;\n"
17090 		"    gl_TessLevelInner[0] = 1.0;\n"
17091 		"    gl_TessLevelInner[1] = 1.0;\n"
17092 		"}\n"
17093 		"\n";
17094 
17095 	static const GLchar* tess_eval_shader_template = "VERSION\n"
17096 													 "\n"
17097 													 "layout(isolines, point_mode) in;\n"
17098 													 "\n"
17099 													 "in  vec4 tcs_tes_result[];\n"
17100 													 "out vec4 tes_gs_result;\n"
17101 													 "\n"
17102 													 "UNIFORMS"
17103 													 "\n"
17104 													 "void main()\n"
17105 													 "{\n"
17106 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
17107 													 "\n"
17108 													 "VERIFICATION"
17109 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17110 													 "    {\n"
17111 													 "         result = vec4(1, 0, 0, 1);\n"
17112 													 "    }\n"
17113 													 "\n"
17114 													 "    tes_gs_result = result;\n"
17115 													 "}\n"
17116 													 "\n";
17117 
17118 	static const GLchar* vertex_shader_template = "VERSION\n"
17119 												  "\n"
17120 												  "out vec4 vs_tcs_result;\n"
17121 												  "\n"
17122 												  "UNIFORMS"
17123 												  "\n"
17124 												  "void main()\n"
17125 												  "{\n"
17126 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
17127 												  "\n"
17128 												  "VERIFICATION"
17129 												  "\n"
17130 												  "    vs_tcs_result = result;\n"
17131 												  "}\n"
17132 												  "\n";
17133 
17134 	const GLchar* shader_template	  = 0;
17135 	const GLchar* verification_snippet = 0;
17136 
17137 	switch (in_stage)
17138 	{
17139 	case Utils::COMPUTE_SHADER:
17140 		shader_template = compute_shader_template;
17141 		break;
17142 	case Utils::FRAGMENT_SHADER:
17143 		shader_template = fragment_shader_template;
17144 		break;
17145 	case Utils::GEOMETRY_SHADER:
17146 		shader_template = geometry_shader_template;
17147 		break;
17148 	case Utils::TESS_CTRL_SHADER:
17149 		shader_template = tess_ctrl_shader_template;
17150 		break;
17151 	case Utils::TESS_EVAL_SHADER:
17152 		shader_template = tess_eval_shader_template;
17153 		break;
17154 	case Utils::VERTEX_SHADER:
17155 		shader_template = vertex_shader_template;
17156 		break;
17157 	default:
17158 		TCU_FAIL("Invalid enum");
17159 		break;
17160 	}
17161 
17162 	switch (m_case)
17163 	{
17164 	case INVALID_Y:
17165 		verification_snippet = verification_invalid_y;
17166 		break;
17167 	case INVALID_B:
17168 		verification_snippet = verification_invalid_b;
17169 		break;
17170 	case INVALID_Q:
17171 		verification_snippet = verification_invalid_q;
17172 		break;
17173 	case INVALID_XY:
17174 		verification_snippet = verification_invalid_xy;
17175 		break;
17176 	case INVALID_XRS:
17177 		verification_snippet = verification_invalid_xrs;
17178 		break;
17179 	case WRONG:
17180 		verification_snippet = verification_wrong_u;
17181 		break;
17182 	case MISSING_PARENTHESIS:
17183 		verification_snippet = verification_missing_parenthesis;
17184 		break;
17185 	default:
17186 		TCU_FAIL("Invalid enum");
17187 		break;
17188 	};
17189 
17190 	out_source.m_parts[0].m_code = shader_template;
17191 
17192 	size_t position = 0;
17193 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17194 						out_source.m_parts[0].m_code);
17195 
17196 	Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
17197 
17198 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17199 }
17200 
17201 /* Constants used by BuiltInValuesTest */
17202 const GLint BuiltInValuesTest::m_min_program_texel_offset_limit = -8;
17203 const GLint BuiltInValuesTest::m_max_program_texel_offset_limit = 7;
17204 
17205 /** Constructor
17206  *
17207  * @param context Test context
17208  **/
BuiltInValuesTest(deqp::Context & context)17209 BuiltInValuesTest::BuiltInValuesTest(deqp::Context& context)
17210 	: GLSLTestBase(context, "built_in_values", "Test verifies values of gl_Min/Max_ProgramTexelOffset")
17211 {
17212 	/* Nothing to be done here */
17213 }
17214 
17215 /** Prepare source for given shader stage
17216  *
17217  * @param in_stage           Shader stage, compute shader will use 430
17218  * @param in_use_version_400 Select if 400 or 420 should be used
17219  * @param out_source         Prepared shader source instance
17220  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17221 void BuiltInValuesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17222 											Utils::shaderSource& out_source)
17223 {
17224 	static const GLchar* verification_snippet = "    if ((expected_values.x != gl_MinProgramTexelOffset) ||\n"
17225 												"        (expected_values.y != gl_MaxProgramTexelOffset) )\n"
17226 												"    {\n"
17227 												"        result = vec4(1, 0, 0, 1);\n"
17228 												"    }\n";
17229 
17230 	static const GLchar* compute_shader_template =
17231 		"VERSION\n"
17232 		"\n"
17233 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17234 		"\n"
17235 		"writeonly uniform image2D uni_image;\n"
17236 		"          uniform ivec2   expected_values;\n"
17237 		"\n"
17238 		"void main()\n"
17239 		"{\n"
17240 		"    vec4 result = vec4(0, 1, 0, 1);\n"
17241 		"\n"
17242 		"VERIFICATION"
17243 		"\n"
17244 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17245 		"}\n"
17246 		"\n";
17247 
17248 	static const GLchar* fragment_shader_template = "VERSION\n"
17249 													"\n"
17250 													"in  vec4 gs_fs_result;\n"
17251 													"out vec4 fs_out_result;\n"
17252 													"\n"
17253 													"uniform ivec2 expected_values;\n"
17254 													"\n"
17255 													"void main()\n"
17256 													"{\n"
17257 													"    vec4 result = vec4(0, 1, 0, 1);\n"
17258 													"\n"
17259 													"VERIFICATION"
17260 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17261 													"    {\n"
17262 													"         result = vec4(1, 0, 0, 1);\n"
17263 													"    }\n"
17264 													"\n"
17265 													"    fs_out_result = result;\n"
17266 													"}\n"
17267 													"\n";
17268 
17269 	static const GLchar* geometry_shader_template = "VERSION\n"
17270 													"\n"
17271 													"layout(points)                           in;\n"
17272 													"layout(triangle_strip, max_vertices = 4) out;\n"
17273 													"\n"
17274 													"in  vec4 tes_gs_result[];\n"
17275 													"out vec4 gs_fs_result;\n"
17276 													"\n"
17277 													"uniform ivec2 expected_values;\n"
17278 													"\n"
17279 													"void main()\n"
17280 													"{\n"
17281 													"    vec4 result = vec4(0, 1, 0, 1);\n"
17282 													"\n"
17283 													"VERIFICATION"
17284 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17285 													"    {\n"
17286 													"         result = vec4(1, 0, 0, 1);\n"
17287 													"    }\n"
17288 													"\n"
17289 													"    gs_fs_result  = result;\n"
17290 													"    gl_Position   = vec4(-1, -1, 0, 1);\n"
17291 													"    EmitVertex();\n"
17292 													"    gs_fs_result  = result;\n"
17293 													"    gl_Position   = vec4(-1, 1, 0, 1);\n"
17294 													"    EmitVertex();\n"
17295 													"    gs_fs_result  = result;\n"
17296 													"    gl_Position   = vec4(1, -1, 0, 1);\n"
17297 													"    EmitVertex();\n"
17298 													"    gs_fs_result  = result;\n"
17299 													"    gl_Position   = vec4(1, 1, 0, 1);\n"
17300 													"    EmitVertex();\n"
17301 													"}\n"
17302 													"\n";
17303 
17304 	static const GLchar* tess_ctrl_shader_template =
17305 		"VERSION\n"
17306 		"\n"
17307 		"layout(vertices = 1) out;\n"
17308 		"\n"
17309 		"in  vec4 vs_tcs_result[];\n"
17310 		"out vec4 tcs_tes_result[];\n"
17311 		"\n"
17312 		"uniform ivec2 expected_values;\n"
17313 		"\n"
17314 		"void main()\n"
17315 		"{\n"
17316 		"    vec4 result = vec4(0, 1, 0, 1);\n"
17317 		"\n"
17318 		"VERIFICATION"
17319 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17320 		"    {\n"
17321 		"         result = vec4(1, 0, 0, 1);\n"
17322 		"    }\n"
17323 		"\n"
17324 		"    tcs_tes_result[gl_InvocationID] = result;\n"
17325 		"\n"
17326 		"    gl_TessLevelOuter[0] = 1.0;\n"
17327 		"    gl_TessLevelOuter[1] = 1.0;\n"
17328 		"    gl_TessLevelOuter[2] = 1.0;\n"
17329 		"    gl_TessLevelOuter[3] = 1.0;\n"
17330 		"    gl_TessLevelInner[0] = 1.0;\n"
17331 		"    gl_TessLevelInner[1] = 1.0;\n"
17332 		"}\n"
17333 		"\n";
17334 
17335 	static const GLchar* tess_eval_shader_template = "VERSION\n"
17336 													 "\n"
17337 													 "layout(isolines, point_mode) in;\n"
17338 													 "\n"
17339 													 "in  vec4 tcs_tes_result[];\n"
17340 													 "out vec4 tes_gs_result;\n"
17341 													 "\n"
17342 													 "uniform ivec2 expected_values;\n"
17343 													 "\n"
17344 													 "void main()\n"
17345 													 "{\n"
17346 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
17347 													 "\n"
17348 													 "VERIFICATION"
17349 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17350 													 "    {\n"
17351 													 "         result = vec4(1, 0, 0, 1);\n"
17352 													 "    }\n"
17353 													 "\n"
17354 													 "    tes_gs_result = result;\n"
17355 													 "}\n"
17356 													 "\n";
17357 
17358 	static const GLchar* vertex_shader_template = "VERSION\n"
17359 												  "\n"
17360 												  "out vec4 vs_tcs_result;\n"
17361 												  "\n"
17362 												  "uniform ivec2 expected_values;\n"
17363 												  "\n"
17364 												  "void main()\n"
17365 												  "{\n"
17366 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
17367 												  "\n"
17368 												  "VERIFICATION"
17369 												  "\n"
17370 												  "    vs_tcs_result = result;\n"
17371 												  "}\n"
17372 												  "\n";
17373 
17374 	const GLchar* shader_template = 0;
17375 
17376 	switch (in_stage)
17377 	{
17378 	case Utils::COMPUTE_SHADER:
17379 		shader_template = compute_shader_template;
17380 		break;
17381 	case Utils::FRAGMENT_SHADER:
17382 		shader_template = fragment_shader_template;
17383 		break;
17384 	case Utils::GEOMETRY_SHADER:
17385 		shader_template = geometry_shader_template;
17386 		break;
17387 	case Utils::TESS_CTRL_SHADER:
17388 		shader_template = tess_ctrl_shader_template;
17389 		break;
17390 	case Utils::TESS_EVAL_SHADER:
17391 		shader_template = tess_eval_shader_template;
17392 		break;
17393 	case Utils::VERTEX_SHADER:
17394 		shader_template = vertex_shader_template;
17395 		break;
17396 	default:
17397 		TCU_FAIL("Invalid enum");
17398 		break;
17399 	}
17400 
17401 	out_source.m_parts[0].m_code = shader_template;
17402 
17403 	size_t position = 0;
17404 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17405 						out_source.m_parts[0].m_code);
17406 
17407 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17408 }
17409 
17410 /** Overwritte of prepareUniforms method
17411  *
17412  * @param program Current program
17413  **/
prepareUniforms(Utils::program & program)17414 void BuiltInValuesTest::prepareUniforms(Utils::program& program)
17415 {
17416 	const GLint expected_values_data[2] = { m_min_program_texel_offset, m_max_program_texel_offset };
17417 
17418 	program.uniform("expected_values", Utils::INT, 1 /* n_cols */, 2 /* n_rows */, expected_values_data);
17419 }
17420 
17421 /** Prepare test cases
17422  *
17423  * @return true
17424  **/
testInit()17425 bool BuiltInValuesTest::testInit()
17426 {
17427 	const Functions& gl = m_context.getRenderContext().getFunctions();
17428 
17429 	gl.getIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, &m_min_program_texel_offset);
17430 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17431 
17432 	gl.getIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, &m_max_program_texel_offset);
17433 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17434 
17435 	if ((m_min_program_texel_offset_limit > m_min_program_texel_offset) ||
17436 		(m_max_program_texel_offset_limit > m_max_program_texel_offset))
17437 	{
17438 		m_context.getTestContext().getLog()
17439 			<< tcu::TestLog::Message << "Invalid GL_PROGRAM_TEXEL_OFFSET values."
17440 			<< " Min: " << m_min_program_texel_offset << " expected at top: " << m_min_program_texel_offset_limit
17441 			<< " Max: " << m_min_program_texel_offset << " expected at least: " << m_max_program_texel_offset_limit
17442 			<< tcu::TestLog::EndMessage;
17443 
17444 		return false;
17445 	}
17446 
17447 	return true;
17448 }
17449 
17450 /** Constructor
17451  *
17452  * @param context Test context
17453  **/
BuiltInAssignmentTest(deqp::Context & context)17454 BuiltInAssignmentTest::BuiltInAssignmentTest(deqp::Context& context)
17455 	: NegativeTestBase(context, "built_in_assignment",
17456 					   "Test verifies that built in gl_Min/MaxProgramTexelOffset cannot be assigned")
17457 {
17458 	/* Nothing to be done here */
17459 }
17460 
17461 /** Set up next test case
17462  *
17463  * @param test_case_index Index of next test case
17464  *
17465  * @return false if there is no more test cases, true otherwise
17466  **/
prepareNextTestCase(glw::GLuint test_case_index)17467 bool BuiltInAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
17468 {
17469 	const GLchar* description = 0;
17470 
17471 	switch (test_case_index)
17472 	{
17473 	case (glw::GLuint)-1:
17474 	case 0:
17475 		description = "Testing gl_MinProgramTexelOffset";
17476 		break;
17477 	case 1:
17478 		description = "Testing gl_MaxProgramTexelOffset";
17479 		break;
17480 	default:
17481 		return false;
17482 	}
17483 
17484 	m_case = test_case_index;
17485 
17486 	m_context.getTestContext().getLog() << tcu::TestLog::Message << description << tcu::TestLog::EndMessage;
17487 
17488 	return true;
17489 }
17490 
17491 /** Prepare source for given shader stage
17492  *
17493  * @param in_stage           Shader stage, compute shader will use 430
17494  * @param in_use_version_400 Select if 400 or 420 should be used
17495  * @param out_source         Prepared shader source instance
17496  **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17497 void BuiltInAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17498 												Utils::shaderSource& out_source)
17499 {
17500 	static const GLchar* min_verification_snippet = "    gl_MinProgramTexelOffset += gl_MaxProgramTexelOffset\n"
17501 													"\n"
17502 													"    if (expected_value != gl_MinProgramTexelOffset)\n"
17503 													"    {\n"
17504 													"        result = vec4(1, 0, 0, 1);\n"
17505 													"    }\n";
17506 
17507 	static const GLchar* max_verification_snippet = "    gl_MaxProgramTexelOffset += gl_MinProgramTexelOffset\n"
17508 													"\n"
17509 													"    if (expected_value != gl_MaxProgramTexelOffset)\n"
17510 													"    {\n"
17511 													"        result = vec4(1, 0, 0, 1);\n"
17512 													"    }\n";
17513 
17514 	static const GLchar* compute_shader_template =
17515 		"VERSION\n"
17516 		"\n"
17517 		"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17518 		"\n"
17519 		"writeonly uniform image2D uni_image;\n"
17520 		"          uniform ivec2   expected_values;\n"
17521 		"\n"
17522 		"void main()\n"
17523 		"{\n"
17524 		"    vec4 result = vec4(0, 1, 0, 1);\n"
17525 		"\n"
17526 		"VERIFICATION"
17527 		"\n"
17528 		"    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17529 		"}\n"
17530 		"\n";
17531 
17532 	static const GLchar* fragment_shader_template = "VERSION\n"
17533 													"\n"
17534 													"in  vec4 gs_fs_result;\n"
17535 													"out vec4 fs_out_result;\n"
17536 													"\n"
17537 													"uniform ivec2 expected_values;\n"
17538 													"\n"
17539 													"void main()\n"
17540 													"{\n"
17541 													"    vec4 result = vec4(0, 1, 0, 1);\n"
17542 													"\n"
17543 													"VERIFICATION"
17544 													"    else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17545 													"    {\n"
17546 													"         result = vec4(1, 0, 0, 1);\n"
17547 													"    }\n"
17548 													"\n"
17549 													"    fs_out_result = result;\n"
17550 													"}\n"
17551 													"\n";
17552 
17553 	static const GLchar* geometry_shader_template = "VERSION\n"
17554 													"\n"
17555 													"layout(points)                           in;\n"
17556 													"layout(triangle_strip, max_vertices = 4) out;\n"
17557 													"\n"
17558 													"in  vec4 tes_gs_result[];\n"
17559 													"out vec4 gs_fs_result;\n"
17560 													"\n"
17561 													"uniform ivec2 expected_values;\n"
17562 													"\n"
17563 													"void main()\n"
17564 													"{\n"
17565 													"    vec4 result = vec4(0, 1, 0, 1);\n"
17566 													"\n"
17567 													"VERIFICATION"
17568 													"    else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17569 													"    {\n"
17570 													"         result = vec4(1, 0, 0, 1);\n"
17571 													"    }\n"
17572 													"\n"
17573 													"    gs_fs_result  = result;\n"
17574 													"    gl_Position   = vec4(-1, -1, 0, 1);\n"
17575 													"    EmitVertex();\n"
17576 													"    gs_fs_result  = result;\n"
17577 													"    gl_Position   = vec4(-1, 1, 0, 1);\n"
17578 													"    EmitVertex();\n"
17579 													"    gs_fs_result  = result;\n"
17580 													"    gl_Position   = vec4(1, -1, 0, 1);\n"
17581 													"    EmitVertex();\n"
17582 													"    gs_fs_result  = result;\n"
17583 													"    gl_Position   = vec4(1, 1, 0, 1);\n"
17584 													"    EmitVertex();\n"
17585 													"}\n"
17586 													"\n";
17587 
17588 	static const GLchar* tess_ctrl_shader_template =
17589 		"VERSION\n"
17590 		"\n"
17591 		"layout(vertices = 1) out;\n"
17592 		"\n"
17593 		"in  vec4 vs_tcs_result[];\n"
17594 		"out vec4 tcs_tes_result[];\n"
17595 		"\n"
17596 		"uniform ivec2 expected_values;\n"
17597 		"\n"
17598 		"void main()\n"
17599 		"{\n"
17600 		"    vec4 result = vec4(0, 1, 0, 1);\n"
17601 		"\n"
17602 		"VERIFICATION"
17603 		"    else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17604 		"    {\n"
17605 		"         result = vec4(1, 0, 0, 1);\n"
17606 		"    }\n"
17607 		"\n"
17608 		"    tcs_tes_result[gl_InvocationID] = result;\n"
17609 		"\n"
17610 		"    gl_TessLevelOuter[0] = 1.0;\n"
17611 		"    gl_TessLevelOuter[1] = 1.0;\n"
17612 		"    gl_TessLevelOuter[2] = 1.0;\n"
17613 		"    gl_TessLevelOuter[3] = 1.0;\n"
17614 		"    gl_TessLevelInner[0] = 1.0;\n"
17615 		"    gl_TessLevelInner[1] = 1.0;\n"
17616 		"}\n"
17617 		"\n";
17618 
17619 	static const GLchar* tess_eval_shader_template = "VERSION\n"
17620 													 "\n"
17621 													 "layout(isolines, point_mode) in;\n"
17622 													 "\n"
17623 													 "in  vec4 tcs_tes_result[];\n"
17624 													 "out vec4 tes_gs_result;\n"
17625 													 "\n"
17626 													 "uniform ivec2 expected_values;\n"
17627 													 "\n"
17628 													 "void main()\n"
17629 													 "{\n"
17630 													 "    vec4 result = vec4(0, 1, 0, 1);\n"
17631 													 "\n"
17632 													 "VERIFICATION"
17633 													 "    else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17634 													 "    {\n"
17635 													 "         result = vec4(1, 0, 0, 1);\n"
17636 													 "    }\n"
17637 													 "\n"
17638 													 "    tes_gs_result = result;\n"
17639 													 "}\n"
17640 													 "\n";
17641 
17642 	static const GLchar* vertex_shader_template = "VERSION\n"
17643 												  "\n"
17644 												  "out vec4 vs_tcs_result;\n"
17645 												  "\n"
17646 												  "uniform ivec2 expected_values;\n"
17647 												  "\n"
17648 												  "void main()\n"
17649 												  "{\n"
17650 												  "    vec4 result = vec4(0, 1, 0, 1);\n"
17651 												  "\n"
17652 												  "VERIFICATION"
17653 												  "\n"
17654 												  "    vs_tcs_result = result;\n"
17655 												  "}\n"
17656 												  "\n";
17657 
17658 	const GLchar* shader_template	  = 0;
17659 	const GLchar* verification_snippet = 0;
17660 
17661 	switch (in_stage)
17662 	{
17663 	case Utils::COMPUTE_SHADER:
17664 		shader_template = compute_shader_template;
17665 		break;
17666 	case Utils::FRAGMENT_SHADER:
17667 		shader_template = fragment_shader_template;
17668 		break;
17669 	case Utils::GEOMETRY_SHADER:
17670 		shader_template = geometry_shader_template;
17671 		break;
17672 	case Utils::TESS_CTRL_SHADER:
17673 		shader_template = tess_ctrl_shader_template;
17674 		break;
17675 	case Utils::TESS_EVAL_SHADER:
17676 		shader_template = tess_eval_shader_template;
17677 		break;
17678 	case Utils::VERTEX_SHADER:
17679 		shader_template = vertex_shader_template;
17680 		break;
17681 	default:
17682 		TCU_FAIL("Invalid enum");
17683 		break;
17684 	}
17685 
17686 	switch (m_case)
17687 	{
17688 	case (glw::GLuint)-1:
17689 	case 0:
17690 		verification_snippet = min_verification_snippet;
17691 		break;
17692 	case 1:
17693 		verification_snippet = max_verification_snippet;
17694 		break;
17695 	}
17696 
17697 	out_source.m_parts[0].m_code = shader_template;
17698 
17699 	size_t position = 0;
17700 	Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17701 						out_source.m_parts[0].m_code);
17702 
17703 	Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17704 }
17705 
17706 /** Constructor.
17707  *
17708  * @param context CTS context.
17709  **/
buffer(deqp::Context & context)17710 Utils::buffer::buffer(deqp::Context& context) : m_id(0), m_context(context), m_target(0)
17711 {
17712 }
17713 
17714 /** Destructor
17715  *
17716  **/
~buffer()17717 Utils::buffer::~buffer()
17718 {
17719 	release();
17720 }
17721 
17722 /** Execute BindBuffer
17723  *
17724  **/
bind() const17725 void Utils::buffer::bind() const
17726 {
17727 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17728 
17729 	gl.bindBuffer(m_target, m_id);
17730 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
17731 }
17732 
17733 /** Execute BindBufferRange
17734  *
17735  * @param index  <index> parameter
17736  * @param offset <offset> parameter
17737  * @param size   <size> parameter
17738  **/
bindRange(glw::GLuint index,glw::GLintptr offset,glw::GLsizeiptr size)17739 void Utils::buffer::bindRange(glw::GLuint index, glw::GLintptr offset, glw::GLsizeiptr size)
17740 {
17741 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17742 
17743 	gl.bindBufferRange(m_target, index, m_id, offset, size);
17744 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
17745 }
17746 
17747 /** Execute GenBuffer
17748  *
17749  * @param target Target that will be used by this buffer
17750  **/
generate(glw::GLenum target)17751 void Utils::buffer::generate(glw::GLenum target)
17752 {
17753 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17754 
17755 	m_target = target;
17756 
17757 	gl.genBuffers(1, &m_id);
17758 	GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
17759 }
17760 
17761 /** Maps buffer content
17762  *
17763  * @param access Access rights for mapped region
17764  *
17765  * @return Mapped memory
17766  **/
map(GLenum access) const17767 void* Utils::buffer::map(GLenum access) const
17768 {
17769 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17770 
17771 	gl.bindBuffer(m_target, m_id);
17772 	GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17773 
17774 	void* result = gl.mapBuffer(m_target, access);
17775 	GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
17776 
17777 	return result;
17778 }
17779 
17780 /** Unmaps buffer
17781  *
17782  **/
unmap() const17783 void Utils::buffer::unmap() const
17784 {
17785 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17786 
17787 	gl.bindBuffer(m_target, m_id);
17788 	GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17789 
17790 	gl.unmapBuffer(m_target);
17791 	GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
17792 }
17793 
17794 /** Execute BufferData
17795  *
17796  * @param size   <size> parameter
17797  * @param data   <data> parameter
17798  * @param usage  <usage> parameter
17799  **/
update(glw::GLsizeiptr size,glw::GLvoid * data,glw::GLenum usage)17800 void Utils::buffer::update(glw::GLsizeiptr size, glw::GLvoid* data, glw::GLenum usage)
17801 {
17802 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17803 
17804 	gl.bindBuffer(m_target, m_id);
17805 	GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17806 
17807 	gl.bufferData(m_target, size, data, usage);
17808 	GLU_EXPECT_NO_ERROR(gl.getError(), "bufferData");
17809 }
17810 
17811 /** Release buffer
17812  *
17813  **/
release()17814 void Utils::buffer::release()
17815 {
17816 	if (0 != m_id)
17817 	{
17818 		const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17819 
17820 		gl.deleteBuffers(1, &m_id);
17821 		m_id = 0;
17822 	}
17823 }
17824 
17825 /** Constructor
17826  *
17827  * @param context CTS context
17828  **/
framebuffer(deqp::Context & context)17829 Utils::framebuffer::framebuffer(deqp::Context& context) : m_id(0), m_context(context)
17830 {
17831 	/* Nothing to be done here */
17832 }
17833 
17834 /** Destructor
17835  *
17836  **/
~framebuffer()17837 Utils::framebuffer::~framebuffer()
17838 {
17839 	if (0 != m_id)
17840 	{
17841 		const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17842 
17843 		gl.deleteFramebuffers(1, &m_id);
17844 		m_id = 0;
17845 	}
17846 }
17847 
17848 /** Attach texture to specified attachment
17849  *
17850  * @param attachment Attachment
17851  * @param texture_id Texture id
17852  * @param width      Texture width
17853  * @param height     Texture height
17854  **/
attachTexture(glw::GLenum attachment,glw::GLuint texture_id,glw::GLuint width,glw::GLuint height)17855 void Utils::framebuffer::attachTexture(glw::GLenum attachment, glw::GLuint texture_id, glw::GLuint width,
17856 									   glw::GLuint height)
17857 {
17858 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17859 
17860 	bind();
17861 
17862 	gl.bindTexture(GL_TEXTURE_2D, texture_id);
17863 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
17864 
17865 	gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture_id, 0 /* level */);
17866 	GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture2D");
17867 
17868 	gl.viewport(0 /* x */, 0 /* y */, width, height);
17869 	GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
17870 }
17871 
17872 /** Binds framebuffer to DRAW_FRAMEBUFFER
17873  *
17874  **/
bind()17875 void Utils::framebuffer::bind()
17876 {
17877 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17878 
17879 	gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_id);
17880 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
17881 }
17882 
17883 /** Clear framebuffer
17884  *
17885  * @param mask <mask> parameter of glClear. Decides which shall be cleared
17886  **/
clear(glw::GLenum mask)17887 void Utils::framebuffer::clear(glw::GLenum mask)
17888 {
17889 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17890 
17891 	gl.clear(mask);
17892 	GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
17893 }
17894 
17895 /** Specifies clear color
17896  *
17897  * @param red   Red channel
17898  * @param green Green channel
17899  * @param blue  Blue channel
17900  * @param alpha Alpha channel
17901  **/
clearColor(GLfloat red,GLfloat green,GLfloat blue,GLfloat alpha)17902 void Utils::framebuffer::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
17903 {
17904 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17905 
17906 	gl.clearColor(red, green, blue, alpha);
17907 	GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
17908 }
17909 
17910 /** Generate framebuffer
17911  *
17912  **/
generate()17913 void Utils::framebuffer::generate()
17914 {
17915 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17916 
17917 	gl.genFramebuffers(1, &m_id);
17918 	GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
17919 }
17920 
shaderSource()17921 Utils::shaderSource::shaderSource()
17922 {
17923 }
17924 
shaderSource(const shaderSource & source)17925 Utils::shaderSource::shaderSource(const shaderSource& source) : m_parts(source.m_parts)
17926 {
17927 }
17928 
shaderSource(const glw::GLchar * source_code)17929 Utils::shaderSource::shaderSource(const glw::GLchar* source_code)
17930 {
17931 	if (0 != source_code)
17932 	{
17933 		m_parts.resize(1);
17934 
17935 		m_parts[0].m_code = source_code;
17936 	}
17937 }
17938 
shaderCompilationException(const shaderSource & source,const glw::GLchar * message)17939 Utils::shaderCompilationException::shaderCompilationException(const shaderSource& source, const glw::GLchar* message)
17940 	: m_shader_source(source), m_error_message(message)
17941 {
17942 	/* Nothing to be done */
17943 }
17944 
what() const17945 const char* Utils::shaderCompilationException::what() const throw()
17946 {
17947 	return "Shader compilation failed";
17948 }
17949 
programLinkageException(const glw::GLchar * message)17950 Utils::programLinkageException::programLinkageException(const glw::GLchar* message) : m_error_message(message)
17951 {
17952 	/* Nothing to be done */
17953 }
17954 
what() const17955 const char* Utils::programLinkageException::what() const throw()
17956 {
17957 	return "Program linking failed";
17958 }
17959 
17960 const glw::GLenum Utils::program::ARB_COMPUTE_SHADER = 0x91B9;
17961 
17962 /** Constructor.
17963  *
17964  * @param context CTS context.
17965  **/
program(deqp::Context & context)17966 Utils::program::program(deqp::Context& context)
17967 	: m_compute_shader_id(0)
17968 	, m_fragment_shader_id(0)
17969 	, m_geometry_shader_id(0)
17970 	, m_program_object_id(0)
17971 	, m_tesselation_control_shader_id(0)
17972 	, m_tesselation_evaluation_shader_id(0)
17973 	, m_vertex_shader_id(0)
17974 	, m_context(context)
17975 {
17976 	/* Nothing to be done here */
17977 }
17978 
17979 /** Destructor
17980  *
17981  **/
~program()17982 Utils::program::~program()
17983 {
17984 	remove();
17985 }
17986 
17987 /** Build program
17988  *
17989  * @param compute_shader_code                Compute shader source code
17990  * @param fragment_shader_code               Fragment shader source code
17991  * @param geometry_shader_code               Geometry shader source code
17992  * @param tesselation_control_shader_code    Tesselation control shader source code
17993  * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17994  * @param vertex_shader_code                 Vertex shader source code
17995  * @param varying_names                      Array of strings containing names of varyings to be captured with transfrom feedback
17996  * @param n_varying_names                    Number of varyings to be captured with transfrom feedback
17997  * @param is_separable                       Selects if monolithis or separable program should be built. Defaults to false
17998  **/
build(const glw::GLchar * compute_shader_code,const glw::GLchar * fragment_shader_code,const glw::GLchar * geometry_shader_code,const glw::GLchar * tesselation_control_shader_code,const glw::GLchar * tesselation_evaluation_shader_code,const glw::GLchar * vertex_shader_code,const glw::GLchar * const * varying_names,glw::GLuint n_varying_names,bool is_separable)17999 void Utils::program::build(const glw::GLchar* compute_shader_code, const glw::GLchar* fragment_shader_code,
18000 						   const glw::GLchar* geometry_shader_code, const glw::GLchar* tesselation_control_shader_code,
18001 						   const glw::GLchar* tesselation_evaluation_shader_code, const glw::GLchar* vertex_shader_code,
18002 						   const glw::GLchar* const* varying_names, glw::GLuint n_varying_names, bool is_separable)
18003 {
18004 	const shaderSource compute_shader(compute_shader_code);
18005 	const shaderSource fragment_shader(fragment_shader_code);
18006 	const shaderSource geometry_shader(geometry_shader_code);
18007 	const shaderSource tesselation_control_shader(tesselation_control_shader_code);
18008 	const shaderSource tesselation_evaluation_shader(tesselation_evaluation_shader_code);
18009 	const shaderSource vertex_shader(vertex_shader_code);
18010 
18011 	build(compute_shader, fragment_shader, geometry_shader, tesselation_control_shader, tesselation_evaluation_shader,
18012 		  vertex_shader, varying_names, n_varying_names, is_separable);
18013 }
18014 
18015 /** Build program
18016  *
18017  * @param compute_shader_code                Compute shader source code
18018  * @param fragment_shader_code               Fragment shader source code
18019  * @param geometry_shader_code               Geometry shader source code
18020  * @param tesselation_control_shader_code    Tesselation control shader source code
18021  * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
18022  * @param vertex_shader_code                 Vertex shader source code
18023  * @param varying_names                      Array of strings containing names of varyings to be captured with transfrom feedback
18024  * @param n_varying_names                    Number of varyings to be captured with transfrom feedback
18025  * @param is_separable                       Selects if monolithis or separable program should be built. Defaults to false
18026  **/
build(const shaderSource & compute_shader,const shaderSource & fragment_shader,const shaderSource & geometry_shader,const shaderSource & tesselation_control_shader,const shaderSource & tesselation_evaluation_shader,const shaderSource & vertex_shader,const glw::GLchar * const * varying_names,glw::GLuint n_varying_names,bool is_separable)18027 void Utils::program::build(const shaderSource& compute_shader, const shaderSource& fragment_shader,
18028 						   const shaderSource& geometry_shader, const shaderSource& tesselation_control_shader,
18029 						   const shaderSource& tesselation_evaluation_shader, const shaderSource& vertex_shader,
18030 						   const glw::GLchar* const* varying_names, glw::GLuint n_varying_names, bool is_separable)
18031 {
18032 	/* GL entry points */
18033 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18034 
18035 	/* Create shader objects and compile */
18036 	if (false == compute_shader.m_parts.empty())
18037 	{
18038 		m_compute_shader_id = gl.createShader(ARB_COMPUTE_SHADER);
18039 		GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18040 
18041 		compile(m_compute_shader_id, compute_shader);
18042 	}
18043 
18044 	if (false == fragment_shader.m_parts.empty())
18045 	{
18046 		m_fragment_shader_id = gl.createShader(GL_FRAGMENT_SHADER);
18047 		GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18048 
18049 		compile(m_fragment_shader_id, fragment_shader);
18050 	}
18051 
18052 	if (false == geometry_shader.m_parts.empty())
18053 	{
18054 		m_geometry_shader_id = gl.createShader(GL_GEOMETRY_SHADER);
18055 		GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18056 
18057 		compile(m_geometry_shader_id, geometry_shader);
18058 	}
18059 
18060 	if (false == tesselation_control_shader.m_parts.empty())
18061 	{
18062 		m_tesselation_control_shader_id = gl.createShader(GL_TESS_CONTROL_SHADER);
18063 		GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18064 
18065 		compile(m_tesselation_control_shader_id, tesselation_control_shader);
18066 	}
18067 
18068 	if (false == tesselation_evaluation_shader.m_parts.empty())
18069 	{
18070 		m_tesselation_evaluation_shader_id = gl.createShader(GL_TESS_EVALUATION_SHADER);
18071 		GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18072 
18073 		compile(m_tesselation_evaluation_shader_id, tesselation_evaluation_shader);
18074 	}
18075 
18076 	if (false == vertex_shader.m_parts.empty())
18077 	{
18078 		m_vertex_shader_id = gl.createShader(GL_VERTEX_SHADER);
18079 		GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18080 
18081 		compile(m_vertex_shader_id, vertex_shader);
18082 	}
18083 
18084 	/* Create program object */
18085 	m_program_object_id = gl.createProgram();
18086 	GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
18087 
18088 	/* Set up captyured varyings' names */
18089 	if (0 != n_varying_names)
18090 	{
18091 		gl.transformFeedbackVaryings(m_program_object_id, n_varying_names, varying_names, GL_INTERLEAVED_ATTRIBS);
18092 		GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
18093 	}
18094 
18095 	/* Set separable parameter */
18096 	if (true == is_separable)
18097 	{
18098 		gl.programParameteri(m_program_object_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
18099 		GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
18100 	}
18101 
18102 	/* Link program */
18103 	link();
18104 }
18105 
compile(glw::GLuint shader_id,const Utils::shaderSource & source) const18106 void Utils::program::compile(glw::GLuint shader_id, const Utils::shaderSource& source) const
18107 {
18108 	/* GL entry points */
18109 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18110 
18111 	/* Compilation status */
18112 	glw::GLint status = GL_FALSE;
18113 
18114 	/* Source parts and lengths vectors */
18115 	std::vector<const GLchar*> parts;
18116 	std::vector<GLint>		   lengths_vector;
18117 	GLint*					   lengths = 0;
18118 
18119 	/* Prepare storage */
18120 	parts.resize(source.m_parts.size());
18121 
18122 	/* Prepare arrays */
18123 	for (GLuint i = 0; i < source.m_parts.size(); ++i)
18124 	{
18125 		parts[i] = source.m_parts[i].m_code.c_str();
18126 	}
18127 
18128 	if (true == source.m_use_lengths)
18129 	{
18130 		lengths_vector.resize(source.m_parts.size());
18131 
18132 		for (GLuint i = 0; i < source.m_parts.size(); ++i)
18133 		{
18134 			lengths_vector[i] = source.m_parts[i].m_length;
18135 		}
18136 
18137 		lengths = &lengths_vector[0];
18138 	}
18139 
18140 	/* Set source code */
18141 	gl.shaderSource(shader_id, static_cast<GLsizei>(source.m_parts.size()), &parts[0], lengths);
18142 	GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
18143 
18144 	/* Compile */
18145 	gl.compileShader(shader_id);
18146 	GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
18147 
18148 	/* Get compilation status */
18149 	gl.getShaderiv(shader_id, GL_COMPILE_STATUS, &status);
18150 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
18151 
18152 	/* Log compilation error */
18153 	if (GL_TRUE != status)
18154 	{
18155 		glw::GLint				 length = 0;
18156 		std::vector<glw::GLchar> message;
18157 
18158 		/* Error log length */
18159 		gl.getShaderiv(shader_id, GL_INFO_LOG_LENGTH, &length);
18160 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
18161 
18162 		/* Prepare storage */
18163 		message.resize(length);
18164 
18165 		/* Get error log */
18166 		gl.getShaderInfoLog(shader_id, length, 0, &message[0]);
18167 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
18168 
18169 		throw shaderCompilationException(source, &message[0]);
18170 	}
18171 }
18172 
18173 /** Create program from provided binary
18174  *
18175  * @param binary        Buffer with binary form of program
18176  * @param binary_format Format of <binary> data
18177  **/
createFromBinary(const std::vector<GLubyte> & binary,GLenum binary_format)18178 void Utils::program::createFromBinary(const std::vector<GLubyte>& binary, GLenum binary_format)
18179 {
18180 	/* GL entry points */
18181 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18182 
18183 	/* Create program object */
18184 	m_program_object_id = gl.createProgram();
18185 	GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
18186 
18187 	gl.programBinary(m_program_object_id, binary_format, &binary[0], static_cast<GLsizei>(binary.size()));
18188 	GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramBinary");
18189 }
18190 
getAttribLocation(const glw::GLchar * name) const18191 glw::GLint Utils::program::getAttribLocation(const glw::GLchar* name) const
18192 {
18193 	/* GL entry points */
18194 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18195 
18196 	GLint location = gl.getAttribLocation(m_program_object_id, name);
18197 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
18198 
18199 	return location;
18200 }
18201 
18202 /** Get binary form of program
18203  *
18204  * @param binary        Buffer for binary data
18205  * @param binary_format Format of binary data
18206  **/
getBinary(std::vector<GLubyte> & binary,GLenum & binary_format) const18207 void Utils::program::getBinary(std::vector<GLubyte>& binary, GLenum& binary_format) const
18208 {
18209 	/* GL entry points */
18210 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18211 
18212 	/* Get binary size */
18213 	GLint length = 0;
18214 	gl.getProgramiv(m_program_object_id, GL_PROGRAM_BINARY_LENGTH, &length);
18215 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18216 
18217 	/* Allocate storage */
18218 	binary.resize(length);
18219 
18220 	/* Get binary */
18221 	gl.getProgramBinary(m_program_object_id, static_cast<GLsizei>(binary.size()), &length, &binary_format, &binary[0]);
18222 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramBinary");
18223 }
18224 
18225 /** Get subroutine index
18226  *
18227  * @param subroutine_name Subroutine name
18228  *
18229  * @return Index of subroutine
18230  **/
getSubroutineIndex(const glw::GLchar * subroutine_name,glw::GLenum shader_stage) const18231 GLuint Utils::program::getSubroutineIndex(const glw::GLchar* subroutine_name, glw::GLenum shader_stage) const
18232 {
18233 	const glw::Functions& gl	= m_context.getRenderContext().getFunctions();
18234 	GLuint				  index = -1;
18235 
18236 	index = gl.getSubroutineIndex(m_program_object_id, shader_stage, subroutine_name);
18237 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineIndex");
18238 
18239 	if (GL_INVALID_INDEX == index)
18240 	{
18241 		m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine: " << subroutine_name
18242 											<< " is not available" << tcu::TestLog::EndMessage;
18243 
18244 		TCU_FAIL("Subroutine is not available");
18245 	}
18246 
18247 	return index;
18248 }
18249 
18250 /** Get subroutine uniform location
18251  *
18252  * @param uniform_name Subroutine uniform name
18253  *
18254  * @return Location of subroutine uniform
18255  **/
getSubroutineUniformLocation(const glw::GLchar * uniform_name,glw::GLenum shader_stage) const18256 GLint Utils::program::getSubroutineUniformLocation(const glw::GLchar* uniform_name, glw::GLenum shader_stage) const
18257 {
18258 	const glw::Functions& gl	   = m_context.getRenderContext().getFunctions();
18259 	GLint				  location = -1;
18260 
18261 	location = gl.getSubroutineUniformLocation(m_program_object_id, shader_stage, uniform_name);
18262 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineUniformLocation");
18263 
18264 	if (-1 == location)
18265 	{
18266 		m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine uniform: " << uniform_name
18267 											<< " is not available" << tcu::TestLog::EndMessage;
18268 
18269 		TCU_FAIL("Subroutine uniform is not available");
18270 	}
18271 
18272 	return location;
18273 }
18274 
18275 /** Get integer uniform at given location
18276  *
18277  * @param location Uniform location
18278  *
18279  * @return Value
18280  **/
getUniform1i(GLuint location) const18281 GLint Utils::program::getUniform1i(GLuint location) const
18282 {
18283 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18284 
18285 	GLint result;
18286 
18287 	gl.getUniformiv(m_program_object_id, location, &result);
18288 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformiv");
18289 
18290 	return result;
18291 }
18292 
18293 /** Get uniform location
18294  *
18295  * @param uniform_name Subroutine uniform name
18296  *
18297  * @return Location of uniform
18298  **/
getUniformLocation(const glw::GLchar * uniform_name) const18299 GLint Utils::program::getUniformLocation(const glw::GLchar* uniform_name) const
18300 {
18301 	const glw::Functions& gl	   = m_context.getRenderContext().getFunctions();
18302 	GLint				  location = -1;
18303 
18304 	location = gl.getUniformLocation(m_program_object_id, uniform_name);
18305 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
18306 
18307 	if (-1 == location)
18308 	{
18309 		m_context.getTestContext().getLog() << tcu::TestLog::Message << "Uniform: " << uniform_name
18310 											<< " is not available" << tcu::TestLog::EndMessage;
18311 
18312 		TCU_FAIL("Uniform is not available");
18313 	}
18314 
18315 	return location;
18316 }
18317 
18318 /** Attach shaders and link program
18319  *
18320  **/
link() const18321 void Utils::program::link() const
18322 {
18323 	/* GL entry points */
18324 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18325 
18326 	/* Link status */
18327 	glw::GLint status = GL_FALSE;
18328 
18329 	/* Attach shaders */
18330 	if (0 != m_compute_shader_id)
18331 	{
18332 		gl.attachShader(m_program_object_id, m_compute_shader_id);
18333 		GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18334 	}
18335 
18336 	if (0 != m_fragment_shader_id)
18337 	{
18338 		gl.attachShader(m_program_object_id, m_fragment_shader_id);
18339 		GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18340 	}
18341 
18342 	if (0 != m_geometry_shader_id)
18343 	{
18344 		gl.attachShader(m_program_object_id, m_geometry_shader_id);
18345 		GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18346 	}
18347 
18348 	if (0 != m_tesselation_control_shader_id)
18349 	{
18350 		gl.attachShader(m_program_object_id, m_tesselation_control_shader_id);
18351 		GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18352 	}
18353 
18354 	if (0 != m_tesselation_evaluation_shader_id)
18355 	{
18356 		gl.attachShader(m_program_object_id, m_tesselation_evaluation_shader_id);
18357 		GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18358 	}
18359 
18360 	if (0 != m_vertex_shader_id)
18361 	{
18362 		gl.attachShader(m_program_object_id, m_vertex_shader_id);
18363 		GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18364 	}
18365 
18366 	/* Link */
18367 	gl.linkProgram(m_program_object_id);
18368 	GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
18369 
18370 	/* Get link status */
18371 	gl.getProgramiv(m_program_object_id, GL_LINK_STATUS, &status);
18372 	GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18373 
18374 	/* Log link error */
18375 	if (GL_TRUE != status)
18376 	{
18377 		glw::GLint				 length = 0;
18378 		std::vector<glw::GLchar> message;
18379 
18380 		/* Get error log length */
18381 		gl.getProgramiv(m_program_object_id, GL_INFO_LOG_LENGTH, &length);
18382 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18383 
18384 		message.resize(length);
18385 
18386 		/* Get error log */
18387 		gl.getProgramInfoLog(m_program_object_id, length, 0, &message[0]);
18388 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
18389 
18390 		throw programLinkageException(&message[0]);
18391 	}
18392 }
18393 
18394 /** Delete program object and all attached shaders
18395  *
18396  **/
remove()18397 void Utils::program::remove()
18398 {
18399 	/* GL entry points */
18400 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18401 
18402 	/* Make sure program object is no longer used by GL */
18403 	gl.useProgram(0);
18404 
18405 	/* Clean program object */
18406 	if (0 != m_program_object_id)
18407 	{
18408 		gl.deleteProgram(m_program_object_id);
18409 		m_program_object_id = 0;
18410 	}
18411 
18412 	/* Clean shaders */
18413 	if (0 != m_compute_shader_id)
18414 	{
18415 		gl.deleteShader(m_compute_shader_id);
18416 		m_compute_shader_id = 0;
18417 	}
18418 
18419 	if (0 != m_fragment_shader_id)
18420 	{
18421 		gl.deleteShader(m_fragment_shader_id);
18422 		m_fragment_shader_id = 0;
18423 	}
18424 
18425 	if (0 != m_geometry_shader_id)
18426 	{
18427 		gl.deleteShader(m_geometry_shader_id);
18428 		m_geometry_shader_id = 0;
18429 	}
18430 
18431 	if (0 != m_tesselation_control_shader_id)
18432 	{
18433 		gl.deleteShader(m_tesselation_control_shader_id);
18434 		m_tesselation_control_shader_id = 0;
18435 	}
18436 
18437 	if (0 != m_tesselation_evaluation_shader_id)
18438 	{
18439 		gl.deleteShader(m_tesselation_evaluation_shader_id);
18440 		m_tesselation_evaluation_shader_id = 0;
18441 	}
18442 
18443 	if (0 != m_vertex_shader_id)
18444 	{
18445 		gl.deleteShader(m_vertex_shader_id);
18446 		m_vertex_shader_id = 0;
18447 	}
18448 }
18449 
uniform(const glw::GLchar * uniform_name,TYPES type,glw::GLuint n_columns,glw::GLuint n_rows,const void * data) const18450 void Utils::program::uniform(const glw::GLchar* uniform_name, TYPES type, glw::GLuint n_columns, glw::GLuint n_rows,
18451 							 const void* data) const
18452 {
18453 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18454 
18455 	GLuint location = getUniformLocation(uniform_name);
18456 
18457 	if ((glw::GLuint)-1 == location)
18458 	{
18459 		TCU_FAIL("Uniform is inactive");
18460 	}
18461 
18462 	switch (type)
18463 	{
18464 	case DOUBLE:
18465 		if (1 == n_columns)
18466 		{
18467 			getUniformNdv(gl, n_rows)(location, 1 /* count */, (const GLdouble*)data);
18468 			GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
18469 		}
18470 		else
18471 		{
18472 			getUniformMatrixNdv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLdouble*)data);
18473 			GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
18474 		}
18475 		break;
18476 	case FLOAT:
18477 		if (1 == n_columns)
18478 		{
18479 			getUniformNfv(gl, n_rows)(location, 1 /* count */, (const GLfloat*)data);
18480 			GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
18481 		}
18482 		else
18483 		{
18484 			getUniformMatrixNfv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLfloat*)data);
18485 			GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
18486 		}
18487 		break;
18488 	case INT:
18489 		getUniformNiv(gl, n_rows)(location, 1 /* count */, (const GLint*)data);
18490 		GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
18491 		break;
18492 	case UINT:
18493 		getUniformNuiv(gl, n_rows)(location, 1 /* count */, (const GLuint*)data);
18494 		GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
18495 		break;
18496 	default:
18497 		TCU_FAIL("Invalid enum");
18498 	}
18499 }
18500 
18501 /** Execute UseProgram
18502  *
18503  **/
use() const18504 void Utils::program::use() const
18505 {
18506 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18507 
18508 	gl.useProgram(m_program_object_id);
18509 	GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
18510 }
18511 
printShaderSource(const shaderSource & source,tcu::MessageBuilder & log)18512 void Utils::program::printShaderSource(const shaderSource& source, tcu::MessageBuilder& log)
18513 {
18514 	GLuint line_number = 0;
18515 
18516 	log << "Shader source.";
18517 
18518 	for (GLuint i = 0; i < source.m_parts.size(); ++i)
18519 	{
18520 		log << "\nLine||Part: " << (i + 1) << "/" << source.m_parts.size();
18521 
18522 		if (true == source.m_use_lengths)
18523 		{
18524 			log << " Length: " << source.m_parts[i].m_length;
18525 		}
18526 
18527 		log << "\n";
18528 
18529 		const GLchar* part = source.m_parts[i].m_code.c_str();
18530 
18531 		while (0 != part)
18532 		{
18533 			std::string   line;
18534 			const GLchar* next_line = strchr(part, '\n');
18535 
18536 			if (0 != next_line)
18537 			{
18538 				next_line += 1;
18539 				line.assign(part, next_line - part);
18540 			}
18541 			else
18542 			{
18543 				line = part;
18544 			}
18545 
18546 			if (0 != *part)
18547 			{
18548 				log << std::setw(4) << line_number << "||" << line;
18549 			}
18550 
18551 			part = next_line;
18552 			line_number += 1;
18553 		}
18554 	}
18555 }
18556 
18557 /** Constructor.
18558  *
18559  * @param context CTS context.
18560  **/
texture(deqp::Context & context)18561 Utils::texture::texture(deqp::Context& context) : m_id(0), m_context(context), m_texture_type(TEX_2D)
18562 {
18563 	/* Nothing to done here */
18564 }
18565 
18566 /** Destructor
18567  *
18568  **/
~texture()18569 Utils::texture::~texture()
18570 {
18571 	release();
18572 }
18573 
18574 /** Bind texture to GL_TEXTURE_2D
18575  *
18576  **/
bind() const18577 void Utils::texture::bind() const
18578 {
18579 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18580 
18581 	GLenum target = getTextureTartet(m_texture_type);
18582 
18583 	gl.bindTexture(target, m_id);
18584 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
18585 }
18586 
18587 /** Create 2d texture
18588  *
18589  * @param width           Width of texture
18590  * @param height          Height of texture
18591  * @param internal_format Internal format of texture
18592  **/
create(glw::GLuint width,glw::GLuint height,glw::GLenum internal_format)18593 void Utils::texture::create(glw::GLuint width, glw::GLuint height, glw::GLenum internal_format)
18594 {
18595 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18596 
18597 	release();
18598 
18599 	m_texture_type = TEX_2D;
18600 
18601 	gl.genTextures(1, &m_id);
18602 	GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18603 
18604 	bind();
18605 
18606 	gl.texStorage2D(GL_TEXTURE_2D, 1 /* levels */, internal_format, width, height);
18607 	GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18608 }
18609 
18610 /** Create texture of given type
18611  *
18612  * @param width           Width of texture
18613  * @param height          Height of texture
18614  * @param depth           Depth of texture
18615  * @param internal_format Internal format of texture
18616  * @param texture_type    Type of texture
18617  **/
create(GLuint width,GLuint height,GLuint depth,GLenum internal_format,TEXTURE_TYPES texture_type)18618 void Utils::texture::create(GLuint width, GLuint height, GLuint depth, GLenum internal_format,
18619 							TEXTURE_TYPES texture_type)
18620 {
18621 	static const GLuint levels = 1;
18622 
18623 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18624 
18625 	release();
18626 
18627 	m_texture_type = texture_type;
18628 
18629 	GLenum target = getTextureTartet(m_texture_type);
18630 
18631 	gl.genTextures(1, &m_id);
18632 	GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18633 
18634 	bind();
18635 
18636 	switch (m_texture_type)
18637 	{
18638 	case TEX_1D:
18639 		gl.texStorage1D(target, levels, internal_format, width);
18640 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18641 		break;
18642 	case TEX_2D:
18643 	case TEX_1D_ARRAY:
18644 	case TEX_2D_RECT:
18645 	case TEX_CUBE:
18646 		gl.texStorage2D(target, levels, internal_format, width, height);
18647 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18648 		break;
18649 	case TEX_3D:
18650 	case TEX_2D_ARRAY:
18651 		gl.texStorage3D(target, levels, internal_format, width, height, depth);
18652 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18653 		break;
18654 	default:
18655 		TCU_FAIL("Invliad enum");
18656 		break;
18657 	}
18658 }
18659 
18660 /** Create buffer texture
18661  *
18662  * @param internal_format Internal format of texture
18663  * @param buffer_id       Id of buffer that will be used as data source
18664  **/
createBuffer(GLenum internal_format,GLuint buffer_id)18665 void Utils::texture::createBuffer(GLenum internal_format, GLuint buffer_id)
18666 {
18667 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18668 
18669 	release();
18670 
18671 	m_texture_type = TEX_BUFFER;
18672 	m_buffer_id	= buffer_id;
18673 
18674 	gl.genTextures(1, &m_id);
18675 	GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18676 
18677 	bind();
18678 
18679 	gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
18680 	GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
18681 }
18682 
18683 /** Get contents of texture
18684  *
18685  * @param format   Format of image
18686  * @param type     Type of image
18687  * @param out_data Buffer for image
18688  **/
get(glw::GLenum format,glw::GLenum type,glw::GLvoid * out_data) const18689 void Utils::texture::get(glw::GLenum format, glw::GLenum type, glw::GLvoid* out_data) const
18690 {
18691 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18692 
18693 	GLenum target = getTextureTartet(m_texture_type);
18694 
18695 	bind();
18696 
18697 	gl.memoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
18698 	GLU_EXPECT_NO_ERROR(gl.getError(), "MemoryBarrier");
18699 
18700 	if (TEX_CUBE != m_texture_type)
18701 	{
18702 		gl.getTexImage(target, 0 /* level */, format, type, out_data);
18703 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18704 	}
18705 	else
18706 	{
18707 		GLint width;
18708 		GLint height;
18709 
18710 		if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
18711 		{
18712 			TCU_FAIL("Not implemented");
18713 		}
18714 
18715 		GLuint texel_size = 4;
18716 
18717 		gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
18718 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18719 
18720 		gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
18721 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18722 
18723 		const GLuint image_size = width * height * texel_size;
18724 
18725 		gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
18726 					   (GLvoid*)((GLchar*)out_data + (image_size * 0)));
18727 		gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
18728 					   (GLvoid*)((GLchar*)out_data + (image_size * 1)));
18729 		gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
18730 					   (GLvoid*)((GLchar*)out_data + (image_size * 2)));
18731 		gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
18732 					   (GLvoid*)((GLchar*)out_data + (image_size * 3)));
18733 		gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
18734 					   (GLvoid*)((GLchar*)out_data + (image_size * 4)));
18735 		gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
18736 					   (GLvoid*)((GLchar*)out_data + (image_size * 5)));
18737 		GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18738 	}
18739 }
18740 
18741 /** Delete texture
18742  *
18743  **/
release()18744 void Utils::texture::release()
18745 {
18746 	if (0 != m_id)
18747 	{
18748 		const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18749 
18750 		gl.deleteTextures(1, &m_id);
18751 		m_id = 0;
18752 
18753 		if ((m_texture_type == TEX_BUFFER) && (0 != m_buffer_id))
18754 		{
18755 			gl.deleteBuffers(1, &m_buffer_id);
18756 			m_buffer_id = 0;
18757 		}
18758 	}
18759 }
18760 
18761 /** Update contents of texture
18762  *
18763  * @param width  Width of texture
18764  * @param height Height of texture
18765  * @param format Format of data
18766  * @param type   Type of data
18767  * @param data   Buffer with image
18768  **/
update(glw::GLuint width,glw::GLuint height,glw::GLuint depth,glw::GLenum format,glw::GLenum type,glw::GLvoid * data)18769 void Utils::texture::update(glw::GLuint width, glw::GLuint height, glw::GLuint depth, glw::GLenum format,
18770 							glw::GLenum type, glw::GLvoid* data)
18771 {
18772 	static const GLuint level = 0;
18773 
18774 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18775 
18776 	GLenum target = getTextureTartet(m_texture_type);
18777 
18778 	bind();
18779 
18780 	switch (m_texture_type)
18781 	{
18782 	case TEX_1D:
18783 		gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
18784 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18785 		break;
18786 	case TEX_2D:
18787 	case TEX_1D_ARRAY:
18788 	case TEX_2D_RECT:
18789 		gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
18790 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18791 		break;
18792 	case TEX_CUBE:
18793 		gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18794 						 data);
18795 		gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18796 						 data);
18797 		gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18798 						 data);
18799 		gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18800 						 data);
18801 		gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18802 						 data);
18803 		gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18804 						 data);
18805 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18806 		break;
18807 	case TEX_3D:
18808 	case TEX_2D_ARRAY:
18809 		gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
18810 		GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18811 		break;
18812 	default:
18813 		TCU_FAIL("Invliad enum");
18814 		break;
18815 	}
18816 }
18817 
18818 /** Constructor.
18819  *
18820  * @param context CTS context.
18821  **/
vertexArray(deqp::Context & context)18822 Utils::vertexArray::vertexArray(deqp::Context& context) : m_id(0), m_context(context)
18823 {
18824 }
18825 
18826 /** Destructor
18827  *
18828  **/
~vertexArray()18829 Utils::vertexArray::~vertexArray()
18830 {
18831 	if (0 != m_id)
18832 	{
18833 		const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18834 
18835 		gl.deleteVertexArrays(1, &m_id);
18836 
18837 		m_id = 0;
18838 	}
18839 }
18840 
18841 /** Execute BindVertexArray
18842  *
18843  **/
bind()18844 void Utils::vertexArray::bind()
18845 {
18846 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18847 
18848 	gl.bindVertexArray(m_id);
18849 	GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
18850 }
18851 
18852 /** Execute GenVertexArrays
18853  *
18854  **/
generate()18855 void Utils::vertexArray::generate()
18856 {
18857 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18858 
18859 	gl.genVertexArrays(1, &m_id);
18860 	GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
18861 }
18862 } /* GLSL420Pack namespace */
18863 
18864 /** Constructor.
18865  *
18866  *  @param context Rendering context.
18867  **/
ShadingLanguage420PackTests(deqp::Context & context)18868 ShadingLanguage420PackTests::ShadingLanguage420PackTests(deqp::Context& context)
18869 	: TestCaseGroup(context, "shading_language_420pack", "Verifies \"shading_language_420pack\" functionality")
18870 {
18871 	/* Left blank on purpose */
18872 }
18873 
18874 /** Initializes a texture_storage_multisample test group.
18875  *
18876  **/
init(void)18877 void ShadingLanguage420PackTests::init(void)
18878 {
18879 	addChild(new GLSL420Pack::BindingSamplerSingleTest(m_context));
18880 	addChild(new GLSL420Pack::BindingImageSingleTest(m_context));
18881 	addChild(new GLSL420Pack::UTF8CharactersTest(m_context));
18882 	addChild(new GLSL420Pack::UTF8InSourceTest(m_context));
18883 	addChild(new GLSL420Pack::QualifierOrderTest(m_context));
18884 	addChild(new GLSL420Pack::QualifierOrderBlockTest(m_context));
18885 	addChild(new GLSL420Pack::LineContinuationTest(m_context));
18886 	addChild(new GLSL420Pack::LineNumberingTest(m_context));
18887 	addChild(new GLSL420Pack::ImplicitConversionsValidTest(m_context));
18888 	addChild(new GLSL420Pack::ImplicitConversionsInvalidTest(m_context));
18889 	addChild(new GLSL420Pack::ConstDynamicValueTest(m_context));
18890 	addChild(new GLSL420Pack::ConstAssignmentTest(m_context));
18891 	addChild(new GLSL420Pack::ConstDynamicValueAsConstExprTest(m_context));
18892 	addChild(new GLSL420Pack::QualifierOrderUniformTest(m_context));
18893 	addChild(new GLSL420Pack::QualifierOrderFunctionInoutTest(m_context));
18894 	addChild(new GLSL420Pack::QualifierOrderFunctionInputTest(m_context));
18895 	addChild(new GLSL420Pack::QualifierOrderFunctionOutputTest(m_context));
18896 	addChild(new GLSL420Pack::QualifierOverrideLayoutTest(m_context));
18897 	addChild(new GLSL420Pack::BindingUniformBlocksTest(m_context));
18898 	addChild(new GLSL420Pack::BindingUniformSingleBlockTest(m_context));
18899 	addChild(new GLSL420Pack::BindingUniformBlockArrayTest(m_context));
18900 	addChild(new GLSL420Pack::BindingUniformDefaultTest(m_context));
18901 	addChild(new GLSL420Pack::BindingUniformAPIOverirdeTest(m_context));
18902 	addChild(new GLSL420Pack::BindingUniformGlobalBlockTest(m_context));
18903 	addChild(new GLSL420Pack::BindingUniformInvalidTest(m_context));
18904 	addChild(new GLSL420Pack::BindingSamplersTest(m_context));
18905 	addChild(new GLSL420Pack::BindingSamplerArrayTest(m_context));
18906 	addChild(new GLSL420Pack::BindingSamplerDefaultTest(m_context));
18907 	addChild(new GLSL420Pack::BindingSamplerAPIOverrideTest(m_context));
18908 	addChild(new GLSL420Pack::BindingSamplerInvalidTest(m_context));
18909 	addChild(new GLSL420Pack::BindingImagesTest(m_context));
18910 	addChild(new GLSL420Pack::BindingImageArrayTest(m_context));
18911 	addChild(new GLSL420Pack::BindingImageDefaultTest(m_context));
18912 	addChild(new GLSL420Pack::BindingImageAPIOverrideTest(m_context));
18913 	addChild(new GLSL420Pack::BindingImageInvalidTest(m_context));
18914 	addChild(new GLSL420Pack::InitializerListTest(m_context));
18915 	addChild(new GLSL420Pack::InitializerListNegativeTest(m_context));
18916 	addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context));
18917 	addChild(new GLSL420Pack::LengthOfComputeResultTest(m_context));
18918 	addChild(new GLSL420Pack::ScalarSwizzlersTest(m_context));
18919 	addChild(new GLSL420Pack::ScalarSwizzlersInvalidTest(m_context));
18920 	addChild(new GLSL420Pack::BuiltInValuesTest(m_context));
18921 	addChild(new GLSL420Pack::BuiltInAssignmentTest(m_context));
18922 }
18923 
18924 } /* gl4cts namespace */
18925