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 }
1069
1070 /* Get qualifiers list */
1071 const std::string& list = getQualifiersListString(qualifiers);
1072
1073 /* Replace tokens */
1074 replaceToken(token_qual_list, position, list.c_str(), variable_definition);
1075 replaceToken(token_type, position, type_name, variable_definition);
1076 replaceToken(token_variable_name, position, variable_name, variable_definition);
1077
1078 /* Done */
1079 return variable_definition;
1080 }
1081
1082 /** Get "flavour" of variable
1083 *
1084 * @param stage Shader stage
1085 * @param storage Storage of variable
1086 * @param qualifiers Set of qualifiers for variable
1087 *
1088 * @return "Flavour" of variable
1089 **/
getVariableFlavour(SHADER_STAGES stage,VARIABLE_STORAGE storage,const qualifierSet & qualifiers)1090 Utils::VARIABLE_FLAVOUR Utils::getVariableFlavour(SHADER_STAGES stage, VARIABLE_STORAGE storage,
1091 const qualifierSet& qualifiers)
1092 {
1093 VARIABLE_FLAVOUR result;
1094
1095 if (UNIFORM == storage)
1096 {
1097 result = BASIC;
1098 }
1099 else
1100 {
1101 switch (stage)
1102 {
1103 case Utils::GEOMETRY_SHADER:
1104 if (Utils::INPUT == storage)
1105 {
1106 result = ARRAY;
1107 }
1108 else /* OUTPUT */
1109 {
1110 result = BASIC;
1111 }
1112 break;
1113 case Utils::TESS_EVAL_SHADER:
1114 if ((false == Utils::doesContainQualifier(Utils::QUAL_PATCH, qualifiers)) && (Utils::INPUT == storage))
1115 {
1116 result = ARRAY;
1117 }
1118 else /* OUTPUT */
1119 {
1120 result = BASIC;
1121 }
1122 break;
1123 case Utils::TESS_CTRL_SHADER:
1124 if ((true == Utils::doesContainQualifier(Utils::QUAL_PATCH, qualifiers)) && (Utils::OUTPUT == storage))
1125 {
1126 result = BASIC;
1127 }
1128 else
1129 {
1130 result = INDEXED_BY_INVOCATION_ID;
1131 }
1132 break;
1133 case Utils::VERTEX_SHADER:
1134 case Utils::FRAGMENT_SHADER:
1135 result = BASIC;
1136 break;
1137 default:
1138 TCU_FAIL("Invliad enum");
1139 }
1140 }
1141
1142 return result;
1143 }
1144
1145 /** Prepare name of input or output variable
1146 *
1147 * @param stage Shader stage
1148 * @param storage Storage of variable
1149 * @param variable_name Meaningful part of variable name, eg. tex_coord
1150 *
1151 * @return Name of variable
1152 **/
getVariableName(SHADER_STAGES stage,VARIABLE_STORAGE storage,const glw::GLchar * variable_name)1153 std::string Utils::getVariableName(SHADER_STAGES stage, VARIABLE_STORAGE storage, const glw::GLchar* variable_name)
1154 {
1155 /* Variable name template */
1156 static const GLchar* variable_name_template = "PRECEEDING_PREFIX_VARIABLE_NAME";
1157
1158 /* Tokens */
1159 static const GLchar* token_preceeding = "PRECEEDING";
1160 static const GLchar* token_prefix = "PREFIX";
1161 static const GLchar* token_variable_name = "VARIABLE_NAME";
1162
1163 static const GLchar* prefixes[Utils::STORAGE_MAX][Utils::SHADER_STAGES_MAX][2] = {
1164 /* COMPUTE, VERTEX, TCS, TES, GEOMETRY, FRAGMENT */
1165 { { "", "" },
1166 { "in", "vs" },
1167 { "vs", "tcs" },
1168 { "tcs", "tes" },
1169 { "tes", "gs" },
1170 { "gs", "fs" } }, /* INPUT */
1171 { { "", "" },
1172 { "vs", "tcs" },
1173 { "tcs", "tes" },
1174 { "tes", "gs" },
1175 { "gs", "fs" },
1176 { "fs", "out" } }, /* OUTPUT */
1177 { { "uni", "comp" },
1178 { "uni", "vs" },
1179 { "uni", "tcs" },
1180 { "uni", "tes" },
1181 { "uni", "gs" },
1182 { "uni", "fs" } } /* UNIFORM */
1183 };
1184
1185 /* Variables */
1186 const GLchar* preceeding = prefixes[storage][stage][0];
1187 const GLchar* prefix = prefixes[storage][stage][1];
1188 std::string name = variable_name_template;
1189 size_t position = 0;
1190
1191 /* Replace tokens */
1192 Utils::replaceToken(token_preceeding, position, preceeding, name);
1193 Utils::replaceToken(token_prefix, position, prefix, name);
1194 Utils::replaceToken(token_variable_name, position, variable_name, name);
1195
1196 /* Done */
1197 return name;
1198 }
1199
1200 /** Prepare reference to input or output variable
1201 *
1202 * @param flavour "Flavour" of variable
1203 * @param variable_name Meaningful part of variable name, eg. tex_coord
1204 *
1205 * @return Reference to variable
1206 **/
getVariableReference(VARIABLE_FLAVOUR flavour,const glw::GLchar * variable_name)1207 std::string Utils::getVariableReference(VARIABLE_FLAVOUR flavour, const glw::GLchar* variable_name)
1208 {
1209 /* Templates */
1210 static const GLchar* ref_template = "VARIABLE_NAME";
1211 static const GLchar* array_ref_template = "VARIABLE_NAME[0]";
1212 static const GLchar* tcs_ref_template = "VARIABLE_NAME[gl_InvocationID]";
1213
1214 /* Token */
1215 static const GLchar* token_variable_name = "VARIABLE_NAME";
1216
1217 /* Variables */
1218 std::string variable_definition;
1219 size_t position = 0;
1220
1221 /* Select variable reference template */
1222 switch (flavour)
1223 {
1224 case BASIC:
1225 variable_definition = ref_template;
1226 break;
1227 case ARRAY:
1228 variable_definition = array_ref_template;
1229 break;
1230 case INDEXED_BY_INVOCATION_ID:
1231 variable_definition = tcs_ref_template;
1232 break;
1233 default:
1234 variable_definition = ref_template;
1235 break;
1236 }
1237
1238 /* Replace token */
1239 Utils::replaceToken(token_variable_name, position, variable_name, variable_definition);
1240
1241 /* Done */
1242 return variable_definition;
1243 }
1244
1245 /** Prepare definition and reference string for block varaible
1246 *
1247 * @param in_stage Shader stage
1248 * @param in_storage Storage of variable
1249 * @param in_qualifiers Set of qualifiers
1250 * @param in_type_name Type name
1251 * @param in_variable_name Meaningful part of variable name, like "color"
1252 * @param in_block_name Name of block, like "input"
1253 * @param out_definition Definition string
1254 * @param out_reference Reference string
1255 **/
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)1256 void Utils::prepareBlockVariableStrings(Utils::SHADER_STAGES in_stage, Utils::VARIABLE_STORAGE in_storage,
1257 const Utils::qualifierSet& in_qualifiers, const glw::GLchar* in_type_name,
1258 const glw::GLchar* in_variable_name, const glw::GLchar* in_block_name,
1259 std::string& out_definition, std::string& out_reference)
1260 {
1261 VARIABLE_FLAVOUR flavour = getVariableFlavour(in_stage, in_storage, in_qualifiers);
1262 const qualifierSet& qualifiers = prepareQualifiersSet(in_qualifiers, in_stage, in_storage);
1263 const std::string& name = getVariableName(in_stage, in_storage, in_variable_name);
1264
1265 out_definition = getBlockVariableDefinition(qualifiers, in_type_name, name.c_str());
1266 out_reference = getBlockVariableReference(flavour, name.c_str(), in_block_name);
1267 }
1268
1269 /** Prepare definition and reference string for block varaible
1270 *
1271 * @param in_stage Shader stage
1272 * @param in_storage Storage of variable
1273 * @param in_qualifiers Set of qualifiers
1274 * @param in_type_name Type name
1275 * @param in_variable_name Meaningful part of variable name, like "color"
1276 * @param out_definition Definition string
1277 * @param out_reference Reference string
1278 **/
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)1279 void Utils::prepareVariableStrings(Utils::SHADER_STAGES in_stage, Utils::VARIABLE_STORAGE in_storage,
1280 const Utils::qualifierSet& in_qualifiers, const glw::GLchar* in_type_name,
1281 const glw::GLchar* in_variable_name, std::string& out_definition,
1282 std::string& out_reference)
1283 {
1284 VARIABLE_FLAVOUR flavour = getVariableFlavour(in_stage, in_storage, in_qualifiers);
1285 const qualifierSet& qualifiers = prepareQualifiersSet(in_qualifiers, in_stage, in_storage);
1286 const std::string& name = getVariableName(in_stage, in_storage, in_variable_name);
1287
1288 out_definition = getVariableDefinition(flavour, qualifiers, in_type_name, name.c_str());
1289 out_reference = getVariableReference(flavour, name.c_str());
1290 }
1291
1292 /** Returns string with UTF8 character for current test case
1293 *
1294 * @return String with UTF8 character
1295 **/
getUtf8Character(Utils::UTF8_CHARACTERS character)1296 const GLchar* Utils::getUtf8Character(Utils::UTF8_CHARACTERS character)
1297 {
1298 static const unsigned char two_bytes[] = { 0xd7, 0x84, 0x00 };
1299 static const unsigned char three_bytes[] = { 0xe3, 0x82, 0x81, 0x00 };
1300 static const unsigned char four_bytes[] = { 0xf0, 0x93, 0x83, 0x93, 0x00 };
1301 static const unsigned char five_bytes[] = { 0xfa, 0x82, 0x82, 0x82, 0x82, 0x00 };
1302 static const unsigned char six_bytes[] = { 0xfd, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00 };
1303 static const unsigned char redundant_bytes[] = { 0xf2, 0x80, 0x80, 0x5e, 0x00 };
1304
1305 const GLchar* result = 0;
1306
1307 switch (character)
1308 {
1309 case TWO_BYTES:
1310 result = (const GLchar*)two_bytes;
1311 break;
1312 case THREE_BYTES:
1313 result = (const GLchar*)three_bytes;
1314 break;
1315 case FOUR_BYTES:
1316 result = (const GLchar*)four_bytes;
1317 break;
1318 case FIVE_BYTES:
1319 result = (const GLchar*)five_bytes;
1320 break;
1321 case SIX_BYTES:
1322 result = (const GLchar*)six_bytes;
1323 break;
1324 case REDUNDANT_ASCII:
1325 result = (const GLchar*)redundant_bytes;
1326 break;
1327 case EMPTY:
1328 result = "";
1329 break;
1330 default:
1331 TCU_FAIL("Invalid enum");
1332 }
1333
1334 return result;
1335 }
1336 /** Check if extension is supported
1337 *
1338 * @param context Test context
1339 * @param extension_name Name of extension
1340 *
1341 * @return true if extension is supported, false otherwise
1342 **/
isExtensionSupported(deqp::Context & context,const GLchar * extension_name)1343 bool Utils::isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1344 {
1345 const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1346
1347 if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1348 {
1349 return false;
1350 }
1351
1352 return true;
1353 }
1354
1355 /** Check if GL context meets version requirements
1356 *
1357 * @param gl Functions
1358 * @param required_major Minimum required MAJOR_VERSION
1359 * @param required_minor Minimum required MINOR_VERSION
1360 *
1361 * @return true if GL context version is at least as requested, false otherwise
1362 **/
isGLVersionAtLeast(const glw::Functions & gl,glw::GLint required_major,glw::GLint required_minor)1363 bool Utils::isGLVersionAtLeast(const glw::Functions& gl, glw::GLint required_major, glw::GLint required_minor)
1364 {
1365 glw::GLint major = 0;
1366 glw::GLint minor = 0;
1367
1368 gl.getIntegerv(GL_MAJOR_VERSION, &major);
1369 gl.getIntegerv(GL_MINOR_VERSION, &minor);
1370
1371 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1372
1373 if (major > required_major)
1374 {
1375 /* Major is higher than required one */
1376 return true;
1377 }
1378 else if (major == required_major)
1379 {
1380 if (minor >= required_minor)
1381 {
1382 /* Major is equal to required one */
1383 /* Minor is higher than or equal to required one */
1384 return true;
1385 }
1386 else
1387 {
1388 /* Major is equal to required one */
1389 /* Minor is lower than required one */
1390 return false;
1391 }
1392 }
1393 else
1394 {
1395 /* Major is lower than required one */
1396 return false;
1397 }
1398 }
1399
1400 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1401 *
1402 * @param token Token string
1403 * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1404 * @param text String that will be used as replacement for <token>
1405 * @param string String to work on
1406 **/
replaceToken(const glw::GLchar * token,size_t & search_position,const glw::GLchar * text,std::string & string)1407 void Utils::replaceToken(const glw::GLchar* token, size_t& search_position, const glw::GLchar* text,
1408 std::string& string)
1409 {
1410 const size_t text_length = strlen(text);
1411 const size_t token_length = strlen(token);
1412 const size_t token_position = string.find(token, search_position);
1413
1414 string.replace(token_position, token_length, text, text_length);
1415
1416 search_position = token_position + text_length;
1417 }
1418
1419 /** Replace all occurances of <token> with <text> in <string>
1420 *
1421 * @param token Token string
1422 * @param text String that will be used as replacement for <token>
1423 * @param string String to work on
1424 **/
replaceAllTokens(const glw::GLchar * token,const glw::GLchar * text,std::string & string)1425 void Utils::replaceAllTokens(const glw::GLchar* token, const glw::GLchar* text, std::string& string)
1426 {
1427 const size_t text_length = strlen(text);
1428 const size_t token_length = strlen(token);
1429
1430 size_t search_position = 0;
1431
1432 while (1)
1433 {
1434 const size_t token_position = string.find(token, search_position);
1435
1436 if (std::string::npos == token_position)
1437 {
1438 break;
1439 }
1440
1441 search_position = token_position + text_length;
1442
1443 string.replace(token_position, token_length, text, text_length);
1444 }
1445 }
1446
1447 /** Constructor
1448 *
1449 * @param context Test context
1450 * @param test_name Test name
1451 * @param test_description Test description
1452 **/
TestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1453 TestBase::TestBase(deqp::Context& context, const glw::GLchar* test_name, const glw::GLchar* test_description)
1454 : TestCase(context, test_name, test_description)
1455 , m_is_compute_shader_supported(false)
1456 , m_is_explicit_uniform_location(false)
1457 , m_is_shader_language_420pack(false)
1458 {
1459 /* Nothing to be done here */
1460 }
1461
1462 /** Execute test
1463 *
1464 * @return tcu::TestNode::CONTINUE after executing test case, tcu::TestNode::STOP otherwise
1465 **/
iterate()1466 tcu::TestNode::IterateResult TestBase::iterate()
1467 {
1468 /* GL entry points */
1469 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1470
1471 /* Check extension support and version */
1472 m_is_explicit_uniform_location = Utils::isExtensionSupported(m_context, "GL_ARB_explicit_uniform_location");
1473 m_is_shader_language_420pack = Utils::isExtensionSupported(m_context, "GL_ARB_shading_language_420pack");
1474 m_is_compute_shader_supported = Utils::isGLVersionAtLeast(gl, 4, 3);
1475
1476 /* Execute test */
1477 bool test_result = test();
1478
1479 /* Set result */
1480 if (true == test_result)
1481 {
1482 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
1483 }
1484 else
1485 {
1486 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
1487 }
1488
1489 /* Done */
1490 return tcu::TestNode::STOP;
1491 }
1492
1493 /** Basic implementation of getShaderSourceConfig method.
1494 *
1495 * @param out_n_parts Number of source parts used by this test case
1496 * @param out_use_lengths If source lengths shall be provided to compiler
1497 **/
getShaderSourceConfig(glw::GLuint & out_n_parts,bool & out_use_lengths)1498 void TestBase::getShaderSourceConfig(glw::GLuint& out_n_parts, bool& out_use_lengths)
1499 {
1500 out_n_parts = 1;
1501 out_use_lengths = false;
1502 }
1503
1504 /** Basic implementation of prepareNextTestCase method.
1505 *
1506 * @param test_case_index Index of test case
1507 *
1508 * @return true if index is -1 or 0, false otherwise
1509 **/
prepareNextTestCase(GLuint test_case_index)1510 bool TestBase::prepareNextTestCase(GLuint test_case_index)
1511 {
1512 if (((GLuint)-1 == test_case_index) || (0 == test_case_index))
1513 {
1514 return true;
1515 }
1516 else
1517 {
1518 return false;
1519 }
1520 }
1521
1522 /** Basic implementation of prepareUniforms method
1523 *
1524 * @param ignored
1525 **/
prepareUniforms(Utils::program &)1526 void TestBase::prepareUniforms(Utils::program& /* program */)
1527 {
1528 /* Nothing to be done */
1529 }
1530
1531 /** Basic implementation of testInit method
1532 *
1533 * @return true if test can be executed, false otherwise
1534 **/
testInit()1535 bool TestBase::testInit()
1536 {
1537 return true;
1538 }
1539
1540 /** Get layout specific for given stage
1541 *
1542 * @param stage Shader stage
1543 *
1544 * @return Stage specific part
1545 **/
getStageSpecificLayout(Utils::SHADER_STAGES stage) const1546 const GLchar* TestBase::getStageSpecificLayout(Utils::SHADER_STAGES stage) const
1547 {
1548 static const GLchar* stage_layout_geometry = "layout(points) in;\n"
1549 "layout(triangle_strip, max_vertices = 4) out;\n";
1550 static const GLchar* stage_layout_tess_ctrl = "layout(vertices = 1) out;\n";
1551 static const GLchar* stage_layout_tess_eval = "layout(isolines, point_mode) in;\n";
1552
1553 const GLchar* result = "";
1554
1555 switch (stage)
1556 {
1557 case Utils::GEOMETRY_SHADER:
1558 result = stage_layout_geometry;
1559 break;
1560 case Utils::TESS_CTRL_SHADER:
1561 result = stage_layout_tess_ctrl;
1562 break;
1563 case Utils::TESS_EVAL_SHADER:
1564 result = stage_layout_tess_eval;
1565 break;
1566 case Utils::VERTEX_SHADER:
1567 case Utils::FRAGMENT_SHADER:
1568 default:
1569 break;
1570 }
1571
1572 return result;
1573 }
1574
1575 /** Get "version" string
1576 *
1577 * @param stage Shader stage, compute shader will use 430
1578 * @param use_version_400 Select if 400 or 420 should be used
1579 *
1580 * @return Version string
1581 **/
getVersionString(Utils::SHADER_STAGES stage,bool use_version_400) const1582 const GLchar* TestBase::getVersionString(Utils::SHADER_STAGES stage, bool use_version_400) const
1583 {
1584 static const GLchar* version_400 = "#version 400\n"
1585 "#extension GL_ARB_shading_language_420pack : require\n"
1586 "#extension GL_ARB_separate_shader_objects : enable";
1587 static const GLchar* version_420 = "#version 420";
1588 static const GLchar* version_430 = "#version 430";
1589
1590 const GLchar* result = "";
1591
1592 if (Utils::COMPUTE_SHADER == stage)
1593 {
1594 result = version_430;
1595 }
1596 else if (true == use_version_400)
1597 {
1598 result = version_400;
1599 }
1600 else
1601 {
1602 result = version_420;
1603 }
1604
1605 return result;
1606 }
1607
1608 /** Initialize shaderSource instance, reserve storage and prepare shader source
1609 *
1610 * @param in_stage Shader stage
1611 * @param in_use_version_400 If version 400 or 420 should be used
1612 * @param out_source Shader source instance
1613 **/
initShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)1614 void TestBase::initShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400, Utils::shaderSource& out_source)
1615 {
1616 /* Shader source configuration */
1617 glw::GLuint n_parts = 0;
1618 bool use_lengths = false;
1619
1620 getShaderSourceConfig(n_parts, use_lengths);
1621
1622 out_source.m_parts.resize(n_parts);
1623 out_source.m_use_lengths = use_lengths;
1624
1625 /* Request child class to prepare shader sources */
1626 prepareShaderSource(in_stage, in_use_version_400, out_source);
1627
1628 /* Prepare source lengths */
1629 if (true == use_lengths)
1630 {
1631 for (GLuint i = 0; i < n_parts; ++i)
1632 {
1633 out_source.m_parts[i].m_length = static_cast<glw::GLint>(out_source.m_parts[i].m_code.length());
1634
1635 out_source.m_parts[i].m_code.append("This should be ignored by compiler, as source length is provided");
1636 }
1637 }
1638 else
1639 {
1640 for (GLuint i = 0; i < n_parts; ++i)
1641 {
1642 out_source.m_parts[i].m_length = 0;
1643 }
1644 }
1645 }
1646
1647 /** Execute test
1648 *
1649 * @return true if test pass, false otherwise
1650 **/
test()1651 bool TestBase::test()
1652 {
1653 bool result = true;
1654 GLuint test_case_index = 0;
1655
1656 /* Prepare test cases */
1657 testInit();
1658
1659 /* GL entry points */
1660 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1661
1662 /* Tesselation patch set up */
1663 gl.patchParameteri(GL_PATCH_VERTICES, 1);
1664 GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
1665
1666 while (true == prepareNextTestCase(test_case_index))
1667 {
1668 bool case_result = true;
1669
1670 /* Execute drawing case */
1671 if (false == testDrawArray(false))
1672 {
1673 case_result = false;
1674 }
1675
1676 if (true == m_is_shader_language_420pack)
1677 {
1678 if (false == testDrawArray(true))
1679 {
1680 case_result = false;
1681 }
1682 }
1683
1684 /* Execute compute shader case */
1685 if (true == m_is_compute_shader_supported)
1686 {
1687 if (false == testCompute())
1688 {
1689 case_result = false;
1690 }
1691 }
1692
1693 /* Log failure */
1694 if (false == case_result)
1695 {
1696 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case failed."
1697 << tcu::TestLog::EndMessage;
1698
1699 result = false;
1700 }
1701
1702 /* Go to next test case */
1703 test_case_index += 1;
1704 }
1705
1706 /* Done */
1707 return result;
1708 }
1709
maxImageUniforms(Utils::SHADER_STAGES stage) const1710 int TestBase::maxImageUniforms(Utils::SHADER_STAGES stage) const
1711 {
1712 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1713 GLint max_image_uniforms;
1714
1715 switch (stage)
1716 {
1717 case Utils::COMPUTE_SHADER:
1718 gl.getIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &max_image_uniforms);
1719 break;
1720 case Utils::FRAGMENT_SHADER:
1721 gl.getIntegerv(GL_MAX_FRAGMENT_IMAGE_UNIFORMS, &max_image_uniforms);
1722 break;
1723 case Utils::GEOMETRY_SHADER:
1724 gl.getIntegerv(GL_MAX_GEOMETRY_IMAGE_UNIFORMS, &max_image_uniforms);
1725 break;
1726 case Utils::TESS_CTRL_SHADER:
1727 gl.getIntegerv(GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS, &max_image_uniforms);
1728 break;
1729 case Utils::TESS_EVAL_SHADER:
1730 gl.getIntegerv(GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS, &max_image_uniforms);
1731 break;
1732 case Utils::VERTEX_SHADER:
1733 gl.getIntegerv(GL_MAX_VERTEX_IMAGE_UNIFORMS, &max_image_uniforms);
1734 break;
1735 default:
1736 TCU_FAIL("Invalid enum");
1737 }
1738 return max_image_uniforms;
1739 }
1740
1741 /** Constructor
1742 *
1743 * @param context Test context
1744 * @param test_name Name of test
1745 * @param test_description Description of test
1746 **/
APITestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1747 APITestBase::APITestBase(deqp::Context& context, const glw::GLchar* test_name, const glw::GLchar* test_description)
1748 : TestBase(context, test_name, test_description)
1749 {
1750 /* Nothing to be done here */
1751 }
1752
1753 /** Execute test with compute shader
1754 *
1755 * @return true if test pass, false otherwise
1756 **/
testCompute()1757 bool APITestBase::testCompute()
1758 {
1759 /* GL objects */
1760 Utils::program program(m_context);
1761
1762 /* Shaders */
1763 Utils::shaderSource compute_shader;
1764 initShaderSource(Utils::COMPUTE_SHADER, false, compute_shader);
1765
1766 /* Check if test support compute shaders */
1767 if (true == compute_shader.m_parts[0].m_code.empty())
1768 {
1769 return true;
1770 }
1771
1772 /* Build program */
1773 try
1774 {
1775 program.build(compute_shader, 0 /* fragment shader */, 0 /* geometry shader */,
1776 0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
1777 0 /* varying names */, 0 /* n varying names */, false);
1778 }
1779 catch (Utils::shaderCompilationException& exc)
1780 {
1781 /* Something wrong with compilation, test case failed */
1782 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
1783
1784 message << "Shader compilation failed. Error message: " << exc.m_error_message;
1785
1786 Utils::program::printShaderSource(exc.m_shader_source, message);
1787
1788 message << tcu::TestLog::EndMessage;
1789
1790 return false;
1791 }
1792 catch (Utils::programLinkageException& exc)
1793 {
1794 /* Something wrong with linking, test case failed */
1795 m_context.getTestContext().getLog() << tcu::TestLog::Message
1796 << "Program linking failed. Error message: " << exc.m_error_message
1797 << tcu::TestLog::EndMessage;
1798 return false;
1799 }
1800
1801 /* Set current program */
1802 program.use();
1803
1804 /* Return result of verification */
1805 return checkResults(program);
1806 }
1807
1808 /** Execute test with VS, TCS, TES, GS and FS
1809 *
1810 * @param use_version_400 Select if 400 or 420 should be used
1811 *
1812 * @return true if test pass, false otherwise
1813 **/
testDrawArray(bool use_version_400)1814 bool APITestBase::testDrawArray(bool use_version_400)
1815 {
1816 /* GL objects */
1817 Utils::program program(m_context);
1818
1819 /* Shaders */
1820 Utils::shaderSource fragment_data;
1821 Utils::shaderSource geometry_data;
1822 Utils::shaderSource tess_ctrl_data;
1823 Utils::shaderSource tess_eval_data;
1824 Utils::shaderSource vertex_data;
1825
1826 initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
1827 initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
1828 initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
1829 initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
1830 initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
1831
1832 /* Build program */
1833 try
1834 {
1835 program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
1836 0 /* varying names */, 0 /* n varying names */, false);
1837 }
1838 catch (Utils::shaderCompilationException& exc)
1839 {
1840 /* Something wrong with compilation, test case failed */
1841 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
1842
1843 message << "Shader compilation failed. Error message: " << exc.m_error_message;
1844
1845 Utils::program::printShaderSource(exc.m_shader_source, message);
1846
1847 message << tcu::TestLog::EndMessage;
1848
1849 return false;
1850 }
1851 catch (Utils::programLinkageException& exc)
1852 {
1853 /* Something wrong with linking, test case failed */
1854 m_context.getTestContext().getLog() << tcu::TestLog::Message
1855 << "Program linking failed. Error message: " << exc.m_error_message
1856 << tcu::TestLog::EndMessage;
1857 return false;
1858 }
1859
1860 /* Set current program */
1861 program.use();
1862
1863 /* Return result of verification */
1864 return checkResults(program);
1865 }
1866
1867 /* Constants used by GLSLTestBase */
1868 const glw::GLenum GLSLTestBase::m_color_texture_internal_format = GL_RGBA8;
1869 const glw::GLenum GLSLTestBase::m_color_texture_format = GL_RGBA;
1870 const glw::GLenum GLSLTestBase::m_color_texture_type = GL_UNSIGNED_BYTE;
1871 const glw::GLuint GLSLTestBase::m_color_texture_width = 16;
1872 const glw::GLuint GLSLTestBase::m_color_texture_height = 16;
1873
1874 /** Constructor
1875 *
1876 * @param context Test context
1877 * @param test_name Test name
1878 * @param test_description Test description
1879 **/
GLSLTestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)1880 GLSLTestBase::GLSLTestBase(deqp::Context& context, const glw::GLchar* test_name, const glw::GLchar* test_description)
1881 : TestBase(context, test_name, test_description)
1882 {
1883 /* Nothing to be done here */
1884 }
1885
1886 /** Basic implementation of prepareSourceTexture method.
1887 *
1888 * @param ignored Texture instance
1889 *
1890 * @return 0
1891 **/
prepareSourceTexture(Utils::texture &)1892 const GLchar* GLSLTestBase::prepareSourceTexture(Utils::texture&)
1893 {
1894 return 0;
1895 }
1896
1897 /** Basic implementation of prepareVertexBuffer method.
1898 *
1899 * @param ignored Program instance
1900 * @param ignored Buffer instance
1901 * @param vao VertexArray instance
1902 *
1903 * @return 0
1904 **/
prepareVertexBuffer(const Utils::program &,Utils::buffer &,Utils::vertexArray & vao)1905 void GLSLTestBase::prepareVertexBuffer(const Utils::program&, Utils::buffer&, Utils::vertexArray& vao)
1906 {
1907 vao.generate();
1908 vao.bind();
1909 }
1910
1911 /** Basic implementation of verifyAdditionalResults
1912 *
1913 * @return true
1914 **/
verifyAdditionalResults() const1915 bool GLSLTestBase::verifyAdditionalResults() const
1916 {
1917 return true;
1918 }
1919
1920 /** Basic implementation of releaseResource method
1921 *
1922 * @param ignored
1923 **/
releaseResource()1924 void GLSLTestBase::releaseResource()
1925 {
1926 /* Nothing to be done */
1927 }
1928
1929 /** Bind texture to first image unit and set image uniform to that unit
1930 *
1931 * @param program Program object
1932 * @param texture Texture object
1933 * @param uniform_name Name of image uniform
1934 **/
bindTextureToimage(Utils::program & program,Utils::texture & texture,const glw::GLchar * uniform_name) const1935 void GLSLTestBase::bindTextureToimage(Utils::program& program, Utils::texture& texture,
1936 const glw::GLchar* uniform_name) const
1937 {
1938 /* GL entry points */
1939 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1940
1941 gl.bindImageTexture(0 /* unit */, texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* layer */, GL_WRITE_ONLY,
1942 GL_RGBA8);
1943 GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
1944
1945 GLint location = program.getUniformLocation(uniform_name);
1946 gl.uniform1i(location, 0);
1947 GLU_EXPECT_NO_ERROR(gl.getError(), "Uniform1i");
1948 }
1949
1950 /** Bind texture to first texture unit and set sampler uniform to that unit
1951 *
1952 * @param program Program object
1953 * @param texture Texture object
1954 * @param uniform_name Name of sampler uniform
1955 **/
bindTextureToSampler(Utils::program & program,Utils::texture & texture,const glw::GLchar * uniform_name) const1956 void GLSLTestBase::bindTextureToSampler(Utils::program& program, Utils::texture& texture,
1957 const glw::GLchar* uniform_name) const
1958 {
1959 /* GL entry points */
1960 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1961
1962 gl.activeTexture(GL_TEXTURE0);
1963 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
1964
1965 texture.bind();
1966
1967 GLint location = program.getUniformLocation(uniform_name);
1968 gl.uniform1i(location, 0);
1969 GLU_EXPECT_NO_ERROR(gl.getError(), "Uniform1i");
1970 }
1971
1972 /** Check contents of texture. It is expected that it will be filled with green color
1973 *
1974 * @param color_texture Texture that will be verified
1975 *
1976 * @return true if texture is all green, false otherwise
1977 **/
checkResults(Utils::texture & color_texture) const1978 bool GLSLTestBase::checkResults(Utils::texture& color_texture) const
1979 {
1980 static const GLuint green_color = 0xff00ff00;
1981 const GLuint texture_data_size = m_color_texture_width * m_color_texture_height;
1982 std::vector<glw::GLuint> texture_data;
1983
1984 texture_data.resize(texture_data_size);
1985
1986 color_texture.get(m_color_texture_format, m_color_texture_type, &texture_data[0]);
1987
1988 for (GLuint i = 0; i < texture_data_size; ++i)
1989 {
1990 if (green_color != texture_data[i])
1991 {
1992 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Invalid texel: " << std::setbase(16)
1993 << std::setfill('0') << std::setw(8) << texture_data[i]
1994 << " at index: " << i << tcu::TestLog::EndMessage;
1995
1996 return false;
1997 }
1998 }
1999
2000 return verifyAdditionalResults();
2001 }
2002
2003 /** Prepare framebuffer with texture used as attachment
2004 *
2005 * @param framebuffer Framebuffer
2006 * @param color_texture Textue used as color attachment 0
2007 **/
prepareFramebuffer(Utils::framebuffer & framebuffer,Utils::texture & color_texture) const2008 void GLSLTestBase::prepareFramebuffer(Utils::framebuffer& framebuffer, Utils::texture& color_texture) const
2009 {
2010 framebuffer.generate();
2011
2012 color_texture.create(m_color_texture_width, m_color_texture_height, m_color_texture_internal_format);
2013
2014 framebuffer.attachTexture(GL_COLOR_ATTACHMENT0, color_texture.m_id, m_color_texture_width, m_color_texture_height);
2015
2016 framebuffer.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
2017 framebuffer.clear(GL_COLOR_BUFFER_BIT);
2018 }
2019
2020 /** Prepare texture and bind it to image uniform
2021 *
2022 * @param framebuffer Framebuffer
2023 * @param color_texture Textue used as color attachment 0
2024 **/
prepareImage(Utils::program & program,Utils::texture & color_texture) const2025 void GLSLTestBase::prepareImage(Utils::program& program, Utils::texture& color_texture) const
2026 {
2027 color_texture.create(m_color_texture_width, m_color_texture_height, m_color_texture_internal_format);
2028
2029 bindTextureToimage(program, color_texture, "uni_image");
2030 }
2031
2032 /** Execute test with compute shader
2033 *
2034 * @return true if test pass, false otherwise
2035 **/
testCompute()2036 bool GLSLTestBase::testCompute()
2037 {
2038 /* Test Result */
2039 bool result = true;
2040
2041 /* GL objects */
2042 Utils::texture color_tex(m_context);
2043 Utils::program program(m_context);
2044 Utils::texture source_tex(m_context);
2045
2046 /* Shaders */
2047 Utils::shaderSource compute_shader;
2048 initShaderSource(Utils::COMPUTE_SHADER, false, compute_shader);
2049
2050 /* Check if test support compute shaders */
2051 if (true == compute_shader.m_parts[0].m_code.empty())
2052 {
2053 return true;
2054 }
2055
2056 /* Build program */
2057 try
2058 {
2059 program.build(compute_shader, 0 /* fragment shader */, 0 /* geometry shader */,
2060 0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
2061 0 /* varying names */, 0 /* n varying names */, false);
2062 }
2063 catch (Utils::shaderCompilationException& exc)
2064 {
2065 /* Something wrong with compilation, test case failed */
2066 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2067
2068 message << "Shader compilation failed. Error message: " << exc.m_error_message;
2069
2070 Utils::program::printShaderSource(exc.m_shader_source, message);
2071
2072 message << tcu::TestLog::EndMessage;
2073
2074 return false;
2075 }
2076 catch (Utils::programLinkageException& exc)
2077 {
2078 /* Something wrong with linking, test case failed */
2079 m_context.getTestContext().getLog() << tcu::TestLog::Message
2080 << "Program linking failed. Error message: " << exc.m_error_message
2081 << tcu::TestLog::EndMessage;
2082 return false;
2083 }
2084
2085 /* Log shaders, for debugging */
2086 #if IS_DEBUG
2087 {
2088 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2089
2090 Utils::program::printShaderSource(compute_shader, message);
2091
2092 message << tcu::TestLog::EndMessage;
2093 }
2094 #endif /* IS_DEBUG */
2095
2096 /* Set current program */
2097 program.use();
2098
2099 /* Prepare image unit */
2100 prepareImage(program, color_tex);
2101
2102 /* Test specific preparation of source texture */
2103 const GLchar* sampler_name = prepareSourceTexture(source_tex);
2104 if (0 != sampler_name)
2105 {
2106 bindTextureToSampler(program, source_tex, sampler_name);
2107 }
2108
2109 /* Set up uniforms */
2110 prepareUniforms(program);
2111
2112 /* GL entry points */
2113 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2114
2115 /* Draw */
2116 gl.dispatchCompute(m_color_texture_width, m_color_texture_height, 1);
2117 GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
2118
2119 /* Return result of verification */
2120 result = checkResults(color_tex);
2121
2122 /* Release extra resource for the test */
2123 releaseResource();
2124
2125 return result;
2126 }
2127
2128 /** Execute test with draw array operation
2129 *
2130 * @param use_version_400 Select if 400 or 420 should be used
2131 *
2132 * @return true if test pass, false otherwise
2133 **/
testDrawArray(bool use_version_400)2134 bool GLSLTestBase::testDrawArray(bool use_version_400)
2135 {
2136 /* Test Result */
2137 bool result = true;
2138
2139 /* GL objects */
2140 Utils::texture color_tex(m_context);
2141 Utils::framebuffer framebuffer(m_context);
2142 Utils::program program(m_context);
2143 Utils::texture source_tex(m_context);
2144 Utils::vertexArray vao(m_context);
2145 Utils::buffer vertex_buffer(m_context);
2146
2147 /* Shaders */
2148 Utils::shaderSource fragment_data;
2149 Utils::shaderSource geometry_data;
2150 Utils::shaderSource tess_ctrl_data;
2151 Utils::shaderSource tess_eval_data;
2152 Utils::shaderSource vertex_data;
2153
2154 initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
2155 initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
2156 initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
2157 initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
2158 initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
2159
2160 /* Build program */
2161 try
2162 {
2163 program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
2164 0 /* varying names */, 0 /* n varying names */, false);
2165 }
2166 catch (Utils::shaderCompilationException& exc)
2167 {
2168 /* Something wrong with compilation, test case failed */
2169 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2170
2171 message << "Shader compilation failed. Error message: " << exc.m_error_message;
2172
2173 Utils::program::printShaderSource(exc.m_shader_source, message);
2174
2175 message << tcu::TestLog::EndMessage;
2176
2177 return false;
2178 }
2179 catch (Utils::programLinkageException& exc)
2180 {
2181 /* Something wrong with linking, test case failed */
2182 m_context.getTestContext().getLog() << tcu::TestLog::Message
2183 << "Program linking failed. Error message: " << exc.m_error_message
2184 << tcu::TestLog::EndMessage;
2185 return false;
2186 }
2187
2188 /* Log shaders, for debugging */
2189 #if IS_DEBUG
2190 {
2191 const Utils::shaderSource* data[] = { &vertex_data, &tess_ctrl_data, &tess_eval_data, &geometry_data,
2192 &fragment_data };
2193
2194 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
2195
2196 for (GLuint i = 0; i < 5; ++i)
2197 {
2198 Utils::program::printShaderSource(*data[i], message);
2199 }
2200
2201 message << tcu::TestLog::EndMessage;
2202 }
2203 #endif /* IS_DEBUG */
2204
2205 /* Test specific preparation of vertex buffer and vao*/
2206 prepareVertexBuffer(program, vertex_buffer, vao);
2207
2208 /* Set current program */
2209 program.use();
2210
2211 /* Prepare framebuffer */
2212 prepareFramebuffer(framebuffer, color_tex);
2213
2214 /* Test specific preparation of source texture */
2215 const GLchar* sampler_name = prepareSourceTexture(source_tex);
2216 if (0 != sampler_name)
2217 {
2218 bindTextureToSampler(program, source_tex, sampler_name);
2219 }
2220
2221 /* Set up uniforms */
2222 prepareUniforms(program);
2223
2224 /* GL entry points */
2225 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2226
2227 /* Draw */
2228 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
2229 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
2230
2231 /* Return result of verification */
2232 result = checkResults(color_tex);
2233
2234 /* Release extra resource for the test */
2235 releaseResource();
2236
2237 return result;
2238 }
2239
2240 /** Constructor
2241 *
2242 * @param context Test context
2243 * @param test_name Test name
2244 * @param test_description Test description
2245 **/
NegativeTestBase(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)2246 NegativeTestBase::NegativeTestBase(deqp::Context& context, const glw::GLchar* test_name,
2247 const glw::GLchar* test_description)
2248 : TestBase(context, test_name, test_description)
2249 {
2250 /* Nothing to be done here */
2251 }
2252
2253 /** Execute test with compute shader
2254 *
2255 * @return true if test pass, false otherwise
2256 **/
testCompute()2257 bool NegativeTestBase::testCompute()
2258 {
2259 /* GL objects */
2260 Utils::program program(m_context);
2261
2262 /* Shaders */
2263 Utils::shaderSource conmpute_data;
2264 initShaderSource(Utils::COMPUTE_SHADER, false, conmpute_data);
2265
2266 /* Build program */
2267 try
2268 {
2269 program.build(conmpute_data /* compute shader */, 0 /* fragment shader */, 0 /* geometry shader */,
2270 0 /* tesselation control shader */, 0 /* tesselation evaluation shader */, 0 /* vertex shader */,
2271 0 /* varying names */, 0 /* n varying names */, false);
2272 }
2273 catch (Utils::shaderCompilationException& exc)
2274 {
2275 /* Compilation failed, as expected. Verify that reason of failure is as expected */
2276 m_context.getTestContext().getLog() << tcu::TestLog::Message
2277 << "Shader compilation error message: " << exc.m_error_message
2278 << tcu::TestLog::EndMessage;
2279 return true;
2280 }
2281 catch (Utils::programLinkageException& exc)
2282 {
2283 /* Something wrong with linking, test case failed */
2284 m_context.getTestContext().getLog() << tcu::TestLog::Message
2285 << "Program linking failed. Error message: " << exc.m_error_message
2286 << tcu::TestLog::EndMessage;
2287 return true;
2288 }
2289
2290 /* Build process succeded */
2291 return false;
2292 }
2293
2294 /** Execute test with draw array operation
2295 *
2296 * @param use_version_400 Select if 400 or 420 should be used
2297 *
2298 * @return true if test pass, false otherwise
2299 **/
testDrawArray(bool use_version_400)2300 bool NegativeTestBase::testDrawArray(bool use_version_400)
2301 {
2302 /* GL objects */
2303 Utils::program program(m_context);
2304
2305 /* Shaders */
2306 Utils::shaderSource fragment_data;
2307 Utils::shaderSource geometry_data;
2308 Utils::shaderSource tess_ctrl_data;
2309 Utils::shaderSource tess_eval_data;
2310 Utils::shaderSource vertex_data;
2311
2312 initShaderSource(Utils::FRAGMENT_SHADER, use_version_400, fragment_data);
2313 initShaderSource(Utils::GEOMETRY_SHADER, use_version_400, geometry_data);
2314 initShaderSource(Utils::TESS_CTRL_SHADER, use_version_400, tess_ctrl_data);
2315 initShaderSource(Utils::TESS_EVAL_SHADER, use_version_400, tess_eval_data);
2316 initShaderSource(Utils::VERTEX_SHADER, use_version_400, vertex_data);
2317
2318 /* Build program */
2319 try
2320 {
2321 program.build(0 /* compute shader */, fragment_data, geometry_data, tess_ctrl_data, tess_eval_data, vertex_data,
2322 0 /* varying names */, 0 /* n varying names */, false);
2323 }
2324 catch (Utils::shaderCompilationException& exc)
2325 {
2326 /* Compilation failed, as expected. Verify that reason of failure is as expected */
2327 m_context.getTestContext().getLog() << tcu::TestLog::Message
2328 << "Shader compilation error message: " << exc.m_error_message
2329 << tcu::TestLog::EndMessage;
2330 return true;
2331 }
2332 catch (Utils::programLinkageException& exc)
2333 {
2334 /* Something wrong with linking, test case failed */
2335 m_context.getTestContext().getLog() << tcu::TestLog::Message
2336 << "Program linking failed. Error message: " << exc.m_error_message
2337 << tcu::TestLog::EndMessage;
2338 return true;
2339 }
2340
2341 /* Build process succeded */
2342 return false;
2343 }
2344
2345 /* Constants used by BindingImageTest */
2346 const GLuint BindingImageTest::m_width = 16;
2347 const GLuint BindingImageTest::m_green_color = 0xff00ff00;
2348 const GLuint BindingImageTest::m_height = 16;
2349 const GLuint BindingImageTest::m_depth = 6;
2350
2351 /** Constructor
2352 *
2353 * @param context Test context
2354 **/
BindingImageTest(deqp::Context & context,const glw::GLchar * test_name,const glw::GLchar * test_description)2355 BindingImageTest::BindingImageTest(deqp::Context& context, const glw::GLchar* test_name,
2356 const glw::GLchar* test_description)
2357 : GLSLTestBase(context, test_name, test_description)
2358 {
2359 /* Nothing to be done */
2360 }
2361
2362 /** Prepare buffer, filled with given color
2363 *
2364 * @param buffer Buffer object
2365 * @param color Color
2366 **/
prepareBuffer(Utils::buffer & buffer,GLuint color)2367 void BindingImageTest::prepareBuffer(Utils::buffer& buffer, GLuint color)
2368 {
2369 std::vector<GLuint> texture_data;
2370 texture_data.resize(m_width);
2371
2372 buffer.generate(GL_TEXTURE_BUFFER);
2373
2374 for (GLuint i = 0; i < texture_data.size(); ++i)
2375 {
2376 texture_data[i] = color;
2377 }
2378
2379 buffer.update(m_width * sizeof(GLuint), &texture_data[0], GL_STATIC_DRAW);
2380 }
2381
2382 /** Prepare texture of given type filled with given color and bind to specified image unit
2383 *
2384 * @param texture Texture
2385 * @param buffer Buffer
2386 * @param texture_type Type of texture
2387 * @param color Color
2388 **/
prepareTexture(Utils::texture & texture,const Utils::buffer & buffer,Utils::TEXTURE_TYPES texture_type,GLuint color,GLuint unit)2389 void BindingImageTest::prepareTexture(Utils::texture& texture, const Utils::buffer& buffer,
2390 Utils::TEXTURE_TYPES texture_type, GLuint color, GLuint unit)
2391 {
2392 std::vector<GLuint> texture_data;
2393 texture_data.resize(m_width * m_height * m_depth);
2394
2395 GLboolean is_layered = GL_FALSE;
2396
2397 for (GLuint i = 0; i < texture_data.size(); ++i)
2398 {
2399 texture_data[i] = color;
2400 }
2401
2402 if (Utils::TEX_BUFFER != texture_type)
2403 {
2404 texture.create(m_width, m_height, m_depth, GL_RGBA8, texture_type);
2405
2406 texture.update(m_width, m_height, m_depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
2407 }
2408 else
2409 {
2410 buffer.bind();
2411
2412 texture.createBuffer(GL_RGBA8, buffer.m_id);
2413 }
2414
2415 switch (texture_type)
2416 {
2417 case Utils::TEX_1D_ARRAY:
2418 case Utils::TEX_2D_ARRAY:
2419 case Utils::TEX_3D:
2420 case Utils::TEX_CUBE:
2421 is_layered = GL_TRUE;
2422 break;
2423 default:
2424 break;
2425 }
2426
2427 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2428
2429 gl.bindImageTexture(unit, texture.m_id, 0 /* level */, is_layered /* layered */, 0 /* layer */, GL_READ_WRITE,
2430 GL_RGBA8);
2431 GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
2432 }
2433
2434 /** Verifies that texel at offset 0 is green
2435 *
2436 * @param buffer Buffer object
2437 *
2438 * @return true if texel at offset 0 is green, false otherwise
2439 **/
verifyBuffer(const Utils::buffer & buffer) const2440 bool BindingImageTest::verifyBuffer(const Utils::buffer& buffer) const
2441 {
2442 GLuint* data = (GLuint*)buffer.map(GL_READ_ONLY);
2443
2444 GLuint color = data[0];
2445
2446 buffer.unmap();
2447
2448 return (m_green_color == color);
2449 }
2450
2451 /** Verifies that texel at offset 0 is green
2452 *
2453 * @param buffer Buffer object
2454 *
2455 * @return true if texel at offset 0 is green, false otherwise
2456 **/
verifyTexture(const Utils::texture & texture) const2457 bool BindingImageTest::verifyTexture(const Utils::texture& texture) const
2458 {
2459 static const GLuint texture_data_size = m_width * m_height * m_depth;
2460
2461 std::vector<glw::GLuint> texture_data;
2462 texture_data.resize(texture_data_size);
2463
2464 texture.get(GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
2465
2466 GLuint color = texture_data[0];
2467
2468 return (m_green_color == color);
2469 }
2470
2471 /* Constants used by LineContinuationTest */
2472 const GLuint LineContinuationTest::m_n_repetitions = 20;
2473 const GLchar* LineContinuationTest::m_texture_coordinates_name = "texture_coordinates";
2474
2475 /** Constructor
2476 *
2477 * @param context Test context
2478 **/
LineContinuationTest(deqp::Context & context)2479 LineContinuationTest::LineContinuationTest(deqp::Context& context) : GLSLTestBase(context, "line_continuation", "desc")
2480 {
2481 /* Nothing to be done here */
2482 }
2483
2484 /** Overwrite getShaderSourceConfig method
2485 *
2486 * @param out_n_parts Number of source parts used by this test case
2487 * @param out_use_lengths If source lengths shall be provided to compiler
2488 **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)2489 void LineContinuationTest::getShaderSourceConfig(GLuint& out_n_parts, bool& out_use_lengths)
2490 {
2491 out_n_parts = (true == isShaderMultipart()) ? 2 : 1;
2492 out_use_lengths = useSourceLengths();
2493 }
2494
2495 /** Set up next test case
2496 *
2497 * @param test_case_index Index of next test case
2498 *
2499 * @return false if there is no more test cases, true otherwise
2500 **/
prepareNextTestCase(glw::GLuint test_case_index)2501 bool LineContinuationTest::prepareNextTestCase(glw::GLuint test_case_index)
2502 {
2503 static const testCase test_cases[] = { { ASSIGNMENT_BEFORE_OPERATOR, ONCE, UNIX },
2504 { ASSIGNMENT_BEFORE_OPERATOR, ONCE, DOS },
2505 { ASSIGNMENT_BEFORE_OPERATOR, MULTIPLE_TIMES, UNIX },
2506 { ASSIGNMENT_BEFORE_OPERATOR, MULTIPLE_TIMES, DOS },
2507 { ASSIGNMENT_AFTER_OPERATOR, ONCE, UNIX },
2508 { ASSIGNMENT_AFTER_OPERATOR, ONCE, DOS },
2509 { ASSIGNMENT_AFTER_OPERATOR, MULTIPLE_TIMES, UNIX },
2510 { ASSIGNMENT_AFTER_OPERATOR, MULTIPLE_TIMES, DOS },
2511 { VECTOR_VARIABLE_INITIALIZER, ONCE, UNIX },
2512 { VECTOR_VARIABLE_INITIALIZER, ONCE, DOS },
2513 { VECTOR_VARIABLE_INITIALIZER, MULTIPLE_TIMES, UNIX },
2514 { VECTOR_VARIABLE_INITIALIZER, MULTIPLE_TIMES, DOS },
2515 { TOKEN_INSIDE_FUNCTION_NAME, ONCE, UNIX },
2516 { TOKEN_INSIDE_FUNCTION_NAME, ONCE, DOS },
2517 { TOKEN_INSIDE_FUNCTION_NAME, MULTIPLE_TIMES, UNIX },
2518 { TOKEN_INSIDE_FUNCTION_NAME, MULTIPLE_TIMES, DOS },
2519 { TOKEN_INSIDE_TYPE_NAME, ONCE, UNIX },
2520 { TOKEN_INSIDE_TYPE_NAME, ONCE, DOS },
2521 { TOKEN_INSIDE_TYPE_NAME, MULTIPLE_TIMES, UNIX },
2522 { TOKEN_INSIDE_TYPE_NAME, MULTIPLE_TIMES, DOS },
2523 { TOKEN_INSIDE_VARIABLE_NAME, ONCE, UNIX },
2524 { TOKEN_INSIDE_VARIABLE_NAME, ONCE, DOS },
2525 { TOKEN_INSIDE_VARIABLE_NAME, MULTIPLE_TIMES, UNIX },
2526 { TOKEN_INSIDE_VARIABLE_NAME, MULTIPLE_TIMES, DOS },
2527 { PREPROCESSOR_TOKEN_INSIDE, ONCE, UNIX },
2528 { PREPROCESSOR_TOKEN_INSIDE, ONCE, DOS },
2529 { PREPROCESSOR_TOKEN_INSIDE, MULTIPLE_TIMES, UNIX },
2530 { PREPROCESSOR_TOKEN_INSIDE, MULTIPLE_TIMES, DOS },
2531 { PREPROCESSOR_TOKEN_BETWEEN, ONCE, UNIX },
2532 { PREPROCESSOR_TOKEN_BETWEEN, ONCE, DOS },
2533 { PREPROCESSOR_TOKEN_BETWEEN, MULTIPLE_TIMES, UNIX },
2534 { PREPROCESSOR_TOKEN_BETWEEN, MULTIPLE_TIMES, DOS },
2535 { COMMENT, ONCE, UNIX },
2536 { COMMENT, ONCE, DOS },
2537 { COMMENT, MULTIPLE_TIMES, UNIX },
2538 { COMMENT, MULTIPLE_TIMES, DOS },
2539 { SOURCE_TERMINATION_NULL, ONCE, UNIX },
2540 { SOURCE_TERMINATION_NULL, ONCE, DOS },
2541 { SOURCE_TERMINATION_NULL, MULTIPLE_TIMES, UNIX },
2542 { SOURCE_TERMINATION_NULL, MULTIPLE_TIMES, DOS },
2543 { SOURCE_TERMINATION_NON_NULL, ONCE, UNIX },
2544 { SOURCE_TERMINATION_NON_NULL, ONCE, DOS },
2545 { SOURCE_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX },
2546 { SOURCE_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS },
2547 { PART_TERMINATION_NULL, ONCE, UNIX },
2548 { PART_TERMINATION_NULL, ONCE, DOS },
2549 { PART_TERMINATION_NULL, MULTIPLE_TIMES, UNIX },
2550 { PART_TERMINATION_NULL, MULTIPLE_TIMES, DOS },
2551 { PART_NEXT_TO_TERMINATION_NULL, ONCE, UNIX },
2552 { PART_NEXT_TO_TERMINATION_NULL, ONCE, DOS },
2553 { PART_NEXT_TO_TERMINATION_NULL, MULTIPLE_TIMES, UNIX },
2554 { PART_NEXT_TO_TERMINATION_NULL, MULTIPLE_TIMES, DOS },
2555 { PART_TERMINATION_NON_NULL, ONCE, UNIX },
2556 { PART_TERMINATION_NON_NULL, ONCE, DOS },
2557 { PART_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX },
2558 { PART_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS },
2559 { PART_NEXT_TO_TERMINATION_NON_NULL, ONCE, UNIX },
2560 { PART_NEXT_TO_TERMINATION_NON_NULL, ONCE, DOS },
2561 { PART_NEXT_TO_TERMINATION_NON_NULL, MULTIPLE_TIMES, UNIX },
2562 { PART_NEXT_TO_TERMINATION_NON_NULL, MULTIPLE_TIMES, DOS } };
2563
2564 static const GLuint max_test_cases = sizeof(test_cases) / sizeof(testCase);
2565
2566 if ((GLuint)-1 == test_case_index)
2567 {
2568 m_test_case.m_case = DEBUG_CASE;
2569 }
2570 else if (max_test_cases <= test_case_index)
2571 {
2572 return false;
2573 }
2574 else
2575 {
2576 m_test_case = test_cases[test_case_index];
2577 }
2578
2579 m_context.getTestContext().getLog() << tcu::TestLog::Message
2580 << "Test case: " << repetitionsToStr((REPETITIONS)m_test_case.m_repetitions)
2581 << " line continuation, with "
2582 << lineEndingsToStr((LINE_ENDINGS)m_test_case.m_line_endings)
2583 << " line endings, is placed " << casesToStr((CASES)m_test_case.m_case)
2584 << tcu::TestLog::EndMessage;
2585
2586 return true;
2587 }
2588
2589 /** Prepare source for given shader stage
2590 *
2591 * @param in_stage Shader stage, compute shader will use 430
2592 * @param in_use_version_400 Select if 400 or 420 should be used
2593 * @param out_source Prepared shader source instance
2594 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)2595 void LineContinuationTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
2596 Utils::shaderSource& out_source)
2597 {
2598 if (Utils::COMPUTE_SHADER == in_stage)
2599 {
2600 prepareComputShaderSource(out_source);
2601 }
2602 else
2603 {
2604 prepareShaderSourceForDraw(in_stage, in_use_version_400, out_source);
2605 }
2606 }
2607
2608 /** Prepare compute shader source
2609 *
2610 * @param source Result shader source
2611 **/
prepareComputShaderSource(Utils::shaderSource & source)2612 void LineContinuationTest::prepareComputShaderSource(Utils::shaderSource& source)
2613 {
2614 static const GLchar* shader_template_part_0 =
2615 "#version 430\n"
2616 "\n"
2617 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2618 "\n"
2619 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
2620 "\n"
2621 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2622 "\n"
2623 "writeonly uniform image2D uni_image;\n"
2624 " uniform sampler2D uni_sampler;\n"
2625 "\n"
2626 "void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2627 "{\n"
2628 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), inVARIABLE_CASE_value);\n"
2629 "}\n"
2630 "\n"
2631 "#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2632 "PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2633 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2634
2635 static const GLchar* shader_template_part_1 =
2636 "void main()\n"
2637 "{\n"
2638 " ivec2 coordinates ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE "
2639 "ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
2640 " vec4 sampled_color = texelFetch(uni_sampler, coordinates, 0 /* lod */);\n"
2641 " vec4 result = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2642 "\n"
2643 " if (vec4(0, 0, 1, 1) == sampled_color)\n"
2644 " {\n"
2645 " result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2646 " }\n"
2647 " else\n"
2648 " {\n"
2649 " result = vec4(coordinates.xy, sampled_color.rg);\n"
2650 " }\n"
2651 "\n"
2652 " SET_RESULT(result);"
2653 "}\n";
2654
2655 /* Init strings with templates and replace all CASE tokens */
2656 if (true == isShaderMultipart())
2657 {
2658 source.m_parts[0].m_code = shader_template_part_0;
2659 source.m_parts[1].m_code = shader_template_part_1;
2660
2661 replaceAllCaseTokens(source.m_parts[0].m_code);
2662 replaceAllCaseTokens(source.m_parts[1].m_code);
2663 }
2664 else
2665 {
2666 source.m_parts[0].m_code = shader_template_part_0;
2667 source.m_parts[0].m_code.append(shader_template_part_1);
2668
2669 replaceAllCaseTokens(source.m_parts[0].m_code);
2670 }
2671 }
2672
2673 /** Prepare source for given shader stage
2674 *
2675 * @param stage Shader stage, compute shader will use 430
2676 * @param use_version_400 Select if 400 or 420 should be used
2677 * @param source Result shader sources
2678 **/
prepareShaderSourceForDraw(Utils::SHADER_STAGES stage,bool use_version_400,Utils::shaderSource & source)2679 void LineContinuationTest::prepareShaderSourceForDraw(Utils::SHADER_STAGES stage, bool use_version_400,
2680 Utils::shaderSource& source)
2681 {
2682 /* Templates */
2683 static const GLchar* shader_template_part_0 =
2684 "VERSION\n"
2685 "\n"
2686 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
2687 "\n"
2688 "STAGE_SPECIFIC\n"
2689 "\n"
2690 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
2691 "\n"
2692 "IN_COLOR_DEFINITION\n"
2693 "IN_TEXTURE_COORDINATES_DEFINITION\n"
2694 "OUT_COLOR_DEFINITION\n"
2695 "OUT_TEXTURE_COORDINATES_DEFINITION\n"
2696 "uniform sampler2D uni_sampler;\n"
2697 "\n"
2698 "void funFUNCTION_CASEction(in veTYPE_CASEc4 in_vVARIABLE_CASEalue)\n"
2699 "{\n"
2700 " OUT_COLOR ASSIGNMENT_BEFORE_OPERATOR_CASE=ASSIGNMENT_AFTER_OPERATOR_CASE inVARIABLE_CASE_value;\n"
2701 "}\n"
2702 "\n"
2703 "#define SET_PREPROCESSOR_INSIDE_CASERESULT(XX) "
2704 "PREPROCESSOR_BETWEEN_CASEfuncFUNCTION_CASEtion(XPREPROCESSOR_INSIDE_CASEX)\n"
2705 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2706
2707 static const GLchar* shader_template_part_1 =
2708 "void main()\n"
2709 "{\n"
2710 " vec2 coordinates = TEXTURE_COORDINATES;\n"
2711 " vec4 sampled_color = texture(uni_sampler, coordinates);\n"
2712 " vec4 result = vec4(0, 0VECTOR_VARIABLE_INITIALIZER_CASE, 0, 1);\n"
2713 "\n"
2714 " if (PASS_CONDITION)\n"
2715 " {\n"
2716 " result = vecTYPE_CASE4(VECTOR_VARIABLE_INITIALIZER_CASE0, 1, 0, 1);\n"
2717 " }\n"
2718 " else\n"
2719 " {\n"
2720 " result = vec4(coordinates.xy, sampled_color.rg);\n"
2721 " }\n"
2722 "\n"
2723 "STORE_RESULTS"
2724 "}\n"
2725 "NEXT_TO_TERMINATION_CASE\nTERMINATION_CASE";
2726
2727 static const GLchar* store_results_template = " SET_RESULT(result);\n"
2728 " TEXTURE_COORDINATES = coordinates;\n";
2729
2730 static const GLchar* store_results_tcs_template = " SET_RESULT(result);\n"
2731 " TEXTURE_COORDINATES = coordinates;\n"
2732 " gl_TessLevelOuter[0] = 1.0;\n"
2733 " gl_TessLevelOuter[1] = 1.0;\n"
2734 " gl_TessLevelOuter[2] = 1.0;\n"
2735 " gl_TessLevelOuter[3] = 1.0;\n"
2736 " gl_TessLevelInner[0] = 1.0;\n"
2737 " gl_TessLevelInner[1] = 1.0;\n";
2738
2739 static const GLchar* store_results_fs_template = " SET_RESULT(result);\n";
2740
2741 static const GLchar* store_results_gs_template = " gl_Position = vec4(-1, -1, 0, 1);\n"
2742 " SET_RESULT(result);\n"
2743 " TEXTURE_COORDINATES = coordinates + vec2(-0.25, -0.25);\n"
2744 " EmitVertex();\n"
2745 " gl_Position = vec4(-1, 1, 0, 1);\n"
2746 " SET_RESULT(result);\n"
2747 " TEXTURE_COORDINATES = coordinates + vec2(-0.25, 0.25);\n"
2748 " EmitVertex();\n"
2749 " gl_Position = vec4(1, -1, 0, 1);\n"
2750 " SET_RESULT(result);\n"
2751 " TEXTURE_COORDINATES = coordinates + vec2(0.25, -0.25);\n"
2752 " EmitVertex();\n"
2753 " gl_Position = vec4(1, 1, 0, 1);\n"
2754 " SET_RESULT(result);\n"
2755 " TEXTURE_COORDINATES = coordinates + vec2(0.25, 0.25);\n"
2756 " EmitVertex();\n";
2757
2758 static const GLchar* pass_condition_template = "(EXPECTED_VALUE == sampled_color) &&\n"
2759 " (vec4(0, 1, 0, 1) == IN_COLOR) ";
2760
2761 static const GLchar* pass_condition_vs_template = "EXPECTED_VALUE == sampled_color";
2762
2763 /* Tokens to be replaced with GLSL stuff */
2764 static const GLchar* token_version = "VERSION";
2765 static const GLchar* token_stage_specific = "STAGE_SPECIFIC";
2766
2767 static const GLchar* token_in_color_definition = "IN_COLOR_DEFINITION";
2768 static const GLchar* token_in_tex_coord_definition = "IN_TEXTURE_COORDINATES_DEFINITION";
2769 static const GLchar* token_out_color_definition = "OUT_COLOR_DEFINITION";
2770 static const GLchar* token_out_tex_coord_definition = "OUT_TEXTURE_COORDINATES_DEFINITION";
2771
2772 static const GLchar* token_expected_value = "EXPECTED_VALUE";
2773 static const GLchar* token_texture_coordinates = "TEXTURE_COORDINATES";
2774 static const GLchar* token_in_color = "IN_COLOR";
2775 static const GLchar* token_out_color = "OUT_COLOR";
2776
2777 static const GLchar* token_store_results = "STORE_RESULTS";
2778 static const GLchar* token_pass_condition = "PASS_CONDITION";
2779
2780 /* Name of variable and empty string*/
2781 static const GLchar* color_name = "color";
2782 static const GLchar* empty = "";
2783
2784 /* GLSL stuff */
2785 const GLchar* version = getVersionString(stage, use_version_400);
2786 const GLchar* stage_specific_layout = getStageSpecificLayout(stage);
2787 const GLchar* expected_value = getExpectedValueString();
2788
2789 /* Qualifiers */
2790 Utils::qualifierSet in;
2791 Utils::qualifierSet out;
2792 in.push_back(Utils::QUAL_IN);
2793 out.push_back(Utils::QUAL_OUT);
2794
2795 /* In/Out variables definitions and references */
2796 std::string in_tex_coord_reference;
2797 std::string out_tex_coord_reference;
2798 std::string in_color_reference;
2799 std::string out_color_reference;
2800 std::string in_tex_coord_definition;
2801 std::string out_tex_coord_definition;
2802 std::string in_color_definition;
2803 std::string out_color_definition;
2804
2805 Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec2", m_texture_coordinates_name, in_tex_coord_definition,
2806 in_tex_coord_reference);
2807 Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec2", m_texture_coordinates_name,
2808 out_tex_coord_definition, out_tex_coord_reference);
2809 Utils::prepareVariableStrings(stage, Utils::INPUT, in, "vec4", color_name, in_color_definition, in_color_reference);
2810 Utils::prepareVariableStrings(stage, Utils::OUTPUT, out, "vec4", color_name, out_color_definition,
2811 out_color_reference);
2812
2813 in_tex_coord_definition.append(";");
2814 out_tex_coord_definition.append(";");
2815 in_color_definition.append(";");
2816 out_color_definition.append(";");
2817
2818 /* Select pass condition and store results tempaltes */
2819 const GLchar* store_results = store_results_template;
2820 const GLchar* pass_condition = pass_condition_template;
2821
2822 switch (stage)
2823 {
2824 case Utils::FRAGMENT_SHADER:
2825 store_results = store_results_fs_template;
2826 break;
2827 case Utils::GEOMETRY_SHADER:
2828 store_results = store_results_gs_template;
2829 break;
2830 case Utils::TESS_CTRL_SHADER:
2831 store_results = store_results_tcs_template;
2832 break;
2833 case Utils::VERTEX_SHADER:
2834 pass_condition = pass_condition_vs_template;
2835 break;
2836 default:
2837 break;
2838 }
2839 const GLuint store_results_length = static_cast<GLuint>(strlen(store_results));
2840 const GLuint pass_condition_length = static_cast<GLuint>(strlen(pass_condition));
2841
2842 /* Init strings with templates and replace all CASE tokens */
2843 if (true == isShaderMultipart())
2844 {
2845 source.m_parts[0].m_code = shader_template_part_0;
2846 source.m_parts[1].m_code = shader_template_part_1;
2847
2848 replaceAllCaseTokens(source.m_parts[0].m_code);
2849 replaceAllCaseTokens(source.m_parts[1].m_code);
2850 }
2851 else
2852 {
2853 source.m_parts[0].m_code = shader_template_part_0;
2854 source.m_parts[0].m_code.append(shader_template_part_1);
2855
2856 replaceAllCaseTokens(source.m_parts[0].m_code);
2857 }
2858
2859 /* Get memory for shader source parts */
2860 const bool is_multipart = isShaderMultipart();
2861 size_t position = 0;
2862 std::string& shader_source_part_0 = source.m_parts[0].m_code;
2863 std::string& shader_source_part_1 = (true == is_multipart) ? source.m_parts[1].m_code : source.m_parts[0].m_code;
2864
2865 /* Replace tokens */
2866 /* Part 0 */
2867 Utils::replaceToken(token_version, position, version, shader_source_part_0);
2868
2869 Utils::replaceToken(token_stage_specific, position, stage_specific_layout, shader_source_part_0);
2870
2871 if (Utils::VERTEX_SHADER != stage)
2872 {
2873 Utils::replaceToken(token_in_color_definition, position, in_color_definition.c_str(), shader_source_part_0);
2874 }
2875 else
2876 {
2877 Utils::replaceToken(token_in_color_definition, position, empty, shader_source_part_0);
2878 }
2879 Utils::replaceToken(token_in_tex_coord_definition, position, in_tex_coord_definition.c_str(), shader_source_part_0);
2880 Utils::replaceToken(token_out_color_definition, position, out_color_definition.c_str(), shader_source_part_0);
2881 if (Utils::FRAGMENT_SHADER == stage)
2882 {
2883 Utils::replaceToken(token_out_tex_coord_definition, position, empty, shader_source_part_0);
2884 }
2885 else
2886 {
2887 Utils::replaceToken(token_out_tex_coord_definition, position, out_tex_coord_definition.c_str(),
2888 shader_source_part_0);
2889 }
2890
2891 Utils::replaceToken(token_out_color, position, out_color_reference.c_str(), shader_source_part_0);
2892
2893 /* Part 1 */
2894 if (true == is_multipart)
2895 {
2896 position = 0;
2897 }
2898
2899 Utils::replaceToken(token_texture_coordinates, position, in_tex_coord_reference.c_str(), shader_source_part_1);
2900
2901 Utils::replaceToken(token_pass_condition, position, pass_condition, shader_source_part_1);
2902 position -= pass_condition_length;
2903
2904 Utils::replaceToken(token_expected_value, position, expected_value, shader_source_part_1);
2905 if (Utils::VERTEX_SHADER != stage)
2906 {
2907 Utils::replaceToken(token_in_color, position, in_color_reference.c_str(), shader_source_part_1);
2908 }
2909
2910 Utils::replaceToken(token_store_results, position, store_results, shader_source_part_1);
2911 position -= store_results_length;
2912
2913 if (Utils::GEOMETRY_SHADER == stage)
2914 {
2915 for (GLuint i = 0; i < 4; ++i)
2916 {
2917 Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(),
2918 shader_source_part_1);
2919 }
2920 }
2921 else if (Utils::FRAGMENT_SHADER == stage)
2922 {
2923 /* Nothing to be done */
2924 }
2925 else
2926 {
2927 Utils::replaceToken(token_texture_coordinates, position, out_tex_coord_reference.c_str(), shader_source_part_1);
2928 }
2929 }
2930
2931 /** Prepare texture
2932 *
2933 * @param texture Texutre to be created and filled with content
2934 *
2935 * @return Name of sampler uniform that should be used for the texture
2936 **/
prepareSourceTexture(Utils::texture & texture)2937 const GLchar* LineContinuationTest::prepareSourceTexture(Utils::texture& texture)
2938 {
2939 std::vector<GLuint> data;
2940 static const GLuint width = 64;
2941 static const GLuint height = 64;
2942 static const GLuint data_size = width * height;
2943 static const GLuint blue_color = 0xffff0000;
2944 static const GLuint grey_color = 0xaaaaaaaa;
2945
2946 data.resize(data_size);
2947
2948 for (GLuint i = 0; i < data_size; ++i)
2949 {
2950 data[i] = grey_color;
2951 }
2952
2953 for (GLuint y = 16; y < 48; ++y)
2954 {
2955 const GLuint line_offset = y * 64;
2956
2957 for (GLuint x = 16; x < 48; ++x)
2958 {
2959 const GLuint pixel_offset = x + line_offset;
2960
2961 data[pixel_offset] = blue_color;
2962 }
2963 }
2964
2965 texture.create(width, height, GL_RGBA8);
2966
2967 texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
2968
2969 return "uni_sampler";
2970 }
2971
2972 /** Prepare vertex buffer, vec2 tex_coord
2973 *
2974 * @param program Program object
2975 * @param buffer Vertex buffer
2976 * @param vao Vertex array object
2977 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)2978 void LineContinuationTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
2979 Utils::vertexArray& vao)
2980 {
2981 std::string tex_coord_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, m_texture_coordinates_name);
2982 GLint tex_coord_loc = program.getAttribLocation(tex_coord_name.c_str());
2983
2984 if (-1 == tex_coord_loc)
2985 {
2986 TCU_FAIL("Vertex attribute location is invalid");
2987 }
2988
2989 vao.generate();
2990 vao.bind();
2991
2992 buffer.generate(GL_ARRAY_BUFFER);
2993
2994 GLfloat data[] = { 0.5f, 0.5f, 0.5f, 0.5f };
2995 GLsizeiptr data_size = sizeof(data);
2996
2997 buffer.update(data_size, data, GL_STATIC_DRAW);
2998
2999 /* GL entry points */
3000 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3001
3002 /* Set up vao */
3003 gl.vertexAttribPointer(tex_coord_loc, 2 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
3004 0 /* offset */);
3005 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3006
3007 /* Enable attribute */
3008 gl.enableVertexAttribArray(tex_coord_loc);
3009 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3010 }
3011
3012 /** Get string describing test cases
3013 *
3014 * @param cases Test case
3015 *
3016 * @return String describing current test case
3017 **/
casesToStr(CASES cases) const3018 const GLchar* LineContinuationTest::casesToStr(CASES cases) const
3019 {
3020 const GLchar* result = 0;
3021 switch (cases)
3022 {
3023 case ASSIGNMENT_BEFORE_OPERATOR:
3024 result = "just before assignment operator";
3025 break;
3026 case ASSIGNMENT_AFTER_OPERATOR:
3027 result = "just after assignment operator";
3028 break;
3029 case VECTOR_VARIABLE_INITIALIZER:
3030 result = "inside vector variable initializer";
3031 break;
3032 case TOKEN_INSIDE_FUNCTION_NAME:
3033 result = "inside function name";
3034 break;
3035 case TOKEN_INSIDE_TYPE_NAME:
3036 result = "inside type name";
3037 break;
3038 case TOKEN_INSIDE_VARIABLE_NAME:
3039 result = "inside variable name";
3040 break;
3041 case PREPROCESSOR_TOKEN_INSIDE:
3042 result = "inside preprocessor token";
3043 break;
3044 case PREPROCESSOR_TOKEN_BETWEEN:
3045 result = "between preprocessor token";
3046 break;
3047 case COMMENT:
3048 result = "inside comment";
3049 break;
3050 case SOURCE_TERMINATION_NULL:
3051 result = "just before null terminating source";
3052 break;
3053 case SOURCE_TERMINATION_NON_NULL:
3054 result = "as last character in source string, without null termination";
3055 break;
3056 case PART_TERMINATION_NULL:
3057 result = "just before null terminating part of source";
3058 break;
3059 case PART_NEXT_TO_TERMINATION_NULL:
3060 result = "just before last character in part of source";
3061 break;
3062 case PART_TERMINATION_NON_NULL:
3063 result = "as last character in part string, without null termination";
3064 break;
3065 case PART_NEXT_TO_TERMINATION_NON_NULL:
3066 result = "just before last character in part string, without null termination";
3067 break;
3068 case DEBUG_CASE: /* intended fall through */
3069 default:
3070 result = "nowhere at all. This is debug!";
3071 break;
3072 }
3073
3074 return result;
3075 }
3076
3077 /** Get expected value, blue color as vec4
3078 *
3079 * @return blue color
3080 **/
getExpectedValueString() const3081 const GLchar* LineContinuationTest::getExpectedValueString() const
3082 {
3083 return "vec4(0, 0, 1, 1)";
3084 }
3085
3086 /** Get line continuation string, single or multiple \
3087 *
3088 * @return String
3089 **/
getLineContinuationString() const3090 std::string LineContinuationTest::getLineContinuationString() const
3091 {
3092 static const GLchar line_continuation_ending_dos[] = { '\\', 0x0d, 0x0a, 0x00 };
3093 static const GLchar line_continuation_ending_unix[] = { '\\', 0x0a, 0x00 };
3094
3095 std::string result;
3096 const GLchar* selected_string;
3097
3098 if (DOS == m_test_case.m_line_endings)
3099 {
3100 selected_string = line_continuation_ending_dos;
3101 }
3102 else
3103 {
3104 selected_string = line_continuation_ending_unix;
3105 }
3106
3107 GLuint n_repetitions = (ONCE == m_test_case.m_repetitions) ? 1 : m_n_repetitions;
3108
3109 for (GLuint i = 0; i < n_repetitions; ++i)
3110 {
3111 result.append(selected_string);
3112 }
3113
3114 return result;
3115 }
3116
3117 /** Decides if shader should consist of multiple parts for the current test case
3118 *
3119 * @return true if test case requires multiple parts, false otherwise
3120 **/
isShaderMultipart() const3121 bool LineContinuationTest::isShaderMultipart() const
3122 {
3123 bool result;
3124
3125 switch (m_test_case.m_case)
3126 {
3127 case ASSIGNMENT_BEFORE_OPERATOR:
3128 case ASSIGNMENT_AFTER_OPERATOR:
3129 case VECTOR_VARIABLE_INITIALIZER:
3130 case TOKEN_INSIDE_FUNCTION_NAME:
3131 case TOKEN_INSIDE_TYPE_NAME:
3132 case TOKEN_INSIDE_VARIABLE_NAME:
3133 case PREPROCESSOR_TOKEN_INSIDE:
3134 case PREPROCESSOR_TOKEN_BETWEEN:
3135 case COMMENT:
3136 case SOURCE_TERMINATION_NULL:
3137 case SOURCE_TERMINATION_NON_NULL:
3138 default:
3139 result = false;
3140 break;
3141 case PART_TERMINATION_NULL:
3142 case PART_NEXT_TO_TERMINATION_NULL:
3143 case PART_TERMINATION_NON_NULL:
3144 case PART_NEXT_TO_TERMINATION_NON_NULL:
3145 result = true;
3146 break;
3147 }
3148
3149 return result;
3150 }
3151
3152 /** String describing line endings
3153 *
3154 * @param line_ending Line ending enum
3155 *
3156 * @return "unix" or "dos" strings
3157 **/
lineEndingsToStr(LINE_ENDINGS line_ending) const3158 const GLchar* LineContinuationTest::lineEndingsToStr(LINE_ENDINGS line_ending) const
3159 {
3160 const GLchar* result = 0;
3161
3162 if (UNIX == line_ending)
3163 {
3164 result = "unix";
3165 }
3166 else
3167 {
3168 result = "dos";
3169 }
3170
3171 return result;
3172 }
3173
3174 /** String describing number of repetitions
3175 *
3176 * @param repetitions Repetitions enum
3177 *
3178 * @return "single" or "multiple" strings
3179 **/
repetitionsToStr(REPETITIONS repetitions) const3180 const GLchar* LineContinuationTest::repetitionsToStr(REPETITIONS repetitions) const
3181 {
3182 const GLchar* result = 0;
3183
3184 if (ONCE == repetitions)
3185 {
3186 result = "single";
3187 }
3188 else
3189 {
3190 result = "multiple";
3191 }
3192
3193 return result;
3194 }
3195
3196 /** Replace all CASES tokens
3197 *
3198 * @param source String with shader template
3199 **/
replaceAllCaseTokens(std::string & source) const3200 void LineContinuationTest::replaceAllCaseTokens(std::string& source) const
3201 {
3202
3203 /* Tokens to be replaced with line continuation */
3204 static const GLchar* token_assignment_before_operator_case = "ASSIGNMENT_BEFORE_OPERATOR_CASE";
3205 static const GLchar* token_assignment_after_operator_case = "ASSIGNMENT_AFTER_OPERATOR_CASE";
3206 static const GLchar* token_vector_initializer = "VECTOR_VARIABLE_INITIALIZER_CASE";
3207 static const GLchar* token_function_case = "FUNCTION_CASE";
3208 static const GLchar* token_type_case = "TYPE_CASE";
3209 static const GLchar* token_variable_case = "VARIABLE_CASE";
3210 static const GLchar* token_preprocessor_inside_case = "PREPROCESSOR_INSIDE_CASE";
3211 static const GLchar* token_preprocessor_between_case = "PREPROCESSOR_BETWEEN_CASE";
3212 static const GLchar* token_comment = "COMMENT_CASE";
3213 static const GLchar* token_termination = "TERMINATION_CASE";
3214 static const GLchar* token_next_to_termination = "NEXT_TO_TERMINATION_CASE";
3215
3216 /* Line continuation and empty string*/
3217 static const GLchar* empty = "";
3218 const std::string& line_continuation = getLineContinuationString();
3219
3220 /* These strings will used to replace "CASE" tokens */
3221 const GLchar* assignment_before_operator_case = empty;
3222 const GLchar* assignment_after_operator_case = empty;
3223 const GLchar* vector_variable_initializer_case = empty;
3224 const GLchar* function_case = empty;
3225 const GLchar* type_case = empty;
3226 const GLchar* variable_case = empty;
3227 const GLchar* preprocessor_inside_case = empty;
3228 const GLchar* preprocessor_between_case = empty;
3229 const GLchar* comment_case = empty;
3230 const GLchar* source_termination_case = empty;
3231 const GLchar* part_termination_case = empty;
3232 const GLchar* next_to_part_termination_case = empty;
3233
3234 /* Configuration of test case */
3235 switch (m_test_case.m_case)
3236 {
3237 case ASSIGNMENT_BEFORE_OPERATOR:
3238 assignment_before_operator_case = line_continuation.c_str();
3239 break;
3240 case ASSIGNMENT_AFTER_OPERATOR:
3241 assignment_after_operator_case = line_continuation.c_str();
3242 break;
3243 case VECTOR_VARIABLE_INITIALIZER:
3244 vector_variable_initializer_case = line_continuation.c_str();
3245 break;
3246 case TOKEN_INSIDE_FUNCTION_NAME:
3247 function_case = line_continuation.c_str();
3248 break;
3249 case TOKEN_INSIDE_TYPE_NAME:
3250 type_case = line_continuation.c_str();
3251 break;
3252 case TOKEN_INSIDE_VARIABLE_NAME:
3253 variable_case = line_continuation.c_str();
3254 break;
3255 case PREPROCESSOR_TOKEN_INSIDE:
3256 preprocessor_inside_case = line_continuation.c_str();
3257 break;
3258 case PREPROCESSOR_TOKEN_BETWEEN:
3259 preprocessor_between_case = line_continuation.c_str();
3260 break;
3261 case COMMENT:
3262 comment_case = line_continuation.c_str();
3263 break;
3264 case SOURCE_TERMINATION_NULL: /* intended fall through */
3265 case SOURCE_TERMINATION_NON_NULL:
3266 source_termination_case = line_continuation.c_str();
3267 break;
3268 case PART_TERMINATION_NULL: /* intended fall through */
3269 case PART_TERMINATION_NON_NULL:
3270 part_termination_case = line_continuation.c_str();
3271 source_termination_case = line_continuation.c_str();
3272 break;
3273 case PART_NEXT_TO_TERMINATION_NULL: /* intended fall through */
3274 case PART_NEXT_TO_TERMINATION_NON_NULL:
3275 next_to_part_termination_case = line_continuation.c_str();
3276 break;
3277 case DEBUG_CASE: /* intended fall through */
3278 default:
3279 break; /* no line continuations */
3280 }
3281
3282 Utils::replaceAllTokens(token_assignment_after_operator_case, assignment_after_operator_case, source);
3283 Utils::replaceAllTokens(token_assignment_before_operator_case, assignment_before_operator_case, source);
3284 Utils::replaceAllTokens(token_comment, comment_case, source);
3285 Utils::replaceAllTokens(token_function_case, function_case, source);
3286 Utils::replaceAllTokens(token_next_to_termination, next_to_part_termination_case, source);
3287 Utils::replaceAllTokens(token_termination, part_termination_case, source);
3288 Utils::replaceAllTokens(token_preprocessor_between_case, preprocessor_between_case, source);
3289 Utils::replaceAllTokens(token_preprocessor_inside_case, preprocessor_inside_case, source);
3290 Utils::replaceAllTokens(token_termination, source_termination_case, source);
3291 Utils::replaceAllTokens(token_type_case, type_case, source);
3292 Utils::replaceAllTokens(token_variable_case, variable_case, source);
3293 Utils::replaceAllTokens(token_vector_initializer, vector_variable_initializer_case, source);
3294 }
3295
3296 /** Decides if the current test case requires source lengths
3297 *
3298 * @return true if test requires lengths, false otherwise
3299 **/
useSourceLengths() const3300 bool LineContinuationTest::useSourceLengths() const
3301 {
3302 bool result;
3303
3304 switch (m_test_case.m_case)
3305 {
3306 case ASSIGNMENT_BEFORE_OPERATOR:
3307 case ASSIGNMENT_AFTER_OPERATOR:
3308 case VECTOR_VARIABLE_INITIALIZER:
3309 case TOKEN_INSIDE_FUNCTION_NAME:
3310 case TOKEN_INSIDE_TYPE_NAME:
3311 case TOKEN_INSIDE_VARIABLE_NAME:
3312 case PREPROCESSOR_TOKEN_INSIDE:
3313 case PREPROCESSOR_TOKEN_BETWEEN:
3314 case COMMENT:
3315 case SOURCE_TERMINATION_NULL:
3316 case PART_TERMINATION_NULL:
3317 case PART_NEXT_TO_TERMINATION_NULL:
3318 default:
3319 result = false;
3320 break;
3321 case SOURCE_TERMINATION_NON_NULL:
3322 case PART_TERMINATION_NON_NULL:
3323 case PART_NEXT_TO_TERMINATION_NON_NULL:
3324 result = true;
3325 break;
3326 }
3327
3328 return result;
3329 }
3330
3331 /** Constructor
3332 *
3333 * @param context Test context
3334 **/
LineNumberingTest(deqp::Context & context)3335 LineNumberingTest::LineNumberingTest(deqp::Context& context)
3336 : GLSLTestBase(context, "line_numbering", "Verify if line numbering is correct after line continuation")
3337 {
3338 /* Nothing to be done here */
3339 }
3340
3341 /** Prepare source for given shader stage
3342 *
3343 * @param in_stage Shader stage, compute shader will use 430
3344 * @param in_use_version_400 Select if 400 or 420 should be used
3345 * @param out_source Prepared shader source instance
3346 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3347 void LineNumberingTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3348 Utils::shaderSource& out_source)
3349 {
3350 static const GLchar* test_result_snippet_normal[6] = { /* Utils::COMPUTE_SHADER */
3351 "ivec4(11, 1, 2, 3)",
3352 /* Utils::VERTEX_SHADER */
3353 "ivec4(9, 1, 2, 3)",
3354 /* Utils::TESS_CTRL_SHADER */
3355 "ivec4(12, 1, 2, 3)",
3356 /* Utils::TESS_EVAL_SHADER */
3357 "ivec4(12, 1, 2, 3)",
3358 /* Utils::GEOMETRY_SHADER */
3359 "ivec4(13, 1, 2, 3)",
3360 /* Utils::FRAGMENT_SHADER */
3361 "ivec4(10, 1, 2, 3)"
3362 };
3363
3364 static const GLchar* test_result_snippet_400[6] = { /* Utils::COMPUTE_SHADER */
3365 "ivec4(13, 1, 2, 3)",
3366 /* Utils::VERTEX_SHADER */
3367 "ivec4(11, 1, 2, 3)",
3368 /* Utils::TESS_CTRL_SHADER */
3369 "ivec4(14, 1, 2, 3)",
3370 /* Utils::TESS_EVAL_SHADER */
3371 "ivec4(14, 1, 2, 3)",
3372 /* Utils::GEOMETRY_SHADER */
3373 "ivec4(15, 1, 2, 3)",
3374 /* Utils::FRAGMENT_SHADER */
3375 "ivec4(12, 1, 2, 3)"
3376 };
3377
3378 static const GLchar* line_numbering_snippet = "ivec4 glsl\\\n"
3379 "Test\\\n"
3380 "Function(in ivec3 arg)\n"
3381 "{\n"
3382 " return ivec4(__LINE__, arg.xyz);\n"
3383 "}\n";
3384
3385 static const GLchar* compute_shader_template =
3386 "VERSION\n"
3387 "\n"
3388 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3389 "\n"
3390 "writeonly uniform image2D uni_image;\n"
3391 "\n"
3392 "GLSL_TEST_FUNCTION"
3393 "\n"
3394 "void main()\n"
3395 "{\n"
3396 " vec4 result = vec4(1, 0, 0, 1);\n"
3397 "\n"
3398 " if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3399 " {\n"
3400 " result = vec4(0, 1, 0, 1);\n"
3401 " }\n"
3402 "\n"
3403 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3404 "}\n"
3405 "\n";
3406
3407 static const GLchar* fragment_shader_template =
3408 "VERSION\n"
3409 "\n"
3410 "in vec4 gs_fs_result;\n"
3411 "out vec4 fs_out_result;\n"
3412 "\n"
3413 "GLSL_TEST_FUNCTION"
3414 "\n"
3415 "void main()\n"
3416 "{\n"
3417 " vec4 result = vec4(1, 0, 0, 1);\n"
3418 "\n"
3419 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3420 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3421 " {\n"
3422 " result = vec4(0, 1, 0, 1);\n"
3423 " }\n"
3424 "\n"
3425 " fs_out_result = result;\n"
3426 "}\n"
3427 "\n";
3428
3429 static const GLchar* geometry_shader_template =
3430 "VERSION\n"
3431 "\n"
3432 "layout(points) in;\n"
3433 "layout(triangle_strip, max_vertices = 4) out;\n"
3434 "\n"
3435 "in vec4 tes_gs_result[];\n"
3436 "out vec4 gs_fs_result;\n"
3437 "\n"
3438 "GLSL_TEST_FUNCTION"
3439 "\n"
3440 "void main()\n"
3441 "{\n"
3442 " vec4 result = vec4(1, 0, 0, 1);\n"
3443 "\n"
3444 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3445 " (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3446 " {\n"
3447 " result = vec4(0, 1, 0, 1);\n"
3448 " }\n"
3449 "\n"
3450 " gs_fs_result = result;\n"
3451 " gl_Position = vec4(-1, -1, 0, 1);\n"
3452 " EmitVertex();\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 "}\n"
3463 "\n";
3464
3465 static const GLchar* tess_ctrl_shader_template =
3466 "VERSION\n"
3467 "\n"
3468 "layout(vertices = 1) out;\n"
3469 "\n"
3470 "in vec4 vs_tcs_result[];\n"
3471 "out vec4 tcs_tes_result[];\n"
3472 "\n"
3473 "GLSL_TEST_FUNCTION"
3474 "\n"
3475 "void main()\n"
3476 "{\n"
3477 " vec4 result = vec4(1, 0, 0, 1);\n"
3478 "\n"
3479 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3480 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3481 " {\n"
3482 " result = vec4(0, 1, 0, 1);\n"
3483 " }\n"
3484 "\n"
3485 " tcs_tes_result[gl_InvocationID] = result;\n"
3486 "\n"
3487 " gl_TessLevelOuter[0] = 1.0;\n"
3488 " gl_TessLevelOuter[1] = 1.0;\n"
3489 " gl_TessLevelOuter[2] = 1.0;\n"
3490 " gl_TessLevelOuter[3] = 1.0;\n"
3491 " gl_TessLevelInner[0] = 1.0;\n"
3492 " gl_TessLevelInner[1] = 1.0;\n"
3493 "}\n"
3494 "\n";
3495
3496 static const GLchar* tess_eval_shader_template =
3497 "VERSION\n"
3498 "\n"
3499 "layout(isolines, point_mode) in;\n"
3500 "\n"
3501 "in vec4 tcs_tes_result[];\n"
3502 "out vec4 tes_gs_result;\n"
3503 "\n"
3504 "GLSL_TEST_FUNCTION"
3505 "\n"
3506 "void main()\n"
3507 "{\n"
3508 " vec4 result = vec4(1, 0, 0, 1);\n"
3509 "\n"
3510 " if ((GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3))) &&\n"
3511 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3512 " {\n"
3513 " result = vec4(0, 1, 0, 1);\n"
3514 " }\n"
3515 "\n"
3516 " tes_gs_result = result;\n"
3517 "}\n"
3518 "\n";
3519
3520 static const GLchar* vertex_shader_template = "VERSION\n"
3521 "\n"
3522 "out vec4 vs_tcs_result;\n"
3523 "\n"
3524 "GLSL_TEST_FUNCTION"
3525 "\n"
3526 "void main()\n"
3527 "{\n"
3528 " vec4 result = vec4(1, 0, 0, 1);\n"
3529 "\n"
3530 " if (GLSL_TEST_RESULT == glslTestFunction(ivec3(1, 2, 3)))\n"
3531 " {\n"
3532 " result = vec4(0, 1, 0, 1);\n"
3533 " }\n"
3534 "\n"
3535 " vs_tcs_result = result;\n"
3536 "}\n"
3537 "\n";
3538
3539 const GLchar* shader_template = 0;
3540
3541 switch (in_stage)
3542 {
3543 case Utils::COMPUTE_SHADER:
3544 shader_template = compute_shader_template;
3545 break;
3546 case Utils::FRAGMENT_SHADER:
3547 shader_template = fragment_shader_template;
3548 break;
3549 case Utils::GEOMETRY_SHADER:
3550 shader_template = geometry_shader_template;
3551 break;
3552 case Utils::TESS_CTRL_SHADER:
3553 shader_template = tess_ctrl_shader_template;
3554 break;
3555 case Utils::TESS_EVAL_SHADER:
3556 shader_template = tess_eval_shader_template;
3557 break;
3558 case Utils::VERTEX_SHADER:
3559 shader_template = vertex_shader_template;
3560 break;
3561 default:
3562 TCU_FAIL("Invalid enum");
3563 }
3564
3565 out_source.m_parts[0].m_code = shader_template;
3566
3567 size_t position = 0;
3568 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3569 out_source.m_parts[0].m_code);
3570
3571 Utils::replaceToken("GLSL_TEST_FUNCTION", position, line_numbering_snippet, out_source.m_parts[0].m_code);
3572
3573 Utils::replaceToken("GLSL_TEST_RESULT", position,
3574 in_use_version_400 ? test_result_snippet_400[in_stage] : test_result_snippet_normal[in_stage],
3575 out_source.m_parts[0].m_code);
3576 }
3577
3578 /** Constructor
3579 *
3580 * @param context Test context
3581 **/
UTF8CharactersTest(deqp::Context & context)3582 UTF8CharactersTest::UTF8CharactersTest(deqp::Context& context)
3583 : GLSLTestBase(context, "utf8_characters", "UTF8 character used in comment or preprocessor")
3584 {
3585 /* Nothing to be done here */
3586 }
3587
3588 /** Overwrite getShaderSourceConfig method
3589 *
3590 * @param out_n_parts Number of source parts used by this test case
3591 * @param out_use_lengths If source lengths shall be provided to compiler
3592 **/
getShaderSourceConfig(GLuint & out_n_parts,bool & out_use_lengths)3593 void UTF8CharactersTest::getShaderSourceConfig(GLuint& out_n_parts, bool& out_use_lengths)
3594 {
3595 out_n_parts = 1;
3596 out_use_lengths = (AS_LAST_CHARACTER_NON_NULL_TERMINATED == m_test_case.m_case) ? true : false;
3597 }
3598
3599 /** Set up next test case
3600 *
3601 * @param test_case_index Index of next test case
3602 *
3603 * @return false if there is no more test cases, true otherwise
3604 **/
prepareNextTestCase(glw::GLuint test_case_index)3605 bool UTF8CharactersTest::prepareNextTestCase(glw::GLuint test_case_index)
3606 {
3607 static const testCase test_cases[] = {
3608 { IN_COMMENT, Utils::TWO_BYTES },
3609 { IN_COMMENT, Utils::THREE_BYTES },
3610 { IN_COMMENT, Utils::FOUR_BYTES },
3611 { IN_COMMENT, Utils::FIVE_BYTES },
3612 { IN_COMMENT, Utils::SIX_BYTES },
3613 { IN_COMMENT, Utils::REDUNDANT_ASCII },
3614 { IN_PREPROCESSOR, Utils::TWO_BYTES },
3615 { IN_PREPROCESSOR, Utils::THREE_BYTES },
3616 { IN_PREPROCESSOR, Utils::FOUR_BYTES },
3617 { IN_PREPROCESSOR, Utils::FIVE_BYTES },
3618 { IN_PREPROCESSOR, Utils::SIX_BYTES },
3619 { IN_PREPROCESSOR, Utils::REDUNDANT_ASCII },
3620 { AS_LAST_CHARACTER_NULL_TERMINATED, Utils::TWO_BYTES },
3621 { AS_LAST_CHARACTER_NULL_TERMINATED, Utils::THREE_BYTES },
3622 { AS_LAST_CHARACTER_NULL_TERMINATED, Utils::FOUR_BYTES },
3623 { AS_LAST_CHARACTER_NULL_TERMINATED, Utils::FIVE_BYTES },
3624 { AS_LAST_CHARACTER_NULL_TERMINATED, Utils::SIX_BYTES },
3625 { AS_LAST_CHARACTER_NULL_TERMINATED, Utils::REDUNDANT_ASCII },
3626 { AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::TWO_BYTES },
3627 { AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::THREE_BYTES },
3628 { AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::FOUR_BYTES },
3629 { AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::FIVE_BYTES },
3630 { AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::SIX_BYTES },
3631 { AS_LAST_CHARACTER_NON_NULL_TERMINATED, Utils::REDUNDANT_ASCII },
3632 };
3633
3634 static const GLuint max_test_cases = sizeof(test_cases) / sizeof(testCase);
3635
3636 if ((GLuint)-1 == test_case_index)
3637 {
3638 m_test_case.m_case = DEBUG_CASE;
3639 m_test_case.m_character = Utils::EMPTY;
3640 }
3641 else if (max_test_cases <= test_case_index)
3642 {
3643 return false;
3644 }
3645 else
3646 {
3647 m_test_case = test_cases[test_case_index];
3648 }
3649
3650 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case: utf8 character: "
3651 << Utils::getUtf8Character(m_test_case.m_character) << " is placed "
3652 << casesToStr() << tcu::TestLog::EndMessage;
3653
3654 return true;
3655 }
3656
3657 /** Prepare source for given shader stage
3658 *
3659 * @param in_stage Shader stage, compute shader will use 430
3660 * @param in_use_version_400 Select if 400 or 420 should be used
3661 * @param out_source Prepared shader source instance
3662 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)3663 void UTF8CharactersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
3664 Utils::shaderSource& out_source)
3665 {
3666 static const GLchar* compute_shader_template =
3667 "VERSION\n"
3668 "\n"
3669 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3670 "\n"
3671 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3672 "\n"
3673 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
3674 "\n"
3675 "writeonly uniform image2D uni_image;\n"
3676 " uniform sampler2D uni_sampler;\n"
3677 "\n"
3678 "#if 0\n"
3679 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3680 "#else\n"
3681 " #define SET_RESULT(XX) result = XX\n"
3682 "#endif\n"
3683 "\n"
3684 "void main()\n"
3685 "{\n"
3686 " ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
3687 " vec4 result = vec4(1, 0, 0, 1);\n"
3688 "\n"
3689 " if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
3690 " {\n"
3691 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3692 " }\n"
3693 "\n"
3694 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
3695 "}\n"
3696 "// Lorem ipsum LAST_CHARACTER_CASE";
3697
3698 static const GLchar* fragment_shader_template =
3699 "VERSION\n"
3700 "\n"
3701 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3702 "\n"
3703 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3704 "\n"
3705 "in vec4 gs_fs_result;\n"
3706 "in vec2 gs_fs_tex_coord;\n"
3707 "out vec4 fs_out_result;\n"
3708 "uniform sampler2D uni_sampler;\n"
3709 "\n"
3710 "#if 0\n"
3711 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3712 "#else\n"
3713 " #define SET_RESULT(XX) result = XX\n"
3714 "#endif\n"
3715 "\n"
3716 "void main()\n"
3717 "{\n"
3718 " vec4 result = vec4(1, 0, 0, 1);\n"
3719 "\n"
3720 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
3721 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
3722 " {\n"
3723 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3724 " }\n"
3725 "\n"
3726 " fs_out_result = result;\n"
3727 "}\n"
3728 "// Lorem ipsum LAST_CHARACTER_CASE";
3729
3730 static const GLchar* geometry_shader_template =
3731 "VERSION\n"
3732 "\n"
3733 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3734 "\n"
3735 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3736 "\n"
3737 "layout(points) in;\n"
3738 "layout(triangle_strip, max_vertices = 4) out;\n"
3739 "\n"
3740 "in vec4 tes_gs_result[];\n"
3741 "out vec2 gs_fs_tex_coord;\n"
3742 "out vec4 gs_fs_result;\n"
3743 "uniform sampler2D uni_sampler;\n"
3744 "\n"
3745 "#if 0\n"
3746 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3747 "#else\n"
3748 " #define SET_RESULT(XX) result = XX\n"
3749 "#endif\n"
3750 "\n"
3751 "void main()\n"
3752 "{\n"
3753 " vec4 result = vec4(1, 0, 0, 1);\n"
3754 "\n"
3755 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
3756 " (vec4(0, 1, 0, 1) == tes_gs_result[0]) )\n"
3757 " {\n"
3758 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3759 " }\n"
3760 "\n"
3761 " gs_fs_tex_coord = vec2(0.25, 0.25);\n"
3762 " gs_fs_result = result;\n"
3763 " gl_Position = vec4(-1, -1, 0, 1);\n"
3764 " EmitVertex();\n"
3765 " gs_fs_tex_coord = vec2(0.25, 0.75);\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.75, 0.25);\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.75);\n"
3774 " gs_fs_result = result;\n"
3775 " gl_Position = vec4(1, 1, 0, 1);\n"
3776 " EmitVertex();\n"
3777 "}\n"
3778 "// Lorem ipsum LAST_CHARACTER_CASE";
3779
3780 static const GLchar* tess_ctrl_shader_template =
3781 "VERSION\n"
3782 "\n"
3783 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3784 "\n"
3785 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3786 "\n"
3787 "layout(vertices = 1) out;\n"
3788 "\n"
3789 "in vec4 vs_tcs_result[];\n"
3790 "out vec4 tcs_tes_result[];\n"
3791 "uniform sampler2D uni_sampler;\n"
3792 "\n"
3793 "#if 0\n"
3794 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3795 "#else\n"
3796 " #define SET_RESULT(XX) result = XX\n"
3797 "#endif\n"
3798 "\n"
3799 "void main()\n"
3800 "{\n"
3801 " vec4 result = vec4(1, 0, 0, 1);\n"
3802 "\n"
3803 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
3804 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
3805 " {\n"
3806 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3807 " }\n"
3808 "\n"
3809 " tcs_tes_result[gl_InvocationID] = result;\n"
3810 "\n"
3811 " gl_TessLevelOuter[0] = 1.0;\n"
3812 " gl_TessLevelOuter[1] = 1.0;\n"
3813 " gl_TessLevelOuter[2] = 1.0;\n"
3814 " gl_TessLevelOuter[3] = 1.0;\n"
3815 " gl_TessLevelInner[0] = 1.0;\n"
3816 " gl_TessLevelInner[1] = 1.0;\n"
3817 "}\n"
3818 "// Lorem ipsum LAST_CHARACTER_CASE";
3819
3820 static const GLchar* tess_eval_shader_template =
3821 "VERSION\n"
3822 "\n"
3823 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3824 "\n"
3825 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3826 "\n"
3827 "layout(isolines, point_mode) in;\n"
3828 "\n"
3829 "in vec4 tcs_tes_result[];\n"
3830 "out vec4 tes_gs_result;\n"
3831 "uniform sampler2D uni_sampler;\n"
3832 "\n"
3833 "#if 0\n"
3834 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3835 "#else\n"
3836 " #define SET_RESULT(XX) result = XX\n"
3837 "#endif\n"
3838 "\n"
3839 "void main()\n"
3840 "{\n"
3841 " vec4 result = vec4(1, 0, 0, 1);\n"
3842 "\n"
3843 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
3844 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
3845 " {\n"
3846 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3847 " }\n"
3848 "\n"
3849 " tes_gs_result = result;\n"
3850 "}\n"
3851 "// Lorem ipsum LAST_CHARACTER_CASE";
3852
3853 static const GLchar* vertex_shader_template =
3854 "VERSION\n"
3855 "\n"
3856 "// Lorem ipsum dolor sit amCOMMENT_CASEet, consectetur adipiscing elit posuere.\n"
3857 "\n"
3858 "/* Lorem ipsum dolor sit amet, conCOMMENT_CASEsectetur adipiscing elit posuere. */\n"
3859 "\n"
3860 "out vec4 vs_tcs_result;\n"
3861 "uniform sampler2D uni_sampler;\n"
3862 "\n"
3863 "#if 0\n"
3864 " #define SET_REPREPROCESSOR_CASESULT(XX) result = XX\n"
3865 "#else\n"
3866 " #define SET_RESULT(XX) result = XX\n"
3867 "#endif\n"
3868 "\n"
3869 "void main()\n"
3870 "{\n"
3871 " vec4 result = vec4(1, 0, 0, 1);\n"
3872 "\n"
3873 " if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
3874 " {\n"
3875 " SET_RESULT(vec4(0, 1, 0, 1));\n"
3876 " }\n"
3877 "\n"
3878 " vs_tcs_result = result;\n"
3879 "}\n"
3880 "// Lorem ipsum LAST_CHARACTER_CASE";
3881
3882 const GLchar* shader_template = 0;
3883 const GLchar* comment_case = "";
3884 const GLchar* preprocessor_case = "";
3885 const GLchar* last_character_case = "";
3886 const GLchar* utf8_character = Utils::getUtf8Character(m_test_case.m_character);
3887
3888 switch (in_stage)
3889 {
3890 case Utils::COMPUTE_SHADER:
3891 shader_template = compute_shader_template;
3892 break;
3893 case Utils::FRAGMENT_SHADER:
3894 shader_template = fragment_shader_template;
3895 break;
3896 case Utils::GEOMETRY_SHADER:
3897 shader_template = geometry_shader_template;
3898 break;
3899 case Utils::TESS_CTRL_SHADER:
3900 shader_template = tess_ctrl_shader_template;
3901 break;
3902 case Utils::TESS_EVAL_SHADER:
3903 shader_template = tess_eval_shader_template;
3904 break;
3905 case Utils::VERTEX_SHADER:
3906 shader_template = vertex_shader_template;
3907 break;
3908 default:
3909 TCU_FAIL("Invalid enum");
3910 }
3911
3912 switch (m_test_case.m_case)
3913 {
3914 case IN_COMMENT:
3915 comment_case = utf8_character;
3916 break;
3917 case IN_PREPROCESSOR:
3918 preprocessor_case = utf8_character;
3919 break;
3920 case AS_LAST_CHARACTER_NULL_TERMINATED:
3921 last_character_case = utf8_character;
3922 break;
3923 case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
3924 last_character_case = utf8_character;
3925 break;
3926 case DEBUG_CASE:
3927 break;
3928 default:
3929 TCU_FAIL("Invalid enum");
3930 }
3931
3932 out_source.m_parts[0].m_code = shader_template;
3933
3934 size_t position = 0;
3935 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
3936 out_source.m_parts[0].m_code);
3937
3938 Utils::replaceAllTokens("COMMENT_CASE", comment_case, out_source.m_parts[0].m_code);
3939
3940 Utils::replaceAllTokens("PREPROCESSOR_CASE", preprocessor_case, out_source.m_parts[0].m_code);
3941
3942 Utils::replaceAllTokens("LAST_CHARACTER_CASE", last_character_case, out_source.m_parts[0].m_code);
3943 }
3944
3945 /** Prepare texture
3946 *
3947 * @param texture Texutre to be created and filled with content
3948 *
3949 * @return Name of sampler uniform that should be used for the texture
3950 **/
prepareSourceTexture(Utils::texture & texture)3951 const GLchar* UTF8CharactersTest::prepareSourceTexture(Utils::texture& texture)
3952 {
3953 std::vector<GLuint> data;
3954 static const GLuint width = 64;
3955 static const GLuint height = 64;
3956 static const GLuint data_size = width * height;
3957 static const GLuint blue_color = 0xffff0000;
3958 static const GLuint grey_color = 0xaaaaaaaa;
3959
3960 data.resize(data_size);
3961
3962 for (GLuint i = 0; i < data_size; ++i)
3963 {
3964 data[i] = grey_color;
3965 }
3966
3967 for (GLuint y = 16; y < 48; ++y)
3968 {
3969 const GLuint line_offset = y * 64;
3970
3971 for (GLuint x = 16; x < 48; ++x)
3972 {
3973 const GLuint pixel_offset = x + line_offset;
3974
3975 data[pixel_offset] = blue_color;
3976 }
3977 }
3978
3979 texture.create(width, height, GL_RGBA8);
3980
3981 texture.update(width, height, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
3982
3983 return "uni_sampler";
3984 }
3985
3986 /** Returns description of current test case
3987 *
3988 * @return String with description
3989 **/
casesToStr() const3990 const GLchar* UTF8CharactersTest::casesToStr() const
3991 {
3992 const GLchar* result = 0;
3993
3994 switch (m_test_case.m_case)
3995 {
3996 case IN_COMMENT:
3997 result = "in comment";
3998 break;
3999 case IN_PREPROCESSOR:
4000 result = "in preprocessor";
4001 break;
4002 case AS_LAST_CHARACTER_NULL_TERMINATED:
4003 result = "just before null";
4004 break;
4005 case AS_LAST_CHARACTER_NON_NULL_TERMINATED:
4006 result = "as last character";
4007 break;
4008 case DEBUG_CASE:
4009 result = "nowhere. This is debug!";
4010 break;
4011 default:
4012 TCU_FAIL("Invalid enum");
4013 }
4014
4015 return result;
4016 }
4017
4018 /** Constructor
4019 *
4020 * @param context Test context
4021 **/
UTF8InSourceTest(deqp::Context & context)4022 UTF8InSourceTest::UTF8InSourceTest(deqp::Context& context)
4023 : NegativeTestBase(context, "utf8_in_source", "UTF8 characters used in shader source")
4024 {
4025 /* Nothing to be done here */
4026 }
4027
4028 /** Set up next test case
4029 *
4030 * @param test_case_index Index of next test case
4031 *
4032 * @return false if there is no more test cases, true otherwise
4033 **/
prepareNextTestCase(glw::GLuint test_case_index)4034 bool UTF8InSourceTest::prepareNextTestCase(glw::GLuint test_case_index)
4035 {
4036 static const Utils::UTF8_CHARACTERS test_cases[] = {
4037 Utils::TWO_BYTES, Utils::THREE_BYTES, Utils::FOUR_BYTES,
4038 Utils::FIVE_BYTES, Utils::SIX_BYTES, Utils::REDUNDANT_ASCII
4039 };
4040
4041 static const GLuint max_test_cases = sizeof(test_cases) / sizeof(Utils::UTF8_CHARACTERS);
4042
4043 if ((GLuint)-1 == test_case_index)
4044 {
4045 m_character = Utils::EMPTY;
4046 }
4047 else if (max_test_cases <= test_case_index)
4048 {
4049 return false;
4050 }
4051 else
4052 {
4053 m_character = test_cases[test_case_index];
4054 }
4055
4056 m_context.getTestContext().getLog() << tcu::TestLog::Message
4057 << "Test case: utf8 character: " << Utils::getUtf8Character(m_character)
4058 << tcu::TestLog::EndMessage;
4059
4060 return true;
4061 }
4062
4063 /** Prepare source for given shader stage
4064 *
4065 * @param in_stage Shader stage, compute shader will use 430
4066 * @param in_use_version_400 Select if 400 or 420 should be used
4067 * @param out_source Prepared shader source instance
4068 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4069 void UTF8InSourceTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4070 Utils::shaderSource& out_source)
4071 {
4072 static const GLchar* compute_shader_template =
4073 "VERSION\n"
4074 "\n"
4075 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4076 "\n"
4077 "writeonly uniform image2D uni_image;\n"
4078 " uniform sampler2D uni_sampler;\n"
4079 "\n"
4080 "#define SET_RESULT(XX) resHEREult = XX\n"
4081 "\n"
4082 "void main()\n"
4083 "{\n"
4084 " ivec2 coordinates = ivec2(gl_GlobalInvocationID.xy + ivec2(16, 16));\n"
4085 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4086 "\n"
4087 " if (vec4(0, 0, 1, 1) == texelFetch(uni_sampler, coordinates, 0 /* lod */))\n"
4088 " {\n"
4089 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4090 " }\n"
4091 "\n"
4092 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), resHEREult);\n"
4093 "}\n"
4094 "";
4095
4096 static const GLchar* fragment_shader_template =
4097 "VERSION\n"
4098 "\n"
4099 "in vec4 gs_fs_result;\n"
4100 "in vec2 gs_fs_tex_coord;\n"
4101 "out vec4 fs_out_result;\n"
4102 "uniform sampler2D uni_sampler;\n"
4103 "\n"
4104 "#define SET_RESULT(XX) resHEREult = XX\n"
4105 "\n"
4106 "void main()\n"
4107 "{\n"
4108 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4109 "\n"
4110 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, gs_fs_tex_coord)) &&\n"
4111 " (vec4(0, 1, 0, 1) == gs_fs_result) )\n"
4112 " {\n"
4113 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4114 " }\n"
4115 "\n"
4116 " fs_out_result = resHEREult;\n"
4117 "}\n"
4118 "\n";
4119
4120 static const GLchar* geometry_shader_template =
4121 "VERSION\n"
4122 "\n"
4123 "layout(points) in;\n"
4124 "layout(triangle_strip, max_vertices = 4) out;\n"
4125 "\n"
4126 "in vec4 tes_gHEREs_result[];\n"
4127 "out vec2 gs_fs_tex_coord;\n"
4128 "out vec4 gs_fs_result;\n"
4129 "uniform sampler2D uni_sampler;\n"
4130 "\n"
4131 "#define SET_RESULT(XX) result = XX\n"
4132 "\n"
4133 "void main()\n"
4134 "{\n"
4135 " vec4 result = vec4(1, 0, 0, 1);\n"
4136 "\n"
4137 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5))) &&\n"
4138 " (vec4(0, 1, 0, 1) == tes_gHEREs_result[0]) )\n"
4139 " {\n"
4140 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4141 " }\n"
4142 "\n"
4143 " gs_fs_tex_coord = vec2(0.25, 0.25);\n"
4144 " gs_fs_result = result;\n"
4145 " gl_Position = vec4(-1, -1, 0, 1);\n"
4146 " EmitVertex();\n"
4147 " gs_fs_tex_coord = vec2(0.25, 0.75);\n"
4148 " gs_fs_result = result;\n"
4149 " gl_Position = vec4(-1, 1, 0, 1);\n"
4150 " EmitVertex();\n"
4151 " gs_fs_tex_coord = vec2(0.75, 0.25);\n"
4152 " gs_fs_result = result;\n"
4153 " gl_Position = vec4(1, -1, 0, 1);\n"
4154 " EmitVertex();\n"
4155 " gs_fs_tex_coord = vec2(0.75, 0.75);\n"
4156 " gs_fs_result = result;\n"
4157 " gl_Position = vec4(1, 1, 0, 1);\n"
4158 " EmitVertex();\n"
4159 "}\n"
4160 "\n";
4161
4162 static const GLchar* tess_ctrl_shader_template =
4163 "VERSION\n"
4164 "\n"
4165 "layout(vertices = 1) out;\n"
4166 "\n"
4167 "in vec4 vs_tcs_result[];\n"
4168 "out vec4 tcHEREs_tes_result[];\n"
4169 "uniform sampler2D uni_sampler;\n"
4170 "\n"
4171 "#define SET_RESULT(XX) resulHEREt = XX\n"
4172 "\n"
4173 "void main()\n"
4174 "{\n"
4175 " vec4 resulHEREt = vec4(1, 0, 0, 1);\n"
4176 "\n"
4177 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.4, 0.4))) &&\n"
4178 " (vec4(0, 1, 0, 1) == vs_tcs_result[gl_InvocationID]) )\n"
4179 " {\n"
4180 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4181 " }\n"
4182 "\n"
4183 " tcHEREs_tes_result[gl_InvocationID] = resulHEREt;\n"
4184 "\n"
4185 " gl_TessLevelOuter[0] = 1.0;\n"
4186 " gl_TessLevelOuter[1] = 1.0;\n"
4187 " gl_TessLevelOuter[2] = 1.0;\n"
4188 " gl_TessLevelOuter[3] = 1.0;\n"
4189 " gl_TessLevelInner[0] = 1.0;\n"
4190 " gl_TessLevelInner[1] = 1.0;\n"
4191 "}\n"
4192 "\n";
4193
4194 static const GLchar* tess_eval_shader_template =
4195 "VERSION\n"
4196 "\n"
4197 "layout(isolines, point_mode) in;\n"
4198 "\n"
4199 "in vec4 tcs_tes_result[];\n"
4200 "out vec4 teHEREs_gs_result;\n"
4201 "uniform sampler2D uni_sampler;\n"
4202 "\n"
4203 "#define SET_RESULT(XX) reHEREsult = XX\n"
4204 "\n"
4205 "void main()\n"
4206 "{\n"
4207 " vec4 reHEREsult = vec4(1, 0, 0, 1);\n"
4208 "\n"
4209 " if ((vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.6, 0.6))) &&\n"
4210 " (vec4(0, 1, 0, 1) == tcs_tes_result[0]) )\n"
4211 " {\n"
4212 " SET_RESULT(vec4(0, 1, 0, 1));\n"
4213 " }\n"
4214 "\n"
4215 " teHEREs_gs_result = reHEREsult;\n"
4216 "}\n"
4217 "\n";
4218
4219 static const GLchar* vertex_shader_template = "VERSION\n"
4220 "\n"
4221 "out vec4 vs_tcs_HEREresult;\n"
4222 "uniform sampler2D uni_sampler;\n"
4223 "\n"
4224 "#define SET_RHEREESULT(XX) resHEREult = XX\n"
4225 "\n"
4226 "void main()\n"
4227 "{\n"
4228 " vec4 resHEREult = vec4(1, 0, 0, 1);\n"
4229 "\n"
4230 " if (vec4(0, 0, 1, 1) == texture(uni_sampler, vec2(0.5, 0.5)) )\n"
4231 " {\n"
4232 " SET_RHEREESULT(vec4(0, 1, 0, 1));\n"
4233 " }\n"
4234 "\n"
4235 " vs_tcs_HEREresult = resHEREult;\n"
4236 "}\n"
4237 "\n";
4238
4239 const GLchar* shader_template = 0;
4240 const GLchar* utf8_character = Utils::getUtf8Character(m_character);
4241
4242 switch (in_stage)
4243 {
4244 case Utils::COMPUTE_SHADER:
4245 shader_template = compute_shader_template;
4246 break;
4247 case Utils::FRAGMENT_SHADER:
4248 shader_template = fragment_shader_template;
4249 break;
4250 case Utils::GEOMETRY_SHADER:
4251 shader_template = geometry_shader_template;
4252 break;
4253 case Utils::TESS_CTRL_SHADER:
4254 shader_template = tess_ctrl_shader_template;
4255 break;
4256 case Utils::TESS_EVAL_SHADER:
4257 shader_template = tess_eval_shader_template;
4258 break;
4259 case Utils::VERTEX_SHADER:
4260 shader_template = vertex_shader_template;
4261 break;
4262 default:
4263 TCU_FAIL("Invalid enum");
4264 }
4265
4266 out_source.m_parts[0].m_code = shader_template;
4267
4268 size_t position = 0;
4269 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4270 out_source.m_parts[0].m_code);
4271
4272 Utils::replaceAllTokens("HERE", utf8_character, out_source.m_parts[0].m_code);
4273 }
4274
4275 /** Constructor
4276 *
4277 * @param context Test context
4278 **/
ImplicitConversionsValidTest(deqp::Context & context)4279 ImplicitConversionsValidTest::ImplicitConversionsValidTest(deqp::Context& context)
4280 : GLSLTestBase(context, "implicit_conversions", "Verifies that implicit conversions are allowed")
4281 {
4282 /* Nothing to be done */
4283 }
4284
4285 /** Set up next test case
4286 *
4287 * @param test_case_index Index of next test case
4288 *
4289 * @return false if there is no more test cases, true otherwise
4290 **/
prepareNextTestCase(glw::GLuint test_case_index)4291 bool ImplicitConversionsValidTest::prepareNextTestCase(glw::GLuint test_case_index)
4292 {
4293 m_current_test_case_index = test_case_index;
4294
4295 if ((glw::GLuint)-1 == test_case_index)
4296 {
4297 return true;
4298 }
4299 else if (m_test_cases.size() <= test_case_index)
4300 {
4301 return false;
4302 }
4303
4304 const testCase& test_case = m_test_cases[test_case_index];
4305
4306 m_context.getTestContext().getLog() << tcu::TestLog::Message
4307 << "T1:" << Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols,
4308 test_case.m_n_rows)
4309 << " T2:" << Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols,
4310 test_case.m_n_rows)
4311 << tcu::TestLog::EndMessage;
4312
4313 return true;
4314 }
4315
4316 /** Prepare source for given shader stage
4317 *
4318 * @param in_stage Shader stage, compute shader will use 430
4319 * @param in_use_version_400 Select if 400 or 420 should be used
4320 * @param out_source Prepared shader source instance
4321 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4322 void ImplicitConversionsValidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4323 Utils::shaderSource& out_source)
4324 {
4325 static const GLchar* function_definition = "T1 function(in T2 left, in T2 right)\n"
4326 "{\n"
4327 " return left + right;\n"
4328 "}\n";
4329
4330 static const GLchar* verification_snippet = " const T2 const_left = T2(VALUE_LIST);\n"
4331 " const T2 const_right = T2(VALUE_LIST);\n"
4332 "\n"
4333 " T1 const_result = function(const_left, const_right);\n"
4334 "\n"
4335 " T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4336 "\n"
4337 " T2 var_left = uni_left;\n"
4338 " T2 var_right = uni_right;\n"
4339 "\n"
4340 " T1 var_result = function(var_left, var_right);\n"
4341 "\n"
4342 " if ((literal_result != const_result) ||\n"
4343 " (const_result != var_result) )\n"
4344 " {\n"
4345 " result = vec4(1, 0, 0, 1);\n"
4346 " }\n";
4347
4348 static const GLchar* compute_shader_template =
4349 "VERSION\n"
4350 "\n"
4351 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4352 "\n"
4353 "writeonly uniform image2D uni_image;\n"
4354 " uniform T2 uni_left;\n"
4355 " uniform T2 uni_right;\n"
4356 "\n"
4357 "FUNCTION_DEFINITION"
4358 "\n"
4359 "void main()\n"
4360 "{\n"
4361 " vec4 result = vec4(0, 1, 0, 1);\n"
4362 "\n"
4363 "VERIFICATION"
4364 "\n"
4365 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4366 "}\n"
4367 "\n";
4368
4369 static const GLchar* fragment_shader_template = "VERSION\n"
4370 "\n"
4371 "in vec4 gs_fs_result;\n"
4372 "out vec4 fs_out_result;\n"
4373 "uniform T2 uni_left;\n"
4374 "uniform T2 uni_right;\n"
4375 "\n"
4376 "FUNCTION_DEFINITION"
4377 "\n"
4378 "void main()\n"
4379 "{\n"
4380 " vec4 result = vec4(0, 1, 0, 1);\n"
4381 "\n"
4382 "VERIFICATION"
4383 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4384 " {\n"
4385 " result = vec4(1, 0, 0, 1);\n"
4386 " }\n"
4387 "\n"
4388 " fs_out_result = result;\n"
4389 "}\n"
4390 "\n";
4391
4392 static const GLchar* geometry_shader_template = "VERSION\n"
4393 "\n"
4394 "layout(points) in;\n"
4395 "layout(triangle_strip, max_vertices = 4) out;\n"
4396 "\n"
4397 "in vec4 tes_gs_result[];\n"
4398 "out vec4 gs_fs_result;\n"
4399 "uniform T2 uni_left;\n"
4400 "uniform T2 uni_right;\n"
4401 "\n"
4402 "FUNCTION_DEFINITION"
4403 "\n"
4404 "void main()\n"
4405 "{\n"
4406 " vec4 result = vec4(0, 1, 0, 1);\n"
4407 "\n"
4408 "VERIFICATION"
4409 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4410 " {\n"
4411 " result = vec4(1, 0, 0, 1);\n"
4412 " }\n"
4413 "\n"
4414 " gs_fs_result = result;\n"
4415 " gl_Position = vec4(-1, -1, 0, 1);\n"
4416 " EmitVertex();\n"
4417 " gs_fs_result = result;\n"
4418 " gl_Position = vec4(-1, 1, 0, 1);\n"
4419 " EmitVertex();\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 "}\n"
4427 "\n";
4428
4429 static const GLchar* tess_ctrl_shader_template =
4430 "VERSION\n"
4431 "\n"
4432 "layout(vertices = 1) out;\n"
4433 "\n"
4434 "in vec4 vs_tcs_result[];\n"
4435 "out vec4 tcs_tes_result[];\n"
4436 "uniform T2 uni_left;\n"
4437 "uniform T2 uni_right;\n"
4438 "\n"
4439 "FUNCTION_DEFINITION"
4440 "\n"
4441 "void main()\n"
4442 "{\n"
4443 " vec4 result = vec4(0, 1, 0, 1);\n"
4444 "\n"
4445 "VERIFICATION"
4446 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4447 " {\n"
4448 " result = vec4(1, 0, 0, 1);\n"
4449 " }\n"
4450 "\n"
4451 " tcs_tes_result[gl_InvocationID] = result;\n"
4452 "\n"
4453 " gl_TessLevelOuter[0] = 1.0;\n"
4454 " gl_TessLevelOuter[1] = 1.0;\n"
4455 " gl_TessLevelOuter[2] = 1.0;\n"
4456 " gl_TessLevelOuter[3] = 1.0;\n"
4457 " gl_TessLevelInner[0] = 1.0;\n"
4458 " gl_TessLevelInner[1] = 1.0;\n"
4459 "}\n"
4460 "\n";
4461
4462 static const GLchar* tess_eval_shader_template = "VERSION\n"
4463 "\n"
4464 "layout(isolines, point_mode) in;\n"
4465 "\n"
4466 "in vec4 tcs_tes_result[];\n"
4467 "out vec4 tes_gs_result;\n"
4468 "uniform T2 uni_left;\n"
4469 "uniform T2 uni_right;\n"
4470 "\n"
4471 "FUNCTION_DEFINITION"
4472 "\n"
4473 "void main()\n"
4474 "{\n"
4475 " vec4 result = vec4(0, 1, 0, 1);\n"
4476 "\n"
4477 "VERIFICATION"
4478 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4479 " {\n"
4480 " result = vec4(1, 0, 0, 1);\n"
4481 " }\n"
4482 "\n"
4483 " tes_gs_result = result;\n"
4484 "}\n"
4485 "\n";
4486
4487 static const GLchar* vertex_shader_template = "VERSION\n"
4488 "\n"
4489 "out vec4 vs_tcs_result;\n"
4490 "uniform T2 uni_left;\n"
4491 "uniform T2 uni_right;\n"
4492 "\n"
4493 "FUNCTION_DEFINITION"
4494 "\n"
4495 "void main()\n"
4496 "{\n"
4497 " vec4 result = vec4(0, 1, 0, 1);\n"
4498 "\n"
4499 "VERIFICATION"
4500 "\n"
4501 " vs_tcs_result = result;\n"
4502 "}\n"
4503 "\n";
4504
4505 const testCase& test_case = getCurrentTestCase();
4506 const GLchar* t1 = Utils::getTypeName(test_case.m_types.m_t1, test_case.m_n_cols, test_case.m_n_rows);
4507 const GLchar* t2 = Utils::getTypeName(test_case.m_types.m_t2, test_case.m_n_cols, test_case.m_n_rows);
4508 const std::string& value_list = getValueList(test_case.m_n_cols, test_case.m_n_rows);
4509 const GLchar* shader_template = 0;
4510
4511 switch (in_stage)
4512 {
4513 case Utils::COMPUTE_SHADER:
4514 shader_template = compute_shader_template;
4515 break;
4516 case Utils::FRAGMENT_SHADER:
4517 shader_template = fragment_shader_template;
4518 break;
4519 case Utils::GEOMETRY_SHADER:
4520 shader_template = geometry_shader_template;
4521 break;
4522 case Utils::TESS_CTRL_SHADER:
4523 shader_template = tess_ctrl_shader_template;
4524 break;
4525 case Utils::TESS_EVAL_SHADER:
4526 shader_template = tess_eval_shader_template;
4527 break;
4528 case Utils::VERTEX_SHADER:
4529 shader_template = vertex_shader_template;
4530 break;
4531 default:
4532 TCU_FAIL("Invalid enum");
4533 }
4534
4535 out_source.m_parts[0].m_code = shader_template;
4536
4537 size_t position = 0;
4538 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4539 out_source.m_parts[0].m_code);
4540
4541 Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4542
4543 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4544
4545 Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4546
4547 Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4548
4549 Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4550 }
4551
4552 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
4553 *
4554 * @param program Current program
4555 **/
prepareUniforms(Utils::program & program)4556 void ImplicitConversionsValidTest::prepareUniforms(Utils::program& program)
4557 {
4558 static const GLdouble double_data[16] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
4559 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
4560 static const GLfloat float_data[16] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
4561 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
4562 static const GLint int_data[4] = { 1, 1, 1, 1 };
4563 static const GLuint uint_data[4] = { 1u, 1u, 1u, 1u };
4564
4565 const testCase& test_case = getCurrentTestCase();
4566
4567 switch (test_case.m_types.m_t2)
4568 {
4569 case Utils::DOUBLE:
4570 program.uniform("uni_left", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4571 program.uniform("uni_right", Utils::DOUBLE, test_case.m_n_cols, test_case.m_n_rows, double_data);
4572 break;
4573 case Utils::FLOAT:
4574 program.uniform("uni_left", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4575 program.uniform("uni_right", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
4576 break;
4577 case Utils::INT:
4578 program.uniform("uni_left", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4579 program.uniform("uni_right", Utils::INT, test_case.m_n_cols, test_case.m_n_rows, int_data);
4580 break;
4581 case Utils::UINT:
4582 program.uniform("uni_left", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4583 program.uniform("uni_right", Utils::UINT, test_case.m_n_cols, test_case.m_n_rows, uint_data);
4584 break;
4585 default:
4586 TCU_FAIL("Invalid enum");
4587 }
4588 }
4589
4590 /** Prepare test cases
4591 *
4592 * @return true
4593 **/
testInit()4594 bool ImplicitConversionsValidTest::testInit()
4595 {
4596 static const typesPair allowed_conversions[] = {
4597 { Utils::UINT, Utils::INT }, { Utils::FLOAT, Utils::INT }, { Utils::DOUBLE, Utils::INT },
4598 { Utils::FLOAT, Utils::UINT }, { Utils::DOUBLE, Utils::UINT }, { Utils::FLOAT, Utils::FLOAT },
4599 };
4600
4601 static GLuint n_allowed_conversions = sizeof(allowed_conversions) / sizeof(typesPair);
4602
4603 m_debug_test_case.m_types.m_t1 = Utils::FLOAT;
4604 m_debug_test_case.m_types.m_t2 = Utils::FLOAT;
4605 m_debug_test_case.m_n_cols = 4;
4606 m_debug_test_case.m_n_rows = 4;
4607
4608 for (GLuint i = 0; i < n_allowed_conversions; ++i)
4609 {
4610 const typesPair& types = allowed_conversions[i];
4611
4612 GLuint allowed_columns = 1;
4613 if ((true == Utils::doesTypeSupportMatrix(types.m_t1)) && (true == Utils::doesTypeSupportMatrix(types.m_t2)))
4614 {
4615 allowed_columns = 4;
4616 }
4617
4618 {
4619 testCase test_case = { types, 1, 1 };
4620
4621 m_test_cases.push_back(test_case);
4622 }
4623
4624 for (GLuint row = 2; row <= 4; ++row)
4625 {
4626 for (GLuint col = 1; col <= allowed_columns; ++col)
4627 {
4628 testCase test_case = { types, col, row };
4629
4630 m_test_cases.push_back(test_case);
4631 }
4632 }
4633 }
4634
4635 return true;
4636 }
4637
4638 /** Returns reference to current test case
4639 *
4640 * @return Reference to testCase
4641 **/
getCurrentTestCase()4642 const ImplicitConversionsValidTest::testCase& ImplicitConversionsValidTest::getCurrentTestCase()
4643 {
4644 if ((glw::GLuint)-1 == m_current_test_case_index)
4645 {
4646 return m_debug_test_case;
4647 }
4648 else
4649 {
4650 return m_test_cases[m_current_test_case_index];
4651 }
4652 }
4653
4654 /** Get list of values to for glsl constants
4655 *
4656 * @param n_columns Number of columns
4657 * @param n_rows Number of rows
4658 *
4659 * @return String with list of values separated with comma
4660 **/
getValueList(glw::GLuint n_columns,glw::GLuint n_rows)4661 std::string ImplicitConversionsValidTest::getValueList(glw::GLuint n_columns, glw::GLuint n_rows)
4662 {
4663 std::string result;
4664
4665 for (GLuint i = 0; i < n_columns * n_rows; ++i)
4666 {
4667 if (i != n_columns * n_rows - 1)
4668 {
4669 result.append("1, ");
4670 }
4671 else
4672 {
4673 result.append("1");
4674 }
4675 }
4676
4677 return result;
4678 }
4679
4680 /** Constructor
4681 *
4682 * @param context Test context
4683 **/
ImplicitConversionsInvalidTest(deqp::Context & context)4684 ImplicitConversionsInvalidTest::ImplicitConversionsInvalidTest(deqp::Context& context)
4685 : NegativeTestBase(context, "implicit_conversions_invalid",
4686 "Verifies that implicit conversions from uint to int are forbidden")
4687 , m_current_test_case_index(0)
4688 {
4689 /* Nothing to be done here */
4690 }
4691
4692 /** Set up next test case
4693 *
4694 * @param test_case_index Index of next test case
4695 *
4696 * @return false if there is no more test cases, true otherwise
4697 **/
prepareNextTestCase(glw::GLuint test_case_index)4698 bool ImplicitConversionsInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
4699 {
4700 m_current_test_case_index = test_case_index;
4701
4702 if ((glw::GLuint)-1 == test_case_index)
4703 {
4704 return false;
4705 }
4706 else if (4 <= test_case_index)
4707 {
4708 return false;
4709 }
4710
4711 m_context.getTestContext().getLog() << tcu::TestLog::Message
4712 << "T1:" << Utils::getTypeName(Utils::UINT, 1, test_case_index + 1)
4713 << " T2:" << Utils::getTypeName(Utils::INT, 1, test_case_index + 1)
4714 << tcu::TestLog::EndMessage;
4715
4716 return true;
4717 }
4718
4719 /** Prepare source for given shader stage
4720 *
4721 * @param in_stage Shader stage, compute shader will use 430
4722 * @param in_use_version_400 Select if 400 or 420 should be used
4723 * @param out_source Prepared shader source instance
4724 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4725 void ImplicitConversionsInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4726 Utils::shaderSource& out_source)
4727 {
4728 static const GLchar* function_definition = "T1 function(in T2 left, in T2 right)\n"
4729 "{\n"
4730 " return left + right;\n"
4731 "}\n";
4732
4733 static const GLchar* verification_snippet = " const T2 const_left = T2(VALUE_LIST);\n"
4734 " const T2 const_right = T2(VALUE_LIST);\n"
4735 "\n"
4736 " T1 const_result = function(const_left, const_right);\n"
4737 "\n"
4738 " T1 literal_result = function(T2(VALUE_LIST), T2(VALUE_LIST));\n"
4739 "\n"
4740 " T2 var_left = uni_left;\n"
4741 " T2 var_right = uni_right;\n"
4742 "\n"
4743 " T1 var_result = function(var_left, var_right);\n"
4744 "\n"
4745 " if ((literal_result != const_result) ||\n"
4746 " (const_result != var_result) )\n"
4747 " {\n"
4748 " result = vec4(1, 0, 0, 1);\n"
4749 " }\n";
4750
4751 static const GLchar* compute_shader_template =
4752 "VERSION\n"
4753 "\n"
4754 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
4755 "\n"
4756 "writeonly uniform image2D uni_image;\n"
4757 " uniform T2 uni_left;\n"
4758 " uniform T2 uni_right;\n"
4759 "\n"
4760 "FUNCTION_DEFINITION"
4761 "\n"
4762 "void main()\n"
4763 "{\n"
4764 " vec4 result = vec4(0, 1, 0, 1);\n"
4765 "\n"
4766 "VERIFICATION"
4767 "\n"
4768 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
4769 "}\n"
4770 "\n";
4771
4772 static const GLchar* fragment_shader_template = "VERSION\n"
4773 "\n"
4774 "in vec4 gs_fs_result;\n"
4775 "out vec4 fs_out_result;\n"
4776 "uniform T2 uni_left;\n"
4777 "uniform T2 uni_right;\n"
4778 "\n"
4779 "FUNCTION_DEFINITION"
4780 "\n"
4781 "void main()\n"
4782 "{\n"
4783 " vec4 result = vec4(0, 1, 0, 1);\n"
4784 "\n"
4785 "VERIFICATION"
4786 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
4787 " {\n"
4788 " result = vec4(1, 0, 0, 1);\n"
4789 " }\n"
4790 "\n"
4791 " fs_out_result = result;\n"
4792 "}\n"
4793 "\n";
4794
4795 static const GLchar* geometry_shader_template = "VERSION\n"
4796 "\n"
4797 "layout(points) in;\n"
4798 "layout(triangle_strip, max_vertices = 4) out;\n"
4799 "\n"
4800 "in vec4 tes_gs_result[];\n"
4801 "out vec4 gs_fs_result;\n"
4802 "uniform T2 uni_left;\n"
4803 "uniform T2 uni_right;\n"
4804 "\n"
4805 "FUNCTION_DEFINITION"
4806 "\n"
4807 "void main()\n"
4808 "{\n"
4809 " vec4 result = vec4(0, 1, 0, 1);\n"
4810 "\n"
4811 "VERIFICATION"
4812 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
4813 " {\n"
4814 " result = vec4(1, 0, 0, 1);\n"
4815 " }\n"
4816 "\n"
4817 " gs_fs_result = result;\n"
4818 " gl_Position = vec4(-1, -1, 0, 1);\n"
4819 " EmitVertex();\n"
4820 " gs_fs_result = result;\n"
4821 " gl_Position = vec4(-1, 1, 0, 1);\n"
4822 " EmitVertex();\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 "}\n"
4830 "\n";
4831
4832 static const GLchar* tess_ctrl_shader_template =
4833 "VERSION\n"
4834 "\n"
4835 "layout(vertices = 1) out;\n"
4836 "\n"
4837 "in vec4 vs_tcs_result[];\n"
4838 "out vec4 tcs_tes_result[];\n"
4839 "uniform T2 uni_left;\n"
4840 "uniform T2 uni_right;\n"
4841 "\n"
4842 "FUNCTION_DEFINITION"
4843 "\n"
4844 "void main()\n"
4845 "{\n"
4846 " vec4 result = vec4(0, 1, 0, 1);\n"
4847 "\n"
4848 "VERIFICATION"
4849 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
4850 " {\n"
4851 " result = vec4(1, 0, 0, 1);\n"
4852 " }\n"
4853 "\n"
4854 " tcs_tes_result[gl_InvocationID] = result;\n"
4855 "\n"
4856 " gl_TessLevelOuter[0] = 1.0;\n"
4857 " gl_TessLevelOuter[1] = 1.0;\n"
4858 " gl_TessLevelOuter[2] = 1.0;\n"
4859 " gl_TessLevelOuter[3] = 1.0;\n"
4860 " gl_TessLevelInner[0] = 1.0;\n"
4861 " gl_TessLevelInner[1] = 1.0;\n"
4862 "}\n"
4863 "\n";
4864
4865 static const GLchar* tess_eval_shader_template = "VERSION\n"
4866 "\n"
4867 "layout(isolines, point_mode) in;\n"
4868 "\n"
4869 "in vec4 tcs_tes_result[];\n"
4870 "out vec4 tes_gs_result;\n"
4871 "uniform T2 uni_left;\n"
4872 "uniform T2 uni_right;\n"
4873 "\n"
4874 "FUNCTION_DEFINITION"
4875 "\n"
4876 "void main()\n"
4877 "{\n"
4878 " vec4 result = vec4(0, 1, 0, 1);\n"
4879 "\n"
4880 "VERIFICATION"
4881 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
4882 " {\n"
4883 " result = vec4(1, 0, 0, 1);\n"
4884 " }\n"
4885 "\n"
4886 " tes_gs_result = result;\n"
4887 "}\n"
4888 "\n";
4889
4890 static const GLchar* vertex_shader_template = "VERSION\n"
4891 "\n"
4892 "out vec4 vs_tcs_result;\n"
4893 "uniform T2 uni_left;\n"
4894 "uniform T2 uni_right;\n"
4895 "\n"
4896 "FUNCTION_DEFINITION"
4897 "\n"
4898 "void main()\n"
4899 "{\n"
4900 " vec4 result = vec4(0, 1, 0, 1);\n"
4901 "\n"
4902 "VERIFICATION"
4903 "\n"
4904 " vs_tcs_result = result;\n"
4905 "}\n"
4906 "\n";
4907
4908 GLuint n_rows = m_current_test_case_index + 1;
4909 const GLchar* t1 = Utils::getTypeName(Utils::INT, 1, n_rows);
4910 const GLchar* t2 = Utils::getTypeName(Utils::UINT, 1, n_rows);
4911 const std::string& value_list = getValueList(n_rows);
4912 const GLchar* shader_template = 0;
4913
4914 switch (in_stage)
4915 {
4916 case Utils::COMPUTE_SHADER:
4917 shader_template = compute_shader_template;
4918 break;
4919 case Utils::FRAGMENT_SHADER:
4920 shader_template = fragment_shader_template;
4921 break;
4922 case Utils::GEOMETRY_SHADER:
4923 shader_template = geometry_shader_template;
4924 break;
4925 case Utils::TESS_CTRL_SHADER:
4926 shader_template = tess_ctrl_shader_template;
4927 break;
4928 case Utils::TESS_EVAL_SHADER:
4929 shader_template = tess_eval_shader_template;
4930 break;
4931 case Utils::VERTEX_SHADER:
4932 shader_template = vertex_shader_template;
4933 break;
4934 default:
4935 TCU_FAIL("Invalid enum");
4936 }
4937
4938 out_source.m_parts[0].m_code = shader_template;
4939
4940 size_t position = 0;
4941 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
4942 out_source.m_parts[0].m_code);
4943
4944 Utils::replaceToken("FUNCTION_DEFINITION", position, function_definition, out_source.m_parts[0].m_code);
4945
4946 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
4947
4948 Utils::replaceAllTokens("VALUE_LIST", value_list.c_str(), out_source.m_parts[0].m_code);
4949
4950 Utils::replaceAllTokens("T1", t1, out_source.m_parts[0].m_code);
4951
4952 Utils::replaceAllTokens("T2", t2, out_source.m_parts[0].m_code);
4953 }
4954
4955 /** Get list of values to for glsl constants
4956 *
4957 * @return String with list of values separated with comma
4958 **/
getValueList(glw::GLuint n_rows)4959 std::string ImplicitConversionsInvalidTest::getValueList(glw::GLuint n_rows)
4960 {
4961 std::string result;
4962
4963 for (GLuint i = 0; i < n_rows; ++i)
4964 {
4965 if (i != n_rows - 1)
4966 {
4967 result.append("1, ");
4968 }
4969 else
4970 {
4971 result.append("1");
4972 }
4973 }
4974
4975 return result;
4976 }
4977
4978 /** Constructor
4979 *
4980 * @param context Test context
4981 **/
ConstDynamicValueTest(deqp::Context & context)4982 ConstDynamicValueTest::ConstDynamicValueTest(deqp::Context& context)
4983 : GLSLTestBase(context, "const_dynamic_value", "Test if constants can be initialized with dynamic values")
4984 {
4985 /* Nothing to be done here */
4986 }
4987
4988 /** Prepare source for given shader stage
4989 *
4990 * @param in_stage Shader stage, compute shader will use 430
4991 * @param in_use_version_400 Select if 400 or 420 should be used
4992 * @param out_source Prepared shader source instance
4993 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)4994 void ConstDynamicValueTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
4995 Utils::shaderSource& out_source)
4996 {
4997 static const GLchar* struct_definition = "struct S {\n"
4998 " float scalar;\n"
4999 " vec4 vector;\n"
5000 " mat2 matrix;\n"
5001 "};\n";
5002
5003 static const GLchar* verification_snippet = " const float c1 = uni_scalar;\n"
5004 " const vec4 c2 = uni_vector;\n"
5005 " const mat2 c3 = uni_matrix;\n"
5006 " const S c4 = { uni_scalar, uni_vector, uni_matrix };\n"
5007 " const vec4 c5[15] = { uni_vector,\n"
5008 " uni_vector,\n"
5009 " uni_vector,\n"
5010 " uni_vector,\n"
5011 " uni_vector,\n"
5012 " uni_vector,\n"
5013 " uni_vector,\n"
5014 " 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 " if ((SCALAR != c1) ||\n"
5023 " (VECTOR != c2) ||\n"
5024 " (MATRIX != c3) ||\n"
5025 " (SCALAR != c4.scalar) ||\n"
5026 " (VECTOR != c4.vector) ||\n"
5027 " (MATRIX != c4.matrix) ||\n"
5028 " (VECTOR != c5[0]) ||\n"
5029 " (VECTOR != c5[1]) ||\n"
5030 " (VECTOR != c5[2]) ||\n"
5031 " (VECTOR != c5[3]) ||\n"
5032 " (VECTOR != c5[4]) ||\n"
5033 " (VECTOR != c5[5]) ||\n"
5034 " (VECTOR != c5[6]) ||\n"
5035 " (VECTOR != c5[7]) ||\n"
5036 " (VECTOR != c5[8]) ||\n"
5037 " (VECTOR != c5[9]) ||\n"
5038 " (VECTOR != c5[10]) ||\n"
5039 " (VECTOR != c5[11]) ||\n"
5040 " (VECTOR != c5[12]) ||\n"
5041 " (VECTOR != c5[13]) ||\n"
5042 " (VECTOR != c5[14]) )\n"
5043 " {\n"
5044 " result = vec4(1, 0, 0, 1);\n"
5045 " }\n";
5046
5047 static const GLchar* compute_shader_template =
5048 "VERSION\n"
5049 "\n"
5050 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5051 "\n"
5052 "writeonly uniform image2D uni_image;\n"
5053 " uniform float uni_scalar;\n"
5054 " uniform vec4 uni_vector;\n"
5055 " uniform mat2 uni_matrix;\n"
5056 "\n"
5057 "STRUCTURE_DEFINITION"
5058 "\n"
5059 "void main()\n"
5060 "{\n"
5061 " vec4 result = vec4(0, 1, 0, 1);\n"
5062 "\n"
5063 "VERIFICATION"
5064 "\n"
5065 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5066 "}\n"
5067 "\n";
5068
5069 static const GLchar* fragment_shader_template = "VERSION\n"
5070 "\n"
5071 "in vec4 gs_fs_result;\n"
5072 "out vec4 fs_out_result;\n"
5073 "uniform float uni_scalar;\n"
5074 "uniform vec4 uni_vector;\n"
5075 "uniform mat2 uni_matrix;\n"
5076 "\n"
5077 "STRUCTURE_DEFINITION"
5078 "\n"
5079 "void main()\n"
5080 "{\n"
5081 " vec4 result = vec4(0, 1, 0, 1);\n"
5082 "\n"
5083 "VERIFICATION"
5084 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5085 " {\n"
5086 " result = vec4(1, 0, 0, 1);\n"
5087 " }\n"
5088 "\n"
5089 " fs_out_result = result;\n"
5090 "}\n"
5091 "\n";
5092
5093 static const GLchar* geometry_shader_template = "VERSION\n"
5094 "\n"
5095 "layout(points) in;\n"
5096 "layout(triangle_strip, max_vertices = 4) out;\n"
5097 "\n"
5098 "in vec4 tes_gs_result[];\n"
5099 "out vec4 gs_fs_result;\n"
5100 "uniform float uni_scalar;\n"
5101 "uniform vec4 uni_vector;\n"
5102 "uniform mat2 uni_matrix;\n"
5103 "\n"
5104 "STRUCTURE_DEFINITION"
5105 "\n"
5106 "void main()\n"
5107 "{\n"
5108 " vec4 result = vec4(0, 1, 0, 1);\n"
5109 "\n"
5110 "VERIFICATION"
5111 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5112 " {\n"
5113 " result = vec4(1, 0, 0, 1);\n"
5114 " }\n"
5115 "\n"
5116 " gs_fs_result = result;\n"
5117 " gl_Position = vec4(-1, -1, 0, 1);\n"
5118 " EmitVertex();\n"
5119 " gs_fs_result = result;\n"
5120 " gl_Position = vec4(-1, 1, 0, 1);\n"
5121 " EmitVertex();\n"
5122 " gs_fs_result = result;\n"
5123 " gl_Position = vec4(1, -1, 0, 1);\n"
5124 " EmitVertex();\n"
5125 " gs_fs_result = result;\n"
5126 " gl_Position = vec4(1, 1, 0, 1);\n"
5127 " EmitVertex();\n"
5128 "}\n"
5129 "\n";
5130
5131 static const GLchar* tess_ctrl_shader_template =
5132 "VERSION\n"
5133 "\n"
5134 "layout(vertices = 1) out;\n"
5135 "\n"
5136 "in vec4 vs_tcs_result[];\n"
5137 "out vec4 tcs_tes_result[];\n"
5138 "uniform float uni_scalar;\n"
5139 "uniform vec4 uni_vector;\n"
5140 "uniform mat2 uni_matrix;\n"
5141 "\n"
5142 "STRUCTURE_DEFINITION"
5143 "\n"
5144 "void main()\n"
5145 "{\n"
5146 " vec4 result = vec4(0, 1, 0, 1);\n"
5147 "\n"
5148 "VERIFICATION"
5149 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5150 " {\n"
5151 " result = vec4(1, 0, 0, 1);\n"
5152 " }\n"
5153 "\n"
5154 " tcs_tes_result[gl_InvocationID] = result;\n"
5155 "\n"
5156 " gl_TessLevelOuter[0] = 1.0;\n"
5157 " gl_TessLevelOuter[1] = 1.0;\n"
5158 " gl_TessLevelOuter[2] = 1.0;\n"
5159 " gl_TessLevelOuter[3] = 1.0;\n"
5160 " gl_TessLevelInner[0] = 1.0;\n"
5161 " gl_TessLevelInner[1] = 1.0;\n"
5162 "}\n"
5163 "\n";
5164
5165 static const GLchar* tess_eval_shader_template = "VERSION\n"
5166 "\n"
5167 "layout(isolines, point_mode) in;\n"
5168 "\n"
5169 "in vec4 tcs_tes_result[];\n"
5170 "out vec4 tes_gs_result;\n"
5171 "uniform float uni_scalar;\n"
5172 "uniform vec4 uni_vector;\n"
5173 "uniform mat2 uni_matrix;\n"
5174 "\n"
5175 "STRUCTURE_DEFINITION"
5176 "\n"
5177 "void main()\n"
5178 "{\n"
5179 " vec4 result = vec4(0, 1, 0, 1);\n"
5180 "\n"
5181 "VERIFICATION"
5182 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5183 " {\n"
5184 " result = vec4(1, 0, 0, 1);\n"
5185 " }\n"
5186 "\n"
5187 " tes_gs_result = result;\n"
5188 "}\n"
5189 "\n";
5190
5191 static const GLchar* vertex_shader_template = "VERSION\n"
5192 "\n"
5193 "out vec4 vs_tcs_result;\n"
5194 "uniform float uni_scalar;\n"
5195 "uniform vec4 uni_vector;\n"
5196 "uniform mat2 uni_matrix;\n"
5197 "\n"
5198 "STRUCTURE_DEFINITION"
5199 "\n"
5200 "void main()\n"
5201 "{\n"
5202 " vec4 result = vec4(0, 1, 0, 1);\n"
5203 "\n"
5204 "VERIFICATION"
5205 "\n"
5206 " vs_tcs_result = result;\n"
5207 "}\n"
5208 "\n";
5209
5210 static const GLchar* scalar = "0.5";
5211 static const GLchar* vector = "vec4(0.5, 0.125, 0.375, 0)";
5212 static const GLchar* matrix = "mat2(0.5, 0.125, 0.375, 0)";
5213
5214 const GLchar* shader_template = 0;
5215
5216 switch (in_stage)
5217 {
5218 case Utils::COMPUTE_SHADER:
5219 shader_template = compute_shader_template;
5220 break;
5221 case Utils::FRAGMENT_SHADER:
5222 shader_template = fragment_shader_template;
5223 break;
5224 case Utils::GEOMETRY_SHADER:
5225 shader_template = geometry_shader_template;
5226 break;
5227 case Utils::TESS_CTRL_SHADER:
5228 shader_template = tess_ctrl_shader_template;
5229 break;
5230 case Utils::TESS_EVAL_SHADER:
5231 shader_template = tess_eval_shader_template;
5232 break;
5233 case Utils::VERTEX_SHADER:
5234 shader_template = vertex_shader_template;
5235 break;
5236 default:
5237 TCU_FAIL("Invalid enum");
5238 }
5239
5240 out_source.m_parts[0].m_code = shader_template;
5241
5242 size_t position = 0;
5243 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5244 out_source.m_parts[0].m_code);
5245
5246 Utils::replaceToken("STRUCTURE_DEFINITION", position, struct_definition, out_source.m_parts[0].m_code);
5247
5248 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5249
5250 Utils::replaceAllTokens("SCALAR", scalar, out_source.m_parts[0].m_code);
5251
5252 Utils::replaceAllTokens("VECTOR", vector, out_source.m_parts[0].m_code);
5253
5254 Utils::replaceAllTokens("MATRIX", matrix, out_source.m_parts[0].m_code);
5255 }
5256
5257 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
5258 *
5259 * @param program Current program
5260 **/
prepareUniforms(Utils::program & program)5261 void ConstDynamicValueTest::prepareUniforms(Utils::program& program)
5262 {
5263 static const GLfloat float_data[4] = { 0.5f, 0.125f, 0.375f, 0.0f };
5264 static const GLfloat scalar = 0.5f;
5265
5266 program.uniform("uni_scalar", Utils::FLOAT, 1, 1, &scalar);
5267 program.uniform("uni_vector", Utils::FLOAT, 1, 4, float_data);
5268 program.uniform("uni_matrix", Utils::FLOAT, 2, 2, float_data);
5269 }
5270
5271 /** Constructor
5272 *
5273 * @param context Test context
5274 **/
ConstAssignmentTest(deqp::Context & context)5275 ConstAssignmentTest::ConstAssignmentTest(deqp::Context& context)
5276 : NegativeTestBase(context, "const_assignment", "Verifies that constants cannot be overwritten")
5277 , m_current_test_case_index(0)
5278 {
5279 /* Nothing to be done here */
5280 }
5281
5282 /** Set up next test case
5283 *
5284 * @param test_case_index Index of next test case
5285 *
5286 * @return false if there is no more test cases, true otherwise
5287 **/
prepareNextTestCase(glw::GLuint test_case_index)5288 bool ConstAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
5289 {
5290 m_current_test_case_index = test_case_index;
5291
5292 if ((glw::GLuint)-1 == test_case_index)
5293 {
5294 return true;
5295 }
5296 else if (2 <= test_case_index)
5297 {
5298 return false;
5299 }
5300
5301 return true;
5302 }
5303
5304 /** Prepare source for given shader stage
5305 *
5306 * @param in_stage Shader stage, compute shader will use 430
5307 * @param in_use_version_400 Select if 400 or 420 should be used
5308 * @param out_source Prepared shader source instance
5309 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5310 void ConstAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5311 Utils::shaderSource& out_source)
5312 {
5313 static const GLchar* verification_snippet = " const float c1 = INIT;\n"
5314 "\n"
5315 " float temp = c1;\n"
5316 "\n"
5317 " for (uint i = 0; i < 4; ++i)"
5318 " {\n"
5319 " temp += c1 + uni_value;\n"
5320 " c1 -= 0.125;\n"
5321 " }\n"
5322 "\n"
5323 " if (0.0 == temp)\n"
5324 " {\n"
5325 " result = vec4(1, 0, 0, 1);\n"
5326 " }\n";
5327
5328 static const GLchar* compute_shader_template =
5329 "VERSION\n"
5330 "\n"
5331 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5332 "\n"
5333 "writeonly uniform image2D uni_image;\n"
5334 " uniform float uni_value;\n"
5335 "\n"
5336 "void main()\n"
5337 "{\n"
5338 " vec4 result = vec4(0, 1, 0, 1);\n"
5339 "\n"
5340 "VERIFICATION"
5341 "\n"
5342 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5343 "}\n"
5344 "\n";
5345
5346 static const GLchar* fragment_shader_template = "VERSION\n"
5347 "\n"
5348 "in vec4 gs_fs_result;\n"
5349 "out vec4 fs_out_result;\n"
5350 "uniform float uni_value;\n"
5351 "\n"
5352 "void main()\n"
5353 "{\n"
5354 " vec4 result = vec4(0, 1, 0, 1);\n"
5355 "\n"
5356 "VERIFICATION"
5357 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5358 " {\n"
5359 " result = vec4(1, 0, 0, 1);\n"
5360 " }\n"
5361 "\n"
5362 " fs_out_result = result;\n"
5363 "}\n"
5364 "\n";
5365
5366 static const GLchar* geometry_shader_template = "VERSION\n"
5367 "\n"
5368 "layout(points) in;\n"
5369 "layout(triangle_strip, max_vertices = 4) out;\n"
5370 "\n"
5371 "in vec4 tes_gs_result[];\n"
5372 "out vec4 gs_fs_result;\n"
5373 "uniform float uni_value;\n"
5374 "\n"
5375 "void main()\n"
5376 "{\n"
5377 " vec4 result = vec4(0, 1, 0, 1);\n"
5378 "\n"
5379 "VERIFICATION"
5380 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5381 " {\n"
5382 " result = vec4(1, 0, 0, 1);\n"
5383 " }\n"
5384 "\n"
5385 " gs_fs_result = result;\n"
5386 " gl_Position = vec4(-1, -1, 0, 1);\n"
5387 " EmitVertex();\n"
5388 " gs_fs_result = result;\n"
5389 " gl_Position = vec4(-1, 1, 0, 1);\n"
5390 " EmitVertex();\n"
5391 " gs_fs_result = result;\n"
5392 " gl_Position = vec4(1, -1, 0, 1);\n"
5393 " EmitVertex();\n"
5394 " gs_fs_result = result;\n"
5395 " gl_Position = vec4(1, 1, 0, 1);\n"
5396 " EmitVertex();\n"
5397 "}\n"
5398 "\n";
5399
5400 static const GLchar* tess_ctrl_shader_template =
5401 "VERSION\n"
5402 "\n"
5403 "layout(vertices = 1) out;\n"
5404 "\n"
5405 "in vec4 vs_tcs_result[];\n"
5406 "out vec4 tcs_tes_result[];\n"
5407 "uniform float uni_value;\n"
5408 "\n"
5409 "void main()\n"
5410 "{\n"
5411 " vec4 result = vec4(0, 1, 0, 1);\n"
5412 "\n"
5413 "VERIFICATION"
5414 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5415 " {\n"
5416 " result = vec4(1, 0, 0, 1);\n"
5417 " }\n"
5418 "\n"
5419 " tcs_tes_result[gl_InvocationID] = result;\n"
5420 "\n"
5421 " gl_TessLevelOuter[0] = 1.0;\n"
5422 " gl_TessLevelOuter[1] = 1.0;\n"
5423 " gl_TessLevelOuter[2] = 1.0;\n"
5424 " gl_TessLevelOuter[3] = 1.0;\n"
5425 " gl_TessLevelInner[0] = 1.0;\n"
5426 " gl_TessLevelInner[1] = 1.0;\n"
5427 "}\n"
5428 "\n";
5429
5430 static const GLchar* tess_eval_shader_template = "VERSION\n"
5431 "\n"
5432 "layout(isolines, point_mode) in;\n"
5433 "\n"
5434 "in vec4 tcs_tes_result[];\n"
5435 "out vec4 tes_gs_result;\n"
5436 "uniform float uni_value;\n"
5437 "\n"
5438 "void main()\n"
5439 "{\n"
5440 " vec4 result = vec4(0, 1, 0, 1);\n"
5441 "\n"
5442 "VERIFICATION"
5443 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5444 " {\n"
5445 " result = vec4(1, 0, 0, 1);\n"
5446 " }\n"
5447 "\n"
5448 " tes_gs_result = result;\n"
5449 "}\n"
5450 "\n";
5451
5452 static const GLchar* vertex_shader_template = "VERSION\n"
5453 "\n"
5454 "out vec4 vs_tcs_result;\n"
5455 "uniform float uni_value;\n"
5456 "\n"
5457 "void main()\n"
5458 "{\n"
5459 " vec4 result = vec4(0, 1, 0, 1);\n"
5460 "\n"
5461 "VERIFICATION"
5462 "\n"
5463 " vs_tcs_result = result;\n"
5464 "}\n"
5465 "\n";
5466
5467 static const GLchar* dynamic_init = "uni_value";
5468 static const GLchar* const_init = "0.75";
5469
5470 const GLchar* shader_template = 0;
5471 const GLchar* l_init = 0;
5472
5473 switch (in_stage)
5474 {
5475 case Utils::COMPUTE_SHADER:
5476 shader_template = compute_shader_template;
5477 break;
5478 case Utils::FRAGMENT_SHADER:
5479 shader_template = fragment_shader_template;
5480 break;
5481 case Utils::GEOMETRY_SHADER:
5482 shader_template = geometry_shader_template;
5483 break;
5484 case Utils::TESS_CTRL_SHADER:
5485 shader_template = tess_ctrl_shader_template;
5486 break;
5487 case Utils::TESS_EVAL_SHADER:
5488 shader_template = tess_eval_shader_template;
5489 break;
5490 case Utils::VERTEX_SHADER:
5491 shader_template = vertex_shader_template;
5492 break;
5493 default:
5494 TCU_FAIL("Invalid enum");
5495 }
5496
5497 if (0 == m_current_test_case_index)
5498 {
5499 l_init = dynamic_init;
5500 }
5501 else
5502 {
5503 l_init = const_init;
5504 }
5505
5506 out_source.m_parts[0].m_code = shader_template;
5507
5508 size_t position = 0;
5509 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5510 out_source.m_parts[0].m_code);
5511
5512 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5513
5514 Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5515 }
5516
5517 /** Constructor
5518 *
5519 * @param context Test context
5520 **/
ConstDynamicValueAsConstExprTest(deqp::Context & context)5521 ConstDynamicValueAsConstExprTest::ConstDynamicValueAsConstExprTest(deqp::Context& context)
5522 : NegativeTestBase(context, "const_dynamic_value_as_const_expr",
5523 "Verifies that dynamic constants cannot be used as constant foldable expressions")
5524 {
5525 /* Nothing to be done here */
5526 }
5527
5528 /** Prepare source for given shader stage
5529 *
5530 * @param in_stage Shader stage, compute shader will use 430
5531 * @param in_use_version_400 Select if 400 or 420 should be used
5532 * @param out_source Prepared shader source instance
5533 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5534 void ConstDynamicValueAsConstExprTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5535 Utils::shaderSource& out_source)
5536 {
5537 static const GLchar* verification_snippet = " const uint c1 = INIT;\n"
5538 "\n"
5539 " float temp[c1];\n"
5540 "\n"
5541 " for (uint i = 0; i < c1; ++i)"
5542 " {\n"
5543 " temp[i] += uni_value;\n"
5544 " }\n"
5545 "\n"
5546 " if (0.0 == temp[c1 - 1])\n"
5547 " {\n"
5548 " result = vec4(1, 0, 0, 1);\n"
5549 " }\n";
5550
5551 static const GLchar* compute_shader_template =
5552 "VERSION\n"
5553 "\n"
5554 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5555 "\n"
5556 "writeonly uniform image2D uni_image;\n"
5557 " uniform uint uni_value;\n"
5558 "\n"
5559 "void main()\n"
5560 "{\n"
5561 " vec4 result = vec4(0, 1, 0, 1);\n"
5562 "\n"
5563 "VERIFICATION"
5564 "\n"
5565 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
5566 "}\n"
5567 "\n";
5568
5569 static const GLchar* fragment_shader_template = "VERSION\n"
5570 "\n"
5571 "in vec4 gs_fs_result;\n"
5572 "out vec4 fs_out_result;\n"
5573 "uniform uint uni_value;\n"
5574 "\n"
5575 "void main()\n"
5576 "{\n"
5577 " vec4 result = vec4(0, 1, 0, 1);\n"
5578 "\n"
5579 "VERIFICATION"
5580 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5581 " {\n"
5582 " result = vec4(1, 0, 0, 1);\n"
5583 " }\n"
5584 "\n"
5585 " fs_out_result = result;\n"
5586 "}\n"
5587 "\n";
5588
5589 static const GLchar* geometry_shader_template = "VERSION\n"
5590 "\n"
5591 "layout(points) in;\n"
5592 "layout(triangle_strip, max_vertices = 4) out;\n"
5593 "\n"
5594 "in vec4 tes_gs_result[];\n"
5595 "out vec4 gs_fs_result;\n"
5596 "uniform uint uni_value;\n"
5597 "\n"
5598 "void main()\n"
5599 "{\n"
5600 " vec4 result = vec4(0, 1, 0, 1);\n"
5601 "\n"
5602 "VERIFICATION"
5603 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5604 " {\n"
5605 " result = vec4(1, 0, 0, 1);\n"
5606 " }\n"
5607 "\n"
5608 " gs_fs_result = result;\n"
5609 " gl_Position = vec4(-1, -1, 0, 1);\n"
5610 " EmitVertex();\n"
5611 " gs_fs_result = result;\n"
5612 " gl_Position = vec4(-1, 1, 0, 1);\n"
5613 " EmitVertex();\n"
5614 " gs_fs_result = result;\n"
5615 " gl_Position = vec4(1, -1, 0, 1);\n"
5616 " EmitVertex();\n"
5617 " gs_fs_result = result;\n"
5618 " gl_Position = vec4(1, 1, 0, 1);\n"
5619 " EmitVertex();\n"
5620 "}\n"
5621 "\n";
5622
5623 static const GLchar* tess_ctrl_shader_template =
5624 "VERSION\n"
5625 "\n"
5626 "layout(vertices = 1) out;\n"
5627 "\n"
5628 "in vec4 vs_tcs_result[];\n"
5629 "out vec4 tcs_tes_result[];\n"
5630 "uniform uint uni_value;\n"
5631 "\n"
5632 "void main()\n"
5633 "{\n"
5634 " vec4 result = vec4(0, 1, 0, 1);\n"
5635 "\n"
5636 "VERIFICATION"
5637 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5638 " {\n"
5639 " result = vec4(1, 0, 0, 1);\n"
5640 " }\n"
5641 "\n"
5642 " tcs_tes_result[gl_InvocationID] = result;\n"
5643 "\n"
5644 " gl_TessLevelOuter[0] = 1.0;\n"
5645 " gl_TessLevelOuter[1] = 1.0;\n"
5646 " gl_TessLevelOuter[2] = 1.0;\n"
5647 " gl_TessLevelOuter[3] = 1.0;\n"
5648 " gl_TessLevelInner[0] = 1.0;\n"
5649 " gl_TessLevelInner[1] = 1.0;\n"
5650 "}\n"
5651 "\n";
5652
5653 static const GLchar* tess_eval_shader_template = "VERSION\n"
5654 "\n"
5655 "layout(isolines, point_mode) in;\n"
5656 "\n"
5657 "in vec4 tcs_tes_result[];\n"
5658 "out vec4 tes_gs_result;\n"
5659 "uniform uint uni_value;\n"
5660 "\n"
5661 "void main()\n"
5662 "{\n"
5663 " vec4 result = vec4(0, 1, 0, 1);\n"
5664 "\n"
5665 "VERIFICATION"
5666 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5667 " {\n"
5668 " result = vec4(1, 0, 0, 1);\n"
5669 " }\n"
5670 "\n"
5671 " tes_gs_result = result;\n"
5672 "}\n"
5673 "\n";
5674
5675 static const GLchar* vertex_shader_template = "VERSION\n"
5676 "\n"
5677 "out vec4 vs_tcs_result;\n"
5678 "uniform uint uni_value;\n"
5679 "\n"
5680 "void main()\n"
5681 "{\n"
5682 " vec4 result = vec4(0, 1, 0, 1);\n"
5683 "\n"
5684 "VERIFICATION"
5685 "\n"
5686 " vs_tcs_result = result;\n"
5687 "}\n"
5688 "\n";
5689
5690 static const GLchar* l_init = "uni_value";
5691
5692 const GLchar* shader_template = 0;
5693
5694 switch (in_stage)
5695 {
5696 case Utils::COMPUTE_SHADER:
5697 shader_template = compute_shader_template;
5698 break;
5699 case Utils::FRAGMENT_SHADER:
5700 shader_template = fragment_shader_template;
5701 break;
5702 case Utils::GEOMETRY_SHADER:
5703 shader_template = geometry_shader_template;
5704 break;
5705 case Utils::TESS_CTRL_SHADER:
5706 shader_template = tess_ctrl_shader_template;
5707 break;
5708 case Utils::TESS_EVAL_SHADER:
5709 shader_template = tess_eval_shader_template;
5710 break;
5711 case Utils::VERTEX_SHADER:
5712 shader_template = vertex_shader_template;
5713 break;
5714 default:
5715 TCU_FAIL("Invalid enum");
5716 }
5717
5718 out_source.m_parts[0].m_code = shader_template;
5719
5720 size_t position = 0;
5721 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5722 out_source.m_parts[0].m_code);
5723
5724 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5725
5726 Utils::replaceAllTokens("INIT", l_init, out_source.m_parts[0].m_code);
5727 }
5728
5729 /** Constructor
5730 *
5731 * @param context Test context
5732 **/
QualifierOrderTest(deqp::Context & context)5733 QualifierOrderTest::QualifierOrderTest(deqp::Context& context)
5734 : GLSLTestBase(context, "qualifier_order",
5735 "Test verifies that valid permutation of input and output qalifiers are accepted")
5736 , m_current_test_case_index(0)
5737 {
5738 /* Nothing to be done */
5739 }
5740
5741 /** Set up next test case
5742 *
5743 * @param test_case_index Index of next test case
5744 *
5745 * @return false if there is no more test cases, true otherwise
5746 **/
prepareNextTestCase(glw::GLuint test_case_index)5747 bool QualifierOrderTest::prepareNextTestCase(glw::GLuint test_case_index)
5748 {
5749 m_current_test_case_index = test_case_index;
5750
5751 if ((glw::GLuint)-1 == test_case_index)
5752 {
5753 /* Nothing to be done here */
5754 }
5755 else if (m_test_cases.size() <= test_case_index)
5756 {
5757 return false;
5758 }
5759
5760 const Utils::qualifierSet& set = getCurrentTestCase();
5761
5762 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
5763
5764 for (GLuint i = 0; i < set.size(); ++i)
5765 {
5766 message << Utils::getQualifierString(set[i]) << " ";
5767 }
5768
5769 message << tcu::TestLog::EndMessage;
5770
5771 return true;
5772 }
5773
5774 /** Prepare source for given shader stage
5775 *
5776 * @param in_stage Shader stage, compute shader will use 430
5777 * @param in_use_version_400 Select if 400 or 420 should be used
5778 * @param out_source Prepared shader source instance
5779 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)5780 void QualifierOrderTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
5781 Utils::shaderSource& out_source)
5782 {
5783 static const GLchar* verification_snippet =
5784 " vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
5785 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
5786 " {\n"
5787 " result = INPUT_VARIABLE_NAME;\n"
5788 " }\n";
5789
5790 static const GLchar* fragment_shader_template = "VERSION\n"
5791 "\n"
5792 "in vec4 gs_fs_result;\n"
5793 "layout (location = 0) out vec4 fs_out_result;\n"
5794 "\n"
5795 "VARIABLE_DECLARATION;\n"
5796 "VARIABLE_DECLARATION;\n"
5797 "\n"
5798 "void main()\n"
5799 "{\n"
5800 " vec4 result = vec4(0, 1, 0, 1);\n"
5801 "\n"
5802 "VERIFICATION"
5803 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
5804 " {\n"
5805 " result = vec4(1, 0, 0, 1);\n"
5806 " }\n"
5807 "\n"
5808 " fs_out_result = result;\n"
5809 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5810 "}\n"
5811 "\n";
5812
5813 static const GLchar* geometry_shader_template = "VERSION\n"
5814 "\n"
5815 "layout(points) in;\n"
5816 "layout(triangle_strip, max_vertices = 4) out;\n"
5817 "\n"
5818 "in vec4 tes_gs_result[];\n"
5819 "out vec4 gs_fs_result;\n"
5820 "\n"
5821 "VARIABLE_DECLARATION;\n"
5822 "VARIABLE_DECLARATION;\n"
5823 "\n"
5824 "void main()\n"
5825 "{\n"
5826 " vec4 result = vec4(0, 1, 0, 1);\n"
5827 "\n"
5828 "VERIFICATION"
5829 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
5830 " {\n"
5831 " result = vec4(1, 0, 0, 1);\n"
5832 " }\n"
5833 "\n"
5834 " gs_fs_result = result;\n"
5835 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5836 " gl_Position = vec4(-1, -1, 0, 1);\n"
5837 " EmitVertex();\n"
5838 " gs_fs_result = result;\n"
5839 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5840 " gl_Position = vec4(-1, 1, 0, 1);\n"
5841 " EmitVertex();\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 "}\n"
5851 "\n";
5852
5853 static const GLchar* tess_ctrl_shader_template =
5854 "VERSION\n"
5855 "\n"
5856 "layout(vertices = 1) out;\n"
5857 "\n"
5858 "in vec4 vs_tcs_result[];\n"
5859 "out vec4 tcs_tes_result[];\n"
5860 "\n"
5861 "VARIABLE_DECLARATION;\n"
5862 "VARIABLE_DECLARATION;\n"
5863 "\n"
5864 "void main()\n"
5865 "{\n"
5866 " vec4 result = vec4(0, 1, 0, 1);\n"
5867 "\n"
5868 "VERIFICATION"
5869 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
5870 " {\n"
5871 " result = vec4(1, 0, 0, 1);\n"
5872 " }\n"
5873 "\n"
5874 " tcs_tes_result[gl_InvocationID] = result;\n"
5875 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5876 "\n"
5877 " gl_TessLevelOuter[0] = 1.0;\n"
5878 " gl_TessLevelOuter[1] = 1.0;\n"
5879 " gl_TessLevelOuter[2] = 1.0;\n"
5880 " gl_TessLevelOuter[3] = 1.0;\n"
5881 " gl_TessLevelInner[0] = 1.0;\n"
5882 " gl_TessLevelInner[1] = 1.0;\n"
5883 "}\n"
5884 "\n";
5885
5886 static const GLchar* tess_eval_shader_template = "VERSION\n"
5887 "\n"
5888 "layout(isolines, point_mode) in;\n"
5889 "\n"
5890 "in vec4 tcs_tes_result[];\n"
5891 "out vec4 tes_gs_result;\n"
5892 "\n"
5893 "VARIABLE_DECLARATION;\n"
5894 "VARIABLE_DECLARATION;\n"
5895 "\n"
5896 "void main()\n"
5897 "{\n"
5898 " vec4 result = vec4(0, 1, 0, 1);\n"
5899 "\n"
5900 "VERIFICATION"
5901 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
5902 " {\n"
5903 " result = vec4(1, 0, 0, 1);\n"
5904 " }\n"
5905 "\n"
5906 " tes_gs_result = result;\n"
5907 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5908 "}\n"
5909 "\n";
5910
5911 static const GLchar* vertex_shader_template = "VERSION\n"
5912 "\n"
5913 "out vec4 vs_tcs_result;\n"
5914 "\n"
5915 "VARIABLE_DECLARATION;\n"
5916 "VARIABLE_DECLARATION;\n"
5917 "\n"
5918 "void main()\n"
5919 "{\n"
5920 " vec4 result = vec4(0, 1, 0, 1);\n"
5921 "\n"
5922 "VERIFICATION"
5923 "\n"
5924 " vs_tcs_result = result;\n"
5925 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
5926 "}\n"
5927 "\n";
5928
5929 const GLchar* shader_template = 0;
5930
5931 switch (in_stage)
5932 {
5933 case Utils::COMPUTE_SHADER:
5934 return;
5935 case Utils::FRAGMENT_SHADER:
5936 shader_template = fragment_shader_template;
5937 break;
5938 case Utils::GEOMETRY_SHADER:
5939 shader_template = geometry_shader_template;
5940 break;
5941 case Utils::TESS_CTRL_SHADER:
5942 shader_template = tess_ctrl_shader_template;
5943 break;
5944 case Utils::TESS_EVAL_SHADER:
5945 shader_template = tess_eval_shader_template;
5946 break;
5947 case Utils::VERTEX_SHADER:
5948 shader_template = vertex_shader_template;
5949 break;
5950 default:
5951 TCU_FAIL("Invalid enum");
5952 }
5953
5954 const Utils::qualifierSet& test_case = getCurrentTestCase();
5955
5956 std::string in_test_decl;
5957 std::string in_test_ref;
5958 std::string out_test_decl;
5959 std::string out_test_ref;
5960
5961 Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
5962 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
5963
5964 // sample storage qualifier is not a valid qualifier for fragment output
5965 if (in_stage == Utils::FRAGMENT_SHADER)
5966 {
5967 if (out_test_decl.find("sample") != std::string::npos)
5968 out_test_decl.erase(out_test_decl.find("sample"), 7);
5969 }
5970
5971 out_source.m_parts[0].m_code = shader_template;
5972
5973 size_t position = 0;
5974
5975 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
5976 out_source.m_parts[0].m_code);
5977
5978 Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
5979
5980 Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
5981
5982 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
5983
5984 position -= strlen(verification_snippet);
5985
5986 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
5987
5988 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
5989
5990 Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
5991 }
5992
5993 /**Prepare vertex buffer and vertex array object.
5994 *
5995 * @param program Program instance
5996 * @param buffer Buffer instance
5997 * @param vao VertexArray instance
5998 *
5999 * @return 0
6000 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)6001 void QualifierOrderTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
6002 Utils::vertexArray& vao)
6003 {
6004 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
6005 GLint test_loc = program.getAttribLocation(test_name.c_str());
6006
6007 if (-1 == test_loc)
6008 {
6009 TCU_FAIL("Vertex attribute location is invalid");
6010 }
6011
6012 vao.generate();
6013 vao.bind();
6014
6015 buffer.generate(GL_ARRAY_BUFFER);
6016
6017 GLfloat data[] = { 0.0f, 0.0f, 1.0f, 1.0f };
6018 GLsizeiptr data_size = sizeof(data);
6019
6020 buffer.update(data_size, data, GL_STATIC_DRAW);
6021
6022 /* GL entry points */
6023 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6024
6025 /* Set up vao */
6026 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6027 0 /* offset */);
6028 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6029
6030 /* Enable attribute */
6031 gl.enableVertexAttribArray(test_loc);
6032 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6033 }
6034
6035 /** Prepare test cases
6036 *
6037 * @return true
6038 **/
testInit()6039 bool QualifierOrderTest::testInit()
6040 {
6041 m_test_cases.resize(5);
6042
6043 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6044 m_test_cases[0].push_back(Utils::QUAL_IN);
6045 m_test_cases[0].push_back(Utils::QUAL_LOCATION);
6046 m_test_cases[0].push_back(Utils::QUAL_SMOOTH);
6047 m_test_cases[0].push_back(Utils::QUAL_INVARIANT);
6048
6049 m_test_cases[1].push_back(Utils::QUAL_LOWP);
6050 m_test_cases[1].push_back(Utils::QUAL_IN);
6051 m_test_cases[1].push_back(Utils::QUAL_SAMPLE);
6052 m_test_cases[1].push_back(Utils::QUAL_LOCATION);
6053 m_test_cases[1].push_back(Utils::QUAL_NOPERSPECTIVE);
6054 m_test_cases[1].push_back(Utils::QUAL_INVARIANT);
6055
6056 m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6057 m_test_cases[2].push_back(Utils::QUAL_IN);
6058 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6059 m_test_cases[2].push_back(Utils::QUAL_SMOOTH);
6060 m_test_cases[2].push_back(Utils::QUAL_INVARIANT);
6061 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6062
6063 m_test_cases[3].push_back(Utils::QUAL_LOWP);
6064 m_test_cases[3].push_back(Utils::QUAL_IN);
6065 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6066 m_test_cases[3].push_back(Utils::QUAL_SAMPLE);
6067 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6068 m_test_cases[3].push_back(Utils::QUAL_NOPERSPECTIVE);
6069 m_test_cases[3].push_back(Utils::QUAL_INVARIANT);
6070
6071 m_test_cases[4].push_back(Utils::QUAL_HIGHP);
6072 m_test_cases[4].push_back(Utils::QUAL_IN);
6073 m_test_cases[4].push_back(Utils::QUAL_PATCH);
6074 m_test_cases[4].push_back(Utils::QUAL_LOCATION);
6075 m_test_cases[4].push_back(Utils::QUAL_INVARIANT);
6076
6077 return true;
6078 }
6079
6080 /** Returns reference to current test case
6081 *
6082 * @return Reference to testCase
6083 **/
getCurrentTestCase()6084 const Utils::qualifierSet& QualifierOrderTest::getCurrentTestCase()
6085 {
6086 if ((glw::GLuint)-1 == m_current_test_case_index)
6087 {
6088 return m_test_cases[0];
6089 }
6090 else
6091 {
6092 return m_test_cases[m_current_test_case_index];
6093 }
6094 }
6095
6096 /** Constructor
6097 *
6098 * @param context Test context
6099 **/
QualifierOrderBlockTest(deqp::Context & context)6100 QualifierOrderBlockTest::QualifierOrderBlockTest(deqp::Context& context)
6101 : GLSLTestBase(context, "qualifier_order_block",
6102 "Verifies that qualifiers of members of input block can be arranged in any order")
6103 , m_current_test_case_index(0)
6104 {
6105 /* Nothing to be done here */
6106 }
6107
6108 /** Set up next test case
6109 *
6110 * @param test_case_index Index of next test case
6111 *
6112 * @return false if there is no more test cases, true otherwise
6113 **/
prepareNextTestCase(glw::GLuint test_case_index)6114 bool QualifierOrderBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
6115 {
6116 m_current_test_case_index = test_case_index;
6117
6118 if ((glw::GLuint)-1 == test_case_index)
6119 {
6120 /* Nothing to be done here */
6121 }
6122 else if (m_test_cases.size() <= test_case_index)
6123 {
6124 return false;
6125 }
6126
6127 const Utils::qualifierSet& set = getCurrentTestCase();
6128
6129 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6130
6131 for (GLuint i = 0; i < set.size(); ++i)
6132 {
6133 message << Utils::getQualifierString(set[i]) << " ";
6134 }
6135
6136 message << tcu::TestLog::EndMessage;
6137
6138 return true;
6139 }
6140
6141 /** Prepare source for given shader stage
6142 *
6143 * @param in_stage Shader stage, compute shader will use 430
6144 * @param in_use_version_400 Select if 400 or 420 should be used
6145 * @param out_source Prepared shader source instance
6146 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6147 void QualifierOrderBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6148 Utils::shaderSource& out_source)
6149 {
6150 static const GLchar* verification_snippet =
6151 " vec4 diff = INPUT_VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6152 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6153 " {\n"
6154 " result = INPUT_VARIABLE_NAME;\n"
6155 " }\n";
6156
6157 static const GLchar* fragment_shader_template = "VERSION\n"
6158 "\n"
6159 "in vec4 gs_fs_result;\n"
6160 "layout (location = 0) out vec4 fs_out_result;\n"
6161 "\n"
6162 "in GSOutputBlock {\n"
6163 " VARIABLE_DECLARATION;\n"
6164 "} input_block;\n"
6165 "out VARIABLE_DECLARATION;\n"
6166 "\n"
6167 "void main()\n"
6168 "{\n"
6169 " vec4 result = vec4(0, 1, 0, 1);\n"
6170 "\n"
6171 "VERIFICATION"
6172 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6173 " {\n"
6174 " result = vec4(1, 0, 0, 1);\n"
6175 " }\n"
6176 "\n"
6177 " fs_out_result = result;\n"
6178 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6179 "}\n"
6180 "\n";
6181
6182 static const GLchar* geometry_shader_template = "VERSION\n"
6183 "\n"
6184 "layout(points) in;\n"
6185 "layout(triangle_strip, max_vertices = 4) out;\n"
6186 "\n"
6187 "in vec4 tes_gs_result[];\n"
6188 "out vec4 gs_fs_result;\n"
6189 "\n"
6190 "in TCSOutputBlock {\n"
6191 " VARIABLE_DECLARATION;\n"
6192 "} input_block [];\n"
6193 "out GSOutputBlock {\n"
6194 " VARIABLE_DECLARATION;\n"
6195 "} output_block;\n"
6196 "\n"
6197 "void main()\n"
6198 "{\n"
6199 " vec4 result = vec4(0, 1, 0, 1);\n"
6200 "\n"
6201 "VERIFICATION"
6202 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6203 " {\n"
6204 " result = vec4(1, 0, 0, 1);\n"
6205 " }\n"
6206 "\n"
6207 " gs_fs_result = result;\n"
6208 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6209 " gl_Position = vec4(-1, -1, 0, 1);\n"
6210 " EmitVertex();\n"
6211 " gs_fs_result = result;\n"
6212 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6213 " gl_Position = vec4(-1, 1, 0, 1);\n"
6214 " EmitVertex();\n"
6215 " gs_fs_result = result;\n"
6216 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6217 " gl_Position = vec4(1, -1, 0, 1);\n"
6218 " EmitVertex();\n"
6219 " gs_fs_result = result;\n"
6220 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6221 " gl_Position = vec4(1, 1, 0, 1);\n"
6222 " EmitVertex();\n"
6223 "}\n"
6224 "\n";
6225
6226 static const GLchar* tess_ctrl_shader_template =
6227 "VERSION\n"
6228 "\n"
6229 "layout(vertices = 1) out;\n"
6230 "\n"
6231 "in vec4 vs_tcs_result[];\n"
6232 "out vec4 tcs_tes_result[];\n"
6233 "\n"
6234 "in VSOutputBlock {\n"
6235 " VARIABLE_DECLARATION;\n"
6236 "} input_block [];\n"
6237 "out TCSOutputBlock {\n"
6238 " VARIABLE_DECLARATION;\n"
6239 "} output_block [];\n"
6240 "\n"
6241 "void main()\n"
6242 "{\n"
6243 " vec4 result = vec4(0, 1, 0, 1);\n"
6244 "\n"
6245 "VERIFICATION"
6246 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6247 " {\n"
6248 " result = vec4(1, 0, 0, 1);\n"
6249 " }\n"
6250 "\n"
6251 " tcs_tes_result[gl_InvocationID] = result;\n"
6252 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6253 "\n"
6254 " gl_TessLevelOuter[0] = 1.0;\n"
6255 " gl_TessLevelOuter[1] = 1.0;\n"
6256 " gl_TessLevelOuter[2] = 1.0;\n"
6257 " gl_TessLevelOuter[3] = 1.0;\n"
6258 " gl_TessLevelInner[0] = 1.0;\n"
6259 " gl_TessLevelInner[1] = 1.0;\n"
6260 "}\n"
6261 "\n";
6262
6263 static const GLchar* tess_eval_shader_template = "VERSION\n"
6264 "\n"
6265 "layout(isolines, point_mode) in;\n"
6266 "\n"
6267 "in vec4 tcs_tes_result[];\n"
6268 "out vec4 tes_gs_result;\n"
6269 "\n"
6270 "in TCSOutputBlock {\n"
6271 " VARIABLE_DECLARATION;\n"
6272 "} input_block [];\n"
6273 "out TCSOutputBlock {\n"
6274 " VARIABLE_DECLARATION;\n"
6275 "} output_block;\n"
6276 "\n"
6277 "void main()\n"
6278 "{\n"
6279 " vec4 result = vec4(0, 1, 0, 1);\n"
6280 "\n"
6281 "VERIFICATION"
6282 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6283 " {\n"
6284 " result = vec4(1, 0, 0, 1);\n"
6285 " }\n"
6286 "\n"
6287 " tes_gs_result = result;\n"
6288 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6289 "}\n"
6290 "\n";
6291
6292 static const GLchar* vertex_shader_template = "VERSION\n"
6293 "\n"
6294 "out vec4 vs_tcs_result;\n"
6295 "\n"
6296 "in VARIABLE_DECLARATION;\n"
6297 "out VSOutputBlock {\n"
6298 " VARIABLE_DECLARATION;\n"
6299 "} output_block;\n"
6300 "\n"
6301 "void main()\n"
6302 "{\n"
6303 " vec4 result = vec4(0, 1, 0, 1);\n"
6304 "\n"
6305 "VERIFICATION"
6306 "\n"
6307 " vs_tcs_result = result;\n"
6308 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
6309 "}\n"
6310 "\n";
6311
6312 const GLchar* shader_template = 0;
6313
6314 switch (in_stage)
6315 {
6316 case Utils::COMPUTE_SHADER:
6317 return;
6318 case Utils::FRAGMENT_SHADER:
6319 shader_template = fragment_shader_template;
6320 break;
6321 case Utils::GEOMETRY_SHADER:
6322 shader_template = geometry_shader_template;
6323 break;
6324 case Utils::TESS_CTRL_SHADER:
6325 shader_template = tess_ctrl_shader_template;
6326 break;
6327 case Utils::TESS_EVAL_SHADER:
6328 shader_template = tess_eval_shader_template;
6329 break;
6330 case Utils::VERTEX_SHADER:
6331 shader_template = vertex_shader_template;
6332 break;
6333 default:
6334 TCU_FAIL("Invalid enum");
6335 }
6336
6337 const Utils::qualifierSet& test_case = getCurrentTestCase();
6338
6339 std::string in_test_decl;
6340 std::string in_test_ref;
6341 std::string out_test_decl;
6342 std::string out_test_ref;
6343
6344 switch (in_stage)
6345 {
6346 case Utils::VERTEX_SHADER:
6347 Utils::prepareVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", in_test_decl, in_test_ref);
6348 break;
6349 default:
6350 Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, test_case, "vec4", "test", "input_block",
6351 in_test_decl, in_test_ref);
6352 break;
6353 }
6354
6355 switch (in_stage)
6356 {
6357 case Utils::FRAGMENT_SHADER:
6358 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", out_test_decl, out_test_ref);
6359 break;
6360 default:
6361 Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, test_case, "vec4", "test", "output_block",
6362 out_test_decl, out_test_ref);
6363 break;
6364 }
6365
6366 // sample storage qualifier is not a valid qualifier for fragment output
6367 if (in_stage == Utils::FRAGMENT_SHADER)
6368 {
6369 if (out_test_decl.find("sample") != std::string::npos)
6370 out_test_decl.erase(out_test_decl.find("sample"), 7);
6371 }
6372 out_source.m_parts[0].m_code = shader_template;
6373
6374 size_t position = 0;
6375
6376 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6377 out_source.m_parts[0].m_code);
6378
6379 Utils::replaceToken("VARIABLE_DECLARATION", position, in_test_decl.c_str(), out_source.m_parts[0].m_code);
6380
6381 Utils::replaceToken("VARIABLE_DECLARATION", position, out_test_decl.c_str(), out_source.m_parts[0].m_code);
6382
6383 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6384
6385 position -= strlen(verification_snippet);
6386
6387 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", out_test_ref.c_str(), out_source.m_parts[0].m_code);
6388
6389 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", in_test_ref.c_str(), out_source.m_parts[0].m_code);
6390
6391 Utils::replaceAllTokens("LOC_VALUE", "1", out_source.m_parts[0].m_code);
6392 }
6393
6394 /**Prepare vertex buffer and vertex array object.
6395 *
6396 * @param program Program instance
6397 * @param buffer Buffer instance
6398 * @param vao VertexArray instance
6399 *
6400 * @return 0
6401 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)6402 void QualifierOrderBlockTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
6403 Utils::vertexArray& vao)
6404 {
6405 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
6406 GLint test_loc = program.getAttribLocation(test_name.c_str());
6407
6408 if (-1 == test_loc)
6409 {
6410 TCU_FAIL("Vertex attribute location is invalid");
6411 }
6412
6413 vao.generate();
6414 vao.bind();
6415
6416 buffer.generate(GL_ARRAY_BUFFER);
6417
6418 GLfloat data[] = { 0.0f, 0.0f, 1.0f, 1.0f };
6419 GLsizeiptr data_size = sizeof(data);
6420
6421 buffer.update(data_size, data, GL_STATIC_DRAW);
6422
6423 /* GL entry points */
6424 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
6425
6426 /* Set up vao */
6427 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
6428 0 /* offset */);
6429 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
6430
6431 /* Enable attribute */
6432 gl.enableVertexAttribArray(test_loc);
6433 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
6434 }
6435
6436 /** Prepare test cases
6437 *
6438 * @return true
6439 **/
testInit()6440 bool QualifierOrderBlockTest::testInit()
6441 {
6442 m_test_cases.resize(4);
6443
6444 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6445 m_test_cases[0].push_back(Utils::QUAL_FLAT);
6446 m_test_cases[0].push_back(Utils::QUAL_INVARIANT);
6447
6448 m_test_cases[1].push_back(Utils::QUAL_LOWP);
6449 m_test_cases[1].push_back(Utils::QUAL_SAMPLE);
6450 m_test_cases[1].push_back(Utils::QUAL_NOPERSPECTIVE);
6451 m_test_cases[1].push_back(Utils::QUAL_INVARIANT);
6452
6453 m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6454 m_test_cases[2].push_back(Utils::QUAL_SMOOTH);
6455 m_test_cases[2].push_back(Utils::QUAL_INVARIANT);
6456
6457 m_test_cases[3].push_back(Utils::QUAL_LOWP);
6458 m_test_cases[3].push_back(Utils::QUAL_SAMPLE);
6459 m_test_cases[3].push_back(Utils::QUAL_NOPERSPECTIVE);
6460 m_test_cases[3].push_back(Utils::QUAL_INVARIANT);
6461
6462 return true;
6463 }
6464
6465 /** Returns reference to current test case
6466 *
6467 * @return Reference to testCase
6468 **/
getCurrentTestCase()6469 const Utils::qualifierSet& QualifierOrderBlockTest::getCurrentTestCase()
6470 {
6471 if ((glw::GLuint)-1 == m_current_test_case_index)
6472 {
6473 return m_test_cases[0];
6474 }
6475 else
6476 {
6477 return m_test_cases[m_current_test_case_index];
6478 }
6479 }
6480
6481 /** Constructor
6482 *
6483 * @param context Test context
6484 **/
QualifierOrderUniformTest(deqp::Context & context)6485 QualifierOrderUniformTest::QualifierOrderUniformTest(deqp::Context& context)
6486 : GLSLTestBase(context, "qualifier_order_uniform",
6487 "Test verifies that all valid permutation of input qalifiers are accepted")
6488 , m_current_test_case_index(0)
6489 {
6490 /* Nothing to be done here */
6491 }
6492
6493 /** Set up next test case
6494 *
6495 * @param test_case_index Index of next test case
6496 *
6497 * @return false if there is no more test cases, true otherwise
6498 **/
prepareNextTestCase(glw::GLuint test_case_index)6499 bool QualifierOrderUniformTest::prepareNextTestCase(glw::GLuint test_case_index)
6500 {
6501 m_current_test_case_index = test_case_index;
6502
6503 if ((glw::GLuint)-1 == test_case_index)
6504 {
6505 /* Nothing to be done here */
6506 }
6507 else if (m_test_cases.size() <= test_case_index)
6508 {
6509 return false;
6510 }
6511
6512 const Utils::qualifierSet& set = getCurrentTestCase();
6513
6514 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6515
6516 for (GLuint i = 0; i < set.size(); ++i)
6517 {
6518 message << Utils::getQualifierString(set[i]) << " ";
6519 }
6520
6521 message << tcu::TestLog::EndMessage;
6522
6523 return true;
6524 }
6525
6526 /** Prepare source for given shader stage
6527 *
6528 * @param in_stage Shader stage, compute shader will use 430
6529 * @param in_use_version_400 Select if 400 or 420 should be used
6530 * @param out_source Prepared shader source instance
6531 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6532 void QualifierOrderUniformTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6533 Utils::shaderSource& out_source)
6534 {
6535 static const GLchar* verification_snippet =
6536 " vec4 diff = VARIABLE_NAME - vec4(0, 0, 1, 1);\n"
6537 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6538 " {\n"
6539 " result = VARIABLE_NAME;\n"
6540 " }\n";
6541
6542 static const GLchar* variable_declaration = " QUALIFIERS VARIABLE_NAME";
6543
6544 static const GLchar* fragment_shader_template = "VERSION\n"
6545 "#extension GL_ARB_explicit_uniform_location : enable\n"
6546 "\n"
6547 "in vec4 gs_fs_result;\n"
6548 "out vec4 fs_out_result;\n"
6549 "\n"
6550 "VARIABLE_DECLARATION;\n"
6551 "\n"
6552 "void main()\n"
6553 "{\n"
6554 " vec4 result = vec4(0, 1, 0, 1);\n"
6555 "\n"
6556 "VERIFICATION"
6557 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6558 " {\n"
6559 " result = vec4(1, 0, 0, 1);\n"
6560 " }\n"
6561 "\n"
6562 " fs_out_result = result;\n"
6563 "}\n"
6564 "\n";
6565
6566 static const GLchar* geometry_shader_template = "VERSION\n"
6567 "#extension GL_ARB_explicit_uniform_location : enable\n"
6568 "\n"
6569 "layout(points) in;\n"
6570 "layout(triangle_strip, max_vertices = 4) out;\n"
6571 "\n"
6572 "in vec4 tes_gs_result[];\n"
6573 "out vec4 gs_fs_result;\n"
6574 "\n"
6575 "VARIABLE_DECLARATION;\n"
6576 "\n"
6577 "void main()\n"
6578 "{\n"
6579 " vec4 result = vec4(0, 1, 0, 1);\n"
6580 "\n"
6581 "VERIFICATION"
6582 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6583 " {\n"
6584 " result = vec4(1, 0, 0, 1);\n"
6585 " }\n"
6586 "\n"
6587 " gs_fs_result = result;\n"
6588 " gl_Position = vec4(-1, -1, 0, 1);\n"
6589 " EmitVertex();\n"
6590 " gs_fs_result = result;\n"
6591 " gl_Position = vec4(-1, 1, 0, 1);\n"
6592 " EmitVertex();\n"
6593 " gs_fs_result = result;\n"
6594 " gl_Position = vec4(1, -1, 0, 1);\n"
6595 " EmitVertex();\n"
6596 " gs_fs_result = result;\n"
6597 " gl_Position = vec4(1, 1, 0, 1);\n"
6598 " EmitVertex();\n"
6599 "}\n"
6600 "\n";
6601
6602 static const GLchar* tess_ctrl_shader_template =
6603 "VERSION\n"
6604 "#extension GL_ARB_explicit_uniform_location : enable\n"
6605 "\n"
6606 "layout(vertices = 1) out;\n"
6607 "\n"
6608 "in vec4 vs_tcs_result[];\n"
6609 "out vec4 tcs_tes_result[];\n"
6610 "\n"
6611 "VARIABLE_DECLARATION;\n"
6612 "\n"
6613 "void main()\n"
6614 "{\n"
6615 " vec4 result = vec4(0, 1, 0, 1);\n"
6616 "\n"
6617 "VERIFICATION"
6618 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6619 " {\n"
6620 " result = vec4(1, 0, 0, 1);\n"
6621 " }\n"
6622 "\n"
6623 " tcs_tes_result[gl_InvocationID] = result;\n"
6624 "\n"
6625 " gl_TessLevelOuter[0] = 1.0;\n"
6626 " gl_TessLevelOuter[1] = 1.0;\n"
6627 " gl_TessLevelOuter[2] = 1.0;\n"
6628 " gl_TessLevelOuter[3] = 1.0;\n"
6629 " gl_TessLevelInner[0] = 1.0;\n"
6630 " gl_TessLevelInner[1] = 1.0;\n"
6631 "}\n"
6632 "\n";
6633
6634 static const GLchar* tess_eval_shader_template = "VERSION\n"
6635 "#extension GL_ARB_explicit_uniform_location : enable\n"
6636 "\n"
6637 "layout(isolines, point_mode) in;\n"
6638 "\n"
6639 "in vec4 tcs_tes_result[];\n"
6640 "out vec4 tes_gs_result;\n"
6641 "\n"
6642 "VARIABLE_DECLARATION;\n"
6643 "\n"
6644 "void main()\n"
6645 "{\n"
6646 " vec4 result = vec4(0, 1, 0, 1);\n"
6647 "\n"
6648 "VERIFICATION"
6649 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6650 " {\n"
6651 " result = vec4(1, 0, 0, 1);\n"
6652 " }\n"
6653 "\n"
6654 " tes_gs_result = result;\n"
6655 "}\n"
6656 "\n";
6657
6658 static const GLchar* vertex_shader_template = "VERSION\n"
6659 "#extension GL_ARB_explicit_uniform_location : enable\n"
6660 "\n"
6661 "out vec4 vs_tcs_result;\n"
6662 "\n"
6663 "VARIABLE_DECLARATION;\n"
6664 "\n"
6665 "void main()\n"
6666 "{\n"
6667 " vec4 result = vec4(0, 1, 0, 1);\n"
6668 "\n"
6669 "VERIFICATION"
6670 "\n"
6671 " vs_tcs_result = result;\n"
6672 "}\n"
6673 "\n";
6674
6675 const GLchar* shader_template = 0;
6676 const GLchar* location_string = 0;
6677
6678 switch (in_stage)
6679 {
6680 case Utils::COMPUTE_SHADER:
6681 return;
6682 case Utils::FRAGMENT_SHADER:
6683 shader_template = fragment_shader_template;
6684 location_string = "0";
6685 break;
6686 case Utils::GEOMETRY_SHADER:
6687 shader_template = geometry_shader_template;
6688 location_string = "1";
6689 break;
6690 case Utils::TESS_CTRL_SHADER:
6691 shader_template = tess_ctrl_shader_template;
6692 location_string = "4";
6693 break;
6694 case Utils::TESS_EVAL_SHADER:
6695 shader_template = tess_eval_shader_template;
6696 location_string = "3";
6697 break;
6698 case Utils::VERTEX_SHADER:
6699 shader_template = vertex_shader_template;
6700 location_string = "2";
6701 break;
6702 default:
6703 TCU_FAIL("Invalid enum");
6704 }
6705
6706 const Utils::qualifierSet& test_case = getCurrentTestCase();
6707
6708 std::string uni_declaration;
6709 std::string uni_reference;
6710 Utils::prepareVariableStrings(in_stage, Utils::UNIFORM, test_case, "vec4", "test", uni_declaration, uni_reference);
6711
6712 out_source.m_parts[0].m_code = shader_template;
6713
6714 size_t position = 0;
6715
6716 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
6717 out_source.m_parts[0].m_code);
6718
6719 Utils::replaceToken("VARIABLE_DECLARATION", position, uni_declaration.c_str(), out_source.m_parts[0].m_code);
6720
6721 position -= strlen(variable_declaration);
6722
6723 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
6724
6725 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
6726
6727 Utils::replaceAllTokens("LOC_VALUE", location_string, out_source.m_parts[0].m_code);
6728 }
6729
6730 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
6731 *
6732 * @param program Current program
6733 **/
prepareUniforms(Utils::program & program)6734 void QualifierOrderUniformTest::prepareUniforms(Utils::program& program)
6735 {
6736 static const GLfloat float_data[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
6737
6738 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6739 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6740 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6741 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6742 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
6743 }
6744
6745 /** Prepare test cases
6746 *
6747 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
6748 **/
testInit()6749 bool QualifierOrderUniformTest::testInit()
6750 {
6751 if (false == m_is_explicit_uniform_location)
6752 {
6753 return false;
6754 }
6755
6756 m_test_cases.resize(4);
6757
6758 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
6759 m_test_cases[0].push_back(Utils::QUAL_UNIFORM);
6760 m_test_cases[0].push_back(Utils::QUAL_LOCATION);
6761
6762 m_test_cases[1].push_back(Utils::QUAL_LOWP);
6763 m_test_cases[1].push_back(Utils::QUAL_UNIFORM);
6764 m_test_cases[1].push_back(Utils::QUAL_LOCATION);
6765
6766 m_test_cases[2].push_back(Utils::QUAL_HIGHP);
6767 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6768 m_test_cases[2].push_back(Utils::QUAL_UNIFORM);
6769 m_test_cases[2].push_back(Utils::QUAL_LOCATION);
6770
6771 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6772 m_test_cases[3].push_back(Utils::QUAL_LOWP);
6773 m_test_cases[3].push_back(Utils::QUAL_UNIFORM);
6774 m_test_cases[3].push_back(Utils::QUAL_LOCATION);
6775
6776 return true;
6777 }
6778
6779 /** Returns reference to current test case
6780 *
6781 * @return Reference to testCase
6782 **/
getCurrentTestCase()6783 const Utils::qualifierSet& QualifierOrderUniformTest::getCurrentTestCase()
6784 {
6785 if ((glw::GLuint)-1 == m_current_test_case_index)
6786 {
6787 return m_test_cases[0];
6788 }
6789 else
6790 {
6791 return m_test_cases[m_current_test_case_index];
6792 }
6793 }
6794
6795 /** Constructor
6796 *
6797 * @param context Test context
6798 **/
QualifierOrderFunctionInoutTest(deqp::Context & context)6799 QualifierOrderFunctionInoutTest::QualifierOrderFunctionInoutTest(deqp::Context& context)
6800 : GLSLTestBase(context, "qualifier_order_function_inout", "Verify order of qualifiers of inout function parameters")
6801 , m_current_test_case_index(0)
6802 {
6803 /* Nothing to be done here */
6804 }
6805
6806 /** Set up next test case
6807 *
6808 * @param test_case_index Index of next test case
6809 *
6810 * @return false if there is no more test cases, true otherwise
6811 **/
prepareNextTestCase(glw::GLuint test_case_index)6812 bool QualifierOrderFunctionInoutTest::prepareNextTestCase(glw::GLuint test_case_index)
6813 {
6814 m_current_test_case_index = test_case_index;
6815
6816 if ((glw::GLuint)-1 == test_case_index)
6817 {
6818 /* Nothing to be done here */
6819 }
6820 else if (m_test_cases.size() <= test_case_index)
6821 {
6822 return false;
6823 }
6824
6825 const Utils::qualifierSet& set = getCurrentTestCase();
6826
6827 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
6828
6829 for (GLuint i = 0; i < set.size(); ++i)
6830 {
6831 message << Utils::getQualifierString(set[i]) << " ";
6832 }
6833
6834 message << tcu::TestLog::EndMessage;
6835
6836 return true;
6837 }
6838
6839 /** Prepare source for given shader stage
6840 *
6841 * @param in_stage Shader stage, compute shader will use 430
6842 * @param in_use_version_400 Select if 400 or 420 should be used
6843 * @param out_source Prepared shader source instance
6844 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)6845 void QualifierOrderFunctionInoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
6846 Utils::shaderSource& out_source)
6847 {
6848 static const GLchar* verification_snippet =
6849 " vec4 temp = VARIABLE_NAME;\n"
6850 "\n"
6851 " function(temp);\n"
6852 "\n"
6853 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
6854 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
6855 " {\n"
6856 " result = VARIABLE_NAME;\n"
6857 " }\n";
6858
6859 static const GLchar* function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
6860 "{\n"
6861 " param = param.wzyx;\n"
6862 "}\n";
6863
6864 static const GLchar* fragment_shader_template = "VERSION\n"
6865 "\n"
6866 "in vec4 gs_fs_result;\n"
6867 "out vec4 fs_out_result;\n"
6868 "\n"
6869 "uniform vec4 VARIABLE_NAME;\n"
6870 "\n"
6871 "FUNCTION_DECLARATION\n"
6872 "\n"
6873 "void main()\n"
6874 "{\n"
6875 " vec4 result = vec4(0, 1, 0, 1);\n"
6876 "\n"
6877 "VERIFICATION"
6878 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
6879 " {\n"
6880 " result = vec4(1, 0, 0, 1);\n"
6881 " }\n"
6882 "\n"
6883 " fs_out_result = result;\n"
6884 "}\n"
6885 "\n";
6886
6887 static const GLchar* geometry_shader_template = "VERSION\n"
6888 "\n"
6889 "layout(points) in;\n"
6890 "layout(triangle_strip, max_vertices = 4) out;\n"
6891 "\n"
6892 "in vec4 tes_gs_result[];\n"
6893 "out vec4 gs_fs_result;\n"
6894 "\n"
6895 "uniform vec4 VARIABLE_NAME;\n"
6896 "\n"
6897 "FUNCTION_DECLARATION\n"
6898 "\n"
6899 "void main()\n"
6900 "{\n"
6901 " vec4 result = vec4(0, 1, 0, 1);\n"
6902 "\n"
6903 "VERIFICATION"
6904 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
6905 " {\n"
6906 " result = vec4(1, 0, 0, 1);\n"
6907 " }\n"
6908 "\n"
6909 " gs_fs_result = result;\n"
6910 " gl_Position = vec4(-1, -1, 0, 1);\n"
6911 " EmitVertex();\n"
6912 " gs_fs_result = result;\n"
6913 " gl_Position = vec4(-1, 1, 0, 1);\n"
6914 " EmitVertex();\n"
6915 " gs_fs_result = result;\n"
6916 " gl_Position = vec4(1, -1, 0, 1);\n"
6917 " EmitVertex();\n"
6918 " gs_fs_result = result;\n"
6919 " gl_Position = vec4(1, 1, 0, 1);\n"
6920 " EmitVertex();\n"
6921 "}\n"
6922 "\n";
6923
6924 static const GLchar* tess_ctrl_shader_template =
6925 "VERSION\n"
6926 "\n"
6927 "layout(vertices = 1) out;\n"
6928 "\n"
6929 "in vec4 vs_tcs_result[];\n"
6930 "out vec4 tcs_tes_result[];\n"
6931 "\n"
6932 "uniform vec4 VARIABLE_NAME;\n"
6933 "\n"
6934 "FUNCTION_DECLARATION\n"
6935 "\n"
6936 "void main()\n"
6937 "{\n"
6938 " vec4 result = vec4(0, 1, 0, 1);\n"
6939 "\n"
6940 "VERIFICATION"
6941 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
6942 " {\n"
6943 " result = vec4(1, 0, 0, 1);\n"
6944 " }\n"
6945 "\n"
6946 " tcs_tes_result[gl_InvocationID] = result;\n"
6947 "\n"
6948 " gl_TessLevelOuter[0] = 1.0;\n"
6949 " gl_TessLevelOuter[1] = 1.0;\n"
6950 " gl_TessLevelOuter[2] = 1.0;\n"
6951 " gl_TessLevelOuter[3] = 1.0;\n"
6952 " gl_TessLevelInner[0] = 1.0;\n"
6953 " gl_TessLevelInner[1] = 1.0;\n"
6954 "}\n"
6955 "\n";
6956
6957 static const GLchar* tess_eval_shader_template = "VERSION\n"
6958 "\n"
6959 "layout(isolines, point_mode) in;\n"
6960 "\n"
6961 "in vec4 tcs_tes_result[];\n"
6962 "out vec4 tes_gs_result;\n"
6963 "\n"
6964 "uniform vec4 VARIABLE_NAME;\n"
6965 "\n"
6966 "FUNCTION_DECLARATION\n"
6967 "\n"
6968 "void main()\n"
6969 "{\n"
6970 " vec4 result = vec4(0, 1, 0, 1);\n"
6971 "\n"
6972 "VERIFICATION"
6973 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
6974 " {\n"
6975 " result = vec4(1, 0, 0, 1);\n"
6976 " }\n"
6977 "\n"
6978 " tes_gs_result = result;\n"
6979 "}\n"
6980 "\n";
6981
6982 static const GLchar* vertex_shader_template = "VERSION\n"
6983 "\n"
6984 "out vec4 vs_tcs_result;\n"
6985 "\n"
6986 "uniform vec4 VARIABLE_NAME;\n"
6987 "\n"
6988 "FUNCTION_DECLARATION\n"
6989 "\n"
6990 "void main()\n"
6991 "{\n"
6992 " vec4 result = vec4(0, 1, 0, 1);\n"
6993 "\n"
6994 "VERIFICATION"
6995 "\n"
6996 " vs_tcs_result = result;\n"
6997 "}\n"
6998 "\n";
6999
7000 const GLchar* shader_template = 0;
7001
7002 switch (in_stage)
7003 {
7004 case Utils::COMPUTE_SHADER:
7005 return;
7006 case Utils::FRAGMENT_SHADER:
7007 shader_template = fragment_shader_template;
7008 break;
7009 case Utils::GEOMETRY_SHADER:
7010 shader_template = geometry_shader_template;
7011 break;
7012 case Utils::TESS_CTRL_SHADER:
7013 shader_template = tess_ctrl_shader_template;
7014 break;
7015 case Utils::TESS_EVAL_SHADER:
7016 shader_template = tess_eval_shader_template;
7017 break;
7018 case Utils::VERTEX_SHADER:
7019 shader_template = vertex_shader_template;
7020 break;
7021 default:
7022 TCU_FAIL("Invalid enum");
7023 }
7024
7025 const std::string& uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7026 const std::string& qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7027
7028 out_source.m_parts[0].m_code = shader_template;
7029
7030 size_t position = 0;
7031
7032 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7033 out_source.m_parts[0].m_code);
7034
7035 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7036
7037 position -= strlen(function_declaration);
7038
7039 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7040
7041 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7042
7043 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7044 }
7045
7046 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7047 *
7048 * @param program Current program
7049 **/
prepareUniforms(Utils::program & program)7050 void QualifierOrderFunctionInoutTest::prepareUniforms(Utils::program& program)
7051 {
7052 static const GLfloat float_data[4] = { 1.0f, 1.0f, 0.0f, 0.0f };
7053
7054 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7055 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7056 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7057 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7058 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7059 }
7060
7061 /** Prepare test cases
7062 *
7063 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7064 **/
testInit()7065 bool QualifierOrderFunctionInoutTest::testInit()
7066 {
7067 m_test_cases.resize(6);
7068
7069 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7070 m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7071 m_test_cases[0].push_back(Utils::QUAL_INOUT);
7072
7073 m_test_cases[1].push_back(Utils::QUAL_INOUT);
7074 m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7075 m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7076
7077 m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7078 m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7079 m_test_cases[2].push_back(Utils::QUAL_INOUT);
7080
7081 m_test_cases[3].push_back(Utils::QUAL_INOUT);
7082 m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7083 m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7084
7085 m_test_cases[4].push_back(Utils::QUAL_LOWP);
7086 m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7087 m_test_cases[4].push_back(Utils::QUAL_INOUT);
7088
7089 m_test_cases[5].push_back(Utils::QUAL_INOUT);
7090 m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7091 m_test_cases[5].push_back(Utils::QUAL_LOWP);
7092
7093 return true;
7094 }
7095
7096 /** Returns reference to current test case
7097 *
7098 * @return Reference to testCase
7099 **/
getCurrentTestCase()7100 const Utils::qualifierSet& QualifierOrderFunctionInoutTest::getCurrentTestCase()
7101 {
7102 if ((glw::GLuint)-1 == m_current_test_case_index)
7103 {
7104 return m_test_cases[0];
7105 }
7106 else
7107 {
7108 return m_test_cases[m_current_test_case_index];
7109 }
7110 }
7111
7112 /** Constructor
7113 *
7114 * @param context Test context
7115 **/
QualifierOrderFunctionInputTest(deqp::Context & context)7116 QualifierOrderFunctionInputTest::QualifierOrderFunctionInputTest(deqp::Context& context)
7117 : GLSLTestBase(context, "qualifier_order_function_input", "Verify order of qualifiers of function input parameters")
7118 , m_current_test_case_index(0)
7119 {
7120 /* Nothing to be done here */
7121 }
7122
7123 /** Set up next test case
7124 *
7125 * @param test_case_index Index of next test case
7126 *
7127 * @return false if there is no more test cases, true otherwise
7128 **/
prepareNextTestCase(glw::GLuint test_case_index)7129 bool QualifierOrderFunctionInputTest::prepareNextTestCase(glw::GLuint test_case_index)
7130 {
7131 m_current_test_case_index = test_case_index;
7132
7133 if ((glw::GLuint)-1 == test_case_index)
7134 {
7135 /* Nothing to be done here */
7136 }
7137 else if (m_test_cases.size() <= test_case_index)
7138 {
7139 return false;
7140 }
7141
7142 const Utils::qualifierSet& set = getCurrentTestCase();
7143
7144 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7145
7146 for (GLuint i = 0; i < set.size(); ++i)
7147 {
7148 message << Utils::getQualifierString(set[i]) << " ";
7149 }
7150
7151 message << tcu::TestLog::EndMessage;
7152
7153 return true;
7154 }
7155
7156 /** Prepare source for given shader stage
7157 *
7158 * @param in_stage Shader stage, compute shader will use 430
7159 * @param in_use_version_400 Select if 400 or 420 should be used
7160 * @param out_source Prepared shader source instance
7161 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7162 void QualifierOrderFunctionInputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7163 Utils::shaderSource& out_source)
7164 {
7165 static const GLchar* verification_snippet =
7166 " vec4 temp = function(VARIABLE_NAME);\n"
7167 "\n"
7168 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7169 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7170 " {\n"
7171 " result = VARIABLE_NAME;\n"
7172 " }\n";
7173
7174 static const GLchar* function_declaration = "vec4 function(QUALIFIERS_LIST vec4 param)\n"
7175 "{\n"
7176 " return param.wzyx;\n"
7177 "}\n";
7178
7179 static const GLchar* fragment_shader_template = "VERSION\n"
7180 "\n"
7181 "in vec4 gs_fs_result;\n"
7182 "out vec4 fs_out_result;\n"
7183 "\n"
7184 "uniform vec4 VARIABLE_NAME;\n"
7185 "\n"
7186 "FUNCTION_DECLARATION\n"
7187 "\n"
7188 "void main()\n"
7189 "{\n"
7190 " vec4 result = vec4(0, 1, 0, 1);\n"
7191 "\n"
7192 "VERIFICATION"
7193 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7194 " {\n"
7195 " result = vec4(1, 0, 0, 1);\n"
7196 " }\n"
7197 "\n"
7198 " fs_out_result = result;\n"
7199 "}\n"
7200 "\n";
7201
7202 static const GLchar* geometry_shader_template = "VERSION\n"
7203 "\n"
7204 "layout(points) in;\n"
7205 "layout(triangle_strip, max_vertices = 4) out;\n"
7206 "\n"
7207 "in vec4 tes_gs_result[];\n"
7208 "out vec4 gs_fs_result;\n"
7209 "\n"
7210 "uniform vec4 VARIABLE_NAME;\n"
7211 "\n"
7212 "FUNCTION_DECLARATION\n"
7213 "\n"
7214 "void main()\n"
7215 "{\n"
7216 " vec4 result = vec4(0, 1, 0, 1);\n"
7217 "\n"
7218 "VERIFICATION"
7219 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7220 " {\n"
7221 " result = vec4(1, 0, 0, 1);\n"
7222 " }\n"
7223 "\n"
7224 " gs_fs_result = result;\n"
7225 " gl_Position = vec4(-1, -1, 0, 1);\n"
7226 " EmitVertex();\n"
7227 " gs_fs_result = result;\n"
7228 " gl_Position = vec4(-1, 1, 0, 1);\n"
7229 " EmitVertex();\n"
7230 " gs_fs_result = result;\n"
7231 " gl_Position = vec4(1, -1, 0, 1);\n"
7232 " EmitVertex();\n"
7233 " gs_fs_result = result;\n"
7234 " gl_Position = vec4(1, 1, 0, 1);\n"
7235 " EmitVertex();\n"
7236 "}\n"
7237 "\n";
7238
7239 static const GLchar* tess_ctrl_shader_template =
7240 "VERSION\n"
7241 "\n"
7242 "layout(vertices = 1) out;\n"
7243 "\n"
7244 "in vec4 vs_tcs_result[];\n"
7245 "out vec4 tcs_tes_result[];\n"
7246 "\n"
7247 "uniform vec4 VARIABLE_NAME;\n"
7248 "\n"
7249 "FUNCTION_DECLARATION\n"
7250 "\n"
7251 "void main()\n"
7252 "{\n"
7253 " vec4 result = vec4(0, 1, 0, 1);\n"
7254 "\n"
7255 "VERIFICATION"
7256 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7257 " {\n"
7258 " result = vec4(1, 0, 0, 1);\n"
7259 " }\n"
7260 "\n"
7261 " tcs_tes_result[gl_InvocationID] = result;\n"
7262 "\n"
7263 " gl_TessLevelOuter[0] = 1.0;\n"
7264 " gl_TessLevelOuter[1] = 1.0;\n"
7265 " gl_TessLevelOuter[2] = 1.0;\n"
7266 " gl_TessLevelOuter[3] = 1.0;\n"
7267 " gl_TessLevelInner[0] = 1.0;\n"
7268 " gl_TessLevelInner[1] = 1.0;\n"
7269 "}\n"
7270 "\n";
7271
7272 static const GLchar* tess_eval_shader_template = "VERSION\n"
7273 "\n"
7274 "layout(isolines, point_mode) in;\n"
7275 "\n"
7276 "in vec4 tcs_tes_result[];\n"
7277 "out vec4 tes_gs_result;\n"
7278 "\n"
7279 "uniform vec4 VARIABLE_NAME;\n"
7280 "\n"
7281 "FUNCTION_DECLARATION\n"
7282 "\n"
7283 "void main()\n"
7284 "{\n"
7285 " vec4 result = vec4(0, 1, 0, 1);\n"
7286 "\n"
7287 "VERIFICATION"
7288 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7289 " {\n"
7290 " result = vec4(1, 0, 0, 1);\n"
7291 " }\n"
7292 "\n"
7293 " tes_gs_result = result;\n"
7294 "}\n"
7295 "\n";
7296
7297 static const GLchar* vertex_shader_template = "VERSION\n"
7298 "\n"
7299 "out vec4 vs_tcs_result;\n"
7300 "\n"
7301 "uniform vec4 VARIABLE_NAME;\n"
7302 "\n"
7303 "FUNCTION_DECLARATION\n"
7304 "\n"
7305 "void main()\n"
7306 "{\n"
7307 " vec4 result = vec4(0, 1, 0, 1);\n"
7308 "\n"
7309 "VERIFICATION"
7310 "\n"
7311 " vs_tcs_result = result;\n"
7312 "}\n"
7313 "\n";
7314
7315 const GLchar* shader_template = 0;
7316
7317 switch (in_stage)
7318 {
7319 case Utils::COMPUTE_SHADER:
7320 return;
7321 case Utils::FRAGMENT_SHADER:
7322 shader_template = fragment_shader_template;
7323 break;
7324 case Utils::GEOMETRY_SHADER:
7325 shader_template = geometry_shader_template;
7326 break;
7327 case Utils::TESS_CTRL_SHADER:
7328 shader_template = tess_ctrl_shader_template;
7329 break;
7330 case Utils::TESS_EVAL_SHADER:
7331 shader_template = tess_eval_shader_template;
7332 break;
7333 case Utils::VERTEX_SHADER:
7334 shader_template = vertex_shader_template;
7335 break;
7336 default:
7337 TCU_FAIL("Invalid enum");
7338 }
7339
7340 const std::string& uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7341 const std::string& qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7342
7343 out_source.m_parts[0].m_code = shader_template;
7344
7345 size_t position = 0;
7346
7347 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7348 out_source.m_parts[0].m_code);
7349
7350 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7351
7352 position -= strlen(function_declaration);
7353
7354 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7355
7356 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7357
7358 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7359 }
7360
7361 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7362 *
7363 * @param program Current program
7364 **/
prepareUniforms(Utils::program & program)7365 void QualifierOrderFunctionInputTest::prepareUniforms(Utils::program& program)
7366 {
7367 static const GLfloat float_data[4] = { 1.0f, 1.0f, 0.0f, 0.0f };
7368
7369 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7370 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7371 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7372 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7373 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7374 }
7375
7376 /** Prepare test cases
7377 *
7378 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7379 **/
testInit()7380 bool QualifierOrderFunctionInputTest::testInit()
7381 {
7382 m_test_cases.resize(6);
7383
7384 m_test_cases[0].push_back(Utils::QUAL_CONST);
7385 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7386 m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7387 m_test_cases[0].push_back(Utils::QUAL_IN);
7388
7389 m_test_cases[1].push_back(Utils::QUAL_IN);
7390 m_test_cases[1].push_back(Utils::QUAL_CONST);
7391 m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7392 m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7393
7394 m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7395 m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7396 m_test_cases[2].push_back(Utils::QUAL_CONST);
7397 m_test_cases[2].push_back(Utils::QUAL_IN);
7398
7399 m_test_cases[3].push_back(Utils::QUAL_IN);
7400 m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7401 m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7402 m_test_cases[3].push_back(Utils::QUAL_CONST);
7403
7404 m_test_cases[4].push_back(Utils::QUAL_LOWP);
7405 m_test_cases[4].push_back(Utils::QUAL_CONST);
7406 m_test_cases[4].push_back(Utils::QUAL_IN);
7407 m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7408
7409 m_test_cases[5].push_back(Utils::QUAL_IN);
7410 m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7411 m_test_cases[5].push_back(Utils::QUAL_CONST);
7412 m_test_cases[5].push_back(Utils::QUAL_LOWP);
7413
7414 return true;
7415 }
7416
7417 /** Returns reference to current test case
7418 *
7419 * @return Reference to testCase
7420 **/
getCurrentTestCase()7421 const Utils::qualifierSet& QualifierOrderFunctionInputTest::getCurrentTestCase()
7422 {
7423 if ((glw::GLuint)-1 == m_current_test_case_index)
7424 {
7425 return m_test_cases[0];
7426 }
7427 else
7428 {
7429 return m_test_cases[m_current_test_case_index];
7430 }
7431 }
7432
7433 /** Constructor
7434 *
7435 * @param context Test context
7436 **/
QualifierOrderFunctionOutputTest(deqp::Context & context)7437 QualifierOrderFunctionOutputTest::QualifierOrderFunctionOutputTest(deqp::Context& context)
7438 : GLSLTestBase(context, "qualifier_order_function_output",
7439 "Verify order of qualifiers of output function parameters")
7440 , m_current_test_case_index(0)
7441 {
7442 /* Nothing to be done here */
7443 }
7444
7445 /** Set up next test case
7446 *
7447 * @param test_case_index Index of next test case
7448 *
7449 * @return false if there is no more test cases, true otherwise
7450 **/
prepareNextTestCase(glw::GLuint test_case_index)7451 bool QualifierOrderFunctionOutputTest::prepareNextTestCase(glw::GLuint test_case_index)
7452 {
7453 m_current_test_case_index = test_case_index;
7454
7455 if ((glw::GLuint)-1 == test_case_index)
7456 {
7457 /* Nothing to be done here */
7458 }
7459 else if (m_test_cases.size() <= test_case_index)
7460 {
7461 return false;
7462 }
7463
7464 const Utils::qualifierSet& set = getCurrentTestCase();
7465
7466 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
7467
7468 for (GLuint i = 0; i < set.size(); ++i)
7469 {
7470 message << Utils::getQualifierString(set[i]) << " ";
7471 }
7472
7473 message << tcu::TestLog::EndMessage;
7474
7475 return true;
7476 }
7477
7478 /** Prepare source for given shader stage
7479 *
7480 * @param in_stage Shader stage, compute shader will use 430
7481 * @param in_use_version_400 Select if 400 or 420 should be used
7482 * @param out_source Prepared shader source instance
7483 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7484 void QualifierOrderFunctionOutputTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7485 Utils::shaderSource& out_source)
7486 {
7487 static const GLchar* verification_snippet =
7488 " vec4 temp;\n"
7489 "\n"
7490 " function(temp);\n"
7491 "\n"
7492 " vec4 diff = temp - vec4(0, 0, 1, 1);\n"
7493 " if (false == all(lessThan(diff, vec4(0.001, 0.001, 0.001, 0.001))))\n"
7494 " {\n"
7495 " result = VARIABLE_NAME;\n"
7496 " }\n";
7497
7498 static const GLchar* function_declaration = "void function(QUALIFIERS_LIST vec4 param)\n"
7499 "{\n"
7500 " param = VARIABLE_NAME.wzyx;\n"
7501 "}\n";
7502
7503 static const GLchar* fragment_shader_template = "VERSION\n"
7504 "\n"
7505 "in vec4 gs_fs_result;\n"
7506 "out vec4 fs_out_result;\n"
7507 "\n"
7508 "uniform vec4 VARIABLE_NAME;\n"
7509 "\n"
7510 "FUNCTION_DECLARATION\n"
7511 "\n"
7512 "void main()\n"
7513 "{\n"
7514 " vec4 result = vec4(0, 1, 0, 1);\n"
7515 "\n"
7516 "VERIFICATION"
7517 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7518 " {\n"
7519 " result = vec4(1, 0, 0, 1);\n"
7520 " }\n"
7521 "\n"
7522 " fs_out_result = result;\n"
7523 "}\n"
7524 "\n";
7525
7526 static const GLchar* geometry_shader_template = "VERSION\n"
7527 "\n"
7528 "layout(points) in;\n"
7529 "layout(triangle_strip, max_vertices = 4) out;\n"
7530 "\n"
7531 "in vec4 tes_gs_result[];\n"
7532 "out vec4 gs_fs_result;\n"
7533 "\n"
7534 "uniform vec4 VARIABLE_NAME;\n"
7535 "\n"
7536 "FUNCTION_DECLARATION\n"
7537 "\n"
7538 "void main()\n"
7539 "{\n"
7540 " vec4 result = vec4(0, 1, 0, 1);\n"
7541 "\n"
7542 "VERIFICATION"
7543 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7544 " {\n"
7545 " result = vec4(1, 0, 0, 1);\n"
7546 " }\n"
7547 "\n"
7548 " gs_fs_result = result;\n"
7549 " gl_Position = vec4(-1, -1, 0, 1);\n"
7550 " EmitVertex();\n"
7551 " gs_fs_result = result;\n"
7552 " gl_Position = vec4(-1, 1, 0, 1);\n"
7553 " EmitVertex();\n"
7554 " gs_fs_result = result;\n"
7555 " gl_Position = vec4(1, -1, 0, 1);\n"
7556 " EmitVertex();\n"
7557 " gs_fs_result = result;\n"
7558 " gl_Position = vec4(1, 1, 0, 1);\n"
7559 " EmitVertex();\n"
7560 "}\n"
7561 "\n";
7562
7563 static const GLchar* tess_ctrl_shader_template =
7564 "VERSION\n"
7565 "\n"
7566 "layout(vertices = 1) out;\n"
7567 "\n"
7568 "in vec4 vs_tcs_result[];\n"
7569 "out vec4 tcs_tes_result[];\n"
7570 "\n"
7571 "uniform vec4 VARIABLE_NAME;\n"
7572 "\n"
7573 "FUNCTION_DECLARATION\n"
7574 "\n"
7575 "void main()\n"
7576 "{\n"
7577 " vec4 result = vec4(0, 1, 0, 1);\n"
7578 "\n"
7579 "VERIFICATION"
7580 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7581 " {\n"
7582 " result = vec4(1, 0, 0, 1);\n"
7583 " }\n"
7584 "\n"
7585 " tcs_tes_result[gl_InvocationID] = result;\n"
7586 "\n"
7587 " gl_TessLevelOuter[0] = 1.0;\n"
7588 " gl_TessLevelOuter[1] = 1.0;\n"
7589 " gl_TessLevelOuter[2] = 1.0;\n"
7590 " gl_TessLevelOuter[3] = 1.0;\n"
7591 " gl_TessLevelInner[0] = 1.0;\n"
7592 " gl_TessLevelInner[1] = 1.0;\n"
7593 "}\n"
7594 "\n";
7595
7596 static const GLchar* tess_eval_shader_template = "VERSION\n"
7597 "\n"
7598 "layout(isolines, point_mode) in;\n"
7599 "\n"
7600 "in vec4 tcs_tes_result[];\n"
7601 "out vec4 tes_gs_result;\n"
7602 "\n"
7603 "uniform vec4 VARIABLE_NAME;\n"
7604 "\n"
7605 "FUNCTION_DECLARATION\n"
7606 "\n"
7607 "void main()\n"
7608 "{\n"
7609 " vec4 result = vec4(0, 1, 0, 1);\n"
7610 "\n"
7611 "VERIFICATION"
7612 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7613 " {\n"
7614 " result = vec4(1, 0, 0, 1);\n"
7615 " }\n"
7616 "\n"
7617 " tes_gs_result = result;\n"
7618 "}\n"
7619 "\n";
7620
7621 static const GLchar* vertex_shader_template = "VERSION\n"
7622 "\n"
7623 "out vec4 vs_tcs_result;\n"
7624 "\n"
7625 "uniform vec4 VARIABLE_NAME;\n"
7626 "\n"
7627 "FUNCTION_DECLARATION\n"
7628 "\n"
7629 "void main()\n"
7630 "{\n"
7631 " vec4 result = vec4(0, 1, 0, 1);\n"
7632 "\n"
7633 "VERIFICATION"
7634 "\n"
7635 " vs_tcs_result = result;\n"
7636 "}\n"
7637 "\n";
7638
7639 const GLchar* shader_template = 0;
7640
7641 switch (in_stage)
7642 {
7643 case Utils::COMPUTE_SHADER:
7644 return;
7645 case Utils::FRAGMENT_SHADER:
7646 shader_template = fragment_shader_template;
7647 break;
7648 case Utils::GEOMETRY_SHADER:
7649 shader_template = geometry_shader_template;
7650 break;
7651 case Utils::TESS_CTRL_SHADER:
7652 shader_template = tess_ctrl_shader_template;
7653 break;
7654 case Utils::TESS_EVAL_SHADER:
7655 shader_template = tess_eval_shader_template;
7656 break;
7657 case Utils::VERTEX_SHADER:
7658 shader_template = vertex_shader_template;
7659 break;
7660 default:
7661 TCU_FAIL("Invalid enum");
7662 }
7663
7664 const std::string& uni_reference = Utils::getVariableName(in_stage, Utils::UNIFORM, "test");
7665 const std::string& qualifier_list = Utils::getQualifiersListString(getCurrentTestCase());
7666
7667 out_source.m_parts[0].m_code = shader_template;
7668
7669 size_t position = 0;
7670
7671 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7672 out_source.m_parts[0].m_code);
7673
7674 Utils::replaceToken("FUNCTION_DECLARATION", position, function_declaration, out_source.m_parts[0].m_code);
7675
7676 position -= strlen(function_declaration);
7677
7678 Utils::replaceToken("QUALIFIERS_LIST", position, qualifier_list.c_str(), out_source.m_parts[0].m_code);
7679
7680 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
7681
7682 Utils::replaceAllTokens("VARIABLE_NAME", uni_reference.c_str(), out_source.m_parts[0].m_code);
7683 }
7684
7685 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
7686 *
7687 * @param program Current program
7688 **/
prepareUniforms(Utils::program & program)7689 void QualifierOrderFunctionOutputTest::prepareUniforms(Utils::program& program)
7690 {
7691 static const GLfloat float_data[4] = { 1.0f, 1.0f, 0.0f, 0.0f };
7692
7693 program.uniform("uni_fs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7694 program.uniform("uni_gs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7695 program.uniform("uni_tcs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7696 program.uniform("uni_tes_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7697 program.uniform("uni_vs_test", Utils::FLOAT, 1 /* n_cols */, 4 /* n_rows */, float_data);
7698 }
7699
7700 /** Prepare test cases
7701 *
7702 * @return false if ARB_explicit_uniform_location is not supported, true otherwise
7703 **/
testInit()7704 bool QualifierOrderFunctionOutputTest::testInit()
7705 {
7706 m_test_cases.resize(6);
7707
7708 m_test_cases[0].push_back(Utils::QUAL_HIGHP);
7709 m_test_cases[0].push_back(Utils::QUAL_PRECISE);
7710 m_test_cases[0].push_back(Utils::QUAL_OUT);
7711
7712 m_test_cases[1].push_back(Utils::QUAL_OUT);
7713 m_test_cases[1].push_back(Utils::QUAL_PRECISE);
7714 m_test_cases[1].push_back(Utils::QUAL_HIGHP);
7715
7716 m_test_cases[2].push_back(Utils::QUAL_PRECISE);
7717 m_test_cases[2].push_back(Utils::QUAL_MEDIUMP);
7718 m_test_cases[2].push_back(Utils::QUAL_OUT);
7719
7720 m_test_cases[3].push_back(Utils::QUAL_OUT);
7721 m_test_cases[3].push_back(Utils::QUAL_PRECISE);
7722 m_test_cases[3].push_back(Utils::QUAL_MEDIUMP);
7723
7724 m_test_cases[4].push_back(Utils::QUAL_LOWP);
7725 m_test_cases[4].push_back(Utils::QUAL_OUT);
7726 m_test_cases[4].push_back(Utils::QUAL_PRECISE);
7727
7728 m_test_cases[5].push_back(Utils::QUAL_OUT);
7729 m_test_cases[5].push_back(Utils::QUAL_PRECISE);
7730 m_test_cases[5].push_back(Utils::QUAL_LOWP);
7731
7732 return true;
7733 }
7734
7735 /** Returns reference to current test case
7736 *
7737 * @return Reference to testCase
7738 **/
getCurrentTestCase()7739 const Utils::qualifierSet& QualifierOrderFunctionOutputTest::getCurrentTestCase()
7740 {
7741 if ((glw::GLuint)-1 == m_current_test_case_index)
7742 {
7743 return m_test_cases[0];
7744 }
7745 else
7746 {
7747 return m_test_cases[m_current_test_case_index];
7748 }
7749 }
7750
7751 /** Constructor
7752 *
7753 * @param context Test context
7754 **/
QualifierOverrideLayoutTest(deqp::Context & context)7755 QualifierOverrideLayoutTest::QualifierOverrideLayoutTest(deqp::Context& context)
7756 : GLSLTestBase(context, "qualifier_override_layout", "Verifies overriding layout qualifiers")
7757 {
7758 /* Nothing to be done here */
7759 }
7760
7761 /** Prepare source for given shader stage
7762 *
7763 * @param in_stage Shader stage, compute shader will use 430
7764 * @param in_use_version_400 Select if 400 or 420 should be used
7765 * @param out_source Prepared shader source instance
7766 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7767 void QualifierOverrideLayoutTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7768 Utils::shaderSource& out_source)
7769 {
7770 static const GLchar* fragment_shader_template = "VERSION\n"
7771 "\n"
7772 "in layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7773 "out vec4 fs_out_result;\n"
7774 "\n"
7775 "void main()\n"
7776 "{\n"
7777 " vec4 result = vec4(0, 1, 0, 1);\n"
7778 "\n"
7779 " if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
7780 " {\n"
7781 " result = vec4(1, 0, 0, 1);\n"
7782 " }\n"
7783 "\n"
7784 " fs_out_result = result;\n"
7785 "}\n"
7786 "\n";
7787
7788 static const GLchar* geometry_shader_template =
7789 "VERSION\n"
7790 "\n"
7791 "layout(points) in;\n"
7792 "layout(triangle_strip, max_vertices = 2) layout(max_vertices = 4) out;\n"
7793 "\n"
7794 "in layout(location = 3) layout(location = 2) vec4 tes_gs_result[];\n"
7795 "out layout(location = 3) layout(location = 2) vec4 gs_fs_result;\n"
7796 "\n"
7797 "void main()\n"
7798 "{\n"
7799 " vec4 result = vec4(0, 1, 0, 1);\n"
7800 "\n"
7801 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
7802 " {\n"
7803 " result = vec4(1, 0, 0, 1);\n"
7804 " }\n"
7805 "\n"
7806 " gs_fs_result = result;\n"
7807 " gl_Position = vec4(-1, -1, 0, 1);\n"
7808 " EmitVertex();\n"
7809 " gs_fs_result = result;\n"
7810 " gl_Position = vec4(-1, 1, 0, 1);\n"
7811 " EmitVertex();\n"
7812 " gs_fs_result = result;\n"
7813 " gl_Position = vec4(1, -1, 0, 1);\n"
7814 " EmitVertex();\n"
7815 " gs_fs_result = result;\n"
7816 " gl_Position = vec4(1, 1, 0, 1);\n"
7817 " EmitVertex();\n"
7818 "}\n"
7819 "\n";
7820
7821 static const GLchar* tess_ctrl_shader_template =
7822 "VERSION\n"
7823 "\n"
7824 "layout(vertices = 4) layout(vertices = 1) out;\n"
7825 "\n"
7826 "in layout(location = 3) layout(location = 2) vec4 vs_tcs_result[];\n"
7827 "out layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7828 "\n"
7829 "void main()\n"
7830 "{\n"
7831 " vec4 result = vec4(0, 1, 0, 1);\n"
7832 "\n"
7833 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
7834 " {\n"
7835 " result = vec4(1, 0, 0, 1);\n"
7836 " }\n"
7837 "\n"
7838 " tcs_tes_result[gl_InvocationID] = result;\n"
7839 "\n"
7840 " gl_TessLevelOuter[0] = 1.0;\n"
7841 " gl_TessLevelOuter[1] = 1.0;\n"
7842 " gl_TessLevelOuter[2] = 1.0;\n"
7843 " gl_TessLevelOuter[3] = 1.0;\n"
7844 " gl_TessLevelInner[0] = 1.0;\n"
7845 " gl_TessLevelInner[1] = 1.0;\n"
7846 "}\n"
7847 "\n";
7848
7849 static const GLchar* tess_eval_shader_template =
7850 "VERSION\n"
7851 "\n"
7852 "layout(isolines, point_mode) in;\n"
7853 "\n"
7854 "in layout(location = 3) layout(location = 2) vec4 tcs_tes_result[];\n"
7855 "out layout(location = 3) layout(location = 2) vec4 tes_gs_result;\n"
7856 "\n"
7857 "void main()\n"
7858 "{\n"
7859 " vec4 result = vec4(0, 1, 0, 1);\n"
7860 "\n"
7861 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
7862 " {\n"
7863 " result = vec4(1, 0, 0, 1);\n"
7864 " }\n"
7865 "\n"
7866 " tes_gs_result = result;\n"
7867 "}\n"
7868 "\n";
7869
7870 static const GLchar* vertex_shader_template = "VERSION\n"
7871 "\n"
7872 "in layout(location = 3) layout(location = 2) vec4 in_vs_test;\n"
7873 "out layout(location = 3) layout(location = 2) vec4 vs_tcs_result;\n"
7874 "\n"
7875 "void main()\n"
7876 "{\n"
7877 " vec4 result = in_vs_test;\n"
7878 "\n"
7879 " vs_tcs_result = result;\n"
7880 "}\n"
7881 "\n";
7882
7883 const GLchar* shader_template = 0;
7884
7885 switch (in_stage)
7886 {
7887 case Utils::COMPUTE_SHADER:
7888 return;
7889 case Utils::FRAGMENT_SHADER:
7890 shader_template = fragment_shader_template;
7891 break;
7892 case Utils::GEOMETRY_SHADER:
7893 shader_template = geometry_shader_template;
7894 break;
7895 case Utils::TESS_CTRL_SHADER:
7896 shader_template = tess_ctrl_shader_template;
7897 break;
7898 case Utils::TESS_EVAL_SHADER:
7899 shader_template = tess_eval_shader_template;
7900 break;
7901 case Utils::VERTEX_SHADER:
7902 shader_template = vertex_shader_template;
7903 break;
7904 default:
7905 TCU_FAIL("Invalid enum");
7906 }
7907
7908 out_source.m_parts[0].m_code = shader_template;
7909
7910 size_t position = 0;
7911
7912 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
7913 out_source.m_parts[0].m_code);
7914 }
7915
7916 /**Prepare vertex buffer and vertex array object.
7917 *
7918 * @param program Program instance
7919 * @param buffer Buffer instance
7920 * @param vao VertexArray instance
7921 *
7922 * @return 0
7923 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)7924 void QualifierOverrideLayoutTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
7925 Utils::vertexArray& vao)
7926 {
7927 static const GLint expected_location = 2;
7928
7929 std::string test_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "test");
7930 GLint test_loc = program.getAttribLocation(test_name.c_str());
7931
7932 if (expected_location != test_loc)
7933 {
7934 TCU_FAIL("Vertex attribute location is invalid");
7935 }
7936
7937 vao.generate();
7938 vao.bind();
7939
7940 buffer.generate(GL_ARRAY_BUFFER);
7941
7942 GLfloat data[] = { 0.0f, 1.0f, 0.0f, 1.0f };
7943 GLsizeiptr data_size = sizeof(data);
7944
7945 buffer.update(data_size, data, GL_STATIC_DRAW);
7946
7947 /* GL entry points */
7948 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
7949
7950 /* Set up vao */
7951 gl.vertexAttribPointer(test_loc, 4 /* size */, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0 /* stride */,
7952 0 /* offset */);
7953 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
7954
7955 /* Enable attribute */
7956 gl.enableVertexAttribArray(test_loc);
7957 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
7958 }
7959
7960 /** Constructor
7961 *
7962 * @param context Test context
7963 **/
BindingUniformBlocksTest(deqp::Context & context)7964 BindingUniformBlocksTest::BindingUniformBlocksTest(deqp::Context& context)
7965 : GLSLTestBase(context, "binding_uniform_blocks", "Test verifies uniform block binding")
7966 , m_goku_buffer(context)
7967 , m_vegeta_buffer(context)
7968 , m_children_buffer(context)
7969 {
7970 /* Nothing to be done here */
7971 }
7972
7973 /** Prepare source for given shader stage
7974 *
7975 * @param in_stage Shader stage, compute shader will use 430
7976 * @param in_use_version_400 Select if 400 or 420 should be used
7977 * @param out_source Prepared shader source instance
7978 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)7979 void BindingUniformBlocksTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
7980 Utils::shaderSource& out_source)
7981 {
7982 static const GLchar* uni_goku = "layout(std140, binding = 0) uniform GOKU {\n"
7983 " vec4 chichi;\n"
7984 "} goku;\n";
7985
7986 static const GLchar* uni_vegeta = "layout(std140, binding = 1) uniform VEGETA {\n"
7987 " vec3 bulma;\n"
7988 "} vegeta;\n";
7989
7990 static const GLchar* uni_children = "layout(std140, binding = 3) uniform CHILDREN {\n"
7991 " vec4 gohan;\n"
7992 " vec4 trunks;\n"
7993 "} children;\n\n";
7994
7995 static const GLchar* verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.chichi) ||\n"
7996 " (vec3(0, 1, 0) != vegeta.bulma) ||\n"
7997 " (vec4(0, 0, 1, 0) != children.gohan) ||\n"
7998 " (vec4(0, 0, 0, 1) != children.trunks) )\n"
7999 " {\n"
8000 " result = vec4(1, 0, 0, 1);\n"
8001 " }\n";
8002
8003 static const GLchar* compute_shader_template =
8004 "VERSION\n"
8005 "\n"
8006 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8007 "\n"
8008 "writeonly uniform image2D uni_image;\n"
8009 "\n"
8010 "UNI_GOKU\n"
8011 "UNI_VEGETA\n"
8012 "UNI_CHILDREN\n"
8013 "\n"
8014 "void main()\n"
8015 "{\n"
8016 " vec4 result = vec4(0, 1, 0, 1);\n"
8017 "\n"
8018 "VERIFICATION"
8019 "\n"
8020 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8021 "}\n"
8022 "\n";
8023
8024 static const GLchar* fragment_shader_template = "VERSION\n"
8025 "\n"
8026 "in vec4 gs_fs_result;\n"
8027 "out vec4 fs_out_result;\n"
8028 "\n"
8029 "UNI_GOKU\n"
8030 "UNI_VEGETA\n"
8031 "UNI_CHILDREN\n"
8032 "\n"
8033 "void main()\n"
8034 "{\n"
8035 " vec4 result = vec4(0, 1, 0, 1);\n"
8036 "\n"
8037 "VERIFICATION"
8038 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8039 " {\n"
8040 " result = vec4(1, 0, 0, 1);\n"
8041 " }\n"
8042 "\n"
8043 " fs_out_result = result;\n"
8044 "}\n"
8045 "\n";
8046
8047 static const GLchar* geometry_shader_template = "VERSION\n"
8048 "\n"
8049 "layout(points) in;\n"
8050 "layout(triangle_strip, max_vertices = 4) out;\n"
8051 "\n"
8052 "in vec4 tes_gs_result[];\n"
8053 "out vec4 gs_fs_result;\n"
8054 "\n"
8055 "UNI_CHILDREN\n"
8056 "UNI_GOKU\n"
8057 "UNI_VEGETA\n"
8058 "\n"
8059 "void main()\n"
8060 "{\n"
8061 " vec4 result = vec4(0, 1, 0, 1);\n"
8062 "\n"
8063 "VERIFICATION"
8064 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8065 " {\n"
8066 " result = vec4(1, 0, 0, 1);\n"
8067 " }\n"
8068 "\n"
8069 " gs_fs_result = result;\n"
8070 " gl_Position = vec4(-1, -1, 0, 1);\n"
8071 " EmitVertex();\n"
8072 " gs_fs_result = result;\n"
8073 " gl_Position = vec4(-1, 1, 0, 1);\n"
8074 " EmitVertex();\n"
8075 " gs_fs_result = result;\n"
8076 " gl_Position = vec4(1, -1, 0, 1);\n"
8077 " EmitVertex();\n"
8078 " gs_fs_result = result;\n"
8079 " gl_Position = vec4(1, 1, 0, 1);\n"
8080 " EmitVertex();\n"
8081 "}\n"
8082 "\n";
8083
8084 static const GLchar* tess_ctrl_shader_template =
8085 "VERSION\n"
8086 "\n"
8087 "layout(vertices = 1) out;\n"
8088 "\n"
8089 "in vec4 vs_tcs_result[];\n"
8090 "out vec4 tcs_tes_result[];\n"
8091 "\n"
8092 "UNI_VEGETA\n"
8093 "UNI_CHILDREN\n"
8094 "UNI_GOKU\n"
8095 "\n"
8096 "void main()\n"
8097 "{\n"
8098 " vec4 result = vec4(0, 1, 0, 1);\n"
8099 "\n"
8100 "VERIFICATION"
8101 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8102 " {\n"
8103 " result = vec4(1, 0, 0, 1);\n"
8104 " }\n"
8105 "\n"
8106 " tcs_tes_result[gl_InvocationID] = result;\n"
8107 "\n"
8108 " gl_TessLevelOuter[0] = 1.0;\n"
8109 " gl_TessLevelOuter[1] = 1.0;\n"
8110 " gl_TessLevelOuter[2] = 1.0;\n"
8111 " gl_TessLevelOuter[3] = 1.0;\n"
8112 " gl_TessLevelInner[0] = 1.0;\n"
8113 " gl_TessLevelInner[1] = 1.0;\n"
8114 "}\n"
8115 "\n";
8116
8117 static const GLchar* tess_eval_shader_template = "VERSION\n"
8118 "\n"
8119 "layout(isolines, point_mode) in;\n"
8120 "\n"
8121 "in vec4 tcs_tes_result[];\n"
8122 "out vec4 tes_gs_result;\n"
8123 "\n"
8124 "UNI_GOKU\n"
8125 "UNI_CHILDREN\n"
8126 "UNI_VEGETA\n"
8127 "\n"
8128 "void main()\n"
8129 "{\n"
8130 " vec4 result = vec4(0, 1, 0, 1);\n"
8131 "\n"
8132 "VERIFICATION"
8133 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8134 " {\n"
8135 " result = vec4(1, 0, 0, 1);\n"
8136 " }\n"
8137 "\n"
8138 " tes_gs_result = result;\n"
8139 "}\n"
8140 "\n";
8141
8142 static const GLchar* vertex_shader_template = "VERSION\n"
8143 "\n"
8144 "out vec4 vs_tcs_result;\n"
8145 "\n"
8146 "UNI_CHILDREN\n"
8147 "UNI_VEGETA\n"
8148 "UNI_GOKU\n"
8149 "\n"
8150 "void main()\n"
8151 "{\n"
8152 " vec4 result = vec4(0, 1, 0, 1);\n"
8153 "\n"
8154 "VERIFICATION"
8155 "\n"
8156 " vs_tcs_result = result;\n"
8157 "}\n"
8158 "\n";
8159
8160 const GLchar* shader_template = 0;
8161
8162 switch (in_stage)
8163 {
8164 case Utils::COMPUTE_SHADER:
8165 shader_template = compute_shader_template;
8166 break;
8167 case Utils::FRAGMENT_SHADER:
8168 shader_template = fragment_shader_template;
8169 break;
8170 case Utils::GEOMETRY_SHADER:
8171 shader_template = geometry_shader_template;
8172 break;
8173 case Utils::TESS_CTRL_SHADER:
8174 shader_template = tess_ctrl_shader_template;
8175 break;
8176 case Utils::TESS_EVAL_SHADER:
8177 shader_template = tess_eval_shader_template;
8178 break;
8179 case Utils::VERTEX_SHADER:
8180 shader_template = vertex_shader_template;
8181 break;
8182 default:
8183 TCU_FAIL("Invalid enum");
8184 }
8185
8186 out_source.m_parts[0].m_code = shader_template;
8187
8188 size_t position = 0;
8189
8190 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8191 out_source.m_parts[0].m_code);
8192
8193 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8194
8195 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8196
8197 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
8198
8199 Utils::replaceAllTokens("UNI_CHILDREN", uni_children, out_source.m_parts[0].m_code);
8200 }
8201
8202 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8203 *
8204 * @param program Current program
8205 **/
prepareUniforms(Utils::program & program)8206 void BindingUniformBlocksTest::prepareUniforms(Utils::program& program)
8207 {
8208 (void)program;
8209 static const GLfloat goku_data[4] = { 1.0f, 0.0f, 0.0f, 0.0f };
8210 static const GLfloat vegeta_data[3] = { 0.0f, 1.0f, 0.0f };
8211 static const GLfloat children_data[8] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
8212
8213 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8214 m_vegeta_buffer.generate(GL_UNIFORM_BUFFER);
8215 m_children_buffer.generate(GL_UNIFORM_BUFFER);
8216
8217 m_goku_buffer.update(sizeof(goku_data), (GLvoid*)goku_data, GL_STATIC_DRAW);
8218 m_vegeta_buffer.update(sizeof(vegeta_data), (GLvoid*)vegeta_data, GL_STATIC_DRAW);
8219 m_children_buffer.update(sizeof(children_data), (GLvoid*)children_data, GL_STATIC_DRAW);
8220
8221 m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8222 m_vegeta_buffer.bindRange(1 /* index */, 0 /* offset */, sizeof(vegeta_data));
8223 m_children_buffer.bindRange(3 /* index */, 0 /* offset */, sizeof(children_data));
8224 }
8225
8226 /** Overwrite of releaseResource method, release extra uniform buffer
8227 *
8228 * @param ignored
8229 **/
releaseResource()8230 void BindingUniformBlocksTest::releaseResource()
8231 {
8232 m_goku_buffer.release();
8233 m_vegeta_buffer.release();
8234 m_children_buffer.release();
8235 }
8236
8237 /** Constructor
8238 *
8239 * @param context Test context
8240 **/
BindingUniformSingleBlockTest(deqp::Context & context)8241 BindingUniformSingleBlockTest::BindingUniformSingleBlockTest(deqp::Context& context)
8242 : GLSLTestBase(context, "binding_uniform_single_block", "Test verifies uniform block binding")
8243 , m_goku_buffer(context)
8244 , m_test_stage(Utils::SHADER_STAGES_MAX)
8245 {
8246 /* Nothing to be done here */
8247 }
8248
8249 /** Set up next test case
8250 *
8251 * @param test_case_index Index of next test case
8252 *
8253 * @return false if there is no more test cases, true otherwise
8254 **/
prepareNextTestCase(glw::GLuint test_case_index)8255 bool BindingUniformSingleBlockTest::prepareNextTestCase(glw::GLuint test_case_index)
8256 {
8257 switch (test_case_index)
8258 {
8259 case (glw::GLuint)-1:
8260 case 0:
8261 m_test_stage = Utils::VERTEX_SHADER;
8262 break;
8263 case 1:
8264 m_test_stage = Utils::TESS_CTRL_SHADER;
8265 break;
8266 case 2:
8267 m_test_stage = Utils::TESS_EVAL_SHADER;
8268 break;
8269 case 3:
8270 m_test_stage = Utils::GEOMETRY_SHADER;
8271 break;
8272 case 4:
8273 m_test_stage = Utils::FRAGMENT_SHADER;
8274 break;
8275 default:
8276 return false;
8277 }
8278
8279 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
8280 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
8281 << tcu::TestLog::EndMessage;
8282
8283 return true;
8284 }
8285
8286 /** Prepare source for given shader stage
8287 *
8288 * @param in_stage Shader stage, compute shader will use 430
8289 * @param in_use_version_400 Select if 400 or 420 should be used
8290 * @param out_source Prepared shader source instance
8291 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8292 void BindingUniformSingleBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8293 Utils::shaderSource& out_source)
8294 {
8295 static const GLchar* uni_goku_with_binding = "layout(std140, binding = 0) uniform GOKU {\n"
8296 " vec4 gohan;\n"
8297 " vec4 goten;\n"
8298 "} goku;\n";
8299
8300 static const GLchar* uni_goku_no_binding = "layout(std140) uniform GOKU {\n"
8301 " vec4 gohan;\n"
8302 " vec4 goten;\n"
8303 "} goku;\n";
8304
8305 static const GLchar* verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
8306 " (vec4(0, 1, 0, 0) != goku.goten) )\n"
8307 " {\n"
8308 " result = vec4(1, 0, 0, 1);\n"
8309 " }\n";
8310
8311 static const GLchar* compute_shader_template =
8312 "VERSION\n"
8313 "\n"
8314 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8315 "\n"
8316 "writeonly uniform image2D uni_image;\n"
8317 "\n"
8318 "UNI_GOKU\n"
8319 "\n"
8320 "void main()\n"
8321 "{\n"
8322 " vec4 result = vec4(0, 1, 0, 1);\n"
8323 "\n"
8324 "VERIFICATION"
8325 "\n"
8326 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8327 "}\n"
8328 "\n";
8329
8330 static const GLchar* fragment_shader_template = "VERSION\n"
8331 "\n"
8332 "in vec4 gs_fs_result;\n"
8333 "out vec4 fs_out_result;\n"
8334 "\n"
8335 "UNI_GOKU\n"
8336 "\n"
8337 "void main()\n"
8338 "{\n"
8339 " vec4 result = vec4(0, 1, 0, 1);\n"
8340 "\n"
8341 "VERIFICATION"
8342 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8343 " {\n"
8344 " result = vec4(1, 0, 0, 1);\n"
8345 " }\n"
8346 "\n"
8347 " fs_out_result = result;\n"
8348 "}\n"
8349 "\n";
8350
8351 static const GLchar* geometry_shader_template = "VERSION\n"
8352 "\n"
8353 "layout(points) in;\n"
8354 "layout(triangle_strip, max_vertices = 4) out;\n"
8355 "\n"
8356 "in vec4 tes_gs_result[];\n"
8357 "out vec4 gs_fs_result;\n"
8358 "\n"
8359 "UNI_GOKU\n"
8360 "\n"
8361 "void main()\n"
8362 "{\n"
8363 " vec4 result = vec4(0, 1, 0, 1);\n"
8364 "\n"
8365 "VERIFICATION"
8366 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8367 " {\n"
8368 " result = vec4(1, 0, 0, 1);\n"
8369 " }\n"
8370 "\n"
8371 " gs_fs_result = result;\n"
8372 " gl_Position = vec4(-1, -1, 0, 1);\n"
8373 " EmitVertex();\n"
8374 " gs_fs_result = result;\n"
8375 " gl_Position = vec4(-1, 1, 0, 1);\n"
8376 " EmitVertex();\n"
8377 " gs_fs_result = result;\n"
8378 " gl_Position = vec4(1, -1, 0, 1);\n"
8379 " EmitVertex();\n"
8380 " gs_fs_result = result;\n"
8381 " gl_Position = vec4(1, 1, 0, 1);\n"
8382 " EmitVertex();\n"
8383 "}\n"
8384 "\n";
8385
8386 static const GLchar* tess_ctrl_shader_template =
8387 "VERSION\n"
8388 "\n"
8389 "layout(vertices = 1) out;\n"
8390 "\n"
8391 "in vec4 vs_tcs_result[];\n"
8392 "out vec4 tcs_tes_result[];\n"
8393 "\n"
8394 "UNI_GOKU\n"
8395 "\n"
8396 "void main()\n"
8397 "{\n"
8398 " vec4 result = vec4(0, 1, 0, 1);\n"
8399 "\n"
8400 "VERIFICATION"
8401 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8402 " {\n"
8403 " result = vec4(1, 0, 0, 1);\n"
8404 " }\n"
8405 "\n"
8406 " tcs_tes_result[gl_InvocationID] = result;\n"
8407 "\n"
8408 " gl_TessLevelOuter[0] = 1.0;\n"
8409 " gl_TessLevelOuter[1] = 1.0;\n"
8410 " gl_TessLevelOuter[2] = 1.0;\n"
8411 " gl_TessLevelOuter[3] = 1.0;\n"
8412 " gl_TessLevelInner[0] = 1.0;\n"
8413 " gl_TessLevelInner[1] = 1.0;\n"
8414 "}\n"
8415 "\n";
8416
8417 static const GLchar* tess_eval_shader_template = "VERSION\n"
8418 "\n"
8419 "layout(isolines, point_mode) in;\n"
8420 "\n"
8421 "in vec4 tcs_tes_result[];\n"
8422 "out vec4 tes_gs_result;\n"
8423 "\n"
8424 "UNI_GOKU\n"
8425 "\n"
8426 "void main()\n"
8427 "{\n"
8428 " vec4 result = vec4(0, 1, 0, 1);\n"
8429 "\n"
8430 "VERIFICATION"
8431 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8432 " {\n"
8433 " result = vec4(1, 0, 0, 1);\n"
8434 " }\n"
8435 "\n"
8436 " tes_gs_result = result;\n"
8437 "}\n"
8438 "\n";
8439
8440 static const GLchar* vertex_shader_template = "VERSION\n"
8441 "\n"
8442 "out vec4 vs_tcs_result;\n"
8443 "\n"
8444 "UNI_GOKU\n"
8445 "\n"
8446 "void main()\n"
8447 "{\n"
8448 " vec4 result = vec4(0, 1, 0, 1);\n"
8449 "\n"
8450 "VERIFICATION"
8451 "\n"
8452 " vs_tcs_result = result;\n"
8453 "}\n"
8454 "\n";
8455
8456 const GLchar* shader_template = 0;
8457 const GLchar* uniform_definition = uni_goku_no_binding;
8458
8459 switch (in_stage)
8460 {
8461 case Utils::COMPUTE_SHADER:
8462 shader_template = compute_shader_template;
8463 uniform_definition = uni_goku_with_binding;
8464 break;
8465 case Utils::FRAGMENT_SHADER:
8466 shader_template = fragment_shader_template;
8467 break;
8468 case Utils::GEOMETRY_SHADER:
8469 shader_template = geometry_shader_template;
8470 break;
8471 case Utils::TESS_CTRL_SHADER:
8472 shader_template = tess_ctrl_shader_template;
8473 break;
8474 case Utils::TESS_EVAL_SHADER:
8475 shader_template = tess_eval_shader_template;
8476 break;
8477 case Utils::VERTEX_SHADER:
8478 shader_template = vertex_shader_template;
8479 break;
8480 default:
8481 TCU_FAIL("Invalid enum");
8482 }
8483
8484 if (in_stage == m_test_stage)
8485 {
8486 uniform_definition = uni_goku_with_binding;
8487 }
8488
8489 out_source.m_parts[0].m_code = shader_template;
8490
8491 size_t position = 0;
8492
8493 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8494 out_source.m_parts[0].m_code);
8495
8496 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8497
8498 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
8499 }
8500
8501 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8502 *
8503 * @param program Current program
8504 **/
prepareUniforms(Utils::program & program)8505 void BindingUniformSingleBlockTest::prepareUniforms(Utils::program& program)
8506 {
8507 (void)program;
8508 static const GLfloat goku_data[8] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
8509
8510 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
8511
8512 m_goku_buffer.update(sizeof(goku_data), (GLvoid*)goku_data, GL_STATIC_DRAW);
8513
8514 m_goku_buffer.bindRange(0 /* index */, 0 /* offset */, sizeof(goku_data));
8515 }
8516
8517 /** Overwrite of releaseResource method, release extra uniform buffer
8518 *
8519 * @param ignored
8520 **/
releaseResource()8521 void BindingUniformSingleBlockTest::releaseResource()
8522 {
8523 m_goku_buffer.release();
8524 }
8525
8526 /** Constructor
8527 *
8528 * @param context Test context
8529 **/
BindingUniformBlockArrayTest(deqp::Context & context)8530 BindingUniformBlockArrayTest::BindingUniformBlockArrayTest(deqp::Context& context)
8531 : GLSLTestBase(context, "binding_uniform_block_array", "Test verifies binding of uniform block arrays")
8532 , m_goku_00_buffer(context)
8533 , m_goku_01_buffer(context)
8534 , m_goku_02_buffer(context)
8535 , m_goku_03_buffer(context)
8536 , m_goku_04_buffer(context)
8537 , m_goku_05_buffer(context)
8538 , m_goku_06_buffer(context)
8539 , m_goku_07_buffer(context)
8540 , m_goku_08_buffer(context)
8541 , m_goku_09_buffer(context)
8542 , m_goku_10_buffer(context)
8543 , m_goku_11_buffer(context)
8544 , m_goku_12_buffer(context)
8545 , m_goku_13_buffer(context)
8546 {
8547 /* Nothing to be done here */
8548 }
8549
8550 /** Prepare source for given shader stage
8551 *
8552 * @param in_stage Shader stage, compute shader will use 430
8553 * @param in_use_version_400 Select if 400 or 420 should be used
8554 * @param out_source Prepared shader source instance
8555 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8556 void BindingUniformBlockArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8557 Utils::shaderSource& out_source)
8558 {
8559 static const GLchar* uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
8560 " vec4 gohan;\n"
8561 " vec4 goten;\n"
8562 "} goku[14];\n";
8563
8564 static const GLchar* verification_snippet = " if ((vec4(0, 0, 0, 0) != goku[0].gohan) ||\n"
8565 " (vec4(0, 0, 0, 1) != goku[0].goten) ||\n"
8566 " (vec4(0, 0, 1, 0) != goku[1].gohan) ||\n"
8567 " (vec4(0, 0, 1, 1) != goku[1].goten) ||\n"
8568 " (vec4(0, 1, 0, 0) != goku[2].gohan) ||\n"
8569 " (vec4(0, 1, 0, 1) != goku[2].goten) ||\n"
8570 " (vec4(0, 1, 1, 0) != goku[3].gohan) ||\n"
8571 " (vec4(0, 1, 1, 1) != goku[3].goten) ||\n"
8572 " (vec4(1, 0, 0, 0) != goku[4].gohan) ||\n"
8573 " (vec4(1, 0, 0, 1) != goku[4].goten) ||\n"
8574 " (vec4(1, 0, 1, 0) != goku[5].gohan) ||\n"
8575 " (vec4(1, 0, 1, 1) != goku[5].goten) ||\n"
8576 " (vec4(1, 1, 0, 0) != goku[6].gohan) ||\n"
8577 " (vec4(1, 1, 0, 1) != goku[6].goten) ||\n"
8578 " (vec4(1, 1, 1, 0) != goku[7].gohan) ||\n"
8579 " (vec4(1, 1, 1, 1) != goku[7].goten) ||\n"
8580 " (vec4(0, 0, 0, 0) != goku[8].gohan) ||\n"
8581 " (vec4(0, 0, 0, 1) != goku[8].goten) ||\n"
8582 " (vec4(0, 0, 1, 0) != goku[9].gohan) ||\n"
8583 " (vec4(0, 0, 1, 1) != goku[9].goten) ||\n"
8584 " (vec4(0, 1, 0, 0) != goku[10].gohan) ||\n"
8585 " (vec4(0, 1, 0, 1) != goku[10].goten) ||\n"
8586 " (vec4(0, 1, 1, 0) != goku[11].gohan) ||\n"
8587 " (vec4(0, 1, 1, 1) != goku[11].goten) ||\n"
8588 " (vec4(1, 0, 0, 0) != goku[12].gohan) ||\n"
8589 " (vec4(1, 0, 0, 1) != goku[12].goten) ||\n"
8590 " (vec4(1, 0, 1, 0) != goku[13].gohan) ||\n"
8591 " (vec4(1, 0, 1, 1) != goku[13].goten) )\n"
8592 " {\n"
8593 " result = vec4(1, 0, 0, 1);\n"
8594 " }\n";
8595
8596 static const GLchar* compute_shader_template =
8597 "VERSION\n"
8598 "\n"
8599 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8600 "\n"
8601 "writeonly uniform image2D uni_image;\n"
8602 "\n"
8603 "UNI_GOKU\n"
8604 "\n"
8605 "void main()\n"
8606 "{\n"
8607 " vec4 result = vec4(0, 1, 0, 1);\n"
8608 "\n"
8609 "VERIFICATION"
8610 "\n"
8611 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8612 "}\n"
8613 "\n";
8614
8615 static const GLchar* fragment_shader_template = "VERSION\n"
8616 "\n"
8617 "in vec4 gs_fs_result;\n"
8618 "out vec4 fs_out_result;\n"
8619 "\n"
8620 "UNI_GOKU\n"
8621 "\n"
8622 "void main()\n"
8623 "{\n"
8624 " vec4 result = vec4(0, 1, 0, 1);\n"
8625 "\n"
8626 "VERIFICATION"
8627 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8628 " {\n"
8629 " result = vec4(1, 0, 0, 1);\n"
8630 " }\n"
8631 "\n"
8632 " fs_out_result = result;\n"
8633 "}\n"
8634 "\n";
8635
8636 static const GLchar* geometry_shader_template = "VERSION\n"
8637 "\n"
8638 "layout(points) in;\n"
8639 "layout(triangle_strip, max_vertices = 4) out;\n"
8640 "\n"
8641 "in vec4 tes_gs_result[];\n"
8642 "out vec4 gs_fs_result;\n"
8643 "\n"
8644 "UNI_GOKU\n"
8645 "\n"
8646 "void main()\n"
8647 "{\n"
8648 " vec4 result = vec4(0, 1, 0, 1);\n"
8649 "\n"
8650 "VERIFICATION"
8651 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8652 " {\n"
8653 " result = vec4(1, 0, 0, 1);\n"
8654 " }\n"
8655 "\n"
8656 " gs_fs_result = result;\n"
8657 " gl_Position = vec4(-1, -1, 0, 1);\n"
8658 " EmitVertex();\n"
8659 " gs_fs_result = result;\n"
8660 " gl_Position = vec4(-1, 1, 0, 1);\n"
8661 " EmitVertex();\n"
8662 " gs_fs_result = result;\n"
8663 " gl_Position = vec4(1, -1, 0, 1);\n"
8664 " EmitVertex();\n"
8665 " gs_fs_result = result;\n"
8666 " gl_Position = vec4(1, 1, 0, 1);\n"
8667 " EmitVertex();\n"
8668 "}\n"
8669 "\n";
8670
8671 static const GLchar* tess_ctrl_shader_template =
8672 "VERSION\n"
8673 "\n"
8674 "layout(vertices = 1) out;\n"
8675 "\n"
8676 "in vec4 vs_tcs_result[];\n"
8677 "out vec4 tcs_tes_result[];\n"
8678 "\n"
8679 "UNI_GOKU\n"
8680 "\n"
8681 "void main()\n"
8682 "{\n"
8683 " vec4 result = vec4(0, 1, 0, 1);\n"
8684 "\n"
8685 "VERIFICATION"
8686 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
8687 " {\n"
8688 " result = vec4(1, 0, 0, 1);\n"
8689 " }\n"
8690 "\n"
8691 " tcs_tes_result[gl_InvocationID] = result;\n"
8692 "\n"
8693 " gl_TessLevelOuter[0] = 1.0;\n"
8694 " gl_TessLevelOuter[1] = 1.0;\n"
8695 " gl_TessLevelOuter[2] = 1.0;\n"
8696 " gl_TessLevelOuter[3] = 1.0;\n"
8697 " gl_TessLevelInner[0] = 1.0;\n"
8698 " gl_TessLevelInner[1] = 1.0;\n"
8699 "}\n"
8700 "\n";
8701
8702 static const GLchar* tess_eval_shader_template = "VERSION\n"
8703 "\n"
8704 "layout(isolines, point_mode) in;\n"
8705 "\n"
8706 "in vec4 tcs_tes_result[];\n"
8707 "out vec4 tes_gs_result;\n"
8708 "\n"
8709 "UNI_GOKU\n"
8710 "\n"
8711 "void main()\n"
8712 "{\n"
8713 " vec4 result = vec4(0, 1, 0, 1);\n"
8714 "\n"
8715 "VERIFICATION"
8716 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
8717 " {\n"
8718 " result = vec4(1, 0, 0, 1);\n"
8719 " }\n"
8720 "\n"
8721 " tes_gs_result = result;\n"
8722 "}\n"
8723 "\n";
8724
8725 static const GLchar* vertex_shader_template = "VERSION\n"
8726 "\n"
8727 "out vec4 vs_tcs_result;\n"
8728 "\n"
8729 "UNI_GOKU\n"
8730 "\n"
8731 "void main()\n"
8732 "{\n"
8733 " vec4 result = vec4(0, 1, 0, 1);\n"
8734 "\n"
8735 "VERIFICATION"
8736 "\n"
8737 " vs_tcs_result = result;\n"
8738 "}\n"
8739 "\n";
8740
8741 const GLchar* shader_template = 0;
8742
8743 switch (in_stage)
8744 {
8745 case Utils::COMPUTE_SHADER:
8746 shader_template = compute_shader_template;
8747 break;
8748 case Utils::FRAGMENT_SHADER:
8749 shader_template = fragment_shader_template;
8750 break;
8751 case Utils::GEOMETRY_SHADER:
8752 shader_template = geometry_shader_template;
8753 break;
8754 case Utils::TESS_CTRL_SHADER:
8755 shader_template = tess_ctrl_shader_template;
8756 break;
8757 case Utils::TESS_EVAL_SHADER:
8758 shader_template = tess_eval_shader_template;
8759 break;
8760 case Utils::VERTEX_SHADER:
8761 shader_template = vertex_shader_template;
8762 break;
8763 default:
8764 TCU_FAIL("Invalid enum");
8765 }
8766
8767 out_source.m_parts[0].m_code = shader_template;
8768
8769 size_t position = 0;
8770
8771 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
8772 out_source.m_parts[0].m_code);
8773
8774 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
8775
8776 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
8777 }
8778
8779 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
8780 *
8781 * @param program Current program
8782 **/
prepareUniforms(Utils::program & program)8783 void BindingUniformBlockArrayTest::prepareUniforms(Utils::program& program)
8784 {
8785 static const GLfloat goku_data[][8] = {
8786 { 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 },
8787 { 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 },
8788 { 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 },
8789 { 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 },
8790 { 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 },
8791 { 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 },
8792 { 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 }
8793 };
8794
8795 Utils::buffer* buffers[14] = { &m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8796 &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8797 &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8798 &m_goku_12_buffer, &m_goku_13_buffer };
8799
8800 for (GLuint i = 0; i < 14; ++i)
8801 {
8802 checkBinding(program, i, i + 2);
8803
8804 buffers[i]->generate(GL_UNIFORM_BUFFER);
8805 buffers[i]->update(sizeof(GLfloat) * 8, (GLvoid*)goku_data[i], GL_STATIC_DRAW);
8806 buffers[i]->bindRange(i + 2 /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
8807 }
8808 }
8809
8810 /** Overwrite of releaseResource method, release extra uniform buffer
8811 *
8812 * @param ignored
8813 **/
releaseResource()8814 void BindingUniformBlockArrayTest::releaseResource()
8815 {
8816 Utils::buffer* buffers[14] = { &m_goku_00_buffer, &m_goku_01_buffer, &m_goku_02_buffer, &m_goku_03_buffer,
8817 &m_goku_04_buffer, &m_goku_05_buffer, &m_goku_06_buffer, &m_goku_07_buffer,
8818 &m_goku_08_buffer, &m_goku_09_buffer, &m_goku_10_buffer, &m_goku_11_buffer,
8819 &m_goku_12_buffer, &m_goku_13_buffer };
8820
8821 for (GLuint i = 0; i < 14; ++i)
8822 {
8823 buffers[i]->release();
8824 }
8825 }
8826
8827 /** Verifies that API reports correct uniform binding
8828 *
8829 * @param program Program
8830 * @param index Index of array element
8831 * @param expected_binding Expected binding
8832 **/
checkBinding(Utils::program & program,glw::GLuint index,glw::GLint expected_binding)8833 void BindingUniformBlockArrayTest::checkBinding(Utils::program& program, glw::GLuint index, glw::GLint expected_binding)
8834 {
8835 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8836
8837 GLchar buffer[64];
8838 sprintf(buffer, "GOKU[%d]", index);
8839
8840 const GLuint uniform_index = gl.getUniformBlockIndex(program.m_program_object_id, buffer);
8841 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8842 if (GL_INVALID_INDEX == uniform_index)
8843 {
8844 TCU_FAIL("Uniform block is inactive");
8845 }
8846
8847 GLint binding = -1;
8848
8849 gl.getActiveUniformBlockiv(program.m_program_object_id, uniform_index, GL_UNIFORM_BLOCK_BINDING, &binding);
8850 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8851
8852 if (expected_binding != binding)
8853 {
8854 TCU_FAIL("Wrong binding reported by API");
8855 }
8856 }
8857
8858 /** Constructor
8859 *
8860 * @param context Test context
8861 **/
BindingUniformDefaultTest(deqp::Context & context)8862 BindingUniformDefaultTest::BindingUniformDefaultTest(deqp::Context& context)
8863 : APITestBase(context, "binding_uniform_default", "Test verifies default binding of uniform block")
8864 {
8865 /* Nothing to be done here */
8866 }
8867
8868 /** Execute API call and verifies results
8869 *
8870 * @return true when results are positive, false otherwise
8871 **/
checkResults(Utils::program & program)8872 bool BindingUniformDefaultTest::checkResults(Utils::program& program)
8873 {
8874 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
8875
8876 const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
8877 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
8878 if (GL_INVALID_INDEX == index)
8879 {
8880 TCU_FAIL("Uniform block is inactive");
8881 return false;
8882 }
8883
8884 GLint binding = -1;
8885
8886 gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
8887 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
8888
8889 if (0 != binding)
8890 {
8891 return false;
8892 }
8893
8894 return true;
8895 }
8896
8897 /** Prepare source for given shader stage
8898 *
8899 * @param in_stage Shader stage, compute shader will use 430
8900 * @param in_use_version_400 Select if 400 or 420 should be used
8901 * @param out_source Prepared shader source instance
8902 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)8903 void BindingUniformDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
8904 Utils::shaderSource& out_source)
8905 {
8906 static const GLchar* uni_goku = "layout(std140) uniform GOKU {\n"
8907 " vec4 gohan;\n"
8908 " vec4 goten;\n"
8909 "} goku;\n";
8910
8911 static const GLchar* verification_snippet = " if ((vec4(0, 0, 0, 0) != goku.gohan) ||\n"
8912 " (vec4(0, 0, 0, 1) != goku.goten) )\n"
8913 " {\n"
8914 " result = vec4(1, 0, 0, 1);\n"
8915 " }\n";
8916
8917 static const GLchar* compute_shader_template =
8918 "VERSION\n"
8919 "\n"
8920 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8921 "\n"
8922 "writeonly uniform image2D uni_image;\n"
8923 "\n"
8924 "UNI_GOKU\n"
8925 "\n"
8926 "void main()\n"
8927 "{\n"
8928 " vec4 result = vec4(0, 1, 0, 1);\n"
8929 "\n"
8930 "VERIFICATION"
8931 "\n"
8932 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8933 "}\n"
8934 "\n";
8935
8936 static const GLchar* fragment_shader_template = "VERSION\n"
8937 "\n"
8938 "in vec4 gs_fs_result;\n"
8939 "out vec4 fs_out_result;\n"
8940 "\n"
8941 "UNI_GOKU\n"
8942 "\n"
8943 "void main()\n"
8944 "{\n"
8945 " vec4 result = vec4(0, 1, 0, 1);\n"
8946 "\n"
8947 "VERIFICATION"
8948 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
8949 " {\n"
8950 " result = vec4(1, 0, 0, 1);\n"
8951 " }\n"
8952 "\n"
8953 " fs_out_result = result;\n"
8954 "}\n"
8955 "\n";
8956
8957 static const GLchar* geometry_shader_template = "VERSION\n"
8958 "\n"
8959 "layout(points) in;\n"
8960 "layout(triangle_strip, max_vertices = 4) out;\n"
8961 "\n"
8962 "in vec4 tes_gs_result[];\n"
8963 "out vec4 gs_fs_result;\n"
8964 "\n"
8965 "UNI_GOKU\n"
8966 "\n"
8967 "void main()\n"
8968 "{\n"
8969 " vec4 result = vec4(0, 1, 0, 1);\n"
8970 "\n"
8971 "VERIFICATION"
8972 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
8973 " {\n"
8974 " result = vec4(1, 0, 0, 1);\n"
8975 " }\n"
8976 "\n"
8977 " gs_fs_result = result;\n"
8978 " gl_Position = vec4(-1, -1, 0, 1);\n"
8979 " EmitVertex();\n"
8980 " gs_fs_result = result;\n"
8981 " gl_Position = vec4(-1, 1, 0, 1);\n"
8982 " EmitVertex();\n"
8983 " gs_fs_result = result;\n"
8984 " gl_Position = vec4(1, -1, 0, 1);\n"
8985 " EmitVertex();\n"
8986 " gs_fs_result = result;\n"
8987 " gl_Position = vec4(1, 1, 0, 1);\n"
8988 " EmitVertex();\n"
8989 "}\n"
8990 "\n";
8991
8992 static const GLchar* tess_ctrl_shader_template =
8993 "VERSION\n"
8994 "\n"
8995 "layout(vertices = 1) out;\n"
8996 "\n"
8997 "in vec4 vs_tcs_result[];\n"
8998 "out vec4 tcs_tes_result[];\n"
8999 "\n"
9000 "UNI_GOKU\n"
9001 "\n"
9002 "void main()\n"
9003 "{\n"
9004 " vec4 result = vec4(0, 1, 0, 1);\n"
9005 "\n"
9006 "VERIFICATION"
9007 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9008 " {\n"
9009 " result = vec4(1, 0, 0, 1);\n"
9010 " }\n"
9011 "\n"
9012 " tcs_tes_result[gl_InvocationID] = result;\n"
9013 "\n"
9014 " gl_TessLevelOuter[0] = 1.0;\n"
9015 " gl_TessLevelOuter[1] = 1.0;\n"
9016 " gl_TessLevelOuter[2] = 1.0;\n"
9017 " gl_TessLevelOuter[3] = 1.0;\n"
9018 " gl_TessLevelInner[0] = 1.0;\n"
9019 " gl_TessLevelInner[1] = 1.0;\n"
9020 "}\n"
9021 "\n";
9022
9023 static const GLchar* tess_eval_shader_template = "VERSION\n"
9024 "\n"
9025 "layout(isolines, point_mode) in;\n"
9026 "\n"
9027 "in vec4 tcs_tes_result[];\n"
9028 "out vec4 tes_gs_result;\n"
9029 "\n"
9030 "UNI_GOKU\n"
9031 "\n"
9032 "void main()\n"
9033 "{\n"
9034 " vec4 result = vec4(0, 1, 0, 1);\n"
9035 "\n"
9036 "VERIFICATION"
9037 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9038 " {\n"
9039 " result = vec4(1, 0, 0, 1);\n"
9040 " }\n"
9041 "\n"
9042 " tes_gs_result = result;\n"
9043 "}\n"
9044 "\n";
9045
9046 static const GLchar* vertex_shader_template = "VERSION\n"
9047 "\n"
9048 "out vec4 vs_tcs_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 "\n"
9058 " vs_tcs_result = result;\n"
9059 "}\n"
9060 "\n";
9061
9062 const GLchar* shader_template = 0;
9063
9064 switch (in_stage)
9065 {
9066 case Utils::COMPUTE_SHADER:
9067 shader_template = compute_shader_template;
9068 break;
9069 case Utils::FRAGMENT_SHADER:
9070 shader_template = fragment_shader_template;
9071 break;
9072 case Utils::GEOMETRY_SHADER:
9073 shader_template = geometry_shader_template;
9074 break;
9075 case Utils::TESS_CTRL_SHADER:
9076 shader_template = tess_ctrl_shader_template;
9077 break;
9078 case Utils::TESS_EVAL_SHADER:
9079 shader_template = tess_eval_shader_template;
9080 break;
9081 case Utils::VERTEX_SHADER:
9082 shader_template = vertex_shader_template;
9083 break;
9084 default:
9085 TCU_FAIL("Invalid enum");
9086 }
9087
9088 out_source.m_parts[0].m_code = shader_template;
9089
9090 size_t position = 0;
9091
9092 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9093 out_source.m_parts[0].m_code);
9094
9095 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9096
9097 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9098 }
9099
9100 /** Constructor
9101 *
9102 * @param context Test context
9103 **/
BindingUniformAPIOverirdeTest(deqp::Context & context)9104 BindingUniformAPIOverirdeTest::BindingUniformAPIOverirdeTest(deqp::Context& context)
9105 : GLSLTestBase(context, "binding_uniform_api_overirde", "Test verifies if binding can be overriden with API")
9106 , m_goku_buffer(context)
9107 {
9108 /* Nothing to be done here */
9109 }
9110
9111 /** Prepare source for given shader stage
9112 *
9113 * @param in_stage Shader stage, compute shader will use 430
9114 * @param in_use_version_400 Select if 400 or 420 should be used
9115 * @param out_source Prepared shader source instance
9116 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9117 void BindingUniformAPIOverirdeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9118 Utils::shaderSource& out_source)
9119 {
9120 static const GLchar* uni_goku = "layout(std140, binding = 2) uniform GOKU {\n"
9121 " vec4 gohan;\n"
9122 " vec4 goten;\n"
9123 "} goku;\n";
9124
9125 static const GLchar* verification_snippet = " if ((vec4(1, 0, 0, 0) != goku.gohan) ||\n"
9126 " (vec4(0, 1, 0, 0) != goku.goten) )\n"
9127 " {\n"
9128 " result = vec4(1, 0, 0, 1);\n"
9129 " }\n";
9130
9131 static const GLchar* compute_shader_template =
9132 "VERSION\n"
9133 "\n"
9134 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9135 "\n"
9136 "writeonly uniform image2D uni_image;\n"
9137 "\n"
9138 "UNI_GOKU\n"
9139 "\n"
9140 "void main()\n"
9141 "{\n"
9142 " vec4 result = vec4(0, 1, 0, 1);\n"
9143 "\n"
9144 "VERIFICATION"
9145 "\n"
9146 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9147 "}\n"
9148 "\n";
9149
9150 static const GLchar* fragment_shader_template = "VERSION\n"
9151 "\n"
9152 "in vec4 gs_fs_result;\n"
9153 "out vec4 fs_out_result;\n"
9154 "\n"
9155 "UNI_GOKU\n"
9156 "\n"
9157 "void main()\n"
9158 "{\n"
9159 " vec4 result = vec4(0, 1, 0, 1);\n"
9160 "\n"
9161 "VERIFICATION"
9162 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9163 " {\n"
9164 " result = vec4(1, 0, 0, 1);\n"
9165 " }\n"
9166 "\n"
9167 " fs_out_result = result;\n"
9168 "}\n"
9169 "\n";
9170
9171 static const GLchar* geometry_shader_template = "VERSION\n"
9172 "\n"
9173 "layout(points) in;\n"
9174 "layout(triangle_strip, max_vertices = 4) out;\n"
9175 "\n"
9176 "in vec4 tes_gs_result[];\n"
9177 "out vec4 gs_fs_result;\n"
9178 "\n"
9179 "UNI_GOKU\n"
9180 "\n"
9181 "void main()\n"
9182 "{\n"
9183 " vec4 result = vec4(0, 1, 0, 1);\n"
9184 "\n"
9185 "VERIFICATION"
9186 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9187 " {\n"
9188 " result = vec4(1, 0, 0, 1);\n"
9189 " }\n"
9190 "\n"
9191 " gs_fs_result = result;\n"
9192 " gl_Position = vec4(-1, -1, 0, 1);\n"
9193 " EmitVertex();\n"
9194 " gs_fs_result = result;\n"
9195 " gl_Position = vec4(-1, 1, 0, 1);\n"
9196 " EmitVertex();\n"
9197 " gs_fs_result = result;\n"
9198 " gl_Position = vec4(1, -1, 0, 1);\n"
9199 " EmitVertex();\n"
9200 " gs_fs_result = result;\n"
9201 " gl_Position = vec4(1, 1, 0, 1);\n"
9202 " EmitVertex();\n"
9203 "}\n"
9204 "\n";
9205
9206 static const GLchar* tess_ctrl_shader_template =
9207 "VERSION\n"
9208 "\n"
9209 "layout(vertices = 1) out;\n"
9210 "\n"
9211 "in vec4 vs_tcs_result[];\n"
9212 "out vec4 tcs_tes_result[];\n"
9213 "\n"
9214 "UNI_GOKU\n"
9215 "\n"
9216 "void main()\n"
9217 "{\n"
9218 " vec4 result = vec4(0, 1, 0, 1);\n"
9219 "\n"
9220 "VERIFICATION"
9221 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9222 " {\n"
9223 " result = vec4(1, 0, 0, 1);\n"
9224 " }\n"
9225 "\n"
9226 " tcs_tes_result[gl_InvocationID] = result;\n"
9227 "\n"
9228 " gl_TessLevelOuter[0] = 1.0;\n"
9229 " gl_TessLevelOuter[1] = 1.0;\n"
9230 " gl_TessLevelOuter[2] = 1.0;\n"
9231 " gl_TessLevelOuter[3] = 1.0;\n"
9232 " gl_TessLevelInner[0] = 1.0;\n"
9233 " gl_TessLevelInner[1] = 1.0;\n"
9234 "}\n"
9235 "\n";
9236
9237 static const GLchar* tess_eval_shader_template = "VERSION\n"
9238 "\n"
9239 "layout(isolines, point_mode) in;\n"
9240 "\n"
9241 "in vec4 tcs_tes_result[];\n"
9242 "out vec4 tes_gs_result;\n"
9243 "\n"
9244 "UNI_GOKU\n"
9245 "\n"
9246 "void main()\n"
9247 "{\n"
9248 " vec4 result = vec4(0, 1, 0, 1);\n"
9249 "\n"
9250 "VERIFICATION"
9251 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9252 " {\n"
9253 " result = vec4(1, 0, 0, 1);\n"
9254 " }\n"
9255 "\n"
9256 " tes_gs_result = result;\n"
9257 "}\n"
9258 "\n";
9259
9260 static const GLchar* vertex_shader_template = "VERSION\n"
9261 "\n"
9262 "out vec4 vs_tcs_result;\n"
9263 "\n"
9264 "UNI_GOKU\n"
9265 "\n"
9266 "void main()\n"
9267 "{\n"
9268 " vec4 result = vec4(0, 1, 0, 1);\n"
9269 "\n"
9270 "VERIFICATION"
9271 "\n"
9272 " vs_tcs_result = result;\n"
9273 "}\n"
9274 "\n";
9275
9276 const GLchar* shader_template = 0;
9277
9278 switch (in_stage)
9279 {
9280 case Utils::COMPUTE_SHADER:
9281 shader_template = compute_shader_template;
9282 break;
9283 case Utils::FRAGMENT_SHADER:
9284 shader_template = fragment_shader_template;
9285 break;
9286 case Utils::GEOMETRY_SHADER:
9287 shader_template = geometry_shader_template;
9288 break;
9289 case Utils::TESS_CTRL_SHADER:
9290 shader_template = tess_ctrl_shader_template;
9291 break;
9292 case Utils::TESS_EVAL_SHADER:
9293 shader_template = tess_eval_shader_template;
9294 break;
9295 case Utils::VERTEX_SHADER:
9296 shader_template = vertex_shader_template;
9297 break;
9298 default:
9299 TCU_FAIL("Invalid enum");
9300 }
9301
9302 out_source.m_parts[0].m_code = shader_template;
9303
9304 size_t position = 0;
9305
9306 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9307 out_source.m_parts[0].m_code);
9308
9309 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9310
9311 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
9312 }
9313
9314 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
9315 *
9316 * @param program Current program
9317 **/
prepareUniforms(Utils::program & program)9318 void BindingUniformAPIOverirdeTest::prepareUniforms(Utils::program& program)
9319 {
9320 static const GLfloat goku_data[8] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
9321
9322 static const GLuint new_binding = 11;
9323
9324 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
9325
9326 const GLuint index = gl.getUniformBlockIndex(program.m_program_object_id, "GOKU");
9327 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformBlockIndex");
9328 if (GL_INVALID_INDEX == index)
9329 {
9330 TCU_FAIL("Uniform block is inactive");
9331 return;
9332 }
9333
9334 gl.uniformBlockBinding(program.m_program_object_id, index, new_binding);
9335 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformBlockBinding");
9336
9337 GLint binding = -1;
9338
9339 gl.getActiveUniformBlockiv(program.m_program_object_id, index, GL_UNIFORM_BLOCK_BINDING, &binding);
9340 GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformBlockiv");
9341
9342 if (new_binding != binding)
9343 {
9344 TCU_FAIL("GetActiveUniformBlockiv returned wrong binding");
9345 return;
9346 }
9347
9348 m_goku_buffer.generate(GL_UNIFORM_BUFFER);
9349 m_goku_buffer.update(sizeof(GLfloat) * 8, (GLvoid*)goku_data, GL_STATIC_DRAW);
9350 m_goku_buffer.bindRange(new_binding /* index */, 0 /* offset */, sizeof(GLfloat) * 8);
9351 }
9352
9353 /** Overwrite of releaseResource method, release extra uniform buffer
9354 *
9355 * @param ignored
9356 **/
releaseResource()9357 void BindingUniformAPIOverirdeTest::releaseResource()
9358 {
9359 m_goku_buffer.release();
9360 }
9361
9362 /** Constructor
9363 *
9364 * @param context Test context
9365 **/
BindingUniformGlobalBlockTest(deqp::Context & context)9366 BindingUniformGlobalBlockTest::BindingUniformGlobalBlockTest(deqp::Context& context)
9367 : NegativeTestBase(context, "binding_uniform_global_block",
9368 "Test verifies that global uniform cannot be qualified with binding")
9369 {
9370 /* Nothing to be done here */
9371 }
9372
9373 /** Prepare source for given shader stage
9374 *
9375 * @param in_stage Shader stage, compute shader will use 430
9376 * @param in_use_version_400 Select if 400 or 420 should be used
9377 * @param out_source Prepared shader source instance
9378 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9379 void BindingUniformGlobalBlockTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9380 Utils::shaderSource& out_source)
9381 {
9382 static const GLchar* verification_snippet = " if (vec4(0, 0, 1, 1) != uni_test)\n"
9383 " {\n"
9384 " result = vec4(1, 0, 0, 1);\n"
9385 " }\n";
9386
9387 static const GLchar* uniform_definition = "layout(binding = 0) uniform vec4 uni_test;\n";
9388
9389 static const GLchar* compute_shader_template =
9390 "VERSION\n"
9391 "\n"
9392 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9393 "\n"
9394 "writeonly uniform image2D uni_image;\n"
9395 "\n"
9396 "UNIFORM_DEFINITION\n"
9397 "\n"
9398 "void main()\n"
9399 "{\n"
9400 " vec4 result = vec4(0, 1, 0, 1);\n"
9401 "\n"
9402 "VERIFICATION"
9403 "\n"
9404 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9405 "}\n"
9406 "\n";
9407
9408 static const GLchar* fragment_shader_template = "VERSION\n"
9409 "\n"
9410 "in vec4 gs_fs_result;\n"
9411 "out vec4 fs_out_result;\n"
9412 "\n"
9413 "UNIFORM_DEFINITION\n"
9414 "\n"
9415 "void main()\n"
9416 "{\n"
9417 " vec4 result = vec4(0, 1, 0, 1);\n"
9418 "\n"
9419 "VERIFICATION"
9420 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9421 " {\n"
9422 " result = vec4(1, 0, 0, 1);\n"
9423 " }\n"
9424 "\n"
9425 " fs_out_result = result;\n"
9426 "}\n"
9427 "\n";
9428
9429 static const GLchar* geometry_shader_template = "VERSION\n"
9430 "\n"
9431 "layout(points) in;\n"
9432 "layout(triangle_strip, max_vertices = 4) out;\n"
9433 "\n"
9434 "in vec4 tes_gs_result[];\n"
9435 "out vec4 gs_fs_result;\n"
9436 "\n"
9437 "UNIFORM_DEFINITION\n"
9438 "\n"
9439 "void main()\n"
9440 "{\n"
9441 " vec4 result = vec4(0, 1, 0, 1);\n"
9442 "\n"
9443 "VERIFICATION"
9444 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9445 " {\n"
9446 " result = vec4(1, 0, 0, 1);\n"
9447 " }\n"
9448 "\n"
9449 " gs_fs_result = result;\n"
9450 " gl_Position = vec4(-1, -1, 0, 1);\n"
9451 " EmitVertex();\n"
9452 " gs_fs_result = result;\n"
9453 " gl_Position = vec4(-1, 1, 0, 1);\n"
9454 " EmitVertex();\n"
9455 " gs_fs_result = result;\n"
9456 " gl_Position = vec4(1, -1, 0, 1);\n"
9457 " EmitVertex();\n"
9458 " gs_fs_result = result;\n"
9459 " gl_Position = vec4(1, 1, 0, 1);\n"
9460 " EmitVertex();\n"
9461 "}\n"
9462 "\n";
9463
9464 static const GLchar* tess_ctrl_shader_template =
9465 "VERSION\n"
9466 "\n"
9467 "layout(vertices = 1) out;\n"
9468 "\n"
9469 "in vec4 vs_tcs_result[];\n"
9470 "out vec4 tcs_tes_result[];\n"
9471 "\n"
9472 "UNIFORM_DEFINITION\n"
9473 "\n"
9474 "void main()\n"
9475 "{\n"
9476 " vec4 result = vec4(0, 1, 0, 1);\n"
9477 "\n"
9478 "VERIFICATION"
9479 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9480 " {\n"
9481 " result = vec4(1, 0, 0, 1);\n"
9482 " }\n"
9483 "\n"
9484 " tcs_tes_result[gl_InvocationID] = result;\n"
9485 "\n"
9486 " gl_TessLevelOuter[0] = 1.0;\n"
9487 " gl_TessLevelOuter[1] = 1.0;\n"
9488 " gl_TessLevelOuter[2] = 1.0;\n"
9489 " gl_TessLevelOuter[3] = 1.0;\n"
9490 " gl_TessLevelInner[0] = 1.0;\n"
9491 " gl_TessLevelInner[1] = 1.0;\n"
9492 "}\n"
9493 "\n";
9494
9495 static const GLchar* tess_eval_shader_template = "VERSION\n"
9496 "\n"
9497 "layout(isolines, point_mode) in;\n"
9498 "\n"
9499 "in vec4 tcs_tes_result[];\n"
9500 "out vec4 tes_gs_result;\n"
9501 "\n"
9502 "UNIFORM_DEFINITION\n"
9503 "\n"
9504 "void main()\n"
9505 "{\n"
9506 " vec4 result = vec4(0, 1, 0, 1);\n"
9507 "\n"
9508 "VERIFICATION"
9509 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9510 " {\n"
9511 " result = vec4(1, 0, 0, 1);\n"
9512 " }\n"
9513 "\n"
9514 " tes_gs_result = result;\n"
9515 "}\n"
9516 "\n";
9517
9518 static const GLchar* vertex_shader_template = "VERSION\n"
9519 "\n"
9520 "out vec4 vs_tcs_result;\n"
9521 "\n"
9522 "UNIFORM_DEFINITION\n"
9523 "\n"
9524 "void main()\n"
9525 "{\n"
9526 " vec4 result = vec4(0, 1, 0, 1);\n"
9527 "\n"
9528 "VERIFICATION"
9529 "\n"
9530 " vs_tcs_result = result;\n"
9531 "}\n"
9532 "\n";
9533
9534 const GLchar* shader_template = 0;
9535
9536 switch (in_stage)
9537 {
9538 case Utils::COMPUTE_SHADER:
9539 shader_template = compute_shader_template;
9540 break;
9541 case Utils::FRAGMENT_SHADER:
9542 shader_template = fragment_shader_template;
9543 break;
9544 case Utils::GEOMETRY_SHADER:
9545 shader_template = geometry_shader_template;
9546 break;
9547 case Utils::TESS_CTRL_SHADER:
9548 shader_template = tess_ctrl_shader_template;
9549 break;
9550 case Utils::TESS_EVAL_SHADER:
9551 shader_template = tess_eval_shader_template;
9552 break;
9553 case Utils::VERTEX_SHADER:
9554 shader_template = vertex_shader_template;
9555 break;
9556 default:
9557 TCU_FAIL("Invalid enum");
9558 }
9559
9560 out_source.m_parts[0].m_code = shader_template;
9561
9562 size_t position = 0;
9563 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9564 out_source.m_parts[0].m_code);
9565
9566 Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9567
9568 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9569 }
9570
9571 /** Constructor
9572 *
9573 * @param context Test context
9574 **/
BindingUniformInvalidTest(deqp::Context & context)9575 BindingUniformInvalidTest::BindingUniformInvalidTest(deqp::Context& context)
9576 : NegativeTestBase(context, "binding_uniform_invalid", "Test verifies invalid binding values")
9577 , m_case(TEST_CASES_MAX)
9578 {
9579 /* Nothing to be done here */
9580 }
9581
9582 /** Set up next test case
9583 *
9584 * @param test_case_index Index of next test case
9585 *
9586 * @return false if there is no more test cases, true otherwise
9587 **/
prepareNextTestCase(glw::GLuint test_case_index)9588 bool BindingUniformInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
9589 {
9590 switch (test_case_index)
9591 {
9592 case (glw::GLuint)-1:
9593 m_case = TEST_CASES_MAX;
9594 break;
9595 case NEGATIVE_VALUE:
9596 case VARIABLE_NAME:
9597 case STD140:
9598 case MISSING:
9599 m_case = (TESTCASES)test_case_index;
9600 break;
9601 default:
9602 return false;
9603 }
9604
9605 return true;
9606 }
9607
9608 /** Prepare source for given shader stage
9609 *
9610 * @param in_stage Shader stage, compute shader will use 430
9611 * @param in_use_version_400 Select if 400 or 420 should be used
9612 * @param out_source Prepared shader source instance
9613 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9614 void BindingUniformInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9615 Utils::shaderSource& out_source)
9616 {
9617 static const GLchar* verification_snippet = " if (vec4(0, 0, 1, 1) != goku.gohan)\n"
9618 " {\n"
9619 " result = vec4(1, 0, 0, 1);\n"
9620 " }\n";
9621
9622 static const GLchar* uniform_definition = "layout(std140, binding BINDING) uniform GOKU {\n"
9623 " vec4 gohan;\n"
9624 " vec4 goten;\n"
9625 "} goku;\n";
9626
9627 static const GLchar* compute_shader_template =
9628 "VERSION\n"
9629 "\n"
9630 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9631 "\n"
9632 "writeonly uniform image2D uni_image;\n"
9633 "\n"
9634 "UNIFORM_DEFINITION\n"
9635 "\n"
9636 "void main()\n"
9637 "{\n"
9638 " vec4 result = vec4(0, 1, 0, 1);\n"
9639 "\n"
9640 "VERIFICATION"
9641 "\n"
9642 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9643 "}\n"
9644 "\n";
9645
9646 static const GLchar* fragment_shader_template = "VERSION\n"
9647 "\n"
9648 "in vec4 gs_fs_result;\n"
9649 "out vec4 fs_out_result;\n"
9650 "\n"
9651 "UNIFORM_DEFINITION\n"
9652 "\n"
9653 "void main()\n"
9654 "{\n"
9655 " vec4 result = vec4(0, 1, 0, 1);\n"
9656 "\n"
9657 "VERIFICATION"
9658 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9659 " {\n"
9660 " result = vec4(1, 0, 0, 1);\n"
9661 " }\n"
9662 "\n"
9663 " fs_out_result = result;\n"
9664 "}\n"
9665 "\n";
9666
9667 static const GLchar* geometry_shader_template = "VERSION\n"
9668 "\n"
9669 "layout(points) in;\n"
9670 "layout(triangle_strip, max_vertices = 4) out;\n"
9671 "\n"
9672 "in vec4 tes_gs_result[];\n"
9673 "out vec4 gs_fs_result;\n"
9674 "\n"
9675 "UNIFORM_DEFINITION\n"
9676 "\n"
9677 "void main()\n"
9678 "{\n"
9679 " vec4 result = vec4(0, 1, 0, 1);\n"
9680 "\n"
9681 "VERIFICATION"
9682 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9683 " {\n"
9684 " result = vec4(1, 0, 0, 1);\n"
9685 " }\n"
9686 "\n"
9687 " gs_fs_result = result;\n"
9688 " gl_Position = vec4(-1, -1, 0, 1);\n"
9689 " EmitVertex();\n"
9690 " gs_fs_result = result;\n"
9691 " gl_Position = vec4(-1, 1, 0, 1);\n"
9692 " EmitVertex();\n"
9693 " gs_fs_result = result;\n"
9694 " gl_Position = vec4(1, -1, 0, 1);\n"
9695 " EmitVertex();\n"
9696 " gs_fs_result = result;\n"
9697 " gl_Position = vec4(1, 1, 0, 1);\n"
9698 " EmitVertex();\n"
9699 "}\n"
9700 "\n";
9701
9702 static const GLchar* tess_ctrl_shader_template =
9703 "VERSION\n"
9704 "\n"
9705 "layout(vertices = 1) out;\n"
9706 "\n"
9707 "in vec4 vs_tcs_result[];\n"
9708 "out vec4 tcs_tes_result[];\n"
9709 "\n"
9710 "UNIFORM_DEFINITION\n"
9711 "\n"
9712 "void main()\n"
9713 "{\n"
9714 " vec4 result = vec4(0, 1, 0, 1);\n"
9715 "\n"
9716 "VERIFICATION"
9717 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
9718 " {\n"
9719 " result = vec4(1, 0, 0, 1);\n"
9720 " }\n"
9721 "\n"
9722 " tcs_tes_result[gl_InvocationID] = result;\n"
9723 "\n"
9724 " gl_TessLevelOuter[0] = 1.0;\n"
9725 " gl_TessLevelOuter[1] = 1.0;\n"
9726 " gl_TessLevelOuter[2] = 1.0;\n"
9727 " gl_TessLevelOuter[3] = 1.0;\n"
9728 " gl_TessLevelInner[0] = 1.0;\n"
9729 " gl_TessLevelInner[1] = 1.0;\n"
9730 "}\n"
9731 "\n";
9732
9733 static const GLchar* tess_eval_shader_template = "VERSION\n"
9734 "\n"
9735 "layout(isolines, point_mode) in;\n"
9736 "\n"
9737 "in vec4 tcs_tes_result[];\n"
9738 "out vec4 tes_gs_result;\n"
9739 "\n"
9740 "UNIFORM_DEFINITION\n"
9741 "\n"
9742 "void main()\n"
9743 "{\n"
9744 " vec4 result = vec4(0, 1, 0, 1);\n"
9745 "\n"
9746 "VERIFICATION"
9747 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
9748 " {\n"
9749 " result = vec4(1, 0, 0, 1);\n"
9750 " }\n"
9751 "\n"
9752 " tes_gs_result = result;\n"
9753 "}\n"
9754 "\n";
9755
9756 static const GLchar* vertex_shader_template = "VERSION\n"
9757 "\n"
9758 "out vec4 vs_tcs_result;\n"
9759 "\n"
9760 "UNIFORM_DEFINITION\n"
9761 "\n"
9762 "void main()\n"
9763 "{\n"
9764 " vec4 result = vec4(0, 1, 0, 1);\n"
9765 "\n"
9766 "VERIFICATION"
9767 "\n"
9768 " vs_tcs_result = result;\n"
9769 "}\n"
9770 "\n";
9771
9772 const GLchar* shader_template = 0;
9773
9774 switch (in_stage)
9775 {
9776 case Utils::COMPUTE_SHADER:
9777 shader_template = compute_shader_template;
9778 break;
9779 case Utils::FRAGMENT_SHADER:
9780 shader_template = fragment_shader_template;
9781 break;
9782 case Utils::GEOMETRY_SHADER:
9783 shader_template = geometry_shader_template;
9784 break;
9785 case Utils::TESS_CTRL_SHADER:
9786 shader_template = tess_ctrl_shader_template;
9787 break;
9788 case Utils::TESS_EVAL_SHADER:
9789 shader_template = tess_eval_shader_template;
9790 break;
9791 case Utils::VERTEX_SHADER:
9792 shader_template = vertex_shader_template;
9793 break;
9794 default:
9795 TCU_FAIL("Invalid enum");
9796 }
9797
9798 out_source.m_parts[0].m_code = shader_template;
9799
9800 size_t position = 0;
9801 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
9802 out_source.m_parts[0].m_code);
9803
9804 Utils::replaceToken("UNIFORM_DEFINITION", position, uniform_definition, out_source.m_parts[0].m_code);
9805
9806 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
9807
9808 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
9809 }
9810
getCaseString(TESTCASES test_case)9811 const GLchar* BindingUniformInvalidTest::getCaseString(TESTCASES test_case)
9812 {
9813 (void)test_case;
9814 const GLchar* binding = 0;
9815
9816 switch (m_case)
9817 {
9818 case NEGATIVE_VALUE:
9819 binding = "= -1";
9820 break;
9821 case VARIABLE_NAME:
9822 binding = "= goku";
9823 break;
9824 case STD140:
9825 binding = "= std140";
9826 break;
9827 case MISSING:
9828 binding = "";
9829 break;
9830 case TEST_CASES_MAX:
9831 binding = "= 0";
9832 break;
9833 default:
9834 TCU_FAIL("Invalid enum");
9835 }
9836
9837 return binding;
9838 }
9839
9840 /** Constructor
9841 *
9842 * @param context Test context
9843 **/
BindingSamplersTest(deqp::Context & context)9844 BindingSamplersTest::BindingSamplersTest(deqp::Context& context)
9845 : GLSLTestBase(context, "binding_samplers", "Test verifies smaplers binding")
9846 , m_goku_texture(context)
9847 , m_vegeta_texture(context)
9848 , m_trunks_texture(context)
9849 , m_buffer(context)
9850 , m_test_case(Utils::TEXTURE_TYPES_MAX)
9851 {
9852 /* Nothing to be done here */
9853 }
9854
9855 /** Set up next test case
9856 *
9857 * @param test_case_index Index of next test case
9858 *
9859 * @return false if there is no more test cases, true otherwise
9860 **/
prepareNextTestCase(glw::GLuint test_case_index)9861 bool BindingSamplersTest::prepareNextTestCase(glw::GLuint test_case_index)
9862 {
9863 switch (test_case_index)
9864 {
9865 case (glw::GLuint)-1:
9866 case 0:
9867 m_test_case = Utils::TEX_2D;
9868 break;
9869 case 1:
9870 m_test_case = Utils::TEX_BUFFER;
9871 break;
9872 case 2:
9873 m_test_case = Utils::TEX_2D_RECT;
9874 break;
9875 case 3:
9876 m_test_case = Utils::TEX_2D_ARRAY;
9877 break;
9878 case 4:
9879 m_test_case = Utils::TEX_3D;
9880 break;
9881 case 5:
9882 m_test_case = Utils::TEX_CUBE;
9883 break;
9884 case 6:
9885 m_test_case = Utils::TEX_1D;
9886 break;
9887 case 7:
9888 m_test_case = Utils::TEX_1D_ARRAY;
9889 break;
9890 default:
9891 return false;
9892 }
9893
9894 m_context.getTestContext().getLog() << tcu::TestLog::Message
9895 << "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
9896 << tcu::TestLog::EndMessage;
9897
9898 return true;
9899 }
9900
9901 /** Prepare source for given shader stage
9902 *
9903 * @param in_stage Shader stage, compute shader will use 430
9904 * @param in_use_version_400 Select if 400 or 420 should be used
9905 * @param out_source Prepared shader source instance
9906 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)9907 void BindingSamplersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
9908 Utils::shaderSource& out_source)
9909 {
9910 static const GLchar* uni_goku = "layout(binding = 0) uniform TYPE goku;\n";
9911
9912 static const GLchar* uni_vegeta = "layout(binding = 1) uniform TYPE vegeta;\n";
9913
9914 static const GLchar* uni_trunks = "layout(binding = 3) uniform TYPE trunks;\n\n";
9915
9916 static const GLchar* verification_snippet = " TEX_COORD_TYPE tex_coord = TEX_COORD_TYPE(COORDINATES);\n"
9917 " vec4 goku_color = SAMPLING_FUNCTION(goku, tex_coord);\n"
9918 " vec4 vegeta_color = SAMPLING_FUNCTION(vegeta, tex_coord);\n"
9919 " vec4 trunks_color = SAMPLING_FUNCTION(trunks, tex_coord);\n"
9920 "\n"
9921 " if ((vec4(1, 0, 0, 0) != goku_color) ||\n"
9922 " (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
9923 " (vec4(0, 0, 1, 0) != trunks_color) )\n"
9924 " {\n"
9925 " result = vec4(1, 0, 0, 1);\n"
9926 " }\n";
9927
9928 static const GLchar* compute_shader_template =
9929 "VERSION\n"
9930 "\n"
9931 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9932 "\n"
9933 "writeonly uniform image2D uni_image;\n"
9934 "\n"
9935 "UNI_GOKU\n"
9936 "UNI_VEGETA\n"
9937 "UNI_TRUNKS\n"
9938 "\n"
9939 "void main()\n"
9940 "{\n"
9941 " vec4 result = vec4(0, 1, 0, 1);\n"
9942 "\n"
9943 "VERIFICATION"
9944 "\n"
9945 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9946 "}\n"
9947 "\n";
9948
9949 static const GLchar* fragment_shader_template = "VERSION\n"
9950 "\n"
9951 "in vec4 gs_fs_result;\n"
9952 "out vec4 fs_out_result;\n"
9953 "\n"
9954 "UNI_GOKU\n"
9955 "UNI_VEGETA\n"
9956 "UNI_TRUNKS\n"
9957 "\n"
9958 "void main()\n"
9959 "{\n"
9960 " vec4 result = vec4(0, 1, 0, 1);\n"
9961 "\n"
9962 "VERIFICATION"
9963 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
9964 " {\n"
9965 " result = vec4(1, 0, 0, 1);\n"
9966 " }\n"
9967 "\n"
9968 " fs_out_result = result;\n"
9969 "}\n"
9970 "\n";
9971
9972 static const GLchar* geometry_shader_template = "VERSION\n"
9973 "\n"
9974 "layout(points) in;\n"
9975 "layout(triangle_strip, max_vertices = 4) out;\n"
9976 "\n"
9977 "in vec4 tes_gs_result[];\n"
9978 "out vec4 gs_fs_result;\n"
9979 "\n"
9980 "UNI_TRUNKS\n"
9981 "UNI_GOKU\n"
9982 "UNI_VEGETA\n"
9983 "\n"
9984 "void main()\n"
9985 "{\n"
9986 " vec4 result = vec4(0, 1, 0, 1);\n"
9987 "\n"
9988 "VERIFICATION"
9989 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
9990 " {\n"
9991 " result = vec4(1, 0, 0, 1);\n"
9992 " }\n"
9993 "\n"
9994 " gs_fs_result = result;\n"
9995 " gl_Position = vec4(-1, -1, 0, 1);\n"
9996 " EmitVertex();\n"
9997 " gs_fs_result = result;\n"
9998 " gl_Position = vec4(-1, 1, 0, 1);\n"
9999 " EmitVertex();\n"
10000 " gs_fs_result = result;\n"
10001 " gl_Position = vec4(1, -1, 0, 1);\n"
10002 " EmitVertex();\n"
10003 " gs_fs_result = result;\n"
10004 " gl_Position = vec4(1, 1, 0, 1);\n"
10005 " EmitVertex();\n"
10006 "}\n"
10007 "\n";
10008
10009 static const GLchar* tess_ctrl_shader_template =
10010 "VERSION\n"
10011 "\n"
10012 "layout(vertices = 1) out;\n"
10013 "\n"
10014 "in vec4 vs_tcs_result[];\n"
10015 "out vec4 tcs_tes_result[];\n"
10016 "\n"
10017 "UNI_VEGETA\n"
10018 "UNI_TRUNKS\n"
10019 "UNI_GOKU\n"
10020 "\n"
10021 "void main()\n"
10022 "{\n"
10023 " vec4 result = vec4(0, 1, 0, 1);\n"
10024 "\n"
10025 "VERIFICATION"
10026 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10027 " {\n"
10028 " result = vec4(1, 0, 0, 1);\n"
10029 " }\n"
10030 "\n"
10031 " tcs_tes_result[gl_InvocationID] = result;\n"
10032 "\n"
10033 " gl_TessLevelOuter[0] = 1.0;\n"
10034 " gl_TessLevelOuter[1] = 1.0;\n"
10035 " gl_TessLevelOuter[2] = 1.0;\n"
10036 " gl_TessLevelOuter[3] = 1.0;\n"
10037 " gl_TessLevelInner[0] = 1.0;\n"
10038 " gl_TessLevelInner[1] = 1.0;\n"
10039 "}\n"
10040 "\n";
10041
10042 static const GLchar* tess_eval_shader_template = "VERSION\n"
10043 "\n"
10044 "layout(isolines, point_mode) in;\n"
10045 "\n"
10046 "in vec4 tcs_tes_result[];\n"
10047 "out vec4 tes_gs_result;\n"
10048 "\n"
10049 "UNI_GOKU\n"
10050 "UNI_TRUNKS\n"
10051 "UNI_VEGETA\n"
10052 "\n"
10053 "void main()\n"
10054 "{\n"
10055 " vec4 result = vec4(0, 1, 0, 1);\n"
10056 "\n"
10057 "VERIFICATION"
10058 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10059 " {\n"
10060 " result = vec4(1, 0, 0, 1);\n"
10061 " }\n"
10062 "\n"
10063 " tes_gs_result = result;\n"
10064 "}\n"
10065 "\n";
10066
10067 static const GLchar* vertex_shader_template = "VERSION\n"
10068 "\n"
10069 "out vec4 vs_tcs_result;\n"
10070 "\n"
10071 "UNI_TRUNKS\n"
10072 "UNI_VEGETA\n"
10073 "UNI_GOKU\n"
10074 "\n"
10075 "void main()\n"
10076 "{\n"
10077 " vec4 result = vec4(0, 1, 0, 1);\n"
10078 "\n"
10079 "VERIFICATION"
10080 "\n"
10081 " vs_tcs_result = result;\n"
10082 "}\n"
10083 "\n";
10084
10085 const Utils::TYPES base_tex_coord_type = (Utils::TEX_BUFFER == m_test_case) ? Utils::INT : Utils::FLOAT;
10086 const GLchar* coordinates = 0;
10087 GLuint n_coordinates = Utils::getNumberOfCoordinates(m_test_case);
10088 const GLchar* shader_template = 0;
10089 const GLchar* sampler_type = Utils::getSamplerType(m_test_case);
10090 const GLchar* sampling_function = (Utils::TEX_BUFFER == m_test_case) ? "texelFetch" : "texture";
10091 const GLchar* tex_coord_type = Utils::getTypeName(base_tex_coord_type, 1 /* n_columns */, n_coordinates);
10092
10093 switch (in_stage)
10094 {
10095 case Utils::COMPUTE_SHADER:
10096 shader_template = compute_shader_template;
10097 break;
10098 case Utils::FRAGMENT_SHADER:
10099 shader_template = fragment_shader_template;
10100 break;
10101 case Utils::GEOMETRY_SHADER:
10102 shader_template = geometry_shader_template;
10103 break;
10104 case Utils::TESS_CTRL_SHADER:
10105 shader_template = tess_ctrl_shader_template;
10106 break;
10107 case Utils::TESS_EVAL_SHADER:
10108 shader_template = tess_eval_shader_template;
10109 break;
10110 case Utils::VERTEX_SHADER:
10111 shader_template = vertex_shader_template;
10112 break;
10113 default:
10114 TCU_FAIL("Invalid enum");
10115 }
10116
10117 switch (n_coordinates)
10118 {
10119 case 1:
10120 coordinates = "0";
10121 break;
10122 case 2:
10123 coordinates = "0, 0";
10124 break;
10125 case 3:
10126 coordinates = "0, 0, 0";
10127 break;
10128 case 4:
10129 coordinates = "0, 0, 0, 0";
10130 break;
10131 }
10132
10133 out_source.m_parts[0].m_code = shader_template;
10134
10135 size_t position = 0;
10136
10137 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10138 out_source.m_parts[0].m_code);
10139
10140 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10141
10142 position -= strlen(verification_snippet);
10143
10144 Utils::replaceToken("COORDINATES", position, coordinates, out_source.m_parts[0].m_code);
10145
10146 Utils::replaceAllTokens("SAMPLING_FUNCTION", sampling_function, out_source.m_parts[0].m_code);
10147
10148 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10149
10150 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
10151
10152 Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
10153
10154 Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
10155
10156 Utils::replaceAllTokens("TYPE", sampler_type, out_source.m_parts[0].m_code);
10157 }
10158
10159 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10160 *
10161 * @param program Current program
10162 **/
prepareUniforms(Utils::program & program)10163 void BindingSamplersTest::prepareUniforms(Utils::program& program)
10164 {
10165 (void)program;
10166 static const GLuint goku_data = 0x000000ff;
10167 static const GLuint vegeta_data = 0x0000ff00;
10168 static const GLuint trunks_data = 0x00ff0000;
10169
10170 prepareTexture(m_goku_texture, m_test_case, goku_data);
10171 prepareTexture(m_vegeta_texture, m_test_case, vegeta_data);
10172 prepareTexture(m_trunks_texture, m_test_case, trunks_data);
10173
10174 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10175
10176 gl.activeTexture(GL_TEXTURE0);
10177 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10178
10179 m_goku_texture.bind();
10180
10181 gl.activeTexture(GL_TEXTURE1);
10182 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10183
10184 m_vegeta_texture.bind();
10185
10186 gl.activeTexture(GL_TEXTURE3);
10187 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10188
10189 m_trunks_texture.bind();
10190 }
10191
10192 /** Overwrite of releaseResource method, release extra buffer and texture
10193 *
10194 * @param ignored
10195 **/
releaseResource()10196 void BindingSamplersTest::releaseResource()
10197 {
10198 m_goku_texture.release();
10199 m_vegeta_texture.release();
10200 m_trunks_texture.release();
10201 m_buffer.release();
10202 }
10203
10204 /** Prepare texture of given type filled with given color
10205 *
10206 * @param texture Texture
10207 * @param texture_type Type of texture
10208 * @param color Color
10209 **/
prepareTexture(Utils::texture & texture,Utils::TEXTURE_TYPES texture_type,glw::GLuint color)10210 void BindingSamplersTest::prepareTexture(Utils::texture& texture, Utils::TEXTURE_TYPES texture_type, glw::GLuint color)
10211 {
10212 (void)texture_type;
10213 static const GLuint width = 16;
10214 static const GLuint height = 16;
10215 static const GLuint depth = 1;
10216
10217 std::vector<GLuint> texture_data;
10218 texture_data.resize(width * height);
10219
10220 for (GLuint i = 0; i < texture_data.size(); ++i)
10221 {
10222 texture_data[i] = color;
10223 }
10224
10225 if (Utils::TEX_BUFFER != m_test_case)
10226 {
10227 texture.create(width, height, depth, GL_RGBA8, m_test_case);
10228
10229 texture.update(width, height, depth, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10230 }
10231 else
10232 {
10233 m_buffer.generate(GL_TEXTURE_BUFFER);
10234 m_buffer.update(texture_data.size(), &texture_data[0], GL_STATIC_DRAW);
10235
10236 texture.createBuffer(GL_RGBA8, m_buffer.m_id);
10237 }
10238 }
10239
10240 /** Constructor
10241 *
10242 * @param context Test context
10243 **/
BindingSamplerSingleTest(deqp::Context & context)10244 BindingSamplerSingleTest::BindingSamplerSingleTest(deqp::Context& context)
10245 : GLSLTestBase(context, "binding_sampler_single", "Test verifies sampler binding"), m_goku_texture(context)
10246 {
10247 /* Nothing to be done here */
10248 }
10249
10250 /** Set up next test case
10251 *
10252 * @param test_case_index Index of next test case
10253 *
10254 * @return false if there is no more test cases, true otherwise
10255 **/
prepareNextTestCase(glw::GLuint test_case_index)10256 bool BindingSamplerSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
10257 {
10258 switch (test_case_index)
10259 {
10260 case (glw::GLuint)-1:
10261 case 0:
10262 m_test_stage = Utils::VERTEX_SHADER;
10263 break;
10264 case 1:
10265 m_test_stage = Utils::TESS_CTRL_SHADER;
10266 break;
10267 case 2:
10268 m_test_stage = Utils::TESS_EVAL_SHADER;
10269 break;
10270 case 3:
10271 m_test_stage = Utils::GEOMETRY_SHADER;
10272 break;
10273 case 4:
10274 m_test_stage = Utils::FRAGMENT_SHADER;
10275 break;
10276 default:
10277 return false;
10278 }
10279
10280 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
10281 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
10282 << tcu::TestLog::EndMessage;
10283
10284 return true;
10285 }
10286
10287 /** Prepare source for given shader stage
10288 *
10289 * @param in_stage Shader stage, compute shader will use 430
10290 * @param in_use_version_400 Select if 400 or 420 should be used
10291 * @param out_source Prepared shader source instance
10292 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10293 void BindingSamplerSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10294 Utils::shaderSource& out_source)
10295 {
10296 static const GLchar* uni_goku_with_binding = "layout(binding = 2) uniform sampler2D goku;\n";
10297
10298 static const GLchar* uni_goku_no_binding = "uniform sampler2D goku;\n";
10299
10300 static const GLchar* verification_snippet = " vec4 goku_color = texture(goku, vec2(0,0));\n"
10301 "\n"
10302 " if (vec4(1, 0, 0, 0) != goku_color)\n"
10303 " {\n"
10304 " result = vec4(1, 0, 0, 1);\n"
10305 " }\n";
10306
10307 static const GLchar* compute_shader_template =
10308 "VERSION\n"
10309 "\n"
10310 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10311 "\n"
10312 "writeonly uniform image2D uni_image;\n"
10313 "\n"
10314 "UNI_GOKU\n"
10315 "\n"
10316 "void main()\n"
10317 "{\n"
10318 " vec4 result = vec4(0, 1, 0, 1);\n"
10319 "\n"
10320 "VERIFICATION"
10321 "\n"
10322 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10323 "}\n"
10324 "\n";
10325
10326 static const GLchar* fragment_shader_template = "VERSION\n"
10327 "\n"
10328 "in vec4 gs_fs_result;\n"
10329 "out vec4 fs_out_result;\n"
10330 "\n"
10331 "UNI_GOKU\n"
10332 "\n"
10333 "void main()\n"
10334 "{\n"
10335 " vec4 result = vec4(0, 1, 0, 1);\n"
10336 "\n"
10337 "VERIFICATION"
10338 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10339 " {\n"
10340 " result = vec4(1, 0, 0, 1);\n"
10341 " }\n"
10342 "\n"
10343 " fs_out_result = result;\n"
10344 "}\n"
10345 "\n";
10346
10347 static const GLchar* geometry_shader_template = "VERSION\n"
10348 "\n"
10349 "layout(points) in;\n"
10350 "layout(triangle_strip, max_vertices = 4) out;\n"
10351 "\n"
10352 "in vec4 tes_gs_result[];\n"
10353 "out vec4 gs_fs_result;\n"
10354 "\n"
10355 "UNI_GOKU\n"
10356 "\n"
10357 "void main()\n"
10358 "{\n"
10359 " vec4 result = vec4(0, 1, 0, 1);\n"
10360 "\n"
10361 "VERIFICATION"
10362 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10363 " {\n"
10364 " result = vec4(1, 0, 0, 1);\n"
10365 " }\n"
10366 "\n"
10367 " gs_fs_result = result;\n"
10368 " gl_Position = vec4(-1, -1, 0, 1);\n"
10369 " EmitVertex();\n"
10370 " gs_fs_result = result;\n"
10371 " gl_Position = vec4(-1, 1, 0, 1);\n"
10372 " EmitVertex();\n"
10373 " gs_fs_result = result;\n"
10374 " gl_Position = vec4(1, -1, 0, 1);\n"
10375 " EmitVertex();\n"
10376 " gs_fs_result = result;\n"
10377 " gl_Position = vec4(1, 1, 0, 1);\n"
10378 " EmitVertex();\n"
10379 "}\n"
10380 "\n";
10381
10382 static const GLchar* tess_ctrl_shader_template =
10383 "VERSION\n"
10384 "\n"
10385 "layout(vertices = 1) out;\n"
10386 "\n"
10387 "in vec4 vs_tcs_result[];\n"
10388 "out vec4 tcs_tes_result[];\n"
10389 "\n"
10390 "UNI_GOKU\n"
10391 "\n"
10392 "void main()\n"
10393 "{\n"
10394 " vec4 result = vec4(0, 1, 0, 1);\n"
10395 "\n"
10396 "VERIFICATION"
10397 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10398 " {\n"
10399 " result = vec4(1, 0, 0, 1);\n"
10400 " }\n"
10401 "\n"
10402 " tcs_tes_result[gl_InvocationID] = result;\n"
10403 "\n"
10404 " gl_TessLevelOuter[0] = 1.0;\n"
10405 " gl_TessLevelOuter[1] = 1.0;\n"
10406 " gl_TessLevelOuter[2] = 1.0;\n"
10407 " gl_TessLevelOuter[3] = 1.0;\n"
10408 " gl_TessLevelInner[0] = 1.0;\n"
10409 " gl_TessLevelInner[1] = 1.0;\n"
10410 "}\n"
10411 "\n";
10412
10413 static const GLchar* tess_eval_shader_template = "VERSION\n"
10414 "\n"
10415 "layout(isolines, point_mode) in;\n"
10416 "\n"
10417 "in vec4 tcs_tes_result[];\n"
10418 "out vec4 tes_gs_result;\n"
10419 "\n"
10420 "UNI_GOKU\n"
10421 "\n"
10422 "void main()\n"
10423 "{\n"
10424 " vec4 result = vec4(0, 1, 0, 1);\n"
10425 "\n"
10426 "VERIFICATION"
10427 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10428 " {\n"
10429 " result = vec4(1, 0, 0, 1);\n"
10430 " }\n"
10431 "\n"
10432 " tes_gs_result = result;\n"
10433 "}\n"
10434 "\n";
10435
10436 static const GLchar* vertex_shader_template = "VERSION\n"
10437 "\n"
10438 "out vec4 vs_tcs_result;\n"
10439 "\n"
10440 "UNI_GOKU\n"
10441 "\n"
10442 "void main()\n"
10443 "{\n"
10444 " vec4 result = vec4(0, 1, 0, 1);\n"
10445 "\n"
10446 "VERIFICATION"
10447 "\n"
10448 " vs_tcs_result = result;\n"
10449 "}\n"
10450 "\n";
10451
10452 const GLchar* shader_template = 0;
10453 const GLchar* uniform_definition = uni_goku_no_binding;
10454
10455 switch (in_stage)
10456 {
10457 case Utils::COMPUTE_SHADER:
10458 shader_template = compute_shader_template;
10459 uniform_definition = uni_goku_with_binding;
10460 break;
10461 case Utils::FRAGMENT_SHADER:
10462 shader_template = fragment_shader_template;
10463 break;
10464 case Utils::GEOMETRY_SHADER:
10465 shader_template = geometry_shader_template;
10466 break;
10467 case Utils::TESS_CTRL_SHADER:
10468 shader_template = tess_ctrl_shader_template;
10469 break;
10470 case Utils::TESS_EVAL_SHADER:
10471 shader_template = tess_eval_shader_template;
10472 break;
10473 case Utils::VERTEX_SHADER:
10474 shader_template = vertex_shader_template;
10475 break;
10476 default:
10477 TCU_FAIL("Invalid enum");
10478 }
10479
10480 if (in_stage == m_test_stage)
10481 {
10482 uniform_definition = uni_goku_with_binding;
10483 }
10484
10485 out_source.m_parts[0].m_code = shader_template;
10486
10487 size_t position = 0;
10488
10489 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10490 out_source.m_parts[0].m_code);
10491
10492 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10493
10494 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
10495 }
10496
10497 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10498 *
10499 * @param program Current program
10500 **/
prepareUniforms(Utils::program & program)10501 void BindingSamplerSingleTest::prepareUniforms(Utils::program& program)
10502 {
10503 (void)program;
10504 static const GLuint goku_data = 0x000000ff;
10505
10506 m_goku_texture.create(16, 16, GL_RGBA8);
10507
10508 std::vector<GLuint> texture_data;
10509 texture_data.resize(16 * 16);
10510
10511 for (GLuint i = 0; i < texture_data.size(); ++i)
10512 {
10513 texture_data[i] = goku_data;
10514 }
10515
10516 m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10517
10518 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10519
10520 gl.activeTexture(GL_TEXTURE2);
10521 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10522
10523 m_goku_texture.bind();
10524 }
10525
10526 /** Overwrite of releaseResource method, release extra texture
10527 *
10528 * @param ignored
10529 **/
releaseResource()10530 void BindingSamplerSingleTest::releaseResource()
10531 {
10532 m_goku_texture.release();
10533 }
10534
10535 /** Constructor
10536 *
10537 * @param context Test context
10538 **/
BindingSamplerArrayTest(deqp::Context & context)10539 BindingSamplerArrayTest::BindingSamplerArrayTest(deqp::Context& context)
10540 : GLSLTestBase(context, "binding_sampler_array", "Test verifies binding of sampler arrays")
10541 , m_goku_00_texture(context)
10542 , m_goku_01_texture(context)
10543 , m_goku_02_texture(context)
10544 , m_goku_03_texture(context)
10545 , m_goku_04_texture(context)
10546 , m_goku_05_texture(context)
10547 , m_goku_06_texture(context)
10548 {
10549 /* Nothing to be done here */
10550 }
10551
10552 /** Prepare source for given shader stage
10553 *
10554 * @param in_stage Shader stage, compute shader will use 430
10555 * @param in_use_version_400 Select if 400 or 420 should be used
10556 * @param out_source Prepared shader source instance
10557 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10558 void BindingSamplerArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10559 Utils::shaderSource& out_source)
10560 {
10561 static const GLchar* uni_goku = "layout(binding = 1) uniform sampler2D goku[7];\n";
10562
10563 static const GLchar* verification_snippet = " vec4 color[7];\n"
10564 "\n"
10565 " for (uint i = 0u; i < 7; ++i)\n"
10566 " {\n"
10567 " color[i] = texture(goku[i], vec2(0, 0));\n"
10568 " }\n"
10569 "\n"
10570 " if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
10571 " (vec4(0, 0, 0, 1) != color[1]) ||\n"
10572 " (vec4(0, 0, 1, 0) != color[2]) ||\n"
10573 " (vec4(0, 0, 1, 1) != color[3]) ||\n"
10574 " (vec4(0, 1, 0, 0) != color[4]) ||\n"
10575 " (vec4(0, 1, 0, 1) != color[5]) ||\n"
10576 " (vec4(0, 1, 1, 0) != color[6]) )\n"
10577 " {\n"
10578 " result = vec4(1, 0, 0, 1);\n"
10579 " }\n";
10580
10581 static const GLchar* compute_shader_template =
10582 "VERSION\n"
10583 "\n"
10584 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10585 "\n"
10586 "writeonly uniform image2D uni_image;\n"
10587 "\n"
10588 "UNI_GOKU\n"
10589 "\n"
10590 "void main()\n"
10591 "{\n"
10592 " vec4 result = vec4(0, 1, 0, 1);\n"
10593 "\n"
10594 "VERIFICATION"
10595 "\n"
10596 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10597 "}\n"
10598 "\n";
10599
10600 static const GLchar* fragment_shader_template = "VERSION\n"
10601 "\n"
10602 "in vec4 gs_fs_result;\n"
10603 "out vec4 fs_out_result;\n"
10604 "\n"
10605 "UNI_GOKU\n"
10606 "\n"
10607 "void main()\n"
10608 "{\n"
10609 " vec4 result = vec4(0, 1, 0, 1);\n"
10610 "\n"
10611 "VERIFICATION"
10612 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10613 " {\n"
10614 " result = vec4(1, 0, 0, 1);\n"
10615 " }\n"
10616 "\n"
10617 " fs_out_result = result;\n"
10618 "}\n"
10619 "\n";
10620
10621 static const GLchar* geometry_shader_template = "VERSION\n"
10622 "\n"
10623 "layout(points) in;\n"
10624 "layout(triangle_strip, max_vertices = 4) out;\n"
10625 "\n"
10626 "in vec4 tes_gs_result[];\n"
10627 "out vec4 gs_fs_result;\n"
10628 "\n"
10629 "UNI_GOKU\n"
10630 "\n"
10631 "void main()\n"
10632 "{\n"
10633 " vec4 result = vec4(0, 1, 0, 1);\n"
10634 "\n"
10635 "VERIFICATION"
10636 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10637 " {\n"
10638 " result = vec4(1, 0, 0, 1);\n"
10639 " }\n"
10640 "\n"
10641 " gs_fs_result = result;\n"
10642 " gl_Position = vec4(-1, -1, 0, 1);\n"
10643 " EmitVertex();\n"
10644 " gs_fs_result = result;\n"
10645 " gl_Position = vec4(-1, 1, 0, 1);\n"
10646 " EmitVertex();\n"
10647 " gs_fs_result = result;\n"
10648 " gl_Position = vec4(1, -1, 0, 1);\n"
10649 " EmitVertex();\n"
10650 " gs_fs_result = result;\n"
10651 " gl_Position = vec4(1, 1, 0, 1);\n"
10652 " EmitVertex();\n"
10653 "}\n"
10654 "\n";
10655
10656 static const GLchar* tess_ctrl_shader_template =
10657 "VERSION\n"
10658 "\n"
10659 "layout(vertices = 1) out;\n"
10660 "\n"
10661 "in vec4 vs_tcs_result[];\n"
10662 "out vec4 tcs_tes_result[];\n"
10663 "\n"
10664 "UNI_GOKU\n"
10665 "\n"
10666 "void main()\n"
10667 "{\n"
10668 " vec4 result = vec4(0, 1, 0, 1);\n"
10669 "\n"
10670 "VERIFICATION"
10671 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10672 " {\n"
10673 " result = vec4(1, 0, 0, 1);\n"
10674 " }\n"
10675 "\n"
10676 " tcs_tes_result[gl_InvocationID] = result;\n"
10677 "\n"
10678 " gl_TessLevelOuter[0] = 1.0;\n"
10679 " gl_TessLevelOuter[1] = 1.0;\n"
10680 " gl_TessLevelOuter[2] = 1.0;\n"
10681 " gl_TessLevelOuter[3] = 1.0;\n"
10682 " gl_TessLevelInner[0] = 1.0;\n"
10683 " gl_TessLevelInner[1] = 1.0;\n"
10684 "}\n"
10685 "\n";
10686
10687 static const GLchar* tess_eval_shader_template = "VERSION\n"
10688 "\n"
10689 "layout(isolines, point_mode) in;\n"
10690 "\n"
10691 "in vec4 tcs_tes_result[];\n"
10692 "out vec4 tes_gs_result;\n"
10693 "\n"
10694 "UNI_GOKU\n"
10695 "\n"
10696 "void main()\n"
10697 "{\n"
10698 " vec4 result = vec4(0, 1, 0, 1);\n"
10699 "\n"
10700 "VERIFICATION"
10701 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10702 " {\n"
10703 " result = vec4(1, 0, 0, 1);\n"
10704 " }\n"
10705 "\n"
10706 " tes_gs_result = result;\n"
10707 "}\n"
10708 "\n";
10709
10710 static const GLchar* vertex_shader_template = "VERSION\n"
10711 "\n"
10712 "out vec4 vs_tcs_result;\n"
10713 "\n"
10714 "UNI_GOKU\n"
10715 "\n"
10716 "void main()\n"
10717 "{\n"
10718 " vec4 result = vec4(0, 1, 0, 1);\n"
10719 "\n"
10720 "VERIFICATION"
10721 "\n"
10722 " vs_tcs_result = result;\n"
10723 "}\n"
10724 "\n";
10725
10726 const GLchar* shader_template = 0;
10727
10728 switch (in_stage)
10729 {
10730 case Utils::COMPUTE_SHADER:
10731 shader_template = compute_shader_template;
10732 break;
10733 case Utils::FRAGMENT_SHADER:
10734 shader_template = fragment_shader_template;
10735 break;
10736 case Utils::GEOMETRY_SHADER:
10737 shader_template = geometry_shader_template;
10738 break;
10739 case Utils::TESS_CTRL_SHADER:
10740 shader_template = tess_ctrl_shader_template;
10741 break;
10742 case Utils::TESS_EVAL_SHADER:
10743 shader_template = tess_eval_shader_template;
10744 break;
10745 case Utils::VERTEX_SHADER:
10746 shader_template = vertex_shader_template;
10747 break;
10748 default:
10749 TCU_FAIL("Invalid enum");
10750 }
10751
10752 out_source.m_parts[0].m_code = shader_template;
10753
10754 size_t position = 0;
10755
10756 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
10757 out_source.m_parts[0].m_code);
10758
10759 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
10760
10761 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
10762 }
10763
10764 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
10765 *
10766 * @param program Current program
10767 **/
prepareUniforms(Utils::program & program)10768 void BindingSamplerArrayTest::prepareUniforms(Utils::program& program)
10769 {
10770 static const GLuint goku_data[7] = {
10771 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
10772 };
10773
10774 static const GLuint binding_offset = 1;
10775
10776 Utils::texture* textures[7] = {
10777 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10778 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10779 };
10780
10781 std::vector<GLuint> texture_data;
10782 texture_data.resize(16 * 16);
10783
10784 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
10785
10786 for (GLuint i = 0; i < 7; ++i)
10787 {
10788 GLint expected_binding = i + binding_offset;
10789
10790 checkBinding(program, i, expected_binding);
10791
10792 gl.activeTexture(GL_TEXTURE0 + expected_binding);
10793 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
10794
10795 textures[i]->create(16, 16, GL_RGBA8);
10796
10797 for (GLuint j = 0; j < texture_data.size(); ++j)
10798 {
10799 texture_data[j] = goku_data[i];
10800 }
10801
10802 textures[i]->update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
10803 }
10804 }
10805
10806 /** Overwrite of releaseResource method, release extra textures
10807 *
10808 * @param ignored
10809 **/
releaseResource()10810 void BindingSamplerArrayTest::releaseResource()
10811 {
10812 Utils::texture* textures[7] = {
10813 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
10814 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
10815 };
10816
10817 for (GLuint i = 0; i < 7; ++i)
10818 {
10819 textures[i]->release();
10820 }
10821 }
10822
10823 /** Verifies that API reports correct uniform binding
10824 *
10825 * @param program Program
10826 * @param index Index of array element
10827 * @param expected_binding Expected binding
10828 **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)10829 void BindingSamplerArrayTest::checkBinding(Utils::program& program, GLuint index, GLint expected_binding)
10830 {
10831 if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
10832 {
10833 TCU_FAIL("Wrong binding reported by API");
10834 }
10835 }
10836
10837 /** Constructor
10838 *
10839 * @param context Test context
10840 **/
BindingSamplerDefaultTest(deqp::Context & context)10841 BindingSamplerDefaultTest::BindingSamplerDefaultTest(deqp::Context& context)
10842 : APITestBase(context, "binding_sampler_default", "Test verifies default sampler binding")
10843 {
10844 /* Nothing to be done here */
10845 }
10846
10847 /** Execute API call and verifies results
10848 *
10849 * @return true when results are positive, false otherwise
10850 **/
checkResults(Utils::program & program)10851 bool BindingSamplerDefaultTest::checkResults(Utils::program& program)
10852 {
10853 return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
10854 }
10855
10856 /** Prepare source for given shader stage
10857 *
10858 * @param in_stage Shader stage, compute shader will use 430
10859 * @param in_use_version_400 Select if 400 or 420 should be used
10860 * @param out_source Prepared shader source instance
10861 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)10862 void BindingSamplerDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
10863 Utils::shaderSource& out_source)
10864 {
10865 static const GLchar* uni_goku = "uniform sampler2D goku;\n";
10866
10867 static const GLchar* verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
10868 " if (vec4(1, 0, 0, 0) != color)\n"
10869 " {\n"
10870 " result = vec4(1, 0, 0, 1);\n"
10871 " }\n";
10872
10873 static const GLchar* compute_shader_template =
10874 "VERSION\n"
10875 "\n"
10876 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10877 "\n"
10878 "writeonly uniform image2D uni_image;\n"
10879 "\n"
10880 "UNI_GOKU\n"
10881 "\n"
10882 "void main()\n"
10883 "{\n"
10884 " vec4 result = vec4(0, 1, 0, 1);\n"
10885 "\n"
10886 "VERIFICATION"
10887 "\n"
10888 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10889 "}\n"
10890 "\n";
10891
10892 static const GLchar* fragment_shader_template = "VERSION\n"
10893 "\n"
10894 "in vec4 gs_fs_result;\n"
10895 "out vec4 fs_out_result;\n"
10896 "\n"
10897 "UNI_GOKU\n"
10898 "\n"
10899 "void main()\n"
10900 "{\n"
10901 " vec4 result = vec4(0, 1, 0, 1);\n"
10902 "\n"
10903 "VERIFICATION"
10904 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
10905 " {\n"
10906 " result = vec4(1, 0, 0, 1);\n"
10907 " }\n"
10908 "\n"
10909 " fs_out_result = result;\n"
10910 "}\n"
10911 "\n";
10912
10913 static const GLchar* geometry_shader_template = "VERSION\n"
10914 "\n"
10915 "layout(points) in;\n"
10916 "layout(triangle_strip, max_vertices = 4) out;\n"
10917 "\n"
10918 "in vec4 tes_gs_result[];\n"
10919 "out vec4 gs_fs_result;\n"
10920 "\n"
10921 "UNI_GOKU\n"
10922 "\n"
10923 "void main()\n"
10924 "{\n"
10925 " vec4 result = vec4(0, 1, 0, 1);\n"
10926 "\n"
10927 "VERIFICATION"
10928 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
10929 " {\n"
10930 " result = vec4(1, 0, 0, 1);\n"
10931 " }\n"
10932 "\n"
10933 " gs_fs_result = result;\n"
10934 " gl_Position = vec4(-1, -1, 0, 1);\n"
10935 " EmitVertex();\n"
10936 " gs_fs_result = result;\n"
10937 " gl_Position = vec4(-1, 1, 0, 1);\n"
10938 " EmitVertex();\n"
10939 " gs_fs_result = result;\n"
10940 " gl_Position = vec4(1, -1, 0, 1);\n"
10941 " EmitVertex();\n"
10942 " gs_fs_result = result;\n"
10943 " gl_Position = vec4(1, 1, 0, 1);\n"
10944 " EmitVertex();\n"
10945 "}\n"
10946 "\n";
10947
10948 static const GLchar* tess_ctrl_shader_template =
10949 "VERSION\n"
10950 "\n"
10951 "layout(vertices = 1) out;\n"
10952 "\n"
10953 "in vec4 vs_tcs_result[];\n"
10954 "out vec4 tcs_tes_result[];\n"
10955 "\n"
10956 "UNI_GOKU\n"
10957 "\n"
10958 "void main()\n"
10959 "{\n"
10960 " vec4 result = vec4(0, 1, 0, 1);\n"
10961 "\n"
10962 "VERIFICATION"
10963 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
10964 " {\n"
10965 " result = vec4(1, 0, 0, 1);\n"
10966 " }\n"
10967 "\n"
10968 " tcs_tes_result[gl_InvocationID] = result;\n"
10969 "\n"
10970 " gl_TessLevelOuter[0] = 1.0;\n"
10971 " gl_TessLevelOuter[1] = 1.0;\n"
10972 " gl_TessLevelOuter[2] = 1.0;\n"
10973 " gl_TessLevelOuter[3] = 1.0;\n"
10974 " gl_TessLevelInner[0] = 1.0;\n"
10975 " gl_TessLevelInner[1] = 1.0;\n"
10976 "}\n"
10977 "\n";
10978
10979 static const GLchar* tess_eval_shader_template = "VERSION\n"
10980 "\n"
10981 "layout(isolines, point_mode) in;\n"
10982 "\n"
10983 "in vec4 tcs_tes_result[];\n"
10984 "out vec4 tes_gs_result;\n"
10985 "\n"
10986 "UNI_GOKU\n"
10987 "\n"
10988 "void main()\n"
10989 "{\n"
10990 " vec4 result = vec4(0, 1, 0, 1);\n"
10991 "\n"
10992 "VERIFICATION"
10993 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
10994 " {\n"
10995 " result = vec4(1, 0, 0, 1);\n"
10996 " }\n"
10997 "\n"
10998 " tes_gs_result = result;\n"
10999 "}\n"
11000 "\n";
11001
11002 static const GLchar* vertex_shader_template = "VERSION\n"
11003 "\n"
11004 "out vec4 vs_tcs_result;\n"
11005 "\n"
11006 "UNI_GOKU\n"
11007 "\n"
11008 "void main()\n"
11009 "{\n"
11010 " vec4 result = vec4(0, 1, 0, 1);\n"
11011 "\n"
11012 "VERIFICATION"
11013 "\n"
11014 " vs_tcs_result = result;\n"
11015 "}\n"
11016 "\n";
11017
11018 const GLchar* shader_template = 0;
11019
11020 switch (in_stage)
11021 {
11022 case Utils::COMPUTE_SHADER:
11023 shader_template = compute_shader_template;
11024 break;
11025 case Utils::FRAGMENT_SHADER:
11026 shader_template = fragment_shader_template;
11027 break;
11028 case Utils::GEOMETRY_SHADER:
11029 shader_template = geometry_shader_template;
11030 break;
11031 case Utils::TESS_CTRL_SHADER:
11032 shader_template = tess_ctrl_shader_template;
11033 break;
11034 case Utils::TESS_EVAL_SHADER:
11035 shader_template = tess_eval_shader_template;
11036 break;
11037 case Utils::VERTEX_SHADER:
11038 shader_template = vertex_shader_template;
11039 break;
11040 default:
11041 TCU_FAIL("Invalid enum");
11042 }
11043
11044 out_source.m_parts[0].m_code = shader_template;
11045
11046 size_t position = 0;
11047
11048 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11049 out_source.m_parts[0].m_code);
11050
11051 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11052
11053 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11054 }
11055
11056 /** Constructor
11057 *
11058 * @param context Test context
11059 **/
BindingSamplerAPIOverrideTest(deqp::Context & context)11060 BindingSamplerAPIOverrideTest::BindingSamplerAPIOverrideTest(deqp::Context& context)
11061 : GLSLTestBase(context, "binding_sampler_api_override", "Verifies that API can override sampler binding")
11062 , m_goku_texture(context)
11063 {
11064 /* Nothing to be done here */
11065 }
11066
11067 /** Prepare source for given shader stage
11068 *
11069 * @param in_stage Shader stage, compute shader will use 430
11070 * @param in_use_version_400 Select if 400 or 420 should be used
11071 * @param out_source Prepared shader source instance
11072 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11073 void BindingSamplerAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11074 Utils::shaderSource& out_source)
11075 {
11076 static const GLchar* uni_goku = "layout(binding = 2) uniform sampler2D goku;\n";
11077
11078 static const GLchar* verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
11079 " if (vec4(1, 0, 0, 0) != color)\n"
11080 " {\n"
11081 " result = vec4(1, 0, 0, 1);\n"
11082 " }\n";
11083
11084 static const GLchar* compute_shader_template =
11085 "VERSION\n"
11086 "\n"
11087 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11088 "\n"
11089 "writeonly uniform image2D uni_image;\n"
11090 "\n"
11091 "UNI_GOKU\n"
11092 "\n"
11093 "void main()\n"
11094 "{\n"
11095 " vec4 result = vec4(0, 1, 0, 1);\n"
11096 "\n"
11097 "VERIFICATION"
11098 "\n"
11099 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11100 "}\n"
11101 "\n";
11102
11103 static const GLchar* fragment_shader_template = "VERSION\n"
11104 "\n"
11105 "in vec4 gs_fs_result;\n"
11106 "out vec4 fs_out_result;\n"
11107 "\n"
11108 "UNI_GOKU\n"
11109 "\n"
11110 "void main()\n"
11111 "{\n"
11112 " vec4 result = vec4(0, 1, 0, 1);\n"
11113 "\n"
11114 "VERIFICATION"
11115 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11116 " {\n"
11117 " result = vec4(1, 0, 0, 1);\n"
11118 " }\n"
11119 "\n"
11120 " fs_out_result = result;\n"
11121 "}\n"
11122 "\n";
11123
11124 static const GLchar* geometry_shader_template = "VERSION\n"
11125 "\n"
11126 "layout(points) in;\n"
11127 "layout(triangle_strip, max_vertices = 4) out;\n"
11128 "\n"
11129 "in vec4 tes_gs_result[];\n"
11130 "out vec4 gs_fs_result;\n"
11131 "\n"
11132 "UNI_GOKU\n"
11133 "\n"
11134 "void main()\n"
11135 "{\n"
11136 " vec4 result = vec4(0, 1, 0, 1);\n"
11137 "\n"
11138 "VERIFICATION"
11139 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11140 " {\n"
11141 " result = vec4(1, 0, 0, 1);\n"
11142 " }\n"
11143 "\n"
11144 " gs_fs_result = result;\n"
11145 " gl_Position = vec4(-1, -1, 0, 1);\n"
11146 " EmitVertex();\n"
11147 " gs_fs_result = result;\n"
11148 " gl_Position = vec4(-1, 1, 0, 1);\n"
11149 " EmitVertex();\n"
11150 " gs_fs_result = result;\n"
11151 " gl_Position = vec4(1, -1, 0, 1);\n"
11152 " EmitVertex();\n"
11153 " gs_fs_result = result;\n"
11154 " gl_Position = vec4(1, 1, 0, 1);\n"
11155 " EmitVertex();\n"
11156 "}\n"
11157 "\n";
11158
11159 static const GLchar* tess_ctrl_shader_template =
11160 "VERSION\n"
11161 "\n"
11162 "layout(vertices = 1) out;\n"
11163 "\n"
11164 "in vec4 vs_tcs_result[];\n"
11165 "out vec4 tcs_tes_result[];\n"
11166 "\n"
11167 "UNI_GOKU\n"
11168 "\n"
11169 "void main()\n"
11170 "{\n"
11171 " vec4 result = vec4(0, 1, 0, 1);\n"
11172 "\n"
11173 "VERIFICATION"
11174 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11175 " {\n"
11176 " result = vec4(1, 0, 0, 1);\n"
11177 " }\n"
11178 "\n"
11179 " tcs_tes_result[gl_InvocationID] = result;\n"
11180 "\n"
11181 " gl_TessLevelOuter[0] = 1.0;\n"
11182 " gl_TessLevelOuter[1] = 1.0;\n"
11183 " gl_TessLevelOuter[2] = 1.0;\n"
11184 " gl_TessLevelOuter[3] = 1.0;\n"
11185 " gl_TessLevelInner[0] = 1.0;\n"
11186 " gl_TessLevelInner[1] = 1.0;\n"
11187 "}\n"
11188 "\n";
11189
11190 static const GLchar* tess_eval_shader_template = "VERSION\n"
11191 "\n"
11192 "layout(isolines, point_mode) in;\n"
11193 "\n"
11194 "in vec4 tcs_tes_result[];\n"
11195 "out vec4 tes_gs_result;\n"
11196 "\n"
11197 "UNI_GOKU\n"
11198 "\n"
11199 "void main()\n"
11200 "{\n"
11201 " vec4 result = vec4(0, 1, 0, 1);\n"
11202 "\n"
11203 "VERIFICATION"
11204 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11205 " {\n"
11206 " result = vec4(1, 0, 0, 1);\n"
11207 " }\n"
11208 "\n"
11209 " tes_gs_result = result;\n"
11210 "}\n"
11211 "\n";
11212
11213 static const GLchar* vertex_shader_template = "VERSION\n"
11214 "\n"
11215 "out vec4 vs_tcs_result;\n"
11216 "\n"
11217 "UNI_GOKU\n"
11218 "\n"
11219 "void main()\n"
11220 "{\n"
11221 " vec4 result = vec4(0, 1, 0, 1);\n"
11222 "\n"
11223 "VERIFICATION"
11224 "\n"
11225 " vs_tcs_result = result;\n"
11226 "}\n"
11227 "\n";
11228
11229 const GLchar* shader_template = 0;
11230
11231 switch (in_stage)
11232 {
11233 case Utils::COMPUTE_SHADER:
11234 shader_template = compute_shader_template;
11235 break;
11236 case Utils::FRAGMENT_SHADER:
11237 shader_template = fragment_shader_template;
11238 break;
11239 case Utils::GEOMETRY_SHADER:
11240 shader_template = geometry_shader_template;
11241 break;
11242 case Utils::TESS_CTRL_SHADER:
11243 shader_template = tess_ctrl_shader_template;
11244 break;
11245 case Utils::TESS_EVAL_SHADER:
11246 shader_template = tess_eval_shader_template;
11247 break;
11248 case Utils::VERTEX_SHADER:
11249 shader_template = vertex_shader_template;
11250 break;
11251 default:
11252 TCU_FAIL("Invalid enum");
11253 }
11254
11255 out_source.m_parts[0].m_code = shader_template;
11256
11257 size_t position = 0;
11258
11259 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11260 out_source.m_parts[0].m_code);
11261
11262 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11263
11264 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11265 }
11266
11267 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11268 *
11269 * @param program Current program
11270 **/
prepareUniforms(Utils::program & program)11271 void BindingSamplerAPIOverrideTest::prepareUniforms(Utils::program& program)
11272 {
11273 static const GLuint goku_data = 0x000000ff;
11274 static const GLint new_binding = 11;
11275
11276 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
11277
11278 const GLint uniform_location = program.getUniformLocation("goku");
11279 if (-1 == uniform_location)
11280 {
11281 TCU_FAIL("Uniform is inactive");
11282 }
11283
11284 gl.uniform1i(uniform_location, new_binding);
11285
11286 GLint binding = -1;
11287
11288 gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
11289 GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
11290
11291 if (new_binding != binding)
11292 {
11293 TCU_FAIL("Wrong binding value");
11294 return;
11295 }
11296
11297 m_goku_texture.create(16, 16, GL_RGBA8);
11298
11299 std::vector<GLuint> texture_data;
11300 texture_data.resize(16 * 16);
11301
11302 for (GLuint i = 0; i < texture_data.size(); ++i)
11303 {
11304 texture_data[i] = goku_data;
11305 }
11306
11307 m_goku_texture.update(16, 16, 0 /* depth */, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
11308
11309 gl.activeTexture(GL_TEXTURE11);
11310 GLU_EXPECT_NO_ERROR(gl.getError(), "ActiveTexture");
11311
11312 m_goku_texture.bind();
11313 }
11314
11315 /** Overwrite of releaseResource method, release extra texture
11316 *
11317 * @param ignored
11318 **/
releaseResource()11319 void BindingSamplerAPIOverrideTest::releaseResource()
11320 {
11321 m_goku_texture.release();
11322 }
11323
11324 /** Constructor
11325 *
11326 * @param context Test context
11327 **/
BindingSamplerInvalidTest(deqp::Context & context)11328 BindingSamplerInvalidTest::BindingSamplerInvalidTest(deqp::Context& context)
11329 : NegativeTestBase(context, "binding_sampler_invalid", "Test verifies invalid binding values")
11330 {
11331 /* Nothing to be done here */
11332 }
11333
11334 /** Set up next test case
11335 *
11336 * @param test_case_index Index of next test case
11337 *
11338 * @return false if there is no more test cases, true otherwise
11339 **/
prepareNextTestCase(glw::GLuint test_case_index)11340 bool BindingSamplerInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
11341 {
11342 switch (test_case_index)
11343 {
11344 case (glw::GLuint)-1:
11345 m_case = TEST_CASES_MAX;
11346 break;
11347 case NEGATIVE_VALUE:
11348 case VARIABLE_NAME:
11349 case STD140:
11350 case MISSING:
11351 m_case = (TESTCASES)test_case_index;
11352 break;
11353 default:
11354 return false;
11355 }
11356
11357 return true;
11358 }
11359
11360 /** Prepare source for given shader stage
11361 *
11362 * @param in_stage Shader stage, compute shader will use 430
11363 * @param in_use_version_400 Select if 400 or 420 should be used
11364 * @param out_source Prepared shader source instance
11365 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11366 void BindingSamplerInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11367 Utils::shaderSource& out_source)
11368 {
11369 static const GLchar* uni_goku = "layout(binding BINDING) uniform sampler2D goku;\n";
11370
11371 static const GLchar* verification_snippet = " vec4 color = texture(goku, vec2(0,0));\n"
11372 " if (vec4(1, 0, 0, 0) != color)\n"
11373 " {\n"
11374 " result = vec4(1, 0, 0, 1);\n"
11375 " }\n";
11376
11377 static const GLchar* compute_shader_template =
11378 "VERSION\n"
11379 "\n"
11380 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11381 "\n"
11382 "writeonly uniform image2D uni_image;\n"
11383 "\n"
11384 "UNI_GOKU\n"
11385 "\n"
11386 "void main()\n"
11387 "{\n"
11388 " vec4 result = vec4(0, 1, 0, 1);\n"
11389 "\n"
11390 "VERIFICATION"
11391 "\n"
11392 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11393 "}\n"
11394 "\n";
11395
11396 static const GLchar* fragment_shader_template = "VERSION\n"
11397 "\n"
11398 "in vec4 gs_fs_result;\n"
11399 "out vec4 fs_out_result;\n"
11400 "\n"
11401 "UNI_GOKU\n"
11402 "\n"
11403 "void main()\n"
11404 "{\n"
11405 " vec4 result = vec4(0, 1, 0, 1);\n"
11406 "\n"
11407 "VERIFICATION"
11408 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11409 " {\n"
11410 " result = vec4(1, 0, 0, 1);\n"
11411 " }\n"
11412 "\n"
11413 " fs_out_result = result;\n"
11414 "}\n"
11415 "\n";
11416
11417 static const GLchar* geometry_shader_template = "VERSION\n"
11418 "\n"
11419 "layout(points) in;\n"
11420 "layout(triangle_strip, max_vertices = 4) out;\n"
11421 "\n"
11422 "in vec4 tes_gs_result[];\n"
11423 "out vec4 gs_fs_result;\n"
11424 "\n"
11425 "UNI_GOKU\n"
11426 "\n"
11427 "void main()\n"
11428 "{\n"
11429 " vec4 result = vec4(0, 1, 0, 1);\n"
11430 "\n"
11431 "VERIFICATION"
11432 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11433 " {\n"
11434 " result = vec4(1, 0, 0, 1);\n"
11435 " }\n"
11436 "\n"
11437 " gs_fs_result = result;\n"
11438 " gl_Position = vec4(-1, -1, 0, 1);\n"
11439 " EmitVertex();\n"
11440 " gs_fs_result = result;\n"
11441 " gl_Position = vec4(-1, 1, 0, 1);\n"
11442 " EmitVertex();\n"
11443 " gs_fs_result = result;\n"
11444 " gl_Position = vec4(1, -1, 0, 1);\n"
11445 " EmitVertex();\n"
11446 " gs_fs_result = result;\n"
11447 " gl_Position = vec4(1, 1, 0, 1);\n"
11448 " EmitVertex();\n"
11449 "}\n"
11450 "\n";
11451
11452 static const GLchar* tess_ctrl_shader_template =
11453 "VERSION\n"
11454 "\n"
11455 "layout(vertices = 1) out;\n"
11456 "\n"
11457 "in vec4 vs_tcs_result[];\n"
11458 "out vec4 tcs_tes_result[];\n"
11459 "\n"
11460 "UNI_GOKU\n"
11461 "\n"
11462 "void main()\n"
11463 "{\n"
11464 " vec4 result = vec4(0, 1, 0, 1);\n"
11465 "\n"
11466 "VERIFICATION"
11467 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11468 " {\n"
11469 " result = vec4(1, 0, 0, 1);\n"
11470 " }\n"
11471 "\n"
11472 " tcs_tes_result[gl_InvocationID] = result;\n"
11473 "\n"
11474 " gl_TessLevelOuter[0] = 1.0;\n"
11475 " gl_TessLevelOuter[1] = 1.0;\n"
11476 " gl_TessLevelOuter[2] = 1.0;\n"
11477 " gl_TessLevelOuter[3] = 1.0;\n"
11478 " gl_TessLevelInner[0] = 1.0;\n"
11479 " gl_TessLevelInner[1] = 1.0;\n"
11480 "}\n"
11481 "\n";
11482
11483 static const GLchar* tess_eval_shader_template = "VERSION\n"
11484 "\n"
11485 "layout(isolines, point_mode) in;\n"
11486 "\n"
11487 "in vec4 tcs_tes_result[];\n"
11488 "out vec4 tes_gs_result;\n"
11489 "\n"
11490 "UNI_GOKU\n"
11491 "\n"
11492 "void main()\n"
11493 "{\n"
11494 " vec4 result = vec4(0, 1, 0, 1);\n"
11495 "\n"
11496 "VERIFICATION"
11497 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11498 " {\n"
11499 " result = vec4(1, 0, 0, 1);\n"
11500 " }\n"
11501 "\n"
11502 " tes_gs_result = result;\n"
11503 "}\n"
11504 "\n";
11505
11506 static const GLchar* vertex_shader_template = "VERSION\n"
11507 "\n"
11508 "out vec4 vs_tcs_result;\n"
11509 "\n"
11510 "UNI_GOKU\n"
11511 "\n"
11512 "void main()\n"
11513 "{\n"
11514 " vec4 result = vec4(0, 1, 0, 1);\n"
11515 "\n"
11516 "VERIFICATION"
11517 "\n"
11518 " vs_tcs_result = result;\n"
11519 "}\n"
11520 "\n";
11521
11522 const GLchar* shader_template = 0;
11523
11524 switch (in_stage)
11525 {
11526 case Utils::COMPUTE_SHADER:
11527 shader_template = compute_shader_template;
11528 break;
11529 case Utils::FRAGMENT_SHADER:
11530 shader_template = fragment_shader_template;
11531 break;
11532 case Utils::GEOMETRY_SHADER:
11533 shader_template = geometry_shader_template;
11534 break;
11535 case Utils::TESS_CTRL_SHADER:
11536 shader_template = tess_ctrl_shader_template;
11537 break;
11538 case Utils::TESS_EVAL_SHADER:
11539 shader_template = tess_eval_shader_template;
11540 break;
11541 case Utils::VERTEX_SHADER:
11542 shader_template = vertex_shader_template;
11543 break;
11544 default:
11545 TCU_FAIL("Invalid enum");
11546 }
11547
11548 out_source.m_parts[0].m_code = shader_template;
11549
11550 size_t position = 0;
11551
11552 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11553 out_source.m_parts[0].m_code);
11554
11555 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11556
11557 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11558
11559 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
11560 }
11561
getCaseString(TESTCASES test_case)11562 const GLchar* BindingSamplerInvalidTest::getCaseString(TESTCASES test_case)
11563 {
11564 (void)test_case;
11565 const GLchar* binding = 0;
11566
11567 switch (m_case)
11568 {
11569 case NEGATIVE_VALUE:
11570 binding = "= -1";
11571 break;
11572 case VARIABLE_NAME:
11573 binding = "= goku";
11574 break;
11575 case STD140:
11576 binding = "= std140";
11577 break;
11578 case MISSING:
11579 binding = "";
11580 break;
11581 case TEST_CASES_MAX:
11582 binding = "= 0";
11583 break;
11584 default:
11585 TCU_FAIL("Invalid enum");
11586 }
11587
11588 return binding;
11589 }
11590
11591 /* Constants used by BindingImagesTest */
11592 const GLuint BindingImagesTest::m_goku_data = 0x000000ff;
11593 const GLuint BindingImagesTest::m_vegeta_data = 0x0000ff00;
11594 const GLuint BindingImagesTest::m_trunks_data = 0x00ff0000;
11595
11596 /** Constructor
11597 *
11598 * @param context Test context
11599 **/
BindingImagesTest(deqp::Context & context)11600 BindingImagesTest::BindingImagesTest(deqp::Context& context)
11601 : BindingImageTest(context, "binding_images", "Test verifies binding of images")
11602 , m_goku_texture(context)
11603 , m_vegeta_texture(context)
11604 , m_trunks_texture(context)
11605 , m_goku_buffer(context)
11606 , m_vegeta_buffer(context)
11607 , m_trunks_buffer(context)
11608 {
11609 /* Nothing to be done here */
11610 }
11611
11612 /** Set up next test case
11613 *
11614 * @param test_case_index Index of next test case
11615 *
11616 * @return false if there is no more test cases, true otherwise
11617 **/
prepareNextTestCase(glw::GLuint test_case_index)11618 bool BindingImagesTest::prepareNextTestCase(glw::GLuint test_case_index)
11619 {
11620 switch (test_case_index)
11621 {
11622 case (glw::GLuint)-1:
11623 case 0:
11624 m_test_case = Utils::TEX_2D;
11625 break;
11626 case 1:
11627 m_test_case = Utils::TEX_BUFFER;
11628 break;
11629 case 2:
11630 m_test_case = Utils::TEX_2D_RECT;
11631 break;
11632 case 3:
11633 m_test_case = Utils::TEX_2D_ARRAY;
11634 break;
11635 case 4:
11636 m_test_case = Utils::TEX_3D;
11637 break;
11638 case 5:
11639 m_test_case = Utils::TEX_CUBE;
11640 break;
11641 case 6:
11642 m_test_case = Utils::TEX_1D;
11643 break;
11644 case 7:
11645 m_test_case = Utils::TEX_1D_ARRAY;
11646 break;
11647 default:
11648 return false;
11649 }
11650
11651 m_context.getTestContext().getLog() << tcu::TestLog::Message
11652 << "Tested texture type: " << Utils::getTextureTypeName(m_test_case)
11653 << tcu::TestLog::EndMessage;
11654
11655 return true;
11656 }
11657
11658 /** Prepare source for given shader stage
11659 *
11660 * @param in_stage Shader stage, compute shader will use 430
11661 * @param in_use_version_400 Select if 400 or 420 should be used
11662 * @param out_source Prepared shader source instance
11663 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)11664 void BindingImagesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
11665 Utils::shaderSource& out_source)
11666 {
11667 static const GLchar* uni_goku = "layout(binding = 1, rgba8) uniform TYPE goku;\n";
11668
11669 static const GLchar* uni_vegeta = "layout(binding = 2, rgba8) uniform TYPE vegeta;\n";
11670
11671 static const GLchar* uni_trunks = "layout(binding = 4, rgba8) uniform TYPE trunks;\n\n";
11672
11673 static const GLchar* verification_snippet = " TEX_COORD_TYPE tex_coord_read = TEX_COORD_TYPE(COORDINATES);\n"
11674 " TEX_COORD_TYPE tex_coord_write = TEX_COORD_TYPE(COORDINATES);\n"
11675 " vec4 goku_color = imageLoad(goku, tex_coord_read);\n"
11676 " vec4 vegeta_color = imageLoad(vegeta, tex_coord_read);\n"
11677 " vec4 trunks_color = imageLoad(trunks, tex_coord_read);\n"
11678 "\n"
11679 " imageStore(goku, tex_coord_write, vec4(0, 1, 0, 1));\n"
11680 " imageStore(vegeta, tex_coord_write, vec4(0, 1, 0, 1));\n"
11681 " imageStore(trunks, tex_coord_write, vec4(0, 1, 0, 1));\n"
11682 "\n"
11683 " if ((vec4(1, 0, 0, 0) != goku_color) ||\n"
11684 " (vec4(0, 1, 0, 0) != vegeta_color) ||\n"
11685 " (vec4(0, 0, 1, 0) != trunks_color) )\n"
11686 " {\n"
11687 " result = goku_color;\n"
11688 " //result = vec4(1, 0, 0, 1);\n"
11689 " }\n";
11690
11691 static const GLchar* compute_shader_template =
11692 "VERSION\n"
11693 "#extension GL_ARB_shader_image_load_store : enable\n"
11694 "\n"
11695 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11696 "\n"
11697 "writeonly uniform image2D uni_image;\n"
11698 "\n"
11699 "UNI_GOKU\n"
11700 "UNI_VEGETA\n"
11701 "UNI_TRUNKS\n"
11702 "\n"
11703 "void main()\n"
11704 "{\n"
11705 " vec4 result = vec4(0, 1, 0, 1);\n"
11706 "\n"
11707 " if(gl_GlobalInvocationID.xy == vec2(0, 0)) {\n"
11708 "VERIFICATION"
11709 " }\n"
11710 "\n"
11711 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11712 "}\n"
11713 "\n";
11714
11715 static const GLchar* fragment_shader_template = "VERSION\n"
11716 "#extension GL_ARB_shader_image_load_store : enable\n"
11717 "\n"
11718 "in vec4 gs_fs_result;\n"
11719 "out vec4 fs_out_result;\n"
11720 "\n"
11721 "UNI_GOKU\n"
11722 "UNI_VEGETA\n"
11723 "UNI_TRUNKS\n"
11724 "\n"
11725 "void main()\n"
11726 "{\n"
11727 " vec4 result = vec4(0, 1, 0, 1);\n"
11728 "\n"
11729 "VERIFICATION"
11730 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
11731 " {\n"
11732 " result = vec4(1, 0, 0, 1);\n"
11733 " }\n"
11734 "\n"
11735 " fs_out_result = result;\n"
11736 "}\n"
11737 "\n";
11738
11739 static const GLchar* geometry_shader_template = "VERSION\n"
11740 "#extension GL_ARB_shader_image_load_store : enable\n"
11741 "\n"
11742 "layout(points) in;\n"
11743 "layout(triangle_strip, max_vertices = 4) out;\n"
11744 "\n"
11745 "in vec4 tes_gs_result[];\n"
11746 "out vec4 gs_fs_result;\n"
11747 "\n"
11748 "#if IMAGES\n"
11749 "UNI_TRUNKS\n"
11750 "UNI_GOKU\n"
11751 "UNI_VEGETA\n"
11752 "#endif\n"
11753 "\n"
11754 "void main()\n"
11755 "{\n"
11756 " vec4 result = vec4(0, 1, 0, 1);\n"
11757 "\n"
11758 "#if IMAGES\n"
11759 "VERIFICATION else\n"
11760 "#endif\n"
11761 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
11762 " {\n"
11763 " result = vec4(1, 0, 0, 1);\n"
11764 " }\n"
11765 "\n"
11766 " gs_fs_result = result;\n"
11767 " gl_Position = vec4(-1, -1, 0, 1);\n"
11768 " EmitVertex();\n"
11769 " gs_fs_result = result;\n"
11770 " gl_Position = vec4(-1, 1, 0, 1);\n"
11771 " EmitVertex();\n"
11772 " gs_fs_result = result;\n"
11773 " gl_Position = vec4(1, -1, 0, 1);\n"
11774 " EmitVertex();\n"
11775 " gs_fs_result = result;\n"
11776 " gl_Position = vec4(1, 1, 0, 1);\n"
11777 " EmitVertex();\n"
11778 "}\n"
11779 "\n";
11780
11781 static const GLchar* tess_ctrl_shader_template =
11782 "VERSION\n"
11783 "#extension GL_ARB_shader_image_load_store : enable\n"
11784 "\n"
11785 "layout(vertices = 1) out;\n"
11786 "\n"
11787 "in vec4 vs_tcs_result[];\n"
11788 "out vec4 tcs_tes_result[];\n"
11789 "\n"
11790 "#if IMAGES\n"
11791 "UNI_VEGETA\n"
11792 "UNI_TRUNKS\n"
11793 "UNI_GOKU\n"
11794 "#endif\n"
11795 "\n"
11796 "void main()\n"
11797 "{\n"
11798 " vec4 result = vec4(0, 1, 0, 1);\n"
11799 "\n"
11800 "#if IMAGES\n"
11801 "VERIFICATION else\n"
11802 "#endif\n"
11803 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
11804 " {\n"
11805 " result = vec4(1, 0, 0, 1);\n"
11806 " }\n"
11807 "\n"
11808 " tcs_tes_result[gl_InvocationID] = result;\n"
11809 "\n"
11810 " gl_TessLevelOuter[0] = 1.0;\n"
11811 " gl_TessLevelOuter[1] = 1.0;\n"
11812 " gl_TessLevelOuter[2] = 1.0;\n"
11813 " gl_TessLevelOuter[3] = 1.0;\n"
11814 " gl_TessLevelInner[0] = 1.0;\n"
11815 " gl_TessLevelInner[1] = 1.0;\n"
11816 "}\n"
11817 "\n";
11818
11819 static const GLchar* tess_eval_shader_template = "VERSION\n"
11820 "#extension GL_ARB_shader_image_load_store : enable\n"
11821 "\n"
11822 "layout(isolines, point_mode) in;\n"
11823 "\n"
11824 "in vec4 tcs_tes_result[];\n"
11825 "out vec4 tes_gs_result;\n"
11826 "\n"
11827 "#if IMAGES\n"
11828 "UNI_GOKU\n"
11829 "UNI_TRUNKS\n"
11830 "UNI_VEGETA\n"
11831 "#endif\n"
11832 "\n"
11833 "void main()\n"
11834 "{\n"
11835 " vec4 result = vec4(0, 1, 0, 1);\n"
11836 "\n"
11837 "#if IMAGES\n"
11838 "VERIFICATION else\n"
11839 "#endif\n"
11840 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
11841 " {\n"
11842 " result = vec4(1, 0, 0, 1);\n"
11843 " }\n"
11844 "\n"
11845 " tes_gs_result = result;\n"
11846 "}\n"
11847 "\n";
11848
11849 static const GLchar* vertex_shader_template = "VERSION\n"
11850 "#extension GL_ARB_shader_image_load_store : enable\n"
11851 "\n"
11852 "out vec4 vs_tcs_result;\n"
11853 "\n"
11854 "#if IMAGES\n"
11855 "UNI_TRUNKS\n"
11856 "UNI_VEGETA\n"
11857 "UNI_GOKU\n"
11858 "#endif\n"
11859 "\n"
11860 "void main()\n"
11861 "{\n"
11862 " vec4 result = vec4(0, 1, 0, 1);\n"
11863 "\n"
11864 "#if IMAGES\n"
11865 "VERIFICATION"
11866 "#endif\n"
11867 "\n"
11868 " vs_tcs_result = result;\n"
11869 "}\n"
11870 "\n";
11871
11872 const GLchar* coordinates_read = 0;
11873 const GLchar* coordinates_write = 0;
11874 const GLchar* image_type = Utils::getImageType(m_test_case);
11875 GLuint n_coordinates = Utils::getNumberOfCoordinates(m_test_case);
11876 const GLchar* shader_template = 0;
11877 const GLchar* tex_coord_type = Utils::getTypeName(Utils::INT, 1 /* n_columns */, n_coordinates);
11878
11879 switch (in_stage)
11880 {
11881 case Utils::COMPUTE_SHADER:
11882 shader_template = compute_shader_template;
11883 break;
11884 case Utils::FRAGMENT_SHADER:
11885 shader_template = fragment_shader_template;
11886 break;
11887 case Utils::GEOMETRY_SHADER:
11888 shader_template = geometry_shader_template;
11889 break;
11890 case Utils::TESS_CTRL_SHADER:
11891 shader_template = tess_ctrl_shader_template;
11892 break;
11893 case Utils::TESS_EVAL_SHADER:
11894 shader_template = tess_eval_shader_template;
11895 break;
11896 case Utils::VERTEX_SHADER:
11897 shader_template = vertex_shader_template;
11898 break;
11899 default:
11900 TCU_FAIL("Invalid enum");
11901 }
11902
11903 switch (n_coordinates)
11904 {
11905 case 1:
11906 coordinates_read = "1";
11907 coordinates_write = "0";
11908 break;
11909 case 2:
11910 coordinates_read = "1, 0";
11911 coordinates_write = "0, 0";
11912 break;
11913 case 3:
11914 coordinates_read = "1, 0, 0";
11915 coordinates_write = "0, 0, 0";
11916 break;
11917 case 4:
11918 coordinates_read = "1, 0, 0, 0";
11919 coordinates_write = "0, 0, 0, 0";
11920 break;
11921 }
11922
11923 out_source.m_parts[0].m_code = shader_template;
11924
11925 size_t position = 0;
11926
11927 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
11928 out_source.m_parts[0].m_code);
11929
11930 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
11931
11932 position -= strlen(verification_snippet);
11933
11934 Utils::replaceToken("COORDINATES", position, coordinates_read, out_source.m_parts[0].m_code);
11935
11936 Utils::replaceToken("COORDINATES", position, coordinates_write, out_source.m_parts[0].m_code);
11937
11938 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
11939 out_source.m_parts[0].m_code);
11940
11941 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
11942
11943 Utils::replaceAllTokens("UNI_VEGETA", uni_vegeta, out_source.m_parts[0].m_code);
11944
11945 Utils::replaceAllTokens("UNI_TRUNKS", uni_trunks, out_source.m_parts[0].m_code);
11946
11947 Utils::replaceAllTokens("TEX_COORD_TYPE", tex_coord_type, out_source.m_parts[0].m_code);
11948
11949 Utils::replaceAllTokens("TYPE", image_type, out_source.m_parts[0].m_code);
11950 }
11951
11952 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
11953 *
11954 * @param program Current program
11955 **/
prepareUniforms(Utils::program & program)11956 void BindingImagesTest::prepareUniforms(Utils::program& program)
11957 {
11958 (void)program;
11959 prepareBuffer(m_goku_buffer, m_goku_data);
11960 prepareBuffer(m_vegeta_buffer, m_vegeta_data);
11961 prepareBuffer(m_trunks_buffer, m_trunks_data);
11962
11963 prepareTexture(m_goku_texture, m_goku_buffer, m_test_case, m_goku_data, 1);
11964 prepareTexture(m_vegeta_texture, m_vegeta_buffer, m_test_case, m_vegeta_data, 2);
11965 prepareTexture(m_trunks_texture, m_trunks_buffer, m_test_case, m_trunks_data, 4);
11966 }
11967
11968 /** Overwrite of releaseResource method, release extra buffers and textures
11969 *
11970 * @param ignored
11971 **/
releaseResource()11972 void BindingImagesTest::releaseResource()
11973 {
11974 m_goku_texture.release();
11975 m_vegeta_texture.release();
11976 m_trunks_texture.release();
11977 if (m_test_case != Utils::TEX_BUFFER)
11978 {
11979 m_goku_buffer.release();
11980 m_vegeta_buffer.release();
11981 m_trunks_buffer.release();
11982 }
11983 }
11984
11985 /** Verify that all images have green texel at [0,0,0,0]
11986 *
11987 * @return true texel is green, false otherwise
11988 **/
verifyAdditionalResults() const11989 bool BindingImagesTest::verifyAdditionalResults() const
11990 {
11991 if (Utils::TEX_BUFFER != m_test_case)
11992 {
11993 return (verifyTexture(m_goku_texture) && verifyTexture(m_vegeta_texture) && verifyTexture(m_trunks_texture));
11994 }
11995 else
11996 {
11997 return (verifyBuffer(m_goku_buffer) && verifyBuffer(m_vegeta_buffer) && verifyBuffer(m_trunks_buffer));
11998 }
11999 }
12000
12001 /** Constructor
12002 *
12003 * @param context Test context
12004 **/
BindingImageSingleTest(deqp::Context & context)12005 BindingImageSingleTest::BindingImageSingleTest(deqp::Context& context)
12006 : BindingImageTest(context, "binding_image_single", "Test verifies single binding of image used in multiple stages")
12007 , m_goku_texture(context)
12008 {
12009 /* Nothing to be done here */
12010 }
12011
12012 /** Set up next test case
12013 *
12014 * @param test_case_index Index of next test case
12015 *
12016 * @return false if there is no more test cases, true otherwise
12017 **/
prepareNextTestCase(glw::GLuint test_case_index)12018 bool BindingImageSingleTest::prepareNextTestCase(glw::GLuint test_case_index)
12019 {
12020 switch (test_case_index)
12021 {
12022 case (glw::GLuint)-1:
12023 case 0:
12024 m_test_stage = Utils::VERTEX_SHADER;
12025 break;
12026 case 1:
12027 m_test_stage = Utils::TESS_CTRL_SHADER;
12028 break;
12029 case 2:
12030 m_test_stage = Utils::TESS_EVAL_SHADER;
12031 break;
12032 case 3:
12033 m_test_stage = Utils::GEOMETRY_SHADER;
12034 break;
12035 case 4:
12036 m_test_stage = Utils::FRAGMENT_SHADER;
12037 break;
12038 default:
12039 return false;
12040 }
12041
12042 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested stage: "
12043 << Utils::getShaderStageName((Utils::SHADER_STAGES)m_test_stage)
12044 << tcu::TestLog::EndMessage;
12045
12046 return true;
12047 }
12048
12049 /** Prepare source for given shader stage
12050 *
12051 * @param in_stage Shader stage, compute shader will use 430
12052 * @param in_use_version_400 Select if 400 or 420 should be used
12053 * @param out_source Prepared shader source instance
12054 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12055 void BindingImageSingleTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12056 Utils::shaderSource& out_source)
12057 {
12058 static const GLchar* uni_goku_with_binding = "layout(binding = 2, rgba8) uniform image2D goku;\n";
12059
12060 static const GLchar* uni_goku_no_binding = "layout(rgba8) uniform image2D goku;\n";
12061
12062 static const GLchar* verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,1));\n"
12063 "\n"
12064 " imageStore(goku, ivec2(0,0), vec4(0, 1, 0, 1));\n"
12065 "\n"
12066 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12067 " {\n"
12068 " result = vec4(1, 0, 0, 1);\n"
12069 " }\n";
12070
12071 static const GLchar* compute_shader_template =
12072 "VERSION\n"
12073 "#extension GL_ARB_shader_image_load_store : enable\n"
12074 "\n"
12075 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12076 "\n"
12077 "writeonly uniform image2D uni_image;\n"
12078 "\n"
12079 "UNI_GOKU\n"
12080 "\n"
12081 "void main()\n"
12082 "{\n"
12083 " vec4 result = vec4(0, 1, 0, 1);\n"
12084 "\n"
12085 "VERIFICATION"
12086 "\n"
12087 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12088 "}\n"
12089 "\n";
12090
12091 static const GLchar* fragment_shader_template = "VERSION\n"
12092 "#extension GL_ARB_shader_image_load_store : enable\n"
12093 "\n"
12094 "in vec4 gs_fs_result;\n"
12095 "out vec4 fs_out_result;\n"
12096 "\n"
12097 "UNI_GOKU\n"
12098 "\n"
12099 "void main()\n"
12100 "{\n"
12101 " vec4 result = vec4(0, 1, 0, 1);\n"
12102 "\n"
12103 "VERIFICATION"
12104 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12105 " {\n"
12106 " result = vec4(1, 0, 0, 1);\n"
12107 " }\n"
12108 "\n"
12109 " fs_out_result = result;\n"
12110 "}\n"
12111 "\n";
12112
12113 static const GLchar* geometry_shader_template = "VERSION\n"
12114 "#extension GL_ARB_shader_image_load_store : enable\n"
12115 "\n"
12116 "layout(points) in;\n"
12117 "layout(triangle_strip, max_vertices = 4) out;\n"
12118 "\n"
12119 "in vec4 tes_gs_result[];\n"
12120 "out vec4 gs_fs_result;\n"
12121 "\n"
12122 "#if IMAGES\n"
12123 "UNI_GOKU\n"
12124 "#endif\n"
12125 "\n"
12126 "void main()\n"
12127 "{\n"
12128 " vec4 result = vec4(0, 1, 0, 1);\n"
12129 "\n"
12130 "#if IMAGES\n"
12131 "VERIFICATION else\n"
12132 "#endif\n"
12133 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12134 " {\n"
12135 " result = vec4(1, 0, 0, 1);\n"
12136 " }\n"
12137 "\n"
12138 " gs_fs_result = result;\n"
12139 " gl_Position = vec4(-1, -1, 0, 1);\n"
12140 " EmitVertex();\n"
12141 " gs_fs_result = result;\n"
12142 " gl_Position = vec4(-1, 1, 0, 1);\n"
12143 " EmitVertex();\n"
12144 " gs_fs_result = result;\n"
12145 " gl_Position = vec4(1, -1, 0, 1);\n"
12146 " EmitVertex();\n"
12147 " gs_fs_result = result;\n"
12148 " gl_Position = vec4(1, 1, 0, 1);\n"
12149 " EmitVertex();\n"
12150 "}\n"
12151 "\n";
12152
12153 static const GLchar* tess_ctrl_shader_template =
12154 "VERSION\n"
12155 "#extension GL_ARB_shader_image_load_store : enable\n"
12156 "\n"
12157 "layout(vertices = 1) out;\n"
12158 "\n"
12159 "in vec4 vs_tcs_result[];\n"
12160 "out vec4 tcs_tes_result[];\n"
12161 "\n"
12162 "#if IMAGES\n"
12163 "UNI_GOKU\n"
12164 "#endif\n"
12165 "\n"
12166 "void main()\n"
12167 "{\n"
12168 " vec4 result = vec4(0, 1, 0, 1);\n"
12169 "\n"
12170 "#if IMAGES\n"
12171 "VERIFICATION else\n"
12172 "#endif\n"
12173 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12174 " {\n"
12175 " result = vec4(1, 0, 0, 1);\n"
12176 " }\n"
12177 "\n"
12178 " tcs_tes_result[gl_InvocationID] = result;\n"
12179 "\n"
12180 " gl_TessLevelOuter[0] = 1.0;\n"
12181 " gl_TessLevelOuter[1] = 1.0;\n"
12182 " gl_TessLevelOuter[2] = 1.0;\n"
12183 " gl_TessLevelOuter[3] = 1.0;\n"
12184 " gl_TessLevelInner[0] = 1.0;\n"
12185 " gl_TessLevelInner[1] = 1.0;\n"
12186 "}\n"
12187 "\n";
12188
12189 static const GLchar* tess_eval_shader_template = "VERSION\n"
12190 "#extension GL_ARB_shader_image_load_store : enable\n"
12191 "\n"
12192 "layout(isolines, point_mode) in;\n"
12193 "\n"
12194 "in vec4 tcs_tes_result[];\n"
12195 "out vec4 tes_gs_result;\n"
12196 "\n"
12197 "#if IMAGES\n"
12198 "UNI_GOKU\n"
12199 "#endif\n"
12200 "\n"
12201 "void main()\n"
12202 "{\n"
12203 " vec4 result = vec4(0, 1, 0, 1);\n"
12204 "\n"
12205 "#if IMAGES\n"
12206 "VERIFICATION else\n"
12207 "#endif\n"
12208 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12209 " {\n"
12210 " result = vec4(1, 0, 0, 1);\n"
12211 " }\n"
12212 "\n"
12213 " tes_gs_result = result;\n"
12214 "}\n"
12215 "\n";
12216
12217 static const GLchar* vertex_shader_template = "VERSION\n"
12218 "#extension GL_ARB_shader_image_load_store : enable\n"
12219 "\n"
12220 "out vec4 vs_tcs_result;\n"
12221 "\n"
12222 "#if IMAGES\n"
12223 "UNI_GOKU\n"
12224 "#endif\n"
12225 "\n"
12226 "void main()\n"
12227 "{\n"
12228 " vec4 result = vec4(0, 1, 0, 1);\n"
12229 "\n"
12230 "#if IMAGES\n"
12231 "VERIFICATION"
12232 "#endif\n"
12233 "\n"
12234 " vs_tcs_result = result;\n"
12235 "}\n"
12236 "\n";
12237
12238 const GLchar* shader_template = 0;
12239 const GLchar* uniform_definition = uni_goku_no_binding;
12240
12241 switch (in_stage)
12242 {
12243 case Utils::COMPUTE_SHADER:
12244 shader_template = compute_shader_template;
12245 uniform_definition = uni_goku_with_binding;
12246 break;
12247 case Utils::FRAGMENT_SHADER:
12248 shader_template = fragment_shader_template;
12249 /* We can't rely on the binding qualifier being present in m_test_stage
12250 * if images are unsupported in that stage.
12251 */
12252 if (maxImageUniforms(m_test_stage) == 0)
12253 uniform_definition = uni_goku_with_binding;
12254 break;
12255 case Utils::GEOMETRY_SHADER:
12256 shader_template = geometry_shader_template;
12257 break;
12258 case Utils::TESS_CTRL_SHADER:
12259 shader_template = tess_ctrl_shader_template;
12260 break;
12261 case Utils::TESS_EVAL_SHADER:
12262 shader_template = tess_eval_shader_template;
12263 break;
12264 case Utils::VERTEX_SHADER:
12265 shader_template = vertex_shader_template;
12266 break;
12267 default:
12268 TCU_FAIL("Invalid enum");
12269 }
12270
12271 if (in_stage == m_test_stage)
12272 {
12273 uniform_definition = uni_goku_with_binding;
12274 }
12275
12276 out_source.m_parts[0].m_code = shader_template;
12277
12278 size_t position = 0;
12279
12280 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12281 out_source.m_parts[0].m_code);
12282
12283 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12284
12285 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
12286 out_source.m_parts[0].m_code);
12287
12288 Utils::replaceAllTokens("UNI_GOKU", uniform_definition, out_source.m_parts[0].m_code);
12289 }
12290
12291 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12292 *
12293 * @param program Current program
12294 **/
prepareUniforms(Utils::program & program)12295 void BindingImageSingleTest::prepareUniforms(Utils::program& program)
12296 {
12297 (void)program;
12298 static const GLuint goku_data = 0x000000ff;
12299
12300 prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, 2 /* unit */);
12301 }
12302
12303 /** Overwrite of releaseResource method, release extra texture
12304 *
12305 * @param ignored
12306 **/
releaseResource()12307 void BindingImageSingleTest::releaseResource()
12308 {
12309 m_goku_texture.release();
12310 }
12311
12312 /** Verify that all images have green texel at [0,0,0,0]
12313 *
12314 * @return true texel is green, false otherwise
12315 **/
verifyAdditionalResults() const12316 bool BindingImageSingleTest::verifyAdditionalResults() const
12317 {
12318 return verifyTexture(m_goku_texture);
12319 }
12320
12321 /** Constructor
12322 *
12323 * @param context Test context
12324 **/
BindingImageArrayTest(deqp::Context & context)12325 BindingImageArrayTest::BindingImageArrayTest(deqp::Context& context)
12326 : BindingImageTest(context, "binding_image_array", "Test verifies binding of image array")
12327 , m_goku_00_texture(context)
12328 , m_goku_01_texture(context)
12329 , m_goku_02_texture(context)
12330 , m_goku_03_texture(context)
12331 , m_goku_04_texture(context)
12332 , m_goku_05_texture(context)
12333 , m_goku_06_texture(context)
12334 {
12335 /* Nothing to be done here */
12336 }
12337
12338 /** Prepare source for given shader stage
12339 *
12340 * @param in_stage Shader stage, compute shader will use 430
12341 * @param in_use_version_400 Select if 400 or 420 should be used
12342 * @param out_source Prepared shader source instance
12343 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12344 void BindingImageArrayTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12345 Utils::shaderSource& out_source)
12346 {
12347 static const GLchar* uni_goku = "layout(binding = 1, rgba8) uniform image2D goku[7];\n";
12348
12349 static const GLchar* verification_snippet = " vec4 color[7];\n"
12350 "\n"
12351 " for (uint i = 0u; i < 7; ++i)\n"
12352 " {\n"
12353 " color[i] = imageLoad(goku[i], ivec2(0,0));\n"
12354 " }\n"
12355 "\n"
12356 " if ((vec4(0, 0, 0, 0) != color[0]) ||\n"
12357 " (vec4(0, 0, 0, 1) != color[1]) ||\n"
12358 " (vec4(0, 0, 1, 0) != color[2]) ||\n"
12359 " (vec4(0, 0, 1, 1) != color[3]) ||\n"
12360 " (vec4(0, 1, 0, 0) != color[4]) ||\n"
12361 " (vec4(0, 1, 0, 1) != color[5]) ||\n"
12362 " (vec4(0, 1, 1, 0) != color[6]) )\n"
12363 " {\n"
12364 " result = vec4(1, 0, 0, 1);\n"
12365 " }\n";
12366
12367 static const GLchar* compute_shader_template =
12368 "VERSION\n"
12369 "#extension GL_ARB_shader_image_load_store : enable\n"
12370 "\n"
12371 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12372 "\n"
12373 "writeonly uniform image2D uni_image;\n"
12374 "\n"
12375 "UNI_GOKU\n"
12376 "\n"
12377 "void main()\n"
12378 "{\n"
12379 " vec4 result = vec4(0, 1, 0, 1);\n"
12380 "\n"
12381 "VERIFICATION"
12382 "\n"
12383 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12384 "}\n"
12385 "\n";
12386
12387 static const GLchar* fragment_shader_template = "VERSION\n"
12388 "#extension GL_ARB_shader_image_load_store : enable\n"
12389 "\n"
12390 "in vec4 gs_fs_result;\n"
12391 "out vec4 fs_out_result;\n"
12392 "\n"
12393 "UNI_GOKU\n"
12394 "\n"
12395 "void main()\n"
12396 "{\n"
12397 " vec4 result = vec4(0, 1, 0, 1);\n"
12398 "\n"
12399 "VERIFICATION"
12400 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12401 " {\n"
12402 " result = vec4(1, 0, 0, 1);\n"
12403 " }\n"
12404 "\n"
12405 " fs_out_result = result;\n"
12406 "}\n"
12407 "\n";
12408
12409 static const GLchar* geometry_shader_template = "VERSION\n"
12410 "#extension GL_ARB_shader_image_load_store : enable\n"
12411 "\n"
12412 "layout(points) in;\n"
12413 "layout(triangle_strip, max_vertices = 4) out;\n"
12414 "\n"
12415 "in vec4 tes_gs_result[];\n"
12416 "out vec4 gs_fs_result;\n"
12417 "\n"
12418 "#if IMAGES\n"
12419 "UNI_GOKU\n"
12420 "#endif\n"
12421 "\n"
12422 "void main()\n"
12423 "{\n"
12424 " vec4 result = vec4(0, 1, 0, 1);\n"
12425 "\n"
12426 "#if IMAGES\n"
12427 "VERIFICATION else\n"
12428 "#endif\n"
12429 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12430 " {\n"
12431 " result = vec4(1, 0, 0, 1);\n"
12432 " }\n"
12433 "\n"
12434 " gs_fs_result = result;\n"
12435 " gl_Position = vec4(-1, -1, 0, 1);\n"
12436 " EmitVertex();\n"
12437 " gs_fs_result = result;\n"
12438 " gl_Position = vec4(-1, 1, 0, 1);\n"
12439 " EmitVertex();\n"
12440 " gs_fs_result = result;\n"
12441 " gl_Position = vec4(1, -1, 0, 1);\n"
12442 " EmitVertex();\n"
12443 " gs_fs_result = result;\n"
12444 " gl_Position = vec4(1, 1, 0, 1);\n"
12445 " EmitVertex();\n"
12446 "}\n"
12447 "\n";
12448
12449 static const GLchar* tess_ctrl_shader_template =
12450 "VERSION\n"
12451 "#extension GL_ARB_shader_image_load_store : enable\n"
12452 "\n"
12453 "layout(vertices = 1) out;\n"
12454 "\n"
12455 "in vec4 vs_tcs_result[];\n"
12456 "out vec4 tcs_tes_result[];\n"
12457 "\n"
12458 "#if IMAGES\n"
12459 "UNI_GOKU\n"
12460 "#endif\n"
12461 "\n"
12462 "void main()\n"
12463 "{\n"
12464 " vec4 result = vec4(0, 1, 0, 1);\n"
12465 "\n"
12466 "#if IMAGES\n"
12467 "VERIFICATION else\n"
12468 "#endif\n"
12469 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12470 " {\n"
12471 " result = vec4(1, 0, 0, 1);\n"
12472 " }\n"
12473 "\n"
12474 " tcs_tes_result[gl_InvocationID] = result;\n"
12475 "\n"
12476 " gl_TessLevelOuter[0] = 1.0;\n"
12477 " gl_TessLevelOuter[1] = 1.0;\n"
12478 " gl_TessLevelOuter[2] = 1.0;\n"
12479 " gl_TessLevelOuter[3] = 1.0;\n"
12480 " gl_TessLevelInner[0] = 1.0;\n"
12481 " gl_TessLevelInner[1] = 1.0;\n"
12482 "}\n"
12483 "\n";
12484
12485 static const GLchar* tess_eval_shader_template = "VERSION\n"
12486 "#extension GL_ARB_shader_image_load_store : enable\n"
12487 "\n"
12488 "layout(isolines, point_mode) in;\n"
12489 "\n"
12490 "in vec4 tcs_tes_result[];\n"
12491 "out vec4 tes_gs_result;\n"
12492 "\n"
12493 "#if IMAGES\n"
12494 "UNI_GOKU\n"
12495 "#endif\n"
12496 "\n"
12497 "void main()\n"
12498 "{\n"
12499 " vec4 result = vec4(0, 1, 0, 1);\n"
12500 "\n"
12501 "#if IMAGES\n"
12502 "VERIFICATION else\n"
12503 "#endif\n"
12504 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
12505 " {\n"
12506 " result = vec4(1, 0, 0, 1);\n"
12507 " }\n"
12508 "\n"
12509 " tes_gs_result = result;\n"
12510 "}\n"
12511 "\n";
12512
12513 static const GLchar* vertex_shader_template = "VERSION\n"
12514 "#extension GL_ARB_shader_image_load_store : enable\n"
12515 "\n"
12516 "out vec4 vs_tcs_result;\n"
12517 "\n"
12518 "#if IMAGES\n"
12519 "UNI_GOKU\n"
12520 "#endif\n"
12521 "\n"
12522 "void main()\n"
12523 "{\n"
12524 " vec4 result = vec4(0, 1, 0, 1);\n"
12525 "\n"
12526 "#if IMAGES\n"
12527 "VERIFICATION"
12528 "#endif\n"
12529 "\n"
12530 " vs_tcs_result = result;\n"
12531 "}\n"
12532 "\n";
12533
12534 const GLchar* shader_template = 0;
12535
12536 switch (in_stage)
12537 {
12538 case Utils::COMPUTE_SHADER:
12539 shader_template = compute_shader_template;
12540 break;
12541 case Utils::FRAGMENT_SHADER:
12542 shader_template = fragment_shader_template;
12543 break;
12544 case Utils::GEOMETRY_SHADER:
12545 shader_template = geometry_shader_template;
12546 break;
12547 case Utils::TESS_CTRL_SHADER:
12548 shader_template = tess_ctrl_shader_template;
12549 break;
12550 case Utils::TESS_EVAL_SHADER:
12551 shader_template = tess_eval_shader_template;
12552 break;
12553 case Utils::VERTEX_SHADER:
12554 shader_template = vertex_shader_template;
12555 break;
12556 default:
12557 TCU_FAIL("Invalid enum");
12558 }
12559
12560 out_source.m_parts[0].m_code = shader_template;
12561
12562 size_t position = 0;
12563
12564 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12565 out_source.m_parts[0].m_code);
12566
12567 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12568
12569 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
12570 out_source.m_parts[0].m_code);
12571
12572 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12573 }
12574
12575 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
12576 *
12577 * @param program Current program
12578 **/
prepareUniforms(Utils::program & program)12579 void BindingImageArrayTest::prepareUniforms(Utils::program& program)
12580 {
12581 static const GLuint goku_data[7] = {
12582 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00,
12583 };
12584
12585 Utils::texture* textures[7] = {
12586 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12587 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12588 };
12589
12590 for (GLuint i = 0; i < 7; ++i)
12591 {
12592 GLint expected_binding = i + 1;
12593
12594 checkBinding(program, i, expected_binding);
12595
12596 prepareTexture(*textures[i], Utils::buffer(m_context), Utils::TEX_2D, goku_data[i], expected_binding);
12597 }
12598 }
12599
12600 /** Overwrite of releaseResource method, release extra textures
12601 *
12602 * @param ignored
12603 **/
releaseResource()12604 void BindingImageArrayTest::releaseResource()
12605 {
12606 Utils::texture* textures[7] = {
12607 &m_goku_00_texture, &m_goku_01_texture, &m_goku_02_texture, &m_goku_03_texture,
12608 &m_goku_04_texture, &m_goku_05_texture, &m_goku_06_texture,
12609 };
12610
12611 for (GLuint i = 0; i < 7; ++i)
12612 {
12613 textures[i]->release();
12614 }
12615 }
12616
12617 /** Verifies that API reports correct uniform binding
12618 *
12619 * @param program Program
12620 * @param index Index of array element
12621 * @param expected_binding Expected binding
12622 **/
checkBinding(Utils::program & program,GLuint index,GLint expected_binding)12623 void BindingImageArrayTest::checkBinding(Utils::program& program, GLuint index, GLint expected_binding)
12624 {
12625 if (false == Utils::checkUniformArrayBinding(program, "goku", index, expected_binding))
12626 {
12627 TCU_FAIL("Wrong binding reported by API");
12628 }
12629 }
12630
12631 /** Constructor
12632 *
12633 * @param context Test context
12634 **/
BindingImageDefaultTest(deqp::Context & context)12635 BindingImageDefaultTest::BindingImageDefaultTest(deqp::Context& context)
12636 : APITestBase(context, "binding_image_default", "Test verifies default image binding")
12637 {
12638 /* Nothing to be done here */
12639 }
12640
12641 /** Execute API call and verifies results
12642 *
12643 * @return true when results are positive, false otherwise
12644 **/
checkResults(Utils::program & program)12645 bool BindingImageDefaultTest::checkResults(Utils::program& program)
12646 {
12647 return Utils::checkUniformBinding(program, "goku", 0 /* expected_binding */);
12648 }
12649
12650 /** Prepare source for given shader stage
12651 *
12652 * @param in_stage Shader stage, compute shader will use 430
12653 * @param in_use_version_400 Select if 400 or 420 should be used
12654 * @param out_source Prepared shader source instance
12655 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12656 void BindingImageDefaultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12657 Utils::shaderSource& out_source)
12658 {
12659 static const GLchar* uni_goku = "layout(rgba8) uniform image2D goku;\n";
12660
12661 static const GLchar* verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12662 "\n"
12663 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12664 " {\n"
12665 " result = vec4(1, 0, 0, 1);\n"
12666 " }\n";
12667
12668 static const GLchar* compute_shader_template =
12669 "VERSION\n"
12670 "#extension GL_ARB_shader_image_load_store : enable\n"
12671 "\n"
12672 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12673 "\n"
12674 "writeonly uniform image2D uni_image;\n"
12675 "\n"
12676 "UNI_GOKU\n"
12677 "\n"
12678 "void main()\n"
12679 "{\n"
12680 " vec4 result = vec4(0, 1, 0, 1);\n"
12681 "\n"
12682 "VERIFICATION"
12683 "\n"
12684 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12685 "}\n"
12686 "\n";
12687
12688 static const GLchar* fragment_shader_template = "VERSION\n"
12689 "#extension GL_ARB_shader_image_load_store : enable\n"
12690 "\n"
12691 "in vec4 gs_fs_result;\n"
12692 "out vec4 fs_out_result;\n"
12693 "\n"
12694 "UNI_GOKU\n"
12695 "\n"
12696 "void main()\n"
12697 "{\n"
12698 " vec4 result = vec4(0, 1, 0, 1);\n"
12699 "\n"
12700 "VERIFICATION"
12701 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12702 " {\n"
12703 " result = vec4(1, 0, 0, 1);\n"
12704 " }\n"
12705 "\n"
12706 " fs_out_result = result;\n"
12707 "}\n"
12708 "\n";
12709
12710 static const GLchar* geometry_shader_template = "VERSION\n"
12711 "#extension GL_ARB_shader_image_load_store : enable\n"
12712 "\n"
12713 "layout(points) in;\n"
12714 "layout(triangle_strip, max_vertices = 4) out;\n"
12715 "\n"
12716 "in vec4 tes_gs_result[];\n"
12717 "out vec4 gs_fs_result;\n"
12718 "\n"
12719 "#if IMAGES\n"
12720 "UNI_GOKU\n"
12721 "#endif\n"
12722 "\n"
12723 "void main()\n"
12724 "{\n"
12725 " vec4 result = vec4(0, 1, 0, 1);\n"
12726 "\n"
12727 "#if IMAGES\n"
12728 "VERIFICATION else\n"
12729 "#endif\n"
12730 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12731 " {\n"
12732 " result = vec4(1, 0, 0, 1);\n"
12733 " }\n"
12734 "\n"
12735 " gs_fs_result = result;\n"
12736 " gl_Position = vec4(-1, -1, 0, 1);\n"
12737 " EmitVertex();\n"
12738 " gs_fs_result = result;\n"
12739 " gl_Position = vec4(-1, 1, 0, 1);\n"
12740 " EmitVertex();\n"
12741 " gs_fs_result = result;\n"
12742 " gl_Position = vec4(1, -1, 0, 1);\n"
12743 " EmitVertex();\n"
12744 " gs_fs_result = result;\n"
12745 " gl_Position = vec4(1, 1, 0, 1);\n"
12746 " EmitVertex();\n"
12747 "}\n"
12748 "\n";
12749
12750 static const GLchar* tess_ctrl_shader_template =
12751 "VERSION\n"
12752 "#extension GL_ARB_shader_image_load_store : enable\n"
12753 "\n"
12754 "layout(vertices = 1) out;\n"
12755 "\n"
12756 "in vec4 vs_tcs_result[];\n"
12757 "out vec4 tcs_tes_result[];\n"
12758 "\n"
12759 "#if IMAGES\n"
12760 "UNI_GOKU\n"
12761 "#endif\n"
12762 "\n"
12763 "void main()\n"
12764 "{\n"
12765 " vec4 result = vec4(0, 1, 0, 1);\n"
12766 "\n"
12767 "#if IMAGES\n"
12768 "VERIFICATION else\n"
12769 "#endif\n"
12770 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
12771 " {\n"
12772 " result = vec4(1, 0, 0, 1);\n"
12773 " }\n"
12774 "\n"
12775 " tcs_tes_result[gl_InvocationID] = result;\n"
12776 "\n"
12777 " gl_TessLevelOuter[0] = 1.0;\n"
12778 " gl_TessLevelOuter[1] = 1.0;\n"
12779 " gl_TessLevelOuter[2] = 1.0;\n"
12780 " gl_TessLevelOuter[3] = 1.0;\n"
12781 " gl_TessLevelInner[0] = 1.0;\n"
12782 " gl_TessLevelInner[1] = 1.0;\n"
12783 "}\n"
12784 "\n";
12785
12786 static const GLchar* tess_eval_shader_template = "VERSION\n"
12787 "#extension GL_ARB_shader_image_load_store : enable\n"
12788 "\n"
12789 "layout(isolines, point_mode) in;\n"
12790 "\n"
12791 "in vec4 tcs_tes_result[];\n"
12792 "out vec4 tes_gs_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) != tcs_tes_result[0])\n"
12806 " {\n"
12807 " result = vec4(1, 0, 0, 1);\n"
12808 " }\n"
12809 "\n"
12810 " tes_gs_result = result;\n"
12811 "}\n"
12812 "\n";
12813
12814 static const GLchar* vertex_shader_template = "VERSION\n"
12815 "#extension GL_ARB_shader_image_load_store : enable\n"
12816 "\n"
12817 "out vec4 vs_tcs_result;\n"
12818 "\n"
12819 "#if IMAGES\n"
12820 "UNI_GOKU\n"
12821 "#endif\n"
12822 "\n"
12823 "void main()\n"
12824 "{\n"
12825 " vec4 result = vec4(0, 1, 0, 1);\n"
12826 "\n"
12827 "#if IMAGES\n"
12828 "VERIFICATION"
12829 "#endif\n"
12830 "\n"
12831 " vs_tcs_result = result;\n"
12832 "}\n"
12833 "\n";
12834
12835 const GLchar* shader_template = 0;
12836
12837 switch (in_stage)
12838 {
12839 case Utils::COMPUTE_SHADER:
12840 shader_template = compute_shader_template;
12841 break;
12842 case Utils::FRAGMENT_SHADER:
12843 shader_template = fragment_shader_template;
12844 break;
12845 case Utils::GEOMETRY_SHADER:
12846 shader_template = geometry_shader_template;
12847 break;
12848 case Utils::TESS_CTRL_SHADER:
12849 shader_template = tess_ctrl_shader_template;
12850 break;
12851 case Utils::TESS_EVAL_SHADER:
12852 shader_template = tess_eval_shader_template;
12853 break;
12854 case Utils::VERTEX_SHADER:
12855 shader_template = vertex_shader_template;
12856 break;
12857 default:
12858 TCU_FAIL("Invalid enum");
12859 }
12860
12861 out_source.m_parts[0].m_code = shader_template;
12862
12863 size_t position = 0;
12864
12865 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
12866 out_source.m_parts[0].m_code);
12867
12868 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
12869
12870 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
12871 out_source.m_parts[0].m_code);
12872
12873 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
12874 }
12875
12876 /** Constructor
12877 *
12878 * @param context Test context
12879 **/
BindingImageAPIOverrideTest(deqp::Context & context)12880 BindingImageAPIOverrideTest::BindingImageAPIOverrideTest(deqp::Context& context)
12881 : BindingImageTest(context, "binding_image_api_override", "Verifies that API can override image binding")
12882 , m_goku_texture(context)
12883 {
12884 /* Nothing to be done here */
12885 }
12886
12887 /** Prepare source for given shader stage
12888 *
12889 * @param in_stage Shader stage, compute shader will use 430
12890 * @param in_use_version_400 Select if 400 or 420 should be used
12891 * @param out_source Prepared shader source instance
12892 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)12893 void BindingImageAPIOverrideTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
12894 Utils::shaderSource& out_source)
12895 {
12896 static const GLchar* uni_goku = "layout(binding = 3, rgba8) uniform image2D goku;\n";
12897
12898 static const GLchar* verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
12899 "\n"
12900 " if (vec4(1, 0, 0, 0) != goku_color)\n"
12901 " {\n"
12902 " result = vec4(1, 0, 0, 1);\n"
12903 " }\n";
12904
12905 static const GLchar* compute_shader_template =
12906 "VERSION\n"
12907 "#extension GL_ARB_shader_image_load_store : enable\n"
12908 "\n"
12909 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
12910 "\n"
12911 "writeonly uniform image2D uni_image;\n"
12912 "\n"
12913 "UNI_GOKU\n"
12914 "\n"
12915 "void main()\n"
12916 "{\n"
12917 " vec4 result = vec4(0, 1, 0, 1);\n"
12918 "\n"
12919 "VERIFICATION"
12920 "\n"
12921 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
12922 "}\n"
12923 "\n";
12924
12925 static const GLchar* fragment_shader_template = "VERSION\n"
12926 "#extension GL_ARB_shader_image_load_store : enable\n"
12927 "\n"
12928 "in vec4 gs_fs_result;\n"
12929 "out vec4 fs_out_result;\n"
12930 "\n"
12931 "UNI_GOKU\n"
12932 "\n"
12933 "void main()\n"
12934 "{\n"
12935 " vec4 result = vec4(0, 1, 0, 1);\n"
12936 "\n"
12937 "VERIFICATION"
12938 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
12939 " {\n"
12940 " result = vec4(1, 0, 0, 1);\n"
12941 " }\n"
12942 "\n"
12943 " fs_out_result = result;\n"
12944 "}\n"
12945 "\n";
12946
12947 static const GLchar* geometry_shader_template = "VERSION\n"
12948 "#extension GL_ARB_shader_image_load_store : enable\n"
12949 "\n"
12950 "layout(points) in;\n"
12951 "layout(triangle_strip, max_vertices = 4) out;\n"
12952 "\n"
12953 "in vec4 tes_gs_result[];\n"
12954 "out vec4 gs_fs_result;\n"
12955 "\n"
12956 "#if IMAGES\n"
12957 "UNI_GOKU\n"
12958 "#endif\n"
12959 "\n"
12960 "void main()\n"
12961 "{\n"
12962 " vec4 result = vec4(0, 1, 0, 1);\n"
12963 "\n"
12964 "#if IMAGES\n"
12965 "VERIFICATION else\n"
12966 "#endif\n"
12967 " if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
12968 " {\n"
12969 " result = vec4(1, 0, 0, 1);\n"
12970 " }\n"
12971 "\n"
12972 " gs_fs_result = result;\n"
12973 " gl_Position = vec4(-1, -1, 0, 1);\n"
12974 " EmitVertex();\n"
12975 " gs_fs_result = result;\n"
12976 " gl_Position = vec4(-1, 1, 0, 1);\n"
12977 " EmitVertex();\n"
12978 " gs_fs_result = result;\n"
12979 " gl_Position = vec4(1, -1, 0, 1);\n"
12980 " EmitVertex();\n"
12981 " gs_fs_result = result;\n"
12982 " gl_Position = vec4(1, 1, 0, 1);\n"
12983 " EmitVertex();\n"
12984 "}\n"
12985 "\n";
12986
12987 static const GLchar* tess_ctrl_shader_template =
12988 "VERSION\n"
12989 "#extension GL_ARB_shader_image_load_store : enable\n"
12990 "\n"
12991 "layout(vertices = 1) out;\n"
12992 "\n"
12993 "in vec4 vs_tcs_result[];\n"
12994 "out vec4 tcs_tes_result[];\n"
12995 "\n"
12996 "#if IMAGES\n"
12997 "UNI_GOKU\n"
12998 "#endif\n"
12999 "\n"
13000 "void main()\n"
13001 "{\n"
13002 " vec4 result = vec4(0, 1, 0, 1);\n"
13003 "\n"
13004 "#if IMAGES\n"
13005 "VERIFICATION else\n"
13006 "#endif\n"
13007 " if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13008 " {\n"
13009 " result = vec4(1, 0, 0, 1);\n"
13010 " }\n"
13011 "\n"
13012 " tcs_tes_result[gl_InvocationID] = result;\n"
13013 "\n"
13014 " gl_TessLevelOuter[0] = 1.0;\n"
13015 " gl_TessLevelOuter[1] = 1.0;\n"
13016 " gl_TessLevelOuter[2] = 1.0;\n"
13017 " gl_TessLevelOuter[3] = 1.0;\n"
13018 " gl_TessLevelInner[0] = 1.0;\n"
13019 " gl_TessLevelInner[1] = 1.0;\n"
13020 "}\n"
13021 "\n";
13022
13023 static const GLchar* tess_eval_shader_template = "VERSION\n"
13024 "#extension GL_ARB_shader_image_load_store : enable\n"
13025 "\n"
13026 "layout(isolines, point_mode) in;\n"
13027 "\n"
13028 "in vec4 tcs_tes_result[];\n"
13029 "out vec4 tes_gs_result;\n"
13030 "\n"
13031 "#if IMAGES\n"
13032 "UNI_GOKU\n"
13033 "#endif\n"
13034 "\n"
13035 "void main()\n"
13036 "{\n"
13037 " vec4 result = vec4(0, 1, 0, 1);\n"
13038 "\n"
13039 "#if IMAGES\n"
13040 "VERIFICATION else\n"
13041 "#endif\n"
13042 " if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13043 " {\n"
13044 " result = vec4(1, 0, 0, 1);\n"
13045 " }\n"
13046 "\n"
13047 " tes_gs_result = result;\n"
13048 "}\n"
13049 "\n";
13050
13051 static const GLchar* vertex_shader_template = "VERSION\n"
13052 "#extension GL_ARB_shader_image_load_store : enable\n"
13053 "\n"
13054 "out vec4 vs_tcs_result;\n"
13055 "\n"
13056 "#if IMAGES\n"
13057 "UNI_GOKU\n"
13058 "#endif\n"
13059 "\n"
13060 "void main()\n"
13061 "{\n"
13062 " vec4 result = vec4(0, 1, 0, 1);\n"
13063 "\n"
13064 "#if IMAGES\n"
13065 "VERIFICATION"
13066 "#endif\n"
13067 "\n"
13068 " vs_tcs_result = result;\n"
13069 "}\n"
13070 "\n";
13071
13072 const GLchar* shader_template = 0;
13073
13074 switch (in_stage)
13075 {
13076 case Utils::COMPUTE_SHADER:
13077 shader_template = compute_shader_template;
13078 break;
13079 case Utils::FRAGMENT_SHADER:
13080 shader_template = fragment_shader_template;
13081 break;
13082 case Utils::GEOMETRY_SHADER:
13083 shader_template = geometry_shader_template;
13084 break;
13085 case Utils::TESS_CTRL_SHADER:
13086 shader_template = tess_ctrl_shader_template;
13087 break;
13088 case Utils::TESS_EVAL_SHADER:
13089 shader_template = tess_eval_shader_template;
13090 break;
13091 case Utils::VERTEX_SHADER:
13092 shader_template = vertex_shader_template;
13093 break;
13094 default:
13095 TCU_FAIL("Invalid enum");
13096 }
13097
13098 out_source.m_parts[0].m_code = shader_template;
13099
13100 size_t position = 0;
13101
13102 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13103 out_source.m_parts[0].m_code);
13104
13105 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13106
13107 Utils::replaceAllTokens("IMAGES", maxImageUniforms(in_stage) > 0 ? "1" : "0",
13108 out_source.m_parts[0].m_code);
13109
13110 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13111 }
13112
13113 /** Overwritte of prepareUniforms method, set up values for unit_left and unit_right
13114 *
13115 * @param program Current program
13116 **/
prepareUniforms(Utils::program & program)13117 void BindingImageAPIOverrideTest::prepareUniforms(Utils::program& program)
13118 {
13119 static const GLuint goku_data = 0x000000ff;
13120 static const GLint new_binding = 7;
13121
13122 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
13123
13124 const GLint uniform_location = program.getUniformLocation("goku");
13125 if (-1 == uniform_location)
13126 {
13127 TCU_FAIL("Uniform is inactive");
13128 }
13129
13130 gl.uniform1i(uniform_location, new_binding);
13131
13132 GLint binding = -1;
13133
13134 gl.getUniformiv(program.m_program_object_id, uniform_location, &binding);
13135 GLU_EXPECT_NO_ERROR(gl.getError(), "getUniformiv");
13136
13137 if (new_binding != binding)
13138 {
13139 TCU_FAIL("Wrong binding value");
13140 return;
13141 }
13142
13143 prepareTexture(m_goku_texture, Utils::buffer(m_context), Utils::TEX_2D, goku_data, new_binding);
13144 }
13145
13146 /** Overwrite of releaseResource method, release extra texture
13147 *
13148 * @param ignored
13149 **/
releaseResource()13150 void BindingImageAPIOverrideTest::releaseResource()
13151 {
13152 m_goku_texture.release();
13153 }
13154
13155 /** Constructor
13156 *
13157 * @param context Test context
13158 **/
BindingImageInvalidTest(deqp::Context & context)13159 BindingImageInvalidTest::BindingImageInvalidTest(deqp::Context& context)
13160 : NegativeTestBase(context, "binding_image_invalid", "Test verifies invalid binding values")
13161 {
13162 /* Nothing to be done here */
13163 }
13164
13165 /** Set up next test case
13166 *
13167 * @param test_case_index Index of next test case
13168 *
13169 * @return false if there is no more test cases, true otherwise
13170 **/
prepareNextTestCase(glw::GLuint test_case_index)13171 bool BindingImageInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
13172 {
13173 switch (test_case_index)
13174 {
13175 case (glw::GLuint)-1:
13176 m_case = TEST_CASES_MAX;
13177 break;
13178 case NEGATIVE_VALUE:
13179 case VARIABLE_NAME:
13180 case STD140:
13181 case MISSING:
13182 m_case = (TESTCASES)test_case_index;
13183 break;
13184 default:
13185 return false;
13186 }
13187
13188 return true;
13189 }
13190
13191 /** Prepare source for given shader stage
13192 *
13193 * @param in_stage Shader stage, compute shader will use 430
13194 * @param in_use_version_400 Select if 400 or 420 should be used
13195 * @param out_source Prepared shader source instance
13196 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13197 void BindingImageInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13198 Utils::shaderSource& out_source)
13199 {
13200 static const GLchar* uni_goku = "layout(binding BINDING, rgba8) uniform image2D goku;\n";
13201
13202 static const GLchar* verification_snippet = " vec4 goku_color = imageLoad(goku, ivec2(0,0));\n"
13203 "\n"
13204 " if (vec4(1, 0, 0, 0) != goku_color)\n"
13205 " {\n"
13206 " result = vec4(1, 0, 0, 1);\n"
13207 " }\n";
13208
13209 static const GLchar* compute_shader_template =
13210 "VERSION\n"
13211 "#extension GL_ARB_shader_image_load_store : enable\n"
13212 "\n"
13213 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13214 "\n"
13215 "writeonly uniform image2D uni_image;\n"
13216 "\n"
13217 "UNI_GOKU\n"
13218 "\n"
13219 "void main()\n"
13220 "{\n"
13221 " vec4 result = vec4(0, 1, 0, 1);\n"
13222 "\n"
13223 "VERIFICATION"
13224 "\n"
13225 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13226 "}\n"
13227 "\n";
13228
13229 static const GLchar* fragment_shader_template = "VERSION\n"
13230 "#extension GL_ARB_shader_image_load_store : enable\n"
13231 "\n"
13232 "in vec4 gs_fs_result;\n"
13233 "out vec4 fs_out_result;\n"
13234 "\n"
13235 "UNI_GOKU\n"
13236 "\n"
13237 "void main()\n"
13238 "{\n"
13239 " vec4 result = vec4(0, 1, 0, 1);\n"
13240 "\n"
13241 "VERIFICATION"
13242 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13243 " {\n"
13244 " result = vec4(1, 0, 0, 1);\n"
13245 " }\n"
13246 "\n"
13247 " fs_out_result = result;\n"
13248 "}\n"
13249 "\n";
13250
13251 static const GLchar* geometry_shader_template = "VERSION\n"
13252 "#extension GL_ARB_shader_image_load_store : enable\n"
13253 "\n"
13254 "layout(points) in;\n"
13255 "layout(triangle_strip, max_vertices = 4) out;\n"
13256 "\n"
13257 "in vec4 tes_gs_result[];\n"
13258 "out vec4 gs_fs_result;\n"
13259 "\n"
13260 "UNI_GOKU\n"
13261 "\n"
13262 "void main()\n"
13263 "{\n"
13264 " vec4 result = vec4(0, 1, 0, 1);\n"
13265 "\n"
13266 "VERIFICATION"
13267 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13268 " {\n"
13269 " result = vec4(1, 0, 0, 1);\n"
13270 " }\n"
13271 "\n"
13272 " gs_fs_result = result;\n"
13273 " gl_Position = vec4(-1, -1, 0, 1);\n"
13274 " EmitVertex();\n"
13275 " gs_fs_result = result;\n"
13276 " gl_Position = vec4(-1, 1, 0, 1);\n"
13277 " EmitVertex();\n"
13278 " gs_fs_result = result;\n"
13279 " gl_Position = vec4(1, -1, 0, 1);\n"
13280 " EmitVertex();\n"
13281 " gs_fs_result = result;\n"
13282 " gl_Position = vec4(1, 1, 0, 1);\n"
13283 " EmitVertex();\n"
13284 "}\n"
13285 "\n";
13286
13287 static const GLchar* tess_ctrl_shader_template =
13288 "VERSION\n"
13289 "#extension GL_ARB_shader_image_load_store : enable\n"
13290 "\n"
13291 "layout(vertices = 1) out;\n"
13292 "\n"
13293 "in vec4 vs_tcs_result[];\n"
13294 "out vec4 tcs_tes_result[];\n"
13295 "\n"
13296 "UNI_GOKU\n"
13297 "\n"
13298 "void main()\n"
13299 "{\n"
13300 " vec4 result = vec4(0, 1, 0, 1);\n"
13301 "\n"
13302 "VERIFICATION"
13303 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
13304 " {\n"
13305 " result = vec4(1, 0, 0, 1);\n"
13306 " }\n"
13307 "\n"
13308 " tcs_tes_result[gl_InvocationID] = result;\n"
13309 "\n"
13310 " gl_TessLevelOuter[0] = 1.0;\n"
13311 " gl_TessLevelOuter[1] = 1.0;\n"
13312 " gl_TessLevelOuter[2] = 1.0;\n"
13313 " gl_TessLevelOuter[3] = 1.0;\n"
13314 " gl_TessLevelInner[0] = 1.0;\n"
13315 " gl_TessLevelInner[1] = 1.0;\n"
13316 "}\n"
13317 "\n";
13318
13319 static const GLchar* tess_eval_shader_template = "VERSION\n"
13320 "#extension GL_ARB_shader_image_load_store : enable\n"
13321 "\n"
13322 "layout(isolines, point_mode) in;\n"
13323 "\n"
13324 "in vec4 tcs_tes_result[];\n"
13325 "out vec4 tes_gs_result;\n"
13326 "\n"
13327 "UNI_GOKU\n"
13328 "\n"
13329 "void main()\n"
13330 "{\n"
13331 " vec4 result = vec4(0, 1, 0, 1);\n"
13332 "\n"
13333 "VERIFICATION"
13334 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13335 " {\n"
13336 " result = vec4(1, 0, 0, 1);\n"
13337 " }\n"
13338 "\n"
13339 " tes_gs_result = result;\n"
13340 "}\n"
13341 "\n";
13342
13343 static const GLchar* vertex_shader_template = "VERSION\n"
13344 "#extension GL_ARB_shader_image_load_store : enable\n"
13345 "\n"
13346 "out vec4 vs_tcs_result;\n"
13347 "\n"
13348 "UNI_GOKU\n"
13349 "\n"
13350 "void main()\n"
13351 "{\n"
13352 " vec4 result = vec4(0, 1, 0, 1);\n"
13353 "\n"
13354 "VERIFICATION"
13355 "\n"
13356 " vs_tcs_result = result;\n"
13357 "}\n"
13358 "\n";
13359
13360 const GLchar* shader_template = 0;
13361
13362 switch (in_stage)
13363 {
13364 case Utils::COMPUTE_SHADER:
13365 shader_template = compute_shader_template;
13366 break;
13367 case Utils::FRAGMENT_SHADER:
13368 shader_template = fragment_shader_template;
13369 break;
13370 case Utils::GEOMETRY_SHADER:
13371 shader_template = geometry_shader_template;
13372 break;
13373 case Utils::TESS_CTRL_SHADER:
13374 shader_template = tess_ctrl_shader_template;
13375 break;
13376 case Utils::TESS_EVAL_SHADER:
13377 shader_template = tess_eval_shader_template;
13378 break;
13379 case Utils::VERTEX_SHADER:
13380 shader_template = vertex_shader_template;
13381 break;
13382 default:
13383 TCU_FAIL("Invalid enum");
13384 }
13385
13386 out_source.m_parts[0].m_code = shader_template;
13387
13388 size_t position = 0;
13389
13390 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13391 out_source.m_parts[0].m_code);
13392
13393 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13394
13395 Utils::replaceAllTokens("UNI_GOKU", uni_goku, out_source.m_parts[0].m_code);
13396
13397 Utils::replaceAllTokens("BINDING", getCaseString(m_case), out_source.m_parts[0].m_code);
13398 }
13399
getCaseString(TESTCASES test_case)13400 const GLchar* BindingImageInvalidTest::getCaseString(TESTCASES test_case)
13401 {
13402 (void)test_case;
13403 const GLchar* binding = 0;
13404
13405 switch (m_case)
13406 {
13407 case NEGATIVE_VALUE:
13408 binding = "= -1";
13409 break;
13410 case VARIABLE_NAME:
13411 binding = "= goku";
13412 break;
13413 case STD140:
13414 binding = "= std140";
13415 break;
13416 case MISSING:
13417 binding = "";
13418 break;
13419 case TEST_CASES_MAX:
13420 binding = "= 0";
13421 break;
13422 default:
13423 TCU_FAIL("Invalid enum");
13424 }
13425
13426 return binding;
13427 }
13428
13429 /* Constants used by InitializerListTest */
13430 const GLfloat InitializerListTest::m_value = 0.0625f;
13431
13432 /** Constructor
13433 *
13434 * @param context Test context
13435 **/
InitializerListTest(deqp::Context & context)13436 InitializerListTest::InitializerListTest(deqp::Context& context)
13437 : GLSLTestBase(context, "initializer_list", "Test verifies initializer lists")
13438 , m_current_test_case_index(0)
13439 {
13440 /* Nothing to be done here */
13441 }
13442
13443 /** Set up next test case
13444 *
13445 * @param test_case_index Index of next test case
13446 *
13447 * @return false if there is no more test cases, true otherwise
13448 **/
prepareNextTestCase(glw::GLuint test_case_index)13449 bool InitializerListTest::prepareNextTestCase(glw::GLuint test_case_index)
13450 {
13451 m_current_test_case_index = test_case_index;
13452
13453 if ((glw::GLuint)-1 == test_case_index)
13454 {
13455 m_current_test_case_index = 0;
13456 return true;
13457 }
13458 else if (m_test_cases.size() <= test_case_index)
13459 {
13460 return false;
13461 }
13462
13463 logTestCaseName();
13464
13465 return true;
13466 }
13467
13468 /** Overwritte of prepareUniforms method
13469 *
13470 * @param program Current program
13471 **/
prepareUniforms(Utils::program & program)13472 void InitializerListTest::prepareUniforms(Utils::program& program)
13473 {
13474 static const GLfloat float_data[16] = { m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value,
13475 m_value, m_value, m_value, m_value, m_value, m_value, m_value, m_value };
13476
13477 program.uniform("uni_matrix", Utils::FLOAT, 4, 4, float_data);
13478 }
13479
13480 /** Prepare source for given shader stage
13481 *
13482 * @param in_stage Shader stage, compute shader will use 430
13483 * @param in_use_version_400 Select if 400 or 420 should be used
13484 * @param out_source Prepared shader source instance
13485 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)13486 void InitializerListTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
13487 Utils::shaderSource& out_source)
13488 {
13489 static const GLchar* verification_snippet = " TYPE_NAME variableARRAY_DEFINITION = INITIALIZATION;\n"
13490 "\n"
13491 " float sum = SUM;\n"
13492 "\n"
13493 " if (EXPECTED_VALUE != sum)\n"
13494 " {\n"
13495 " result = vec4(1, 0, 0, 1);\n"
13496 " }\n";
13497
13498 static const GLchar* compute_shader_template =
13499 "VERSION\n"
13500 "\n"
13501 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
13502 "\n"
13503 "writeonly uniform image2D uni_image;\n"
13504 " uniform mat4 uni_matrix;\n"
13505 "\n"
13506 "TYPE_DEFINITION\n"
13507 "\n"
13508 "void main()\n"
13509 "{\n"
13510 " vec4 result = vec4(0, 1, 0, 1);\n"
13511 "\n"
13512 "VERIFICATION"
13513 "\n"
13514 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
13515 "}\n"
13516 "\n";
13517
13518 static const GLchar* fragment_shader_template = "VERSION\n"
13519 "\n"
13520 "in vec4 gs_fs_result;\n"
13521 "out vec4 fs_out_result;\n"
13522 "\n"
13523 "uniform mat4 uni_matrix;\n"
13524 "\n"
13525 "TYPE_DEFINITION\n"
13526 "\n"
13527 "void main()\n"
13528 "{\n"
13529 " vec4 result = vec4(0, 1, 0, 1);\n"
13530 "\n"
13531 "VERIFICATION"
13532 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
13533 " {\n"
13534 " result = vec4(1, 0, 0, 1);\n"
13535 " }\n"
13536 "\n"
13537 " fs_out_result = result;\n"
13538 "}\n"
13539 "\n";
13540
13541 static const GLchar* geometry_shader_template = "VERSION\n"
13542 "\n"
13543 "layout(points) in;\n"
13544 "layout(triangle_strip, max_vertices = 4) out;\n"
13545 "\n"
13546 "in vec4 tes_gs_result[];\n"
13547 "out vec4 gs_fs_result;\n"
13548 "\n"
13549 "uniform mat4 uni_matrix;\n"
13550 "\n"
13551 "TYPE_DEFINITION\n"
13552 "\n"
13553 "void main()\n"
13554 "{\n"
13555 " vec4 result = vec4(0, 1, 0, 1);\n"
13556 "\n"
13557 "VERIFICATION"
13558 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
13559 " {\n"
13560 " result = vec4(1, 0, 0, 1);\n"
13561 " }\n"
13562 "\n"
13563 " gs_fs_result = result;\n"
13564 " gl_Position = vec4(-1, -1, 0, 1);\n"
13565 " EmitVertex();\n"
13566 " gs_fs_result = result;\n"
13567 " gl_Position = vec4(-1, 1, 0, 1);\n"
13568 " EmitVertex();\n"
13569 " gs_fs_result = result;\n"
13570 " gl_Position = vec4(1, -1, 0, 1);\n"
13571 " EmitVertex();\n"
13572 " gs_fs_result = result;\n"
13573 " gl_Position = vec4(1, 1, 0, 1);\n"
13574 " EmitVertex();\n"
13575 "}\n"
13576 "\n";
13577
13578 static const GLchar* tess_ctrl_shader_template =
13579 "VERSION\n"
13580 "\n"
13581 "layout(vertices = 1) out;\n"
13582 "\n"
13583 "in vec4 vs_tcs_result[];\n"
13584 "out vec4 tcs_tes_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) != vs_tcs_result[gl_InvocationID])\n"
13596 " {\n"
13597 " result = vec4(1, 0, 0, 1);\n"
13598 " }\n"
13599 "\n"
13600 " tcs_tes_result[gl_InvocationID] = result;\n"
13601 "\n"
13602 " gl_TessLevelOuter[0] = 1.0;\n"
13603 " gl_TessLevelOuter[1] = 1.0;\n"
13604 " gl_TessLevelOuter[2] = 1.0;\n"
13605 " gl_TessLevelOuter[3] = 1.0;\n"
13606 " gl_TessLevelInner[0] = 1.0;\n"
13607 " gl_TessLevelInner[1] = 1.0;\n"
13608 "}\n"
13609 "\n";
13610
13611 static const GLchar* tess_eval_shader_template = "VERSION\n"
13612 "\n"
13613 "layout(isolines, point_mode) in;\n"
13614 "\n"
13615 "in vec4 tcs_tes_result[];\n"
13616 "out vec4 tes_gs_result;\n"
13617 "\n"
13618 "uniform mat4 uni_matrix;\n"
13619 "\n"
13620 "TYPE_DEFINITION\n"
13621 "\n"
13622 "void main()\n"
13623 "{\n"
13624 " vec4 result = vec4(0, 1, 0, 1);\n"
13625 "\n"
13626 "VERIFICATION"
13627 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
13628 " {\n"
13629 " result = vec4(1, 0, 0, 1);\n"
13630 " }\n"
13631 "\n"
13632 " tes_gs_result = result;\n"
13633 "}\n"
13634 "\n";
13635
13636 static const GLchar* vertex_shader_template = "VERSION\n"
13637 "\n"
13638 "out vec4 vs_tcs_result;\n"
13639 "\n"
13640 "uniform mat4 uni_matrix;\n"
13641 "\n"
13642 "TYPE_DEFINITION\n"
13643 "\n"
13644 "void main()\n"
13645 "{\n"
13646 " vec4 result = vec4(0, 1, 0, 1);\n"
13647 "\n"
13648 "VERIFICATION"
13649 "\n"
13650 " vs_tcs_result = result;\n"
13651 "}\n"
13652 "\n";
13653
13654 const std::string& array_definition = getArrayDefinition();
13655 const std::string& expected_value = getExpectedValue();
13656 const std::string& initialization = getInitialization();
13657 const GLchar* shader_template = 0;
13658 const std::string& sum = getSum();
13659 const std::string& type_definition = getTypeDefinition();
13660 const std::string& type_name = getTypeName();
13661
13662 switch (in_stage)
13663 {
13664 case Utils::COMPUTE_SHADER:
13665 shader_template = compute_shader_template;
13666 break;
13667 case Utils::FRAGMENT_SHADER:
13668 shader_template = fragment_shader_template;
13669 break;
13670 case Utils::GEOMETRY_SHADER:
13671 shader_template = geometry_shader_template;
13672 break;
13673 case Utils::TESS_CTRL_SHADER:
13674 shader_template = tess_ctrl_shader_template;
13675 break;
13676 case Utils::TESS_EVAL_SHADER:
13677 shader_template = tess_eval_shader_template;
13678 break;
13679 case Utils::VERTEX_SHADER:
13680 shader_template = vertex_shader_template;
13681 break;
13682 default:
13683 TCU_FAIL("Invalid enum");
13684 }
13685
13686 out_source.m_parts[0].m_code = shader_template;
13687
13688 size_t position = 0;
13689 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
13690 out_source.m_parts[0].m_code);
13691
13692 Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
13693
13694 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
13695
13696 position -= strlen(verification_snippet);
13697
13698 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
13699
13700 Utils::replaceToken("ARRAY_DEFINITION", position, array_definition.c_str(), out_source.m_parts[0].m_code);
13701
13702 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
13703
13704 Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
13705
13706 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
13707 }
13708
13709 /** Prepare test cases
13710 *
13711 * @return true
13712 **/
testInit()13713 bool InitializerListTest::testInit()
13714 {
13715 for (GLuint i = 0; i < TESTED_INITIALIZERS_MAX; ++i)
13716 {
13717 const TESTED_INITIALIZERS l_init = (TESTED_INITIALIZERS)i;
13718
13719 testCase test_case = { l_init, 1, 1 };
13720
13721 switch (l_init)
13722 {
13723 case VECTOR:
13724 case ARRAY_VECTOR_CTR:
13725 case ARRAY_VECTOR_LIST:
13726 case UNSIZED_ARRAY_VECTOR:
13727 for (GLuint row = 2; row <= 4; ++row)
13728 {
13729 test_case.m_n_rows = row;
13730
13731 m_test_cases.push_back(test_case);
13732 }
13733
13734 break;
13735
13736 case MATRIX:
13737 case MATRIX_ROWS:
13738 case ARRAY_MATRIX_CTR:
13739 case ARRAY_MATRIX_LIST:
13740 case UNSIZED_ARRAY_MATRIX:
13741 for (GLuint col = 2; col <= 4; ++col)
13742 {
13743 for (GLuint row = 2; row <= 4; ++row)
13744 {
13745 test_case.m_n_cols = col;
13746 test_case.m_n_rows = row;
13747
13748 m_test_cases.push_back(test_case);
13749 }
13750 }
13751
13752 break;
13753
13754 case ARRAY_SCALAR:
13755 case UNSIZED_ARRAY_SCALAR:
13756 m_test_cases.push_back(test_case);
13757
13758 break;
13759
13760 case STRUCT:
13761 case ARRAY_STRUCT:
13762 case NESTED_STRUCT_CTR:
13763 case NESTED_STRUCT_LIST:
13764 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13765 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13766 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13767 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13768 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13769 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13770 case UNSIZED_ARRAY_STRUCT:
13771 test_case.m_n_rows = 4;
13772 m_test_cases.push_back(test_case);
13773
13774 break;
13775 default:
13776 DE_ASSERT(0);
13777 break;
13778 }
13779 }
13780
13781 return true;
13782 }
13783
13784 /** Get string representing "[SIZE]" for current test case
13785 *
13786 * @return String
13787 **/
getArrayDefinition()13788 std::string InitializerListTest::getArrayDefinition()
13789 {
13790 const testCase& test_case = m_test_cases[m_current_test_case_index];
13791
13792 std::string array_definition;
13793
13794 switch (test_case.m_initializer)
13795 {
13796 case VECTOR:
13797 case MATRIX:
13798 case MATRIX_ROWS:
13799 case 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_STRUCT_STRUCT_ARRAY_LIST:
13805 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13806 array_definition = "";
13807 break;
13808 case ARRAY_SCALAR:
13809 case ARRAY_VECTOR_CTR:
13810 case ARRAY_VECTOR_LIST:
13811 case ARRAY_MATRIX_CTR:
13812 case ARRAY_MATRIX_LIST:
13813 case ARRAY_STRUCT:
13814 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13815 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13816 array_definition = "[4]";
13817 break;
13818 case UNSIZED_ARRAY_SCALAR:
13819 case UNSIZED_ARRAY_VECTOR:
13820 case UNSIZED_ARRAY_MATRIX:
13821 case UNSIZED_ARRAY_STRUCT:
13822 array_definition = "[]";
13823 break;
13824 default:
13825 TCU_FAIL("Invalid enum");
13826 }
13827
13828 return array_definition;
13829 }
13830
13831 /** Get string representing expected value of sum for current test case
13832 *
13833 * @return String
13834 **/
getExpectedValue()13835 std::string InitializerListTest::getExpectedValue()
13836 {
13837 const testCase& test_case = m_test_cases[m_current_test_case_index];
13838
13839 GLfloat value = 0.0f;
13840
13841 switch (test_case.m_initializer)
13842 {
13843 case VECTOR:
13844 case MATRIX:
13845 case MATRIX_ROWS:
13846 value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows);
13847 break;
13848 case ARRAY_VECTOR_CTR:
13849 case ARRAY_VECTOR_LIST:
13850 case ARRAY_MATRIX_CTR:
13851 case ARRAY_MATRIX_LIST:
13852 case UNSIZED_ARRAY_VECTOR:
13853 case UNSIZED_ARRAY_MATRIX:
13854 value = (GLfloat)(test_case.m_n_cols * test_case.m_n_rows) * 4.0f;
13855 break;
13856 case ARRAY_SCALAR:
13857 case UNSIZED_ARRAY_SCALAR:
13858 value = 4.0f;
13859 break;
13860 case STRUCT:
13861 value = 8.0f;
13862 break;
13863 case NESTED_STRUCT_CTR:
13864 case NESTED_STRUCT_LIST:
13865 value = 12.0f;
13866 break;
13867 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
13868 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
13869 value = 16.0f;
13870 break;
13871 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
13872 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
13873 value = 28.0f;
13874 break;
13875 case ARRAY_STRUCT:
13876 case UNSIZED_ARRAY_STRUCT:
13877 value = 32.0f;
13878 break;
13879 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
13880 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
13881 value = 48.0f;
13882 break;
13883 default:
13884 TCU_FAIL("Invalid enum");
13885 }
13886
13887 value *= m_value;
13888
13889 std::string expected_value;
13890 expected_value.resize(64, 0);
13891
13892 sprintf(&expected_value[0], "%f", value);
13893
13894 return expected_value;
13895 }
13896
13897 /** Get string representing initialization list for current test case
13898 *
13899 * @return String
13900 **/
getInitialization()13901 std::string InitializerListTest::getInitialization()
13902 {
13903 const testCase& test_case = m_test_cases[m_current_test_case_index];
13904
13905 std::string initialization;
13906
13907 switch (test_case.m_initializer)
13908 {
13909 case VECTOR:
13910 initialization.append(getVectorInitializer(0 /*column*/, test_case.m_n_rows));
13911
13912 break;
13913
13914 case MATRIX:
13915 initialization = "{ ";
13916 initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13917 initialization.append(" }");
13918
13919 break;
13920
13921 case MATRIX_ROWS:
13922 {
13923 initialization = "{ ";
13924 initialization.append(getVectorArrayCtr(test_case.m_n_cols, test_case.m_n_rows));
13925 initialization.append(" }");
13926 }
13927 break;
13928
13929 case STRUCT:
13930 initialization = "{ ";
13931 initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
13932 initialization.append(", ");
13933 initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
13934 initialization.append(" }");
13935
13936 break;
13937
13938 case ARRAY_SCALAR:
13939 case UNSIZED_ARRAY_SCALAR:
13940 initialization = "{ ";
13941 initialization.append(getVectorValues(0 /* column */, 4 /* size */));
13942 initialization.append(" }");
13943
13944 break;
13945
13946 case ARRAY_VECTOR_LIST:
13947 case UNSIZED_ARRAY_VECTOR:
13948 initialization = "{ ";
13949 initialization.append(getVectorArrayList(4 /* columns */, test_case.m_n_rows));
13950 initialization.append(" }");
13951
13952 break;
13953
13954 case ARRAY_VECTOR_CTR:
13955 initialization = "{ ";
13956 initialization.append(getVectorArrayCtr(4 /* columns */, test_case.m_n_rows));
13957 initialization.append(" }");
13958
13959 break;
13960
13961 case ARRAY_MATRIX_LIST:
13962 case UNSIZED_ARRAY_MATRIX:
13963 initialization = "{ ";
13964
13965 for (GLuint i = 0; i < 4; ++i)
13966 {
13967 initialization.append("{ ");
13968 initialization.append(getVectorArrayList(test_case.m_n_cols, test_case.m_n_rows));
13969 initialization.append(" }");
13970
13971 if (i + 1 < 4)
13972 {
13973 initialization.append(", ");
13974 }
13975 }
13976
13977 initialization.append(" }");
13978
13979 break;
13980
13981 case ARRAY_MATRIX_CTR:
13982 {
13983 const std::string& type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
13984
13985 initialization = "{ ";
13986
13987 for (GLuint i = 0; i < 4; ++i)
13988 {
13989 initialization.append(type_name);
13990 initialization.append("(");
13991 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
13992 {
13993 initialization.append(getVectorValues(col, test_case.m_n_rows));
13994
13995 if (col + 1 < test_case.m_n_cols)
13996 {
13997 initialization.append(", ");
13998 }
13999 }
14000 initialization.append(")");
14001
14002 if (i + 1 < 4)
14003 {
14004 initialization.append(", ");
14005 }
14006 }
14007
14008 initialization.append(" }");
14009 }
14010 break;
14011
14012 case ARRAY_STRUCT:
14013 case UNSIZED_ARRAY_STRUCT:
14014 initialization = "{ ";
14015
14016 for (GLuint i = 0; i < 4; ++i)
14017 {
14018 initialization.append("{ ");
14019 initialization.append(getVectorInitializer(0 /* column */, test_case.m_n_rows));
14020 initialization.append(", ");
14021 initialization.append(getVectorInitializer(2 /* column */, test_case.m_n_rows));
14022 initialization.append(" }");
14023
14024 if (i + 1 < 4)
14025 {
14026 initialization.append(", ");
14027 }
14028 }
14029
14030 initialization.append(" }");
14031
14032 break;
14033
14034 case NESTED_STRUCT_CTR:
14035 initialization = "StructureWithStructure(BasicStructure(";
14036 initialization.append(getVectorConstructor(0 /* column */, 4));
14037 initialization.append(", ");
14038 initialization.append(getVectorConstructor(2 /* column */, 4));
14039 initialization.append("), ");
14040 initialization.append(getVectorConstructor(3 /* column */, 4));
14041 initialization.append(")");
14042
14043 break;
14044
14045 case NESTED_STRUCT_LIST:
14046 initialization = "{ { ";
14047 initialization.append(getVectorInitializer(0 /* column */, 4));
14048 initialization.append(", ");
14049 initialization.append(getVectorInitializer(2 /* column */, 4));
14050 initialization.append(" }, ");
14051 initialization.append(getVectorInitializer(3 /* column */, 4));
14052 initialization.append(" }");
14053
14054 break;
14055
14056 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14057 initialization = "{ ";
14058 initialization.append(getVectorInitializer(0 /* column */, 4));
14059 initialization.append(", { ");
14060
14061 for (GLuint i = 0; i < 3; ++i)
14062 {
14063 initialization.append("{ ");
14064 initialization.append(getVectorInitializer(2 /* column */, 4));
14065 initialization.append(", ");
14066 initialization.append(getVectorInitializer(3 /* column */, 4));
14067 initialization.append(" }");
14068
14069 if (i + 1 < 3)
14070 {
14071 initialization.append(", ");
14072 }
14073 }
14074
14075 initialization.append(" } }");
14076
14077 break;
14078
14079 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14080 initialization = "{ ";
14081 initialization.append(getVectorConstructor(0 /* column */, 4));
14082 initialization.append(", { ");
14083
14084 for (GLuint i = 0; i < 3; ++i)
14085 {
14086 initialization.append("{ ");
14087 initialization.append(getVectorInitializer(2 /* column */, 4));
14088 initialization.append(", ");
14089 initialization.append(getVectorConstructor(3 /* column */, 4));
14090 initialization.append(" }");
14091
14092 if (i + 1 < 3)
14093 {
14094 initialization.append(", ");
14095 }
14096 }
14097
14098 initialization.append(" } }");
14099
14100 break;
14101
14102 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14103 initialization = "{ ";
14104
14105 for (GLuint i = 0; i < 4; ++i)
14106 {
14107 initialization.append("{ { ");
14108
14109 initialization.append(getVectorInitializer(0 /* column */, 4));
14110 initialization.append(", ");
14111 initialization.append(getVectorInitializer(1 /* column */, 4));
14112
14113 initialization.append(" }, ");
14114
14115 initialization.append(getVectorInitializer(2 /* column */, 4));
14116
14117 initialization.append(" }");
14118
14119 if (i + 1 < 4)
14120 {
14121 initialization.append(", ");
14122 }
14123 }
14124
14125 initialization.append(" }");
14126
14127 break;
14128
14129 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14130 initialization = "{\n";
14131
14132 for (GLuint i = 0; i < 2; ++i)
14133 {
14134 initialization.append("StructureWithStructure(\n");
14135 initialization.append("BasicStructure(");
14136
14137 initialization.append(getVectorConstructor(0 /* column */, 4));
14138 initialization.append(" , ");
14139 initialization.append(getVectorConstructor(1 /* column */, 4));
14140
14141 initialization.append("), ");
14142
14143 initialization.append(getVectorConstructor(2 /* column */, 4));
14144
14145 initialization.append(")");
14146
14147 initialization.append(" , ");
14148
14149 initialization.append("{ { ");
14150
14151 initialization.append(getVectorInitializer(0 /* column */, 4));
14152 initialization.append(", ");
14153 initialization.append(getVectorInitializer(1 /* column */, 4));
14154
14155 initialization.append(" }, ");
14156
14157 initialization.append(getVectorInitializer(2 /* column */, 4));
14158
14159 initialization.append(" }");
14160
14161 if (i + 1 < 2)
14162 {
14163 initialization.append(" , ");
14164 }
14165 }
14166
14167 initialization.append(" }");
14168
14169 break;
14170
14171 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14172 initialization = "{ ";
14173 initialization.append("{ ");
14174 initialization.append(getVectorInitializer(0 /* column */, 4));
14175 initialization.append(", ");
14176 initialization.append("{ ");
14177 initialization.append(getVectorInitializer(1 /* column */, 4));
14178 initialization.append(", ");
14179 initialization.append(getVectorInitializer(2 /* column */, 4));
14180 initialization.append(" }");
14181 initialization.append(" }");
14182 initialization.append(", ");
14183 initialization.append(getVectorInitializer(3 /* column */, 4));
14184 initialization.append(" }");
14185
14186 break;
14187
14188 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14189 initialization = "StructureWithStructureWithArray(";
14190 initialization.append("StructureWithArray(");
14191 initialization.append(getVectorConstructor(0 /* column */, 4));
14192 initialization.append(" , vec4[2]( ");
14193 initialization.append(getVectorConstructor(1 /* column */, 4));
14194 initialization.append(" , ");
14195 initialization.append(getVectorConstructor(2 /* column */, 4));
14196 initialization.append(" )");
14197 initialization.append(")");
14198 initialization.append(" , ");
14199 initialization.append(getVectorConstructor(3 /* column */, 4));
14200 initialization.append(")");
14201
14202 break;
14203
14204 default:
14205 TCU_FAIL("Invalid enum");
14206 }
14207
14208 return initialization;
14209 }
14210
14211 /** Logs description of current test case
14212 *
14213 **/
logTestCaseName()14214 void InitializerListTest::logTestCaseName()
14215 {
14216 const testCase& test_case = m_test_cases[m_current_test_case_index];
14217
14218 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
14219
14220 switch (test_case.m_initializer)
14221 {
14222 case VECTOR:
14223 message << "List. Single vec" << test_case.m_n_rows;
14224 break;
14225 case MATRIX:
14226 message << "List. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14227 break;
14228 case MATRIX_ROWS:
14229 message << "Ctr. Single mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14230 break;
14231 case STRUCT:
14232 message << "List. Structure";
14233 break;
14234 case NESTED_STRUCT_CTR:
14235 message << "Ctr. Nested structure";
14236 break;
14237 case NESTED_STRUCT_LIST:
14238 message << "List. Nested structure";
14239 break;
14240 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14241 message << "List. Structure with structure array";
14242 break;
14243 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14244 message << "Mix. Structure with structure array";
14245 break;
14246 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14247 message << "List. Structure with structure with array";
14248 break;
14249 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14250 message << "Mix. Structure with structure with array";
14251 break;
14252 case ARRAY_SCALAR:
14253 message << "List. Array of scalars";
14254 break;
14255 case ARRAY_VECTOR_CTR:
14256 message << "Ctr. Array of vec" << test_case.m_n_rows;
14257 break;
14258 case ARRAY_VECTOR_LIST:
14259 message << "List. Array of vec" << test_case.m_n_rows;
14260 break;
14261 case ARRAY_MATRIX_CTR:
14262 message << "Ctr. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14263 break;
14264 case ARRAY_MATRIX_LIST:
14265 message << "List. Array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14266 break;
14267 case ARRAY_STRUCT:
14268 message << "List. Array of structures";
14269 break;
14270 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14271 message << "List. Array of structures with structures";
14272 break;
14273 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14274 message << "Mix. Array of structures with structures";
14275 break;
14276 case UNSIZED_ARRAY_SCALAR:
14277 message << "List. Unsized array of scalars";
14278 break;
14279 case UNSIZED_ARRAY_VECTOR:
14280 message << "List. Unsized array of vec" << test_case.m_n_rows;
14281 break;
14282 case UNSIZED_ARRAY_MATRIX:
14283 message << "List. Unsized array of mat" << test_case.m_n_cols << "x" << test_case.m_n_rows;
14284 break;
14285 case UNSIZED_ARRAY_STRUCT:
14286 message << "List. Unsized array of structures";
14287 break;
14288 default:
14289 TCU_FAIL("Invalid enum");
14290 }
14291
14292 message << tcu::TestLog::EndMessage;
14293 }
14294
14295 /** Get string representing sum for current test case
14296 *
14297 * @return String
14298 **/
getSum()14299 std::string InitializerListTest::getSum()
14300 {
14301 static const GLchar* var = "variable";
14302
14303 const testCase& test_case = m_test_cases[m_current_test_case_index];
14304
14305 std::string sum;
14306
14307 switch (test_case.m_initializer)
14308 {
14309 case VECTOR:
14310 sum = getVectorSum(var, test_case.m_n_rows);
14311
14312 break;
14313
14314 case MATRIX:
14315 case MATRIX_ROWS:
14316 sum = getVectorArraySum("variable[INDEX]", test_case.m_n_cols, test_case.m_n_rows);
14317
14318 break;
14319
14320 case STRUCT:
14321 sum = getVectorSum("variable.member_a", test_case.m_n_rows);
14322 sum.append(" + ");
14323 sum.append(getVectorSum("variable.member_b", test_case.m_n_rows));
14324
14325 break;
14326
14327 case ARRAY_SCALAR:
14328 case UNSIZED_ARRAY_SCALAR:
14329 sum = "variable[0] + variable[1] + variable[2] + variable[3]";
14330
14331 break;
14332
14333 case ARRAY_VECTOR_LIST:
14334 case ARRAY_VECTOR_CTR:
14335 case UNSIZED_ARRAY_VECTOR:
14336 sum = getVectorArraySum("variable[INDEX]", 4 /* columns */, test_case.m_n_rows);
14337
14338 break;
14339
14340 case ARRAY_MATRIX_LIST:
14341 case ARRAY_MATRIX_CTR:
14342 case UNSIZED_ARRAY_MATRIX:
14343 sum.append(getVectorArraySum("variable[0][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14344 sum.append(" + ");
14345 sum.append(getVectorArraySum("variable[1][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14346 sum.append(" + ");
14347 sum.append(getVectorArraySum("variable[2][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14348 sum.append(" + ");
14349 sum.append(getVectorArraySum("variable[3][INDEX]", test_case.m_n_cols, test_case.m_n_rows));
14350
14351 break;
14352
14353 case ARRAY_STRUCT:
14354 case UNSIZED_ARRAY_STRUCT:
14355 sum.append(getVectorArraySum("variable[INDEX].member_a", 4, test_case.m_n_rows));
14356 sum.append(" + ");
14357 sum.append(getVectorArraySum("variable[INDEX].member_b", 4, test_case.m_n_rows));
14358
14359 break;
14360
14361 case NESTED_STRUCT_CTR:
14362 case NESTED_STRUCT_LIST:
14363 sum.append(getVectorSum("variable.member_a.member_a", 4));
14364 sum.append(" + ");
14365 sum.append(getVectorSum("variable.member_a.member_b", 4));
14366 sum.append(" + ");
14367 sum.append(getVectorSum("variable.member_b", 4));
14368
14369 break;
14370
14371 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14372 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14373 sum.append(getVectorSum("variable.member_a", 4));
14374 sum.append(" + ");
14375 sum.append(getVectorArraySum("variable.member_b[INDEX].member_a", 3, 4));
14376 sum.append(" + ");
14377 sum.append(getVectorArraySum("variable.member_b[INDEX].member_b", 3, 4));
14378
14379 break;
14380
14381 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14382 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14383 sum.append(getVectorArraySum("variable[INDEX].member_a.member_a", 4, 4));
14384 sum.append(" + ");
14385 sum.append(getVectorArraySum("variable[INDEX].member_a.member_b", 4, 4));
14386 sum.append(" + ");
14387 sum.append(getVectorArraySum("variable[INDEX].member_b", 4, 4));
14388
14389 break;
14390
14391 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14392 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14393 sum.append(getVectorSum("variable.member_a.member_a", 4));
14394 sum.append(" + ");
14395 sum.append(getVectorArraySum("variable.member_a.member_b[INDEX]", 2, 4));
14396 sum.append(" + ");
14397 sum.append(getVectorSum("variable.member_b", 4));
14398
14399 break;
14400
14401 default:
14402 TCU_FAIL("Invalid enum");
14403 }
14404
14405 return sum;
14406 }
14407
14408 /** Get string representing types definition for current test case
14409 *
14410 * @return String
14411 **/
getTypeDefinition()14412 std::string InitializerListTest::getTypeDefinition()
14413 {
14414 const testCase& test_case = m_test_cases[m_current_test_case_index];
14415
14416 static const GLchar* basic_struct = "struct BasicStructure {\n"
14417 " vec4 member_a;\n"
14418 " vec4 member_b;\n"
14419 "};\n";
14420
14421 static const GLchar* struct_with_array = "struct StructureWithArray {\n"
14422 " vec4 member_a;\n"
14423 " vec4 member_b[2];\n"
14424 "};\n";
14425
14426 static const GLchar* struct_with_struct = "struct StructureWithStructure {\n"
14427 " BasicStructure member_a;\n"
14428 " vec4 member_b;\n"
14429 "};\n";
14430
14431 static const GLchar* struct_with_struct_array = "struct StructureWithStructArray {\n"
14432 " vec4 member_a;\n"
14433 " BasicStructure member_b[3];\n"
14434 "};\n";
14435
14436 static const GLchar* struct_with_struct_with_array = "struct StructureWithStructureWithArray {\n"
14437 " StructureWithArray member_a;\n"
14438 " vec4 member_b;\n"
14439 "};\n";
14440
14441 std::string type_definition;
14442
14443 switch (test_case.m_initializer)
14444 {
14445 case VECTOR:
14446 case MATRIX:
14447 case MATRIX_ROWS:
14448 case ARRAY_SCALAR:
14449 case ARRAY_VECTOR_CTR:
14450 case ARRAY_VECTOR_LIST:
14451 case ARRAY_MATRIX_CTR:
14452 case ARRAY_MATRIX_LIST:
14453 case UNSIZED_ARRAY_SCALAR:
14454 case UNSIZED_ARRAY_VECTOR:
14455 case UNSIZED_ARRAY_MATRIX:
14456 type_definition = "";
14457 break;
14458 case STRUCT:
14459 case ARRAY_STRUCT:
14460 case UNSIZED_ARRAY_STRUCT:
14461 type_definition = basic_struct;
14462 break;
14463 case NESTED_STRUCT_CTR:
14464 case NESTED_STRUCT_LIST:
14465 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14466 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14467 type_definition = basic_struct;
14468 type_definition.append(struct_with_struct);
14469 break;
14470 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14471 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14472 type_definition = basic_struct;
14473 type_definition.append(struct_with_struct_array);
14474 break;
14475 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14476 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14477 type_definition = struct_with_array;
14478 type_definition.append(struct_with_struct_with_array);
14479 break;
14480 default:
14481 TCU_FAIL("Invalid enum");
14482 }
14483
14484 return type_definition;
14485 }
14486
14487 /** Get string representing name of variable's type for current test case
14488 *
14489 * @return String
14490 **/
getTypeName()14491 std::string InitializerListTest::getTypeName()
14492 {
14493 const testCase& test_case = m_test_cases[m_current_test_case_index];
14494
14495 static const GLchar* basic_struct = "BasicStructure";
14496
14497 static const GLchar* struct_with_struct = "StructureWithStructure";
14498
14499 static const GLchar* struct_with_struct_array = "StructureWithStructArray";
14500
14501 static const GLchar* struct_with_struct_with_array = "StructureWithStructureWithArray";
14502
14503 std::string type_name;
14504
14505 switch (test_case.m_initializer)
14506 {
14507 case VECTOR:
14508 case MATRIX:
14509 case MATRIX_ROWS:
14510 case ARRAY_VECTOR_CTR:
14511 case ARRAY_VECTOR_LIST:
14512 case ARRAY_MATRIX_CTR:
14513 case ARRAY_MATRIX_LIST:
14514 case UNSIZED_ARRAY_VECTOR:
14515 case UNSIZED_ARRAY_MATRIX:
14516 type_name = Utils::getTypeName(Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows);
14517 break;
14518 case STRUCT:
14519 case ARRAY_STRUCT:
14520 case UNSIZED_ARRAY_STRUCT:
14521 type_name = basic_struct;
14522 break;
14523 case NESTED_STRUCT_CTR:
14524 case NESTED_STRUCT_LIST:
14525 case NESTED_ARRAY_STRUCT_STRUCT_LIST:
14526 case NESTED_ARRAY_STRUCT_STRUCT_MIX:
14527 type_name = struct_with_struct;
14528 break;
14529 case NESTED_STURCT_ARRAYS_STRUCT_LIST:
14530 case NESTED_STURCT_ARRAYS_STRUCT_MIX:
14531 type_name = struct_with_struct_array;
14532 break;
14533 case NESTED_STRUCT_STRUCT_ARRAY_LIST:
14534 case NESTED_STRUCT_STRUCT_ARRAY_MIX:
14535 type_name = struct_with_struct_with_array;
14536 break;
14537 case ARRAY_SCALAR:
14538 case UNSIZED_ARRAY_SCALAR:
14539 type_name = "float";
14540 break;
14541 default:
14542 TCU_FAIL("Invalid enum");
14543 }
14544
14545 return type_name;
14546 }
14547
14548 /** Get string representing array of vector constructors
14549 *
14550 * @param columns Number of columns
14551 * @param size Size of vector
14552 *
14553 * @return String
14554 **/
getVectorArrayCtr(GLuint columns,GLuint size)14555 std::string InitializerListTest::getVectorArrayCtr(GLuint columns, GLuint size)
14556 {
14557 std::string result;
14558
14559 for (GLuint col = 0; col < columns; ++col)
14560 {
14561 result.append(getVectorConstructor(col, size));
14562
14563 if (col + 1 < columns)
14564 {
14565 result.append(", ");
14566 }
14567 }
14568
14569 return result;
14570 }
14571
14572 /** Get string representing array of vector initializers
14573 *
14574 * @param columns Number of columns
14575 * @param size Size of vector
14576 *
14577 * @return String
14578 **/
getVectorArrayList(GLuint columns,GLuint size)14579 std::string InitializerListTest::getVectorArrayList(GLuint columns, GLuint size)
14580 {
14581 std::string result;
14582
14583 for (GLuint col = 0; col < columns; ++col)
14584 {
14585 result.append(getVectorInitializer(col, size));
14586
14587 if (col + 1 < columns)
14588 {
14589 result.append(", ");
14590 }
14591 }
14592
14593 return result;
14594 }
14595
14596 /** Get string representing vector constructor
14597 *
14598 * @param column Index of column of uni_matrix to use as data source
14599 * @param size Size of vector
14600 *
14601 * @return String
14602 **/
getVectorConstructor(GLuint column,GLuint size)14603 std::string InitializerListTest::getVectorConstructor(GLuint column, GLuint size)
14604 {
14605 const std::string& type_name = Utils::getTypeName(Utils::FLOAT, 1 /*n_cols*/, size);
14606
14607 std::string result;
14608
14609 result.append(type_name);
14610 result.append("(");
14611 result.append(getVectorValues(column, size));
14612 result.append(")");
14613
14614 return result;
14615 }
14616
14617 /** Get string representing vector initializer
14618 *
14619 * @param column Index of column of uni_matrix to use as data source
14620 * @param size Size of vector
14621 *
14622 * @return String
14623 **/
getVectorInitializer(GLuint column,GLuint size)14624 std::string InitializerListTest::getVectorInitializer(GLuint column, GLuint size)
14625 {
14626 std::string result;
14627
14628 result.append("{");
14629 result.append(getVectorValues(column, size));
14630 result.append("}");
14631
14632 return result;
14633 }
14634
14635 /** Get string representing sum of vector array. Token INDEX in name will be replaced with element index.
14636 *
14637 * @param array_name Name of array variable
14638 * @param columns Number of columns to sum
14639 * @param size Size of vector
14640 *
14641 * @return String
14642 **/
getVectorArraySum(const GLchar * array_name,GLuint columns,GLuint size)14643 std::string InitializerListTest::getVectorArraySum(const GLchar* array_name, GLuint columns, GLuint size)
14644 {
14645 static const GLchar* lut[] = { "0", "1", "2", "3" };
14646
14647 std::string sum;
14648
14649 for (GLuint i = 0; i < columns; ++i)
14650 {
14651 size_t position = 0;
14652 std::string name = array_name;
14653
14654 Utils::replaceToken("INDEX", position, lut[i], name);
14655
14656 sum.append(getVectorSum(name.c_str(), size));
14657
14658 if (i + 1 < columns)
14659 {
14660 sum.append(" + ");
14661 }
14662 }
14663
14664 return sum;
14665 }
14666
14667 /** Get string representing sum of vectors' elements
14668 *
14669 * @param vector_name Name of vector variable
14670 * @param size Size of vector
14671 *
14672 * @return String
14673 **/
getVectorSum(const GLchar * vector_name,GLuint size)14674 std::string InitializerListTest::getVectorSum(const GLchar* vector_name, GLuint size)
14675 {
14676 static const GLchar* lut[] = {
14677 ".x", ".y", ".z", ".w",
14678 };
14679
14680 std::string sum;
14681
14682 for (GLuint i = 0; i < size; ++i)
14683 {
14684 sum.append(vector_name);
14685 sum.append(lut[i]);
14686
14687 if (i + 1 < size)
14688 {
14689 sum.append(" + ");
14690 }
14691 }
14692
14693 return sum;
14694 }
14695
14696 /** Get string representing vector values
14697 *
14698 * @param column Index of column of uni_matrix to use as data source
14699 * @param size Size of vector
14700 *
14701 * @return String
14702 **/
getVectorValues(GLuint column,GLuint size)14703 std::string InitializerListTest::getVectorValues(GLuint column, GLuint size)
14704 {
14705 const GLchar* init_template = 0;
14706 const GLchar* column_index = 0;
14707
14708 switch (size)
14709 {
14710 case 2:
14711 init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y";
14712 break;
14713 case 3:
14714 init_template = "uni_matrix[COLUMN].x, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z";
14715 break;
14716 case 4:
14717 init_template = "uni_matrix[COLUMN].z, uni_matrix[COLUMN].y, uni_matrix[COLUMN].z, uni_matrix[COLUMN].w";
14718 break;
14719 }
14720
14721 switch (column)
14722 {
14723 case 0:
14724 column_index = "0";
14725 break;
14726 case 1:
14727 column_index = "1";
14728 break;
14729 case 2:
14730 column_index = "2";
14731 break;
14732 case 3:
14733 column_index = "3";
14734 break;
14735 }
14736
14737 std::string initializer = init_template;
14738
14739 Utils::replaceAllTokens("COLUMN", column_index, initializer);
14740
14741 return initializer;
14742 }
14743
14744 /** Constructor
14745 *
14746 * @param context Test context
14747 **/
InitializerListNegativeTest(deqp::Context & context)14748 InitializerListNegativeTest::InitializerListNegativeTest(deqp::Context& context)
14749 : NegativeTestBase(context, "initializer_list_negative", "Verifies invalid initializers")
14750 , m_current_test_case_index(0)
14751 {
14752 /* Nothing to be done here */
14753 }
14754
14755 /** Set up next test case
14756 *
14757 * @param test_case_index Index of next test case
14758 *
14759 * @return false if there is no more test cases, true otherwise
14760 **/
prepareNextTestCase(glw::GLuint test_case_index)14761 bool InitializerListNegativeTest::prepareNextTestCase(glw::GLuint test_case_index)
14762 {
14763 m_current_test_case_index = test_case_index;
14764
14765 if ((glw::GLuint)-1 == test_case_index)
14766 {
14767 m_current_test_case_index = 0;
14768 return true;
14769 }
14770 else if (m_test_cases.size() <= test_case_index)
14771 {
14772 return false;
14773 }
14774
14775 logTestCaseName();
14776
14777 return true;
14778 }
14779
14780 /** Prepare source for given shader stage
14781 *
14782 * @param in_stage Shader stage, compute shader will use 430
14783 * @param in_use_version_400 Select if 400 or 420 should be used
14784 * @param out_source Prepared shader source instance
14785 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)14786 void InitializerListNegativeTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
14787 Utils::shaderSource& out_source)
14788 {
14789 static const GLchar* verification_snippet = " TYPE_NAME variable = INITIALIZATION;\n"
14790 "\n"
14791 " float sum = SUM;\n"
14792 "\n"
14793 " if (0 != sum)\n"
14794 " {\n"
14795 " result = vec4(1, 0, 0, 1);\n"
14796 " }\n";
14797
14798 static const GLchar* compute_shader_template =
14799 "VERSION\n"
14800 "\n"
14801 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
14802 "\n"
14803 "writeonly uniform image2D uni_image;\n"
14804 "\n"
14805 "TYPE_DEFINITION\n"
14806 "\n"
14807 "void main()\n"
14808 "{\n"
14809 " vec4 result = vec4(0, 1, 0, 1);\n"
14810 "\n"
14811 "VERIFICATION"
14812 "\n"
14813 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
14814 "}\n"
14815 "\n";
14816
14817 static const GLchar* fragment_shader_template = "VERSION\n"
14818 "\n"
14819 "in vec4 gs_fs_result;\n"
14820 "out vec4 fs_out_result;\n"
14821 "\n"
14822 "TYPE_DEFINITION\n"
14823 "\n"
14824 "void main()\n"
14825 "{\n"
14826 " vec4 result = vec4(0, 1, 0, 1);\n"
14827 "\n"
14828 "VERIFICATION"
14829 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
14830 " {\n"
14831 " result = vec4(1, 0, 0, 1);\n"
14832 " }\n"
14833 "\n"
14834 " fs_out_result = result;\n"
14835 "}\n"
14836 "\n";
14837
14838 static const GLchar* geometry_shader_template = "VERSION\n"
14839 "\n"
14840 "layout(points) in;\n"
14841 "layout(triangle_strip, max_vertices = 4) out;\n"
14842 "\n"
14843 "in vec4 tes_gs_result[];\n"
14844 "out vec4 gs_fs_result;\n"
14845 "\n"
14846 "TYPE_DEFINITION\n"
14847 "\n"
14848 "void main()\n"
14849 "{\n"
14850 " vec4 result = vec4(0, 1, 0, 1);\n"
14851 "\n"
14852 "VERIFICATION"
14853 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
14854 " {\n"
14855 " result = vec4(1, 0, 0, 1);\n"
14856 " }\n"
14857 "\n"
14858 " gs_fs_result = result;\n"
14859 " gl_Position = vec4(-1, -1, 0, 1);\n"
14860 " EmitVertex();\n"
14861 " gs_fs_result = result;\n"
14862 " gl_Position = vec4(-1, 1, 0, 1);\n"
14863 " EmitVertex();\n"
14864 " gs_fs_result = result;\n"
14865 " gl_Position = vec4(1, -1, 0, 1);\n"
14866 " EmitVertex();\n"
14867 " gs_fs_result = result;\n"
14868 " gl_Position = vec4(1, 1, 0, 1);\n"
14869 " EmitVertex();\n"
14870 "}\n"
14871 "\n";
14872
14873 static const GLchar* tess_ctrl_shader_template =
14874 "VERSION\n"
14875 "\n"
14876 "layout(vertices = 1) out;\n"
14877 "\n"
14878 "in vec4 vs_tcs_result[];\n"
14879 "out vec4 tcs_tes_result[];\n"
14880 "\n"
14881 "TYPE_DEFINITION\n"
14882 "\n"
14883 "void main()\n"
14884 "{\n"
14885 " vec4 result = vec4(0, 1, 0, 1);\n"
14886 "\n"
14887 "VERIFICATION"
14888 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
14889 " {\n"
14890 " result = vec4(1, 0, 0, 1);\n"
14891 " }\n"
14892 "\n"
14893 " tcs_tes_result[gl_InvocationID] = result;\n"
14894 "\n"
14895 " gl_TessLevelOuter[0] = 1.0;\n"
14896 " gl_TessLevelOuter[1] = 1.0;\n"
14897 " gl_TessLevelOuter[2] = 1.0;\n"
14898 " gl_TessLevelOuter[3] = 1.0;\n"
14899 " gl_TessLevelInner[0] = 1.0;\n"
14900 " gl_TessLevelInner[1] = 1.0;\n"
14901 "}\n"
14902 "\n";
14903
14904 static const GLchar* tess_eval_shader_template = "VERSION\n"
14905 "\n"
14906 "layout(isolines, point_mode) in;\n"
14907 "\n"
14908 "in vec4 tcs_tes_result[];\n"
14909 "out vec4 tes_gs_result;\n"
14910 "\n"
14911 "TYPE_DEFINITION\n"
14912 "\n"
14913 "void main()\n"
14914 "{\n"
14915 " vec4 result = vec4(0, 1, 0, 1);\n"
14916 "\n"
14917 "VERIFICATION"
14918 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
14919 " {\n"
14920 " result = vec4(1, 0, 0, 1);\n"
14921 " }\n"
14922 "\n"
14923 " tes_gs_result = result;\n"
14924 "}\n"
14925 "\n";
14926
14927 static const GLchar* vertex_shader_template = "VERSION\n"
14928 "\n"
14929 "out vec4 vs_tcs_result;\n"
14930 "\n"
14931 "TYPE_DEFINITION\n"
14932 "\n"
14933 "void main()\n"
14934 "{\n"
14935 " vec4 result = vec4(0, 1, 0, 1);\n"
14936 "\n"
14937 "VERIFICATION"
14938 "\n"
14939 " vs_tcs_result = result;\n"
14940 "}\n"
14941 "\n";
14942
14943 const std::string& initialization = getInitialization();
14944 const GLchar* shader_template = 0;
14945 const std::string& sum = getSum();
14946 const std::string& type_definition = getTypeDefinition();
14947 const std::string& type_name = getTypeName();
14948
14949 switch (in_stage)
14950 {
14951 case Utils::COMPUTE_SHADER:
14952 shader_template = compute_shader_template;
14953 break;
14954 case Utils::FRAGMENT_SHADER:
14955 shader_template = fragment_shader_template;
14956 break;
14957 case Utils::GEOMETRY_SHADER:
14958 shader_template = geometry_shader_template;
14959 break;
14960 case Utils::TESS_CTRL_SHADER:
14961 shader_template = tess_ctrl_shader_template;
14962 break;
14963 case Utils::TESS_EVAL_SHADER:
14964 shader_template = tess_eval_shader_template;
14965 break;
14966 case Utils::VERTEX_SHADER:
14967 shader_template = vertex_shader_template;
14968 break;
14969 default:
14970 TCU_FAIL("Invalid enum");
14971 }
14972
14973 out_source.m_parts[0].m_code = shader_template;
14974
14975 size_t position = 0;
14976 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
14977 out_source.m_parts[0].m_code);
14978
14979 Utils::replaceToken("TYPE_DEFINITION", position, type_definition.c_str(), out_source.m_parts[0].m_code);
14980
14981 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
14982
14983 position -= strlen(verification_snippet);
14984
14985 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
14986
14987 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
14988
14989 Utils::replaceToken("SUM", position, sum.c_str(), out_source.m_parts[0].m_code);
14990 }
14991
14992 /** Prepare test cases
14993 *
14994 * @return true
14995 **/
testInit()14996 bool InitializerListNegativeTest::testInit()
14997 {
14998 for (GLuint i = 0; i < TESTED_ERRORS_MAX; ++i)
14999 {
15000 const TESTED_ERRORS error = (TESTED_ERRORS)i;
15001
15002 m_test_cases.push_back(error);
15003 }
15004
15005 return true;
15006 }
15007
15008 /** Get string representing initialization list for current test case
15009 *
15010 * @return String
15011 **/
getInitialization()15012 std::string InitializerListNegativeTest::getInitialization()
15013 {
15014 const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15015
15016 std::string initialization;
15017
15018 switch (error)
15019 {
15020 case TYPE_UIVEC_BOOL:
15021 initialization = "{ true, 0, 1, 2 }";
15022
15023 break;
15024
15025 case TYPE_IVEC_BOOL:
15026 initialization = "{ true, 0, -1, 2 }";
15027
15028 break;
15029
15030 case TYPE_VEC_BOOL:
15031 initialization = "{ true, 0.125, 0.25, 0.375 }";
15032
15033 break;
15034
15035 case TYPE_MAT_BOOL:
15036 initialization = "{ {false, 0, 1, 1}, {0, 1, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15037
15038 break;
15039
15040 case COMPONENTS_VEC_LESS:
15041 case COMPONENTS_VEC_MORE:
15042 initialization = "{ 0, 0.25, 0.375 }";
15043
15044 break;
15045
15046 case COMPONENTS_MAT_LESS_ROWS:
15047 initialization = "{ {0, 0, 1, 1}, {0, 0, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15048
15049 break;
15050
15051 case COMPONENTS_MAT_MORE_ROWS:
15052 initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1, 0}, {1, 0, 1} }";
15053
15054 break;
15055
15056 case COMPONENTS_MAT_LESS_COLUMNS:
15057 initialization = "{ {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }";
15058
15059 break;
15060
15061 case COMPONENTS_MAT_MORE_COLUMNS:
15062 initialization = "{ {0, 0, 1}, {0, 0, 1}, {1, 0, 1}, {1, 0, 1} }";
15063
15064 break;
15065
15066 case LIST_IN_CONSTRUCTOR:
15067 initialization = "Struct( { vec4(0, 1, 0, 1), vec3(0, 1, 0) }, vec4(1, 0, 1, 0) )";
15068
15069 break;
15070
15071 case STRUCT_LAYOUT_MEMBER_TYPE:
15072 initialization = "{ { {0, 1, 0, 1}, vec4(0, 1, 0, 1) }, vec4(1, 0, 1, 0) }";
15073
15074 break;
15075
15076 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15077 initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } , vec4(1, 0, 1, 0), vec4(1, 0, 1, 0) }";
15078
15079 break;
15080
15081 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15082 initialization = "{ { {0, 1, 0, 1}, vec3(0, 1, 0) } }";
15083
15084 break;
15085
15086 case STRUCT_LAYOUT_MEMBER_ORDER:
15087 initialization = "{ vec4(1, 0, 1, 0), { vec3(0, 1, 0) , {0, 1, 0, 1} } }";
15088
15089 break;
15090
15091 default:
15092 TCU_FAIL("Invalid enum");
15093 }
15094
15095 return initialization;
15096 }
15097
15098 /** Logs description of current test case
15099 *
15100 **/
logTestCaseName()15101 void InitializerListNegativeTest::logTestCaseName()
15102 {
15103 const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15104
15105 tcu::MessageBuilder message = m_context.getTestContext().getLog() << tcu::TestLog::Message;
15106
15107 switch (error)
15108 {
15109 case TYPE_UIVEC_BOOL:
15110 message << "Wrong type in uvec initializer list";
15111 break;
15112 case TYPE_IVEC_BOOL:
15113 message << "Wrong type in ivec initializer list";
15114 break;
15115 case TYPE_VEC_BOOL:
15116 message << "Wrong type in vec initializer list";
15117 break;
15118 case TYPE_MAT_BOOL:
15119 message << "Wrong type in mat initializer list";
15120 break;
15121 case COMPONENTS_VEC_LESS:
15122 message << "Wrong number of componenets in vec initialize list - less";
15123 break;
15124 case COMPONENTS_VEC_MORE:
15125 message << "Wrong number of componenets in vec initialize list - more";
15126 break;
15127 case COMPONENTS_MAT_LESS_ROWS:
15128 message << "Wrong number of componenets in mat initialize list - less rows";
15129 break;
15130 case COMPONENTS_MAT_LESS_COLUMNS:
15131 message << "Wrong number of componenets in mat initialize list - less columns";
15132 break;
15133 case COMPONENTS_MAT_MORE_ROWS:
15134 message << "Wrong number of componenets in mat initialize list - more rows";
15135 break;
15136 case COMPONENTS_MAT_MORE_COLUMNS:
15137 message << "Wrong number of componenets in mat initialize list - more columns";
15138 break;
15139 case LIST_IN_CONSTRUCTOR:
15140 message << "Initializer list in constructor";
15141 break;
15142 case STRUCT_LAYOUT_MEMBER_TYPE:
15143 message << "Wrong type of structure member";
15144 break;
15145 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15146 message << "Wrong number of structure members - more";
15147 break;
15148 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15149 message << "Wrong number of structure members - less";
15150 break;
15151 case STRUCT_LAYOUT_MEMBER_ORDER:
15152 message << "Wrong order of structure members";
15153 break;
15154 default:
15155 TCU_FAIL("Invalid enum");
15156 }
15157
15158 message << tcu::TestLog::EndMessage;
15159 }
15160
15161 /** Get string representing sum for current test case
15162 *
15163 * @return String
15164 **/
getSum()15165 std::string InitializerListNegativeTest::getSum()
15166 {
15167 const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15168
15169 std::string sum;
15170
15171 switch (error)
15172 {
15173 case TYPE_UIVEC_BOOL:
15174 case TYPE_IVEC_BOOL:
15175 case TYPE_VEC_BOOL:
15176 case COMPONENTS_VEC_LESS:
15177 sum = "variable.x + variable.y + variable.z + variable.w";
15178 break;
15179 case TYPE_MAT_BOOL:
15180 case COMPONENTS_MAT_LESS_ROWS:
15181 case COMPONENTS_MAT_LESS_COLUMNS:
15182 sum = "variable[0].x + variable[0].y + variable[0].z + variable[0].w + "
15183 "variable[1].x + variable[1].y + variable[1].z + variable[1].w + "
15184 "variable[2].x + variable[2].y + variable[2].z + variable[2].w + "
15185 "variable[3].x + variable[3].y + variable[3].z + variable[3].w";
15186 break;
15187 case COMPONENTS_VEC_MORE:
15188 sum = "variable.x + variable.y + variable.z";
15189 break;
15190 case COMPONENTS_MAT_MORE_ROWS:
15191 case COMPONENTS_MAT_MORE_COLUMNS:
15192 sum = "variable[0].x + variable[0].y + variable[0].z"
15193 "variable[1].x + variable[1].y + variable[1].z"
15194 "variable[2].x + variable[2].y + variable[2].z";
15195 break;
15196 case LIST_IN_CONSTRUCTOR:
15197 case STRUCT_LAYOUT_MEMBER_TYPE:
15198 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15199 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15200 case STRUCT_LAYOUT_MEMBER_ORDER:
15201 sum = "variable.member_a.member_a.x + variable.member_a.member_a.y + variable.member_a.member_a.z + "
15202 "variable.member_a.member_a.w + "
15203 "variable.member_a.member_b.x + variable.member_a.member_b.y + variable.member_a.member_b.z + "
15204 "variable.member_b.x + variable.member_b.y + variable.member_b.z + variable.member_b.w";
15205 break;
15206 default:
15207 TCU_FAIL("Invalid enum");
15208 }
15209
15210 return sum;
15211 }
15212
15213 /** Get string representing types definition for current test case
15214 *
15215 * @return String
15216 **/
getTypeDefinition()15217 std::string InitializerListNegativeTest::getTypeDefinition()
15218 {
15219 const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15220
15221 static const GLchar* struct_def = "struct BasicStructure {\n"
15222 " vec4 member_a;\n"
15223 " vec3 member_b;\n"
15224 "};\n"
15225 "\n"
15226 "struct StructureWithStructure {\n"
15227 " BasicStructure member_a;\n"
15228 " vec4 member_b;\n"
15229 "};\n";
15230
15231 std::string type_definition;
15232
15233 switch (error)
15234 {
15235 case TYPE_UIVEC_BOOL:
15236 case TYPE_IVEC_BOOL:
15237 case TYPE_VEC_BOOL:
15238 case TYPE_MAT_BOOL:
15239 case COMPONENTS_VEC_LESS:
15240 case COMPONENTS_VEC_MORE:
15241 case COMPONENTS_MAT_LESS_ROWS:
15242 case COMPONENTS_MAT_LESS_COLUMNS:
15243 case COMPONENTS_MAT_MORE_ROWS:
15244 case COMPONENTS_MAT_MORE_COLUMNS:
15245 type_definition = "";
15246 break;
15247 case LIST_IN_CONSTRUCTOR:
15248 case STRUCT_LAYOUT_MEMBER_TYPE:
15249 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15250 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15251 case STRUCT_LAYOUT_MEMBER_ORDER:
15252 type_definition = struct_def;
15253 break;
15254 default:
15255 TCU_FAIL("Invalid enum");
15256 }
15257
15258 return type_definition;
15259 }
15260
15261 /** Get string representing name of variable's type for current test case
15262 *
15263 * @return String
15264 **/
getTypeName()15265 std::string InitializerListNegativeTest::getTypeName()
15266 {
15267 const TESTED_ERRORS& error = m_test_cases[m_current_test_case_index];
15268
15269 static const GLchar* struct_with_struct = "StructureWithStructure";
15270
15271 std::string type_name;
15272
15273 switch (error)
15274 {
15275 case TYPE_UIVEC_BOOL:
15276 type_name = "uvec4";
15277 break;
15278 case TYPE_IVEC_BOOL:
15279 type_name = "ivec4";
15280 break;
15281 case TYPE_VEC_BOOL:
15282 case COMPONENTS_VEC_LESS:
15283 type_name = "vec4";
15284 break;
15285 case COMPONENTS_VEC_MORE:
15286 type_name = "vec2";
15287 break;
15288 case TYPE_MAT_BOOL:
15289 case COMPONENTS_MAT_LESS_ROWS:
15290 case COMPONENTS_MAT_LESS_COLUMNS:
15291 type_name = "mat4";
15292 break;
15293 case COMPONENTS_MAT_MORE_ROWS:
15294 case COMPONENTS_MAT_MORE_COLUMNS:
15295 type_name = "mat3";
15296 break;
15297 case LIST_IN_CONSTRUCTOR:
15298 case STRUCT_LAYOUT_MEMBER_TYPE:
15299 case STRUCT_LAYOUT_MEMBER_COUNT_MORE:
15300 case STRUCT_LAYOUT_MEMBER_COUNT_LESS:
15301 case STRUCT_LAYOUT_MEMBER_ORDER:
15302 type_name = struct_with_struct;
15303 break;
15304 default:
15305 TCU_FAIL("Invalid enum");
15306 }
15307
15308 return type_name;
15309 }
15310
15311 /** Constructor
15312 *
15313 * @param context Test context
15314 **/
LengthOfVectorAndMatrixTest(deqp::Context & context)15315 LengthOfVectorAndMatrixTest::LengthOfVectorAndMatrixTest(deqp::Context& context)
15316 : GLSLTestBase(context, "length_of_vector_and_matrix", "Test verifies .length() for vectors and matrices")
15317 {
15318 /* Nothing to be done here */
15319 }
15320
15321 /** Set up next test case
15322 *
15323 * @param test_case_index Index of next test case
15324 *
15325 * @return false if there is no more test cases, true otherwise
15326 **/
prepareNextTestCase(glw::GLuint test_case_index)15327 bool LengthOfVectorAndMatrixTest::prepareNextTestCase(glw::GLuint test_case_index)
15328 {
15329 m_current_test_case_index = test_case_index;
15330
15331 if ((glw::GLuint)-1 == test_case_index)
15332 {
15333 m_current_test_case_index = 0;
15334 return true;
15335 }
15336 else if (m_test_cases.size() <= test_case_index)
15337 {
15338 return false;
15339 }
15340
15341 const testCase& test_case = m_test_cases[m_current_test_case_index];
15342
15343 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Tested type: "
15344 << Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows)
15345 << tcu::TestLog::EndMessage;
15346
15347 return true;
15348 }
15349
15350 /** Prepare source for given shader stage
15351 *
15352 * @param in_stage Shader stage, compute shader will use 430
15353 * @param in_use_version_400 Select if 400 or 420 should be used
15354 * @param out_source Prepared shader source instance
15355 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15356 void LengthOfVectorAndMatrixTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15357 Utils::shaderSource& out_source)
15358 {
15359 if (Utils::COMPUTE_SHADER == in_stage)
15360 {
15361 m_is_compute_program = true;
15362 prepareComputeShaderSource(out_source);
15363 }
15364 else
15365 {
15366 m_is_compute_program = false;
15367 prepareDrawShaderSource(in_stage, in_use_version_400, out_source);
15368 }
15369 }
15370
15371 /** Overwritte of prepareUniforms method
15372 *
15373 * @param program Current program
15374 **/
prepareUniforms(Utils::program & program)15375 void LengthOfVectorAndMatrixTest::prepareUniforms(Utils::program& program)
15376 {
15377 static const GLfloat float_value = 0.125;
15378 static const GLint int_value = -1;
15379 static const GLuint uint_value = 1;
15380
15381 static const GLfloat float_data[16] = { float_value, float_value, float_value, float_value,
15382 float_value, float_value, float_value, float_value,
15383 float_value, float_value, float_value, float_value,
15384 float_value, float_value, float_value, float_value };
15385
15386 static const GLint int_data[4] = { int_value, int_value, int_value, int_value };
15387
15388 static const GLuint uint_data[4] = { uint_value, uint_value, uint_value, uint_value };
15389
15390 if (false == m_is_compute_program)
15391 {
15392 return;
15393 }
15394
15395 const testCase& test_case = m_test_cases[m_current_test_case_index];
15396
15397 switch (test_case.m_type)
15398 {
15399 case Utils::FLOAT:
15400 program.uniform("uni_variable", Utils::FLOAT, test_case.m_n_cols, test_case.m_n_rows, float_data);
15401 break;
15402 case Utils::INT:
15403 program.uniform("uni_variable", Utils::INT, 1 /* columns */, test_case.m_n_rows, int_data);
15404 break;
15405 case Utils::UINT:
15406 program.uniform("uni_variable", Utils::UINT, 1 /* columns */, test_case.m_n_rows, uint_data);
15407 break;
15408 default:
15409 TCU_FAIL("Invalid enum");
15410 }
15411 }
15412
15413 /** Prepare vertex buffer
15414 *
15415 * @param program Program object
15416 * @param buffer Vertex buffer
15417 * @param vao Vertex array object
15418 *
15419 * @return 0
15420 **/
prepareVertexBuffer(const Utils::program & program,Utils::buffer & buffer,Utils::vertexArray & vao)15421 void LengthOfVectorAndMatrixTest::prepareVertexBuffer(const Utils::program& program, Utils::buffer& buffer,
15422 Utils::vertexArray& vao)
15423 {
15424 static const GLfloat float_value = 0.125f;
15425 static const GLint int_value = -1;
15426 static const GLuint uint_value = 1;
15427
15428 static const GLfloat float_data[16] = { float_value, float_value, float_value, float_value,
15429 float_value, float_value, float_value, float_value,
15430 float_value, float_value, float_value, float_value,
15431 float_value, float_value, float_value, float_value };
15432
15433 static const GLint int_data[4] = { int_value, int_value, int_value, int_value };
15434
15435 static const GLuint uint_data[4] = { uint_value, uint_value, uint_value, uint_value };
15436
15437 const testCase& test_case = m_test_cases[m_current_test_case_index];
15438
15439 std::string variable_name = Utils::getVariableName(Utils::VERTEX_SHADER, Utils::INPUT, "variable");
15440 GLint variable_loc = program.getAttribLocation(variable_name.c_str());
15441
15442 if (-1 == variable_loc)
15443 {
15444 TCU_FAIL("Vertex attribute location is invalid");
15445 }
15446
15447 vao.generate();
15448 vao.bind();
15449
15450 buffer.generate(GL_ARRAY_BUFFER);
15451
15452 GLvoid* data_ptr = 0;
15453 GLsizeiptr data_size = 0;
15454
15455 switch (test_case.m_type)
15456 {
15457 case Utils::FLOAT:
15458 data_ptr = (GLvoid*)float_data;
15459 data_size = sizeof(float_data);
15460 break;
15461 case Utils::INT:
15462 data_ptr = (GLvoid*)int_data;
15463 data_size = sizeof(int_data);
15464 break;
15465 case Utils::UINT:
15466 data_ptr = (GLvoid*)uint_data;
15467 data_size = sizeof(uint_data);
15468 break;
15469 default:
15470 TCU_FAIL("Invalid enum");
15471 }
15472
15473 buffer.update(data_size, data_ptr, GL_STATIC_DRAW);
15474
15475 /* GL entry points */
15476 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
15477
15478 /* Set up vao */
15479 switch (test_case.m_type)
15480 {
15481 case Utils::FLOAT:
15482 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15483 {
15484 const GLuint index = variable_loc + col;
15485 const GLint size = test_case.m_n_rows;
15486 const GLvoid* offset = (const GLvoid*)(test_case.m_n_rows * sizeof(GLfloat) * col);
15487
15488 gl.vertexAttribPointer(index, size, GL_FLOAT /* type */, GL_FALSE /* normalized*/, 0, offset);
15489 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
15490 }
15491 break;
15492 case Utils::INT:
15493 gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_INT /* type */, 0 /* stride */,
15494 0 /* offset */);
15495 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15496 break;
15497 case Utils::UINT:
15498 gl.vertexAttribIPointer(variable_loc, test_case.m_n_rows /* size */, GL_UNSIGNED_INT /* type */, 0 /* stride */,
15499 0 /* offset */);
15500 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
15501 break;
15502 default:
15503 DE_ASSERT(0);
15504 break;
15505 }
15506
15507 /* Enable attribute */
15508 for (GLuint col = 0; col < test_case.m_n_cols; ++col)
15509 {
15510 gl.enableVertexAttribArray(variable_loc + col);
15511 GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
15512 }
15513 }
15514
15515 /** Prepare test cases
15516 *
15517 * @return true
15518 **/
testInit()15519 bool LengthOfVectorAndMatrixTest::testInit()
15520 {
15521 /* Vectors */
15522 for (GLuint row = 2; row <= 4; ++row)
15523 {
15524 testCase test_case = { Utils::UINT, 1 /* n_cols */, row };
15525
15526 m_test_cases.push_back(test_case);
15527 }
15528
15529 for (GLuint row = 2; row <= 4; ++row)
15530 {
15531 testCase test_case = { Utils::INT, 1 /* n_cols */, row };
15532
15533 m_test_cases.push_back(test_case);
15534 }
15535
15536 for (GLuint row = 2; row <= 4; ++row)
15537 {
15538 testCase test_case = { Utils::FLOAT, 1 /* n_cols */, row };
15539
15540 m_test_cases.push_back(test_case);
15541 }
15542
15543 /* Matrices */
15544 for (GLuint col = 2; col <= 4; ++col)
15545 {
15546 for (GLuint row = 2; row <= 4; ++row)
15547 {
15548 testCase test_case = { Utils::FLOAT, col, row };
15549
15550 m_test_cases.push_back(test_case);
15551 }
15552 }
15553
15554 return true;
15555 }
15556
15557 /** Get string representing value that should be placed at token EXPECTED_VALUE
15558 *
15559 * @param in_stage Shader stage
15560 *
15561 * @return String with value
15562 **/
getExpectedValue(Utils::SHADER_STAGES in_stage)15563 std::string LengthOfVectorAndMatrixTest::getExpectedValue(Utils::SHADER_STAGES in_stage)
15564 {
15565 const testCase& test_case = m_test_cases[m_current_test_case_index];
15566
15567 GLuint count = 0;
15568
15569 switch (in_stage)
15570 {
15571 case Utils::FRAGMENT_SHADER:
15572 count = 3;
15573 break;
15574 case Utils::COMPUTE_SHADER:
15575 count = 2;
15576 break;
15577 default:
15578 count = 4;
15579 }
15580
15581 if (1 == test_case.m_n_cols)
15582 {
15583 count *= test_case.m_n_rows;
15584 }
15585 else
15586 {
15587 count *= test_case.m_n_cols;
15588 }
15589
15590 std::string expected_value;
15591 expected_value.resize(64, 0);
15592
15593 switch (test_case.m_type)
15594 {
15595 case Utils::FLOAT:
15596 {
15597 GLfloat value = 0.125f * (GLfloat)count;
15598 sprintf(&expected_value[0], "%f", value);
15599 }
15600 break;
15601 case Utils::INT:
15602 {
15603 GLint value = -1 * (GLint)count;
15604 sprintf(&expected_value[0], "%d", value);
15605 }
15606 break;
15607 case Utils::UINT:
15608 {
15609 GLuint value = 1 * (GLuint)count;
15610 sprintf(&expected_value[0], "%d", value);
15611 }
15612 break;
15613 default:
15614 DE_ASSERT(0);
15615 break;
15616 }
15617
15618 return expected_value;
15619 }
15620
15621 /** Get string reresenting initialization of local variables for current test case
15622 *
15623 * @return String with initialization
15624 **/
getInitialization()15625 std::string LengthOfVectorAndMatrixTest::getInitialization()
15626 {
15627 const testCase& test_case = m_test_cases[m_current_test_case_index];
15628
15629 std::string initialization;
15630
15631 if (1 == test_case.m_n_cols)
15632 {
15633 initialization = getVectorInitializer(test_case.m_type, test_case.m_n_rows);
15634 }
15635 else
15636 {
15637 initialization = getMatrixInitializer(test_case.m_n_cols, test_case.m_n_rows);
15638 }
15639
15640 return initialization;
15641 }
15642
15643 /** Get string reresenting initialization of local matrix variables
15644 *
15645 * @param n_cols Number of columns
15646 * @param n_rows Number of rows
15647 *
15648 * @return String with initialization
15649 **/
getMatrixInitializer(GLuint n_cols,GLuint n_rows)15650 std::string LengthOfVectorAndMatrixTest::getMatrixInitializer(GLuint n_cols, GLuint n_rows)
15651 {
15652 std::string result;
15653
15654 result.append("{ ");
15655
15656 for (GLuint col = 0; col < n_cols; ++col)
15657 {
15658 result.append(getVectorInitializer(Utils::FLOAT, n_rows));
15659
15660 if (col + 1 < n_cols)
15661 {
15662 result.append(", ");
15663 }
15664 }
15665
15666 result.append(" }");
15667
15668 return result;
15669 }
15670
15671 /** Get string reresenting initialization of local vector variables
15672 *
15673 * @param type Basic type of vector
15674 * @param n_rows Number of rows
15675 *
15676 * @return String with initialization
15677 **/
getVectorInitializer(Utils::TYPES type,glw::GLuint n_rows)15678 std::string LengthOfVectorAndMatrixTest::getVectorInitializer(Utils::TYPES type, glw::GLuint n_rows)
15679 {
15680 std::string result;
15681 const GLchar* value = 0;
15682
15683 switch (type)
15684 {
15685 case Utils::FLOAT:
15686 value = "0.125";
15687 break;
15688 case Utils::UINT:
15689 value = "1";
15690 break;
15691 case Utils::INT:
15692 value = "-1";
15693 break;
15694 default:
15695 TCU_FAIL("Invalid enum");
15696 }
15697
15698 result.append("{");
15699
15700 for (GLuint row = 0; row < n_rows; ++row)
15701 {
15702 result.append(value);
15703
15704 if (row + 1 < n_rows)
15705 {
15706 result.append(", ");
15707 }
15708 }
15709
15710 result.append("}");
15711
15712 return result;
15713 }
15714
15715 /** Prepare source for given shader stage
15716 *
15717 * @param in_stage Shader stage, compute shader will use 430
15718 * @param in_use_version_400 Select if 400 or 420 should be used
15719 * @param out_source Prepared shader source instance
15720 **/
prepareDrawShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)15721 void LengthOfVectorAndMatrixTest::prepareDrawShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
15722 Utils::shaderSource& out_source)
15723 {
15724 static const GLchar* verification_snippet =
15725 " VARIABLE_TYPE variable = INITIALIZATION;\n"
15726 " Structure structure = { { 0, 1, 0, 1 } , INITIALIZATION };\n"
15727 "\n"
15728 " const uint variable_length = variable.length();\n"
15729 " const uint structure_member_b_length = structure.member_b.length();\n"
15730 " const uint input_member_length = INPUT_VARIABLE_NAME.length();\n"
15731 "#ifndef FRAGMENT\n"
15732 " const uint output_member_length = OUTPUT_VARIABLE_NAME.length();\n"
15733 "#endif // FRAGMENT\n"
15734 "\n"
15735 " BASE_TYPE array_var[variable.length()];\n"
15736 " BASE_TYPE array_str[structure.member_b.length()];\n"
15737 " BASE_TYPE array_in [INPUT_VARIABLE_NAME.length()];\n"
15738 "#ifndef FRAGMENT\n"
15739 " BASE_TYPE array_out[OUTPUT_VARIABLE_NAME.length()];\n"
15740 "#endif // FRAGMENT\n"
15741 "\n"
15742 " BASE_TYPE sum = 0;\n"
15743 "\n"
15744 " for (uint i = 0; i < variable_length; ++i)\n"
15745 " {\n"
15746 " array_var[i] = variableARRAY_INDEX.x;\n"
15747 " }\n"
15748 "\n"
15749 " for (uint i = 0; i < structure_member_b_length; ++i)\n"
15750 " {\n"
15751 " array_str[i] = structure.member_bARRAY_INDEX.y;\n"
15752 " }\n"
15753 "\n"
15754 " for (uint i = 0; i < input_member_length; ++i)\n"
15755 " {\n"
15756 " array_in[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.x;\n"
15757 " }\n"
15758 "\n"
15759 "#ifndef FRAGMENT\n"
15760 " for (uint i = 0; i < output_member_length; ++i)\n"
15761 " {\n"
15762 " array_out[i] = INPUT_VARIABLE_NAMEARRAY_INDEX.y;\n"
15763 " }\n"
15764 "#endif // FRAGMENT\n"
15765 "\n"
15766 " for (uint i = 0; i < array_var.length(); ++i)\n"
15767 " {\n"
15768 " sum += array_var[i];\n"
15769 " }\n"
15770 "\n"
15771 " for (uint i = 0; i < array_str.length(); ++i)\n"
15772 " {\n"
15773 " sum += array_str[i];\n"
15774 " }\n"
15775 "\n"
15776 " for (uint i = 0; i < array_in.length(); ++i)\n"
15777 " {\n"
15778 " sum += array_in[i];\n"
15779 " }\n"
15780 "\n"
15781 "#ifndef FRAGMENT\n"
15782 " for (uint i = 0; i < array_out.length(); ++i)\n"
15783 " {\n"
15784 " sum += array_out[i];\n"
15785 " }\n"
15786 "#endif // FRAGMENT\n"
15787 "\n"
15788 " if (EXPECTED_VALUE != sum)\n"
15789 " {\n"
15790 " result = vec4(1, 0, 0, 1);\n"
15791 " }\n";
15792
15793 static const GLchar* fragment_shader_template = "VERSION\n"
15794 "\n"
15795 "#define FRAGMENT\n"
15796 "\n"
15797 "in vec4 gs_fs_result;\n"
15798 "out vec4 fs_out_result;\n"
15799 "\n"
15800 "in GSOutputBlock {\n"
15801 " VARIABLE_DECLARATION;\n"
15802 "} input_block;\n"
15803 "\n"
15804 "struct Structure {\n"
15805 " vec4 member_a;\n"
15806 " TYPE_NAME member_b;\n"
15807 "};\n"
15808 "\n"
15809 "void main()\n"
15810 "{\n"
15811 " vec4 result = vec4(0, 1, 0, 1);\n"
15812 "\n"
15813 "VERIFICATION"
15814 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
15815 " {\n"
15816 " result = vec4(1, 0, 0, 1);\n"
15817 " }\n"
15818 "\n"
15819 " fs_out_result = result;\n"
15820 "}\n"
15821 "\n";
15822
15823 static const GLchar* geometry_shader_template = "VERSION\n"
15824 "\n"
15825 "layout(points) in;\n"
15826 "layout(triangle_strip, max_vertices = 4) out;\n"
15827 "\n"
15828 "in vec4 tes_gs_result[];\n"
15829 "out vec4 gs_fs_result;\n"
15830 "\n"
15831 "in TCSOutputBlock {\n"
15832 " VARIABLE_DECLARATION;\n"
15833 "} input_block[];\n"
15834 "out GSOutputBlock {\n"
15835 " VARIABLE_DECLARATION;\n"
15836 "} output_block;\n"
15837 "\n"
15838 "struct Structure {\n"
15839 " vec4 member_a;\n"
15840 " TYPE_NAME member_b;\n"
15841 "};\n"
15842 "\n"
15843 "void main()\n"
15844 "{\n"
15845 " vec4 result = vec4(0, 1, 0, 1);\n"
15846 "\n"
15847 "VERIFICATION"
15848 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
15849 " {\n"
15850 " result = vec4(1, 0, 0, 1);\n"
15851 " }\n"
15852 "\n"
15853 " gs_fs_result = result;\n"
15854 " gl_Position = vec4(-1, -1, 0, 1);\n"
15855 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15856 " EmitVertex();\n"
15857 " gs_fs_result = result;\n"
15858 " gl_Position = vec4(-1, 1, 0, 1);\n"
15859 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15860 " EmitVertex();\n"
15861 " gs_fs_result = result;\n"
15862 " gl_Position = vec4(1, -1, 0, 1);\n"
15863 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15864 " EmitVertex();\n"
15865 " gs_fs_result = result;\n"
15866 " gl_Position = vec4(1, 1, 0, 1);\n"
15867 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15868 " EmitVertex();\n"
15869 "}\n"
15870 "\n";
15871
15872 static const GLchar* tess_ctrl_shader_template =
15873 "VERSION\n"
15874 "\n"
15875 "layout(vertices = 1) out;\n"
15876 "\n"
15877 "in vec4 vs_tcs_result[];\n"
15878 "out vec4 tcs_tes_result[];\n"
15879 "\n"
15880 "in VSOutputBlock {\n"
15881 " VARIABLE_DECLARATION;\n"
15882 "} input_block[];\n"
15883 "out TCSOutputBlock {\n"
15884 " VARIABLE_DECLARATION;\n"
15885 "} output_block[];\n"
15886 "\n"
15887 "struct Structure {\n"
15888 " vec4 member_a;\n"
15889 " TYPE_NAME member_b;\n"
15890 "};\n"
15891 "\n"
15892 "void main()\n"
15893 "{\n"
15894 " vec4 result = vec4(0, 1, 0, 1);\n"
15895 "\n"
15896 "VERIFICATION"
15897 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
15898 " {\n"
15899 " result = vec4(1, 0, 0, 1);\n"
15900 " }\n"
15901 "\n"
15902 " tcs_tes_result[gl_InvocationID] = result;\n"
15903 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15904 "\n"
15905 " gl_TessLevelOuter[0] = 1.0;\n"
15906 " gl_TessLevelOuter[1] = 1.0;\n"
15907 " gl_TessLevelOuter[2] = 1.0;\n"
15908 " gl_TessLevelOuter[3] = 1.0;\n"
15909 " gl_TessLevelInner[0] = 1.0;\n"
15910 " gl_TessLevelInner[1] = 1.0;\n"
15911 "}\n"
15912 "\n";
15913
15914 static const GLchar* tess_eval_shader_template = "VERSION\n"
15915 "\n"
15916 "layout(isolines, point_mode) in;\n"
15917 "\n"
15918 "in vec4 tcs_tes_result[];\n"
15919 "out vec4 tes_gs_result;\n"
15920 "\n"
15921 "in TCSOutputBlock {\n"
15922 " VARIABLE_DECLARATION;\n"
15923 "} input_block[];\n"
15924 "out TCSOutputBlock {\n"
15925 " VARIABLE_DECLARATION;\n"
15926 "} output_block;\n"
15927 "\n"
15928 "struct Structure {\n"
15929 " vec4 member_a;\n"
15930 " TYPE_NAME member_b;\n"
15931 "};\n"
15932 "\n"
15933 "void main()\n"
15934 "{\n"
15935 " vec4 result = vec4(0, 1, 0, 1);\n"
15936 "\n"
15937 "VERIFICATION"
15938 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
15939 " {\n"
15940 " result = vec4(1, 0, 0, 1);\n"
15941 " }\n"
15942 "\n"
15943 " tes_gs_result = result;\n"
15944 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15945 "}\n"
15946 "\n";
15947
15948 static const GLchar* vertex_shader_template = "VERSION\n"
15949 "\n"
15950 "out vec4 vs_tcs_result;\n"
15951 "\n"
15952 "in VARIABLE_DECLARATION;\n"
15953 "out VSOutputBlock {\n"
15954 " VARIABLE_DECLARATION;\n"
15955 "} output_block;\n"
15956 "\n"
15957 "struct Structure {\n"
15958 " vec4 member_a;\n"
15959 " TYPE_NAME member_b;\n"
15960 "};\n"
15961 "\n"
15962 "void main()\n"
15963 "{\n"
15964 " vec4 result = vec4(0, 1, 0, 1);\n"
15965 "\n"
15966 "VERIFICATION"
15967 "\n"
15968 " vs_tcs_result = result;\n"
15969 " OUTPUT_VARIABLE_NAME = INPUT_VARIABLE_NAME;\n"
15970 "}\n"
15971 "\n";
15972
15973 const GLchar* array_index = "";
15974 const testCase& test_case = m_test_cases[m_current_test_case_index];
15975 const GLchar* shader_template = 0;
15976 const GLchar* input_block_name = "input_block";
15977 const GLchar* output_block_name = "output_block";
15978
15979 const std::string& base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
15980 const std::string& expected_value = getExpectedValue(in_stage);
15981 const std::string& initialization = getInitialization();
15982 const std::string& type_name = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
15983
15984 std::string input_decl;
15985 std::string input_ref;
15986 std::string output_decl;
15987 std::string output_ref;
15988
15989 Utils::qualifierSet in_qualifiers;
15990 Utils::qualifierSet out_qualifiers;
15991
15992 if ((Utils::UINT == test_case.m_type) || (Utils::INT == test_case.m_type))
15993 {
15994 if (Utils::VERTEX_SHADER != in_stage)
15995 {
15996 in_qualifiers.push_back(Utils::QUAL_FLAT);
15997 }
15998
15999 out_qualifiers.push_back(Utils::QUAL_FLAT);
16000 }
16001
16002 switch (in_stage)
16003 {
16004 case Utils::COMPUTE_SHADER:
16005 shader_template = 0;
16006 break;
16007 case Utils::FRAGMENT_SHADER:
16008 shader_template = fragment_shader_template;
16009 break;
16010 case Utils::GEOMETRY_SHADER:
16011 shader_template = geometry_shader_template;
16012 break;
16013 case Utils::TESS_CTRL_SHADER:
16014 shader_template = tess_ctrl_shader_template;
16015 break;
16016 case Utils::TESS_EVAL_SHADER:
16017 shader_template = tess_eval_shader_template;
16018 break;
16019 case Utils::VERTEX_SHADER:
16020 shader_template = vertex_shader_template;
16021 break;
16022 default:
16023 TCU_FAIL("Invalid enum");
16024 }
16025
16026 if (Utils::VERTEX_SHADER != in_stage)
16027 {
16028 Utils::prepareBlockVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable",
16029 input_block_name, input_decl, input_ref);
16030 }
16031 else
16032 {
16033 Utils::prepareVariableStrings(in_stage, Utils::INPUT, in_qualifiers, type_name.c_str(), "variable", input_decl,
16034 input_ref);
16035 }
16036 if (Utils::FRAGMENT_SHADER != in_stage)
16037 {
16038 Utils::prepareBlockVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
16039 output_block_name, output_decl, output_ref);
16040 }
16041 else
16042 {
16043 Utils::prepareVariableStrings(in_stage, Utils::OUTPUT, out_qualifiers, type_name.c_str(), "variable",
16044 output_decl, output_ref);
16045 }
16046
16047 if (1 != test_case.m_n_cols)
16048 {
16049 array_index = "[i]";
16050 }
16051
16052 out_source.m_parts[0].m_code = shader_template;
16053
16054 size_t position = 0;
16055 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16056 out_source.m_parts[0].m_code);
16057
16058 Utils::replaceToken("VARIABLE_DECLARATION", position, input_decl.c_str(), out_source.m_parts[0].m_code);
16059
16060 if (Utils::FRAGMENT_SHADER != in_stage)
16061 {
16062 Utils::replaceToken("VARIABLE_DECLARATION", position, output_decl.c_str(), out_source.m_parts[0].m_code);
16063 }
16064
16065 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16066
16067 size_t temp = position;
16068
16069 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16070
16071 position = temp;
16072
16073 Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
16074
16075 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
16076
16077 Utils::replaceToken("INITIALIZATION", position, initialization.c_str(), out_source.m_parts[0].m_code);
16078
16079 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16080
16081 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16082
16083 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16084
16085 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16086
16087 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16088
16089 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
16090
16091 Utils::replaceAllTokens("INPUT_VARIABLE_NAME", input_ref.c_str(), out_source.m_parts[0].m_code);
16092
16093 Utils::replaceAllTokens("OUTPUT_VARIABLE_NAME", output_ref.c_str(), out_source.m_parts[0].m_code);
16094
16095 Utils::replaceAllTokens("ARRAY_INDEX", array_index, out_source.m_parts[0].m_code);
16096 }
16097
16098 /** Prepare source for compute shader stage
16099 *
16100 * @param out_source Prepared shader source instance
16101 **/
prepareComputeShaderSource(Utils::shaderSource & out_source)16102 void LengthOfVectorAndMatrixTest::prepareComputeShaderSource(Utils::shaderSource& out_source)
16103 {
16104 static const GLchar* verification_snippet =
16105 " VARIABLE_TYPE variable = uni_variable;\n"
16106 " Structure structure = { { 0, 1, 0, 1 } , uni_variable };\n"
16107 "\n"
16108 " const uint variable_length = variable.length();\n"
16109 " const uint structure_member_b_length = structure.member_b.length();\n"
16110 "\n"
16111 " BASE_TYPE array_var[variable.length()];\n"
16112 " BASE_TYPE array_str[structure.member_b.length()];\n"
16113 "\n"
16114 " BASE_TYPE sum = 0;\n"
16115 "\n"
16116 " for (uint i = 0; i < variable_length; ++i)\n"
16117 " {\n"
16118 " array_var[i] = variableARRAY_INDEX.x;\n"
16119 " }\n"
16120 "\n"
16121 " for (uint i = 0; i < structure_member_b_length; ++i)\n"
16122 " {\n"
16123 " array_str[i] = structure.member_bARRAY_INDEX.y;\n"
16124 " }\n"
16125 "\n"
16126 " for (uint i = 0; i < array_var.length(); ++i)\n"
16127 " {\n"
16128 " sum += array_var[i];\n"
16129 " }\n"
16130 "\n"
16131 " for (uint i = 0; i < array_str.length(); ++i)\n"
16132 " {\n"
16133 " sum += array_str[i];\n"
16134 " }\n"
16135 "\n"
16136 " if (EXPECTED_VALUE != sum)\n"
16137 " {\n"
16138 " result = vec4(1, 0, 0, 1);\n"
16139 " }\n";
16140
16141 static const GLchar* compute_shader_template =
16142 "VERSION\n"
16143 "\n"
16144 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16145 "\n"
16146 "writeonly uniform image2D uni_image;\n"
16147 " uniform TYPE_NAME uni_variable;\n"
16148 "\n"
16149 "struct Structure {\n"
16150 " vec4 member_a;\n"
16151 " TYPE_NAME member_b;\n"
16152 "};\n"
16153 "\n"
16154 "void main()\n"
16155 "{\n"
16156 " vec4 result = vec4(0, 1, 0, 1);\n"
16157 "\n"
16158 "VERIFICATION"
16159 "\n"
16160 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16161 "}\n"
16162 "\n";
16163
16164 const testCase& test_case = m_test_cases[m_current_test_case_index];
16165 const GLchar* array_index = "";
16166
16167 const std::string& base_type_name = Utils::getTypeName(test_case.m_type, 1 /* cols */, 1 /* rows */);
16168 const std::string& expected_value = getExpectedValue(Utils::COMPUTE_SHADER);
16169 const std::string& type_name = Utils::getTypeName(test_case.m_type, test_case.m_n_cols, test_case.m_n_rows);
16170
16171 if (1 != test_case.m_n_cols)
16172 {
16173 array_index = "[i]";
16174 }
16175
16176 out_source.m_parts[0].m_code = compute_shader_template;
16177
16178 size_t position = 0;
16179 Utils::replaceToken("VERSION", position, getVersionString(Utils::COMPUTE_SHADER, false),
16180 out_source.m_parts[0].m_code);
16181
16182 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16183
16184 Utils::replaceToken("TYPE_NAME", position, type_name.c_str(), out_source.m_parts[0].m_code);
16185
16186 size_t temp = position;
16187
16188 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16189
16190 position = temp;
16191
16192 Utils::replaceToken("VARIABLE_TYPE", position, type_name.c_str(), out_source.m_parts[0].m_code);
16193
16194 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16195
16196 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16197
16198 Utils::replaceToken("BASE_TYPE", position, base_type_name.c_str(), out_source.m_parts[0].m_code);
16199
16200 Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
16201
16202 Utils::replaceToken("ARRAY_INDEX", position, array_index, out_source.m_parts[0].m_code);
16203
16204 Utils::replaceToken("EXPECTED_VALUE", position, expected_value.c_str(), out_source.m_parts[0].m_code);
16205 }
16206
16207 /** Constructor
16208 *
16209 * @param context Test context
16210 **/
LengthOfComputeResultTest(deqp::Context & context)16211 LengthOfComputeResultTest::LengthOfComputeResultTest(deqp::Context& context)
16212 : GLSLTestBase(context, "length_of_compute_result", "Test verifies .length() for results of computation")
16213 {
16214 /* Nothing to be done here */
16215 }
16216
16217 /** Prepare source for given shader stage
16218 *
16219 * @param in_stage Shader stage, compute shader will use 430
16220 * @param in_use_version_400 Select if 400 or 420 should be used
16221 * @param out_source Prepared shader source instance
16222 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16223 void LengthOfComputeResultTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16224 Utils::shaderSource& out_source)
16225 {
16226 static const GLchar* uniforms = "uniform mat2x4 goten;\n"
16227 "uniform uvec4 indices;\n"
16228 "uniform uvec4 expected_lengths;\n"
16229 "uniform mat4x3 gohan;\n"
16230 "uniform vec3 vegeta;\n"
16231 "uniform vec3 trunks;\n"
16232 "uniform uint variable;\n"
16233 "uniform float expected_sum;\n";
16234
16235 static const GLchar* verification_snippet =
16236 " uint lengths[4];\n"
16237 " float x[(gohan * goten).length()];\n"
16238 " float y[(gohan * goten)[variable - 1].length()];\n"
16239 "\n"
16240 " lengths[indices.x] = gohan[variable].length();\n"
16241 " lengths[indices.y] = (gohan * goten).length();\n"
16242 " lengths[indices.z] = (gohan * goten)[variable].length();\n"
16243 " lengths[indices.w] = (vegeta * trunks).length();\n"
16244 "\n"
16245 " float dot_result = dot(vegeta, trunks);\n"
16246 " mat2x3 mul_result = gohan * goten;\n"
16247 "\n"
16248 "#ifdef TESS_CTRL\n"
16249 " const uint position_length = gl_out[gl_InvocationID].gl_Position.length();\n"
16250 "#endif\n"
16251 "#ifndef COMPUTE\n"
16252 "#ifndef FRAGMENT\n"
16253 "#ifndef TESS_CTRL\n"
16254 " const uint position_length = gl_Position.length();\n"
16255 "#endif /*TESS_CTRL */\n"
16256 "#endif /* FRAGMENT */\n"
16257 "#endif /* COMPUTE */\n"
16258 "#ifdef FRAGMENT\n"
16259 " const uint point_coord_length = gl_PointCoord.length();\n"
16260 " const uint sample_position_length = gl_SamplePosition.length();\n"
16261 "#endif /* FRAGMENT */\n"
16262 " const uint outer_length = outerProduct(vegeta, trunks).length();\n"
16263 "\n"
16264 " for (uint i = 0; i < x.length(); ++i)\n"
16265 " {\n"
16266 " x[i] = mul_result[i].x;\n"
16267 " }\n"
16268 "\n"
16269 " for (uint i = 0; i < y.length(); ++i)\n"
16270 " {\n"
16271 " y[i] = mul_result[0][i];\n"
16272 " }\n"
16273 "\n"
16274 " if ( (expected_lengths.x != lengths[0]) ||\n"
16275 " (expected_lengths.y != lengths[1]) ||\n"
16276 " (expected_lengths.z != lengths[2]) ||\n"
16277 " (expected_lengths.w != lengths[3]) ||\n"
16278 "#ifndef COMPUTE\n"
16279 "#ifndef FRAGMENT\n"
16280 " (4 /* vec4 */ != position_length) ||\n"
16281 "#endif /* FRAGMENT */\n"
16282 "#endif /* COMPUTE */\n"
16283 "#ifdef FRAGMENT\n"
16284 " (2 /* vec2 */ != point_coord_length) ||\n"
16285 " (2 /* vec2 */ != sample_position_length) ||\n"
16286 "#endif /* FRAGMENT */\n"
16287 " (0.5 != dot_result) ||\n"
16288 " (3 /* mat3 */ != outer_length) ||\n"
16289 " (expected_sum != x[variable] + y[variable]) )\n"
16290 " {\n"
16291 " result = vec4(1, 0, 0, 1);\n"
16292 " }\n";
16293
16294 static const GLchar* compute_shader_template =
16295 "VERSION\n"
16296 "\n"
16297 "#define COMPUTE\n"
16298 "\n"
16299 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16300 "\n"
16301 "writeonly uniform image2D uni_image;\n"
16302 "\n"
16303 "UNIFORMS"
16304 "\n"
16305 "void main()\n"
16306 "{\n"
16307 " vec4 result = vec4(0, 1, 0, 1);\n"
16308 "\n"
16309 "VERIFICATION"
16310 "\n"
16311 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16312 "}\n"
16313 "\n";
16314
16315 static const GLchar* fragment_shader_template = "VERSION\n"
16316 "\n"
16317 "#define FRAGMENT\n"
16318 "\n"
16319 "in vec4 gs_fs_result;\n"
16320 "out vec4 fs_out_result;\n"
16321 "\n"
16322 "UNIFORMS"
16323 "\n"
16324 "void main()\n"
16325 "{\n"
16326 " vec4 result = vec4(0, 1, 0, 1);\n"
16327 "\n"
16328 "VERIFICATION"
16329 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16330 " {\n"
16331 " result = vec4(1, 0, 0, 1);\n"
16332 " }\n"
16333 "\n"
16334 " fs_out_result = result;\n"
16335 "}\n"
16336 "\n";
16337
16338 static const GLchar* geometry_shader_template = "VERSION\n"
16339 "\n"
16340 "layout(points) in;\n"
16341 "layout(triangle_strip, max_vertices = 4) out;\n"
16342 "\n"
16343 "in vec4 tes_gs_result[];\n"
16344 "out vec4 gs_fs_result;\n"
16345 "\n"
16346 "UNIFORMS"
16347 "\n"
16348 "void main()\n"
16349 "{\n"
16350 " vec4 result = vec4(0, 1, 0, 1);\n"
16351 "\n"
16352 "VERIFICATION"
16353 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16354 " {\n"
16355 " result = vec4(1, 0, 0, 1);\n"
16356 " }\n"
16357 "\n"
16358 " gs_fs_result = result;\n"
16359 " gl_Position = vec4(-1, -1, 0, 1);\n"
16360 " EmitVertex();\n"
16361 " gs_fs_result = result;\n"
16362 " gl_Position = vec4(-1, 1, 0, 1);\n"
16363 " EmitVertex();\n"
16364 " gs_fs_result = result;\n"
16365 " gl_Position = vec4(1, -1, 0, 1);\n"
16366 " EmitVertex();\n"
16367 " gs_fs_result = result;\n"
16368 " gl_Position = vec4(1, 1, 0, 1);\n"
16369 " EmitVertex();\n"
16370 "}\n"
16371 "\n";
16372
16373 static const GLchar* tess_ctrl_shader_template =
16374 "VERSION\n"
16375 "#define TESS_CTRL\n"
16376 "\n"
16377 "layout(vertices = 1) out;\n"
16378 "\n"
16379 "in vec4 vs_tcs_result[];\n"
16380 "out vec4 tcs_tes_result[];\n"
16381 "\n"
16382 "UNIFORMS"
16383 "\n"
16384 "void main()\n"
16385 "{\n"
16386 " vec4 result = vec4(0, 1, 0, 1);\n"
16387 "\n"
16388 "VERIFICATION"
16389 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16390 " {\n"
16391 " result = vec4(1, 0, 0, 1);\n"
16392 " }\n"
16393 "\n"
16394 " tcs_tes_result[gl_InvocationID] = result;\n"
16395 "\n"
16396 " gl_TessLevelOuter[0] = 1.0;\n"
16397 " gl_TessLevelOuter[1] = 1.0;\n"
16398 " gl_TessLevelOuter[2] = 1.0;\n"
16399 " gl_TessLevelOuter[3] = 1.0;\n"
16400 " gl_TessLevelInner[0] = 1.0;\n"
16401 " gl_TessLevelInner[1] = 1.0;\n"
16402 "}\n"
16403 "\n";
16404
16405 static const GLchar* tess_eval_shader_template = "VERSION\n"
16406 "\n"
16407 "layout(isolines, point_mode) in;\n"
16408 "\n"
16409 "in vec4 tcs_tes_result[];\n"
16410 "out vec4 tes_gs_result;\n"
16411 "\n"
16412 "UNIFORMS"
16413 "\n"
16414 "void main()\n"
16415 "{\n"
16416 " vec4 result = vec4(0, 1, 0, 1);\n"
16417 "\n"
16418 "VERIFICATION"
16419 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16420 " {\n"
16421 " result = vec4(1, 0, 0, 1);\n"
16422 " }\n"
16423 "\n"
16424 " tes_gs_result = result;\n"
16425 "}\n"
16426 "\n";
16427
16428 static const GLchar* vertex_shader_template = "VERSION\n"
16429 "\n"
16430 "out vec4 vs_tcs_result;\n"
16431 "\n"
16432 "UNIFORMS"
16433 "\n"
16434 "void main()\n"
16435 "{\n"
16436 " vec4 result = vec4(0, 1, 0, 1);\n"
16437 "\n"
16438 "VERIFICATION"
16439 "\n"
16440 " vs_tcs_result = result;\n"
16441 "}\n"
16442 "\n";
16443
16444 const GLchar* shader_template = 0;
16445
16446 switch (in_stage)
16447 {
16448 case Utils::COMPUTE_SHADER:
16449 shader_template = compute_shader_template;
16450 break;
16451 case Utils::FRAGMENT_SHADER:
16452 shader_template = fragment_shader_template;
16453 break;
16454 case Utils::GEOMETRY_SHADER:
16455 shader_template = geometry_shader_template;
16456 break;
16457 case Utils::TESS_CTRL_SHADER:
16458 shader_template = tess_ctrl_shader_template;
16459 break;
16460 case Utils::TESS_EVAL_SHADER:
16461 shader_template = tess_eval_shader_template;
16462 break;
16463 case Utils::VERTEX_SHADER:
16464 shader_template = vertex_shader_template;
16465 break;
16466 default:
16467 TCU_FAIL("Invalid enum");
16468 }
16469
16470 out_source.m_parts[0].m_code = shader_template;
16471
16472 size_t position = 0;
16473 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16474 out_source.m_parts[0].m_code);
16475
16476 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16477
16478 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16479 }
16480
16481 /** Overwritte of prepareUniforms method
16482 *
16483 * @param program Current program
16484 **/
prepareUniforms(Utils::program & program)16485 void LengthOfComputeResultTest::prepareUniforms(Utils::program& program)
16486 {
16487 static const GLfloat gohan_data[12] = { 0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f,
16488 0.125f, 0.125f, 0.125f, 0.125f, 0.125f, 0.125f };
16489
16490 static const GLfloat goten_data[8] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
16491
16492 static const GLfloat vegeta_data[3] = { 0.5f, 0.5f, 0.0f };
16493
16494 static const GLfloat trunks_data[3] = { 0.5f, 0.5f, 0.0f };
16495
16496 static const GLuint indices_data[4] = { 2, 1, 0, 3 };
16497
16498 static const GLuint variable_data[1] = { 1 };
16499
16500 static const GLuint expected_lengths_data[4] = { 3, 2, 3, 3 };
16501
16502 static const GLfloat expected_sum_data[1] = { 1.0f };
16503
16504 program.uniform("gohan", Utils::FLOAT, 4 /* n_cols */, 3 /* n_rows */, gohan_data);
16505 program.uniform("goten", Utils::FLOAT, 2 /* n_cols */, 4 /* n_rows */, goten_data);
16506 program.uniform("vegeta", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, vegeta_data);
16507 program.uniform("trunks", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, trunks_data);
16508 program.uniform("indices", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, indices_data);
16509 program.uniform("variable", Utils::UINT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16510 program.uniform("expected_lengths", Utils::UINT, 1 /* n_cols */, 4 /* n_rows */, expected_lengths_data);
16511 program.uniform("expected_sum", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, expected_sum_data);
16512 }
16513
16514 /** Constructor
16515 *
16516 * @param context Test context
16517 **/
ScalarSwizzlersTest(deqp::Context & context)16518 ScalarSwizzlersTest::ScalarSwizzlersTest(deqp::Context& context)
16519 : GLSLTestBase(context, "scalar_swizzlers", "Verifies that swizzlers can be used on scalars")
16520 {
16521 /* Nothing to be done here */
16522 }
16523
16524 /** Prepare source for given shader stage
16525 *
16526 * @param in_stage Shader stage, compute shader will use 430
16527 * @param in_use_version_400 Select if 400 or 420 should be used
16528 * @param out_source Prepared shader source instance
16529 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16530 void ScalarSwizzlersTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16531 Utils::shaderSource& out_source)
16532 {
16533 static const GLchar* uniforms = "uniform float variable;\n"
16534 "uniform vec3 expected_values;\n";
16535
16536 static const GLchar* literal = "#define LITERAL 0.375\n";
16537
16538 static const GLchar* structure = "struct Structure {\n"
16539 " vec2 m_xx;\n"
16540 " vec3 m_xxx;\n"
16541 " vec4 m_xxxx;\n"
16542 " vec2 m_nested_xx;\n"
16543 " vec3 m_nested_xxx;\n"
16544 " vec4 m_nested_xxxx;\n"
16545 "};\n";
16546
16547 static const GLchar* function = "bool check_values(in Structure structure, in float value)\n"
16548 "{\n"
16549 " const vec2 xx = vec2(value, value);\n"
16550 " const vec3 xxx = vec3(value, value, value);\n"
16551 " const vec4 xxxx = vec4(value, value, value, value);\n"
16552 "\n"
16553 " bool result = true;\n"
16554 "\n"
16555 " if ((xx != structure.m_xx) ||\n"
16556 " (xxx != structure.m_xxx) ||\n"
16557 " (xxxx != structure.m_xxxx) ||\n"
16558 " (xx != structure.m_nested_xx) ||\n"
16559 " (xxx != structure.m_nested_xxx) ||\n"
16560 " (xxxx != structure.m_nested_xxxx) )\n"
16561 " {\n"
16562 " result = false;\n"
16563 " }\n"
16564 "\n"
16565 " return result;\n"
16566 "}\n";
16567
16568 static const GLchar* verification_snippet =
16569 " Structure literal_result;\n"
16570 " Structure constant_result;\n"
16571 " Structure variable_result;\n"
16572 "\n"
16573 " literal_result.m_xx = LITERAL.xx ;\n"
16574 " literal_result.m_xxx = LITERAL.xxx ;\n"
16575 " literal_result.m_xxxx = LITERAL.xxxx;\n"
16576 " literal_result.m_nested_xx = LITERAL.x.rr.sss.rr ;\n"
16577 " literal_result.m_nested_xxx = LITERAL.s.xx.rrr.xxx ;\n"
16578 " literal_result.m_nested_xxxx = LITERAL.r.ss.xxx.ssss;\n"
16579 "\n"
16580 " const float constant = 0.125;\n"
16581 "\n"
16582 " constant_result.m_xx = constant.xx ;\n"
16583 " constant_result.m_xxx = constant.xxx ;\n"
16584 " constant_result.m_xxxx = constant.xxxx;\n"
16585 " constant_result.m_nested_xx = constant.x.rr.sss.rr ;\n"
16586 " constant_result.m_nested_xxx = constant.s.xx.rrr.xxx ;\n"
16587 " constant_result.m_nested_xxxx = constant.r.ss.xxx.ssss;\n"
16588 "\n"
16589 " variable_result.m_xx = variable.xx ;\n"
16590 " variable_result.m_xxx = variable.xxx ;\n"
16591 " variable_result.m_xxxx = variable.xxxx;\n"
16592 " variable_result.m_nested_xx = variable.x.rr.sss.rr ;\n"
16593 " variable_result.m_nested_xxx = variable.s.xx.rrr.xxx ;\n"
16594 " variable_result.m_nested_xxxx = variable.r.ss.xxx.ssss;\n"
16595 "\n"
16596 " if ((false == check_values(literal_result, expected_values.x)) ||\n"
16597 " (false == check_values(constant_result, expected_values.y)) ||\n"
16598 " (false == check_values(variable_result, expected_values.z)) )\n"
16599 " {\n"
16600 " result = vec4(1, 0, 0, 1);\n"
16601 " }\n";
16602
16603 static const GLchar* compute_shader_template =
16604 "VERSION\n"
16605 "\n"
16606 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16607 "\n"
16608 "writeonly uniform image2D uni_image;\n"
16609 "\n"
16610 "STRUCTURE"
16611 "\n"
16612 "UNIFORMS"
16613 "\n"
16614 "FUNCTION"
16615 "\n"
16616 "LITERAL"
16617 "\n"
16618 "void main()\n"
16619 "{\n"
16620 " vec4 result = vec4(0, 1, 0, 1);\n"
16621 "\n"
16622 "VERIFICATION"
16623 "\n"
16624 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16625 "}\n"
16626 "\n";
16627
16628 static const GLchar* fragment_shader_template = "VERSION\n"
16629 "\n"
16630 "#define FRAGMENT\n"
16631 "\n"
16632 "in vec4 gs_fs_result;\n"
16633 "out vec4 fs_out_result;\n"
16634 "\n"
16635 "STRUCTURE"
16636 "\n"
16637 "UNIFORMS"
16638 "\n"
16639 "FUNCTION"
16640 "\n"
16641 "LITERAL"
16642 "\n"
16643 "void main()\n"
16644 "{\n"
16645 " vec4 result = vec4(0, 1, 0, 1);\n"
16646 "\n"
16647 "VERIFICATION"
16648 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16649 " {\n"
16650 " result = vec4(1, 0, 0, 1);\n"
16651 " }\n"
16652 "\n"
16653 " fs_out_result = result;\n"
16654 "}\n"
16655 "\n";
16656
16657 static const GLchar* geometry_shader_template = "VERSION\n"
16658 "\n"
16659 "layout(points) in;\n"
16660 "layout(triangle_strip, max_vertices = 4) out;\n"
16661 "\n"
16662 "in vec4 tes_gs_result[];\n"
16663 "out vec4 gs_fs_result;\n"
16664 "\n"
16665 "STRUCTURE"
16666 "\n"
16667 "UNIFORMS"
16668 "\n"
16669 "FUNCTION"
16670 "\n"
16671 "LITERAL"
16672 "\n"
16673 "void main()\n"
16674 "{\n"
16675 " vec4 result = vec4(0, 1, 0, 1);\n"
16676 "\n"
16677 "VERIFICATION"
16678 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16679 " {\n"
16680 " result = vec4(1, 0, 0, 1);\n"
16681 " }\n"
16682 "\n"
16683 " gs_fs_result = result;\n"
16684 " gl_Position = vec4(-1, -1, 0, 1);\n"
16685 " EmitVertex();\n"
16686 " gs_fs_result = result;\n"
16687 " gl_Position = vec4(-1, 1, 0, 1);\n"
16688 " EmitVertex();\n"
16689 " gs_fs_result = result;\n"
16690 " gl_Position = vec4(1, -1, 0, 1);\n"
16691 " EmitVertex();\n"
16692 " gs_fs_result = result;\n"
16693 " gl_Position = vec4(1, 1, 0, 1);\n"
16694 " EmitVertex();\n"
16695 "}\n"
16696 "\n";
16697
16698 static const GLchar* tess_ctrl_shader_template =
16699 "VERSION\n"
16700 "\n"
16701 "layout(vertices = 1) out;\n"
16702 "\n"
16703 "in vec4 vs_tcs_result[];\n"
16704 "out vec4 tcs_tes_result[];\n"
16705 "\n"
16706 "STRUCTURE"
16707 "\n"
16708 "UNIFORMS"
16709 "\n"
16710 "FUNCTION"
16711 "\n"
16712 "LITERAL"
16713 "\n"
16714 "void main()\n"
16715 "{\n"
16716 " vec4 result = vec4(0, 1, 0, 1);\n"
16717 "\n"
16718 "VERIFICATION"
16719 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
16720 " {\n"
16721 " result = vec4(1, 0, 0, 1);\n"
16722 " }\n"
16723 "\n"
16724 " tcs_tes_result[gl_InvocationID] = result;\n"
16725 "\n"
16726 " gl_TessLevelOuter[0] = 1.0;\n"
16727 " gl_TessLevelOuter[1] = 1.0;\n"
16728 " gl_TessLevelOuter[2] = 1.0;\n"
16729 " gl_TessLevelOuter[3] = 1.0;\n"
16730 " gl_TessLevelInner[0] = 1.0;\n"
16731 " gl_TessLevelInner[1] = 1.0;\n"
16732 "}\n"
16733 "\n";
16734
16735 static const GLchar* tess_eval_shader_template = "VERSION\n"
16736 "\n"
16737 "layout(isolines, point_mode) in;\n"
16738 "\n"
16739 "in vec4 tcs_tes_result[];\n"
16740 "out vec4 tes_gs_result;\n"
16741 "\n"
16742 "STRUCTURE"
16743 "\n"
16744 "UNIFORMS"
16745 "\n"
16746 "FUNCTION"
16747 "\n"
16748 "LITERAL"
16749 "\n"
16750 "void main()\n"
16751 "{\n"
16752 " vec4 result = vec4(0, 1, 0, 1);\n"
16753 "\n"
16754 "VERIFICATION"
16755 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
16756 " {\n"
16757 " result = vec4(1, 0, 0, 1);\n"
16758 " }\n"
16759 "\n"
16760 " tes_gs_result = result;\n"
16761 "}\n"
16762 "\n";
16763
16764 static const GLchar* vertex_shader_template = "VERSION\n"
16765 "\n"
16766 "out vec4 vs_tcs_result;\n"
16767 "\n"
16768 "STRUCTURE"
16769 "\n"
16770 "UNIFORMS"
16771 "\n"
16772 "FUNCTION"
16773 "\n"
16774 "LITERAL"
16775 "\n"
16776 "void main()\n"
16777 "{\n"
16778 " vec4 result = vec4(0, 1, 0, 1);\n"
16779 "\n"
16780 "VERIFICATION"
16781 "\n"
16782 " vs_tcs_result = result;\n"
16783 "}\n"
16784 "\n";
16785
16786 const GLchar* shader_template = 0;
16787
16788 switch (in_stage)
16789 {
16790 case Utils::COMPUTE_SHADER:
16791 shader_template = compute_shader_template;
16792 break;
16793 case Utils::FRAGMENT_SHADER:
16794 shader_template = fragment_shader_template;
16795 break;
16796 case Utils::GEOMETRY_SHADER:
16797 shader_template = geometry_shader_template;
16798 break;
16799 case Utils::TESS_CTRL_SHADER:
16800 shader_template = tess_ctrl_shader_template;
16801 break;
16802 case Utils::TESS_EVAL_SHADER:
16803 shader_template = tess_eval_shader_template;
16804 break;
16805 case Utils::VERTEX_SHADER:
16806 shader_template = vertex_shader_template;
16807 break;
16808 default:
16809 TCU_FAIL("Invalid enum");
16810 }
16811
16812 out_source.m_parts[0].m_code = shader_template;
16813
16814 size_t position = 0;
16815 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
16816 out_source.m_parts[0].m_code);
16817
16818 Utils::replaceToken("STRUCTURE", position, structure, out_source.m_parts[0].m_code);
16819
16820 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
16821
16822 Utils::replaceToken("FUNCTION", position, function, out_source.m_parts[0].m_code);
16823
16824 Utils::replaceToken("LITERAL", position, literal, out_source.m_parts[0].m_code);
16825
16826 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
16827 }
16828
16829 /** Overwritte of prepareUniforms method
16830 *
16831 * @param program Current program
16832 **/
prepareUniforms(Utils::program & program)16833 void ScalarSwizzlersTest::prepareUniforms(Utils::program& program)
16834 {
16835 static const GLfloat variable_data[4] = { 0.75f };
16836 static const GLfloat expected_values_data[3] = { 0.375f, 0.125f, 0.75f };
16837
16838 program.uniform("variable", Utils::FLOAT, 1 /* n_cols */, 1 /* n_rows */, variable_data);
16839 program.uniform("expected_values", Utils::FLOAT, 1 /* n_cols */, 3 /* n_rows */, expected_values_data);
16840 }
16841
16842 /** Constructor
16843 *
16844 * @param context Test context
16845 **/
ScalarSwizzlersInvalidTest(deqp::Context & context)16846 ScalarSwizzlersInvalidTest::ScalarSwizzlersInvalidTest(deqp::Context& context)
16847 : NegativeTestBase(context, "scalar_swizzlers_invalid",
16848 "Verifies if invalid use of swizzlers on scalars is reported as error")
16849 {
16850 /* Nothing to be done here */
16851 }
16852
16853 /** Set up next test case
16854 *
16855 * @param test_case_index Index of next test case
16856 *
16857 * @return false if there is no more test cases, true otherwise
16858 **/
prepareNextTestCase(glw::GLuint test_case_index)16859 bool ScalarSwizzlersInvalidTest::prepareNextTestCase(glw::GLuint test_case_index)
16860 {
16861 switch (test_case_index)
16862 {
16863 case (glw::GLuint)-1:
16864 case INVALID_Y:
16865 case INVALID_B:
16866 case INVALID_Q:
16867 case INVALID_XY:
16868 case INVALID_XRS:
16869 case WRONG:
16870 case MISSING_PARENTHESIS:
16871 m_case = (TESTED_CASES)test_case_index;
16872 break;
16873 default:
16874 return false;
16875 }
16876
16877 return true;
16878 }
16879
16880 /** Prepare source for given shader stage
16881 *
16882 * @param in_stage Shader stage, compute shader will use 430
16883 * @param in_use_version_400 Select if 400 or 420 should be used
16884 * @param out_source Prepared shader source instance
16885 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)16886 void ScalarSwizzlersInvalidTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
16887 Utils::shaderSource& out_source)
16888 {
16889 static const GLchar* uniforms = "uniform float variable;\n";
16890
16891 static const GLchar* verification_invalid_y = "\n"
16892 " if (0.125 != variable.y) )\n"
16893 " {\n"
16894 " result = vec4(1, 0, 0, 1);\n"
16895 " }\n";
16896
16897 static const GLchar* verification_invalid_b = "\n"
16898 " if (0.125 != variable.b) )\n"
16899 " {\n"
16900 " result = vec4(1, 0, 0, 1);\n"
16901 " }\n";
16902
16903 static const GLchar* verification_invalid_q = "\n"
16904 " if (0.125 != variable.q) )\n"
16905 " {\n"
16906 " result = vec4(1, 0, 0, 1);\n"
16907 " }\n";
16908
16909 static const GLchar* verification_invalid_xy = "\n"
16910 " if (vec2(0.125, 0.25) != variable.xy) )\n"
16911 " {\n"
16912 " result = vec4(1, 0, 0, 1);\n"
16913 " }\n";
16914
16915 static const GLchar* verification_invalid_xrs = "\n"
16916 " if (vec3(0.125, 0.125, 0.25) != variable.xrs) )\n"
16917 " {\n"
16918 " result = vec4(1, 0, 0, 1);\n"
16919 " }\n";
16920
16921 static const GLchar* verification_wrong_u = "\n"
16922 " if (0.125 != variable.u) )\n"
16923 " {\n"
16924 " result = vec4(1, 0, 0, 1);\n"
16925 " }\n";
16926
16927 static const GLchar* verification_missing_parenthesis = "\n"
16928 " if (variable != 1.x) )\n"
16929 " {\n"
16930 " result = vec4(1, 0, 0, 1);\n"
16931 " }\n";
16932
16933 static const GLchar* compute_shader_template =
16934 "VERSION\n"
16935 "\n"
16936 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
16937 "\n"
16938 "writeonly uniform image2D uni_image;\n"
16939 "\n"
16940 "UNIFORMS"
16941 "\n"
16942 "void main()\n"
16943 "{\n"
16944 " vec4 result = vec4(0, 1, 0, 1);\n"
16945 "\n"
16946 "VERIFICATION"
16947 "\n"
16948 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
16949 "}\n"
16950 "\n";
16951
16952 static const GLchar* fragment_shader_template = "VERSION\n"
16953 "\n"
16954 "#define FRAGMENT\n"
16955 "\n"
16956 "in vec4 gs_fs_result;\n"
16957 "out vec4 fs_out_result;\n"
16958 "\n"
16959 "UNIFORMS"
16960 "\n"
16961 "void main()\n"
16962 "{\n"
16963 " vec4 result = vec4(0, 1, 0, 1);\n"
16964 "\n"
16965 "VERIFICATION"
16966 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
16967 " {\n"
16968 " result = vec4(1, 0, 0, 1);\n"
16969 " }\n"
16970 "\n"
16971 " fs_out_result = result;\n"
16972 "}\n"
16973 "\n";
16974
16975 static const GLchar* geometry_shader_template = "VERSION\n"
16976 "\n"
16977 "layout(points) in;\n"
16978 "layout(triangle_strip, max_vertices = 4) out;\n"
16979 "\n"
16980 "in vec4 tes_gs_result[];\n"
16981 "out vec4 gs_fs_result;\n"
16982 "\n"
16983 "UNIFORMS"
16984 "\n"
16985 "void main()\n"
16986 "{\n"
16987 " vec4 result = vec4(0, 1, 0, 1);\n"
16988 "\n"
16989 "VERIFICATION"
16990 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
16991 " {\n"
16992 " result = vec4(1, 0, 0, 1);\n"
16993 " }\n"
16994 "\n"
16995 " gs_fs_result = result;\n"
16996 " gl_Position = vec4(-1, -1, 0, 1);\n"
16997 " EmitVertex();\n"
16998 " gs_fs_result = result;\n"
16999 " gl_Position = vec4(-1, 1, 0, 1);\n"
17000 " EmitVertex();\n"
17001 " gs_fs_result = result;\n"
17002 " gl_Position = vec4(1, -1, 0, 1);\n"
17003 " EmitVertex();\n"
17004 " gs_fs_result = result;\n"
17005 " gl_Position = vec4(1, 1, 0, 1);\n"
17006 " EmitVertex();\n"
17007 "}\n"
17008 "\n";
17009
17010 static const GLchar* tess_ctrl_shader_template =
17011 "VERSION\n"
17012 "\n"
17013 "layout(vertices = 1) out;\n"
17014 "\n"
17015 "in vec4 vs_tcs_result[];\n"
17016 "out vec4 tcs_tes_result[];\n"
17017 "\n"
17018 "UNIFORMS"
17019 "\n"
17020 "void main()\n"
17021 "{\n"
17022 " vec4 result = vec4(0, 1, 0, 1);\n"
17023 "\n"
17024 "VERIFICATION"
17025 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17026 " {\n"
17027 " result = vec4(1, 0, 0, 1);\n"
17028 " }\n"
17029 "\n"
17030 " tcs_tes_result[gl_InvocationID] = result;\n"
17031 "\n"
17032 " gl_TessLevelOuter[0] = 1.0;\n"
17033 " gl_TessLevelOuter[1] = 1.0;\n"
17034 " gl_TessLevelOuter[2] = 1.0;\n"
17035 " gl_TessLevelOuter[3] = 1.0;\n"
17036 " gl_TessLevelInner[0] = 1.0;\n"
17037 " gl_TessLevelInner[1] = 1.0;\n"
17038 "}\n"
17039 "\n";
17040
17041 static const GLchar* tess_eval_shader_template = "VERSION\n"
17042 "\n"
17043 "layout(isolines, point_mode) in;\n"
17044 "\n"
17045 "in vec4 tcs_tes_result[];\n"
17046 "out vec4 tes_gs_result;\n"
17047 "\n"
17048 "UNIFORMS"
17049 "\n"
17050 "void main()\n"
17051 "{\n"
17052 " vec4 result = vec4(0, 1, 0, 1);\n"
17053 "\n"
17054 "VERIFICATION"
17055 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17056 " {\n"
17057 " result = vec4(1, 0, 0, 1);\n"
17058 " }\n"
17059 "\n"
17060 " tes_gs_result = result;\n"
17061 "}\n"
17062 "\n";
17063
17064 static const GLchar* vertex_shader_template = "VERSION\n"
17065 "\n"
17066 "out vec4 vs_tcs_result;\n"
17067 "\n"
17068 "UNIFORMS"
17069 "\n"
17070 "void main()\n"
17071 "{\n"
17072 " vec4 result = vec4(0, 1, 0, 1);\n"
17073 "\n"
17074 "VERIFICATION"
17075 "\n"
17076 " vs_tcs_result = result;\n"
17077 "}\n"
17078 "\n";
17079
17080 const GLchar* shader_template = 0;
17081 const GLchar* verification_snippet = 0;
17082
17083 switch (in_stage)
17084 {
17085 case Utils::COMPUTE_SHADER:
17086 shader_template = compute_shader_template;
17087 break;
17088 case Utils::FRAGMENT_SHADER:
17089 shader_template = fragment_shader_template;
17090 break;
17091 case Utils::GEOMETRY_SHADER:
17092 shader_template = geometry_shader_template;
17093 break;
17094 case Utils::TESS_CTRL_SHADER:
17095 shader_template = tess_ctrl_shader_template;
17096 break;
17097 case Utils::TESS_EVAL_SHADER:
17098 shader_template = tess_eval_shader_template;
17099 break;
17100 case Utils::VERTEX_SHADER:
17101 shader_template = vertex_shader_template;
17102 break;
17103 default:
17104 TCU_FAIL("Invalid enum");
17105 }
17106
17107 switch (m_case)
17108 {
17109 case INVALID_Y:
17110 verification_snippet = verification_invalid_y;
17111 break;
17112 case INVALID_B:
17113 verification_snippet = verification_invalid_b;
17114 break;
17115 case INVALID_Q:
17116 verification_snippet = verification_invalid_q;
17117 break;
17118 case INVALID_XY:
17119 verification_snippet = verification_invalid_xy;
17120 break;
17121 case INVALID_XRS:
17122 verification_snippet = verification_invalid_xrs;
17123 break;
17124 case WRONG:
17125 verification_snippet = verification_wrong_u;
17126 break;
17127 case MISSING_PARENTHESIS:
17128 verification_snippet = verification_missing_parenthesis;
17129 break;
17130 default:
17131 TCU_FAIL("Invalid enum");
17132 }
17133
17134 out_source.m_parts[0].m_code = shader_template;
17135
17136 size_t position = 0;
17137 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17138 out_source.m_parts[0].m_code);
17139
17140 Utils::replaceToken("UNIFORMS", position, uniforms, out_source.m_parts[0].m_code);
17141
17142 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17143 }
17144
17145 /* Constants used by BuiltInValuesTest */
17146 const GLint BuiltInValuesTest::m_min_program_texel_offset_limit = -8;
17147 const GLint BuiltInValuesTest::m_max_program_texel_offset_limit = 7;
17148
17149 /** Constructor
17150 *
17151 * @param context Test context
17152 **/
BuiltInValuesTest(deqp::Context & context)17153 BuiltInValuesTest::BuiltInValuesTest(deqp::Context& context)
17154 : GLSLTestBase(context, "built_in_values", "Test verifies values of gl_Min/Max_ProgramTexelOffset")
17155 {
17156 /* Nothing to be done here */
17157 }
17158
17159 /** Prepare source for given shader stage
17160 *
17161 * @param in_stage Shader stage, compute shader will use 430
17162 * @param in_use_version_400 Select if 400 or 420 should be used
17163 * @param out_source Prepared shader source instance
17164 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17165 void BuiltInValuesTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17166 Utils::shaderSource& out_source)
17167 {
17168 static const GLchar* verification_snippet = " if ((expected_values.x != gl_MinProgramTexelOffset) ||\n"
17169 " (expected_values.y != gl_MaxProgramTexelOffset) )\n"
17170 " {\n"
17171 " result = vec4(1, 0, 0, 1);\n"
17172 " }\n";
17173
17174 static const GLchar* compute_shader_template =
17175 "VERSION\n"
17176 "\n"
17177 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17178 "\n"
17179 "writeonly uniform image2D uni_image;\n"
17180 " uniform ivec2 expected_values;\n"
17181 "\n"
17182 "void main()\n"
17183 "{\n"
17184 " vec4 result = vec4(0, 1, 0, 1);\n"
17185 "\n"
17186 "VERIFICATION"
17187 "\n"
17188 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17189 "}\n"
17190 "\n";
17191
17192 static const GLchar* fragment_shader_template = "VERSION\n"
17193 "\n"
17194 "in vec4 gs_fs_result;\n"
17195 "out vec4 fs_out_result;\n"
17196 "\n"
17197 "uniform ivec2 expected_values;\n"
17198 "\n"
17199 "void main()\n"
17200 "{\n"
17201 " vec4 result = vec4(0, 1, 0, 1);\n"
17202 "\n"
17203 "VERIFICATION"
17204 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17205 " {\n"
17206 " result = vec4(1, 0, 0, 1);\n"
17207 " }\n"
17208 "\n"
17209 " fs_out_result = result;\n"
17210 "}\n"
17211 "\n";
17212
17213 static const GLchar* geometry_shader_template = "VERSION\n"
17214 "\n"
17215 "layout(points) in;\n"
17216 "layout(triangle_strip, max_vertices = 4) out;\n"
17217 "\n"
17218 "in vec4 tes_gs_result[];\n"
17219 "out vec4 gs_fs_result;\n"
17220 "\n"
17221 "uniform ivec2 expected_values;\n"
17222 "\n"
17223 "void main()\n"
17224 "{\n"
17225 " vec4 result = vec4(0, 1, 0, 1);\n"
17226 "\n"
17227 "VERIFICATION"
17228 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17229 " {\n"
17230 " result = vec4(1, 0, 0, 1);\n"
17231 " }\n"
17232 "\n"
17233 " gs_fs_result = result;\n"
17234 " gl_Position = vec4(-1, -1, 0, 1);\n"
17235 " EmitVertex();\n"
17236 " gs_fs_result = result;\n"
17237 " gl_Position = vec4(-1, 1, 0, 1);\n"
17238 " EmitVertex();\n"
17239 " gs_fs_result = result;\n"
17240 " gl_Position = vec4(1, -1, 0, 1);\n"
17241 " EmitVertex();\n"
17242 " gs_fs_result = result;\n"
17243 " gl_Position = vec4(1, 1, 0, 1);\n"
17244 " EmitVertex();\n"
17245 "}\n"
17246 "\n";
17247
17248 static const GLchar* tess_ctrl_shader_template =
17249 "VERSION\n"
17250 "\n"
17251 "layout(vertices = 1) out;\n"
17252 "\n"
17253 "in vec4 vs_tcs_result[];\n"
17254 "out vec4 tcs_tes_result[];\n"
17255 "\n"
17256 "uniform ivec2 expected_values;\n"
17257 "\n"
17258 "void main()\n"
17259 "{\n"
17260 " vec4 result = vec4(0, 1, 0, 1);\n"
17261 "\n"
17262 "VERIFICATION"
17263 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17264 " {\n"
17265 " result = vec4(1, 0, 0, 1);\n"
17266 " }\n"
17267 "\n"
17268 " tcs_tes_result[gl_InvocationID] = result;\n"
17269 "\n"
17270 " gl_TessLevelOuter[0] = 1.0;\n"
17271 " gl_TessLevelOuter[1] = 1.0;\n"
17272 " gl_TessLevelOuter[2] = 1.0;\n"
17273 " gl_TessLevelOuter[3] = 1.0;\n"
17274 " gl_TessLevelInner[0] = 1.0;\n"
17275 " gl_TessLevelInner[1] = 1.0;\n"
17276 "}\n"
17277 "\n";
17278
17279 static const GLchar* tess_eval_shader_template = "VERSION\n"
17280 "\n"
17281 "layout(isolines, point_mode) in;\n"
17282 "\n"
17283 "in vec4 tcs_tes_result[];\n"
17284 "out vec4 tes_gs_result;\n"
17285 "\n"
17286 "uniform ivec2 expected_values;\n"
17287 "\n"
17288 "void main()\n"
17289 "{\n"
17290 " vec4 result = vec4(0, 1, 0, 1);\n"
17291 "\n"
17292 "VERIFICATION"
17293 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17294 " {\n"
17295 " result = vec4(1, 0, 0, 1);\n"
17296 " }\n"
17297 "\n"
17298 " tes_gs_result = result;\n"
17299 "}\n"
17300 "\n";
17301
17302 static const GLchar* vertex_shader_template = "VERSION\n"
17303 "\n"
17304 "out vec4 vs_tcs_result;\n"
17305 "\n"
17306 "uniform ivec2 expected_values;\n"
17307 "\n"
17308 "void main()\n"
17309 "{\n"
17310 " vec4 result = vec4(0, 1, 0, 1);\n"
17311 "\n"
17312 "VERIFICATION"
17313 "\n"
17314 " vs_tcs_result = result;\n"
17315 "}\n"
17316 "\n";
17317
17318 const GLchar* shader_template = 0;
17319
17320 switch (in_stage)
17321 {
17322 case Utils::COMPUTE_SHADER:
17323 shader_template = compute_shader_template;
17324 break;
17325 case Utils::FRAGMENT_SHADER:
17326 shader_template = fragment_shader_template;
17327 break;
17328 case Utils::GEOMETRY_SHADER:
17329 shader_template = geometry_shader_template;
17330 break;
17331 case Utils::TESS_CTRL_SHADER:
17332 shader_template = tess_ctrl_shader_template;
17333 break;
17334 case Utils::TESS_EVAL_SHADER:
17335 shader_template = tess_eval_shader_template;
17336 break;
17337 case Utils::VERTEX_SHADER:
17338 shader_template = vertex_shader_template;
17339 break;
17340 default:
17341 TCU_FAIL("Invalid enum");
17342 }
17343
17344 out_source.m_parts[0].m_code = shader_template;
17345
17346 size_t position = 0;
17347 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17348 out_source.m_parts[0].m_code);
17349
17350 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17351 }
17352
17353 /** Overwritte of prepareUniforms method
17354 *
17355 * @param program Current program
17356 **/
prepareUniforms(Utils::program & program)17357 void BuiltInValuesTest::prepareUniforms(Utils::program& program)
17358 {
17359 const GLint expected_values_data[2] = { m_min_program_texel_offset, m_max_program_texel_offset };
17360
17361 program.uniform("expected_values", Utils::INT, 1 /* n_cols */, 2 /* n_rows */, expected_values_data);
17362 }
17363
17364 /** Prepare test cases
17365 *
17366 * @return true
17367 **/
testInit()17368 bool BuiltInValuesTest::testInit()
17369 {
17370 const Functions& gl = m_context.getRenderContext().getFunctions();
17371
17372 gl.getIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, &m_min_program_texel_offset);
17373 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17374
17375 gl.getIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, &m_max_program_texel_offset);
17376 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
17377
17378 if ((m_min_program_texel_offset_limit > m_min_program_texel_offset) ||
17379 (m_max_program_texel_offset_limit > m_max_program_texel_offset))
17380 {
17381 m_context.getTestContext().getLog()
17382 << tcu::TestLog::Message << "Invalid GL_PROGRAM_TEXEL_OFFSET values."
17383 << " Min: " << m_min_program_texel_offset << " expected at top: " << m_min_program_texel_offset_limit
17384 << " Max: " << m_min_program_texel_offset << " expected at least: " << m_max_program_texel_offset_limit
17385 << tcu::TestLog::EndMessage;
17386
17387 return false;
17388 }
17389
17390 return true;
17391 }
17392
17393 /** Constructor
17394 *
17395 * @param context Test context
17396 **/
BuiltInAssignmentTest(deqp::Context & context)17397 BuiltInAssignmentTest::BuiltInAssignmentTest(deqp::Context& context)
17398 : NegativeTestBase(context, "built_in_assignment",
17399 "Test verifies that built in gl_Min/MaxProgramTexelOffset cannot be assigned")
17400 {
17401 /* Nothing to be done here */
17402 }
17403
17404 /** Set up next test case
17405 *
17406 * @param test_case_index Index of next test case
17407 *
17408 * @return false if there is no more test cases, true otherwise
17409 **/
prepareNextTestCase(glw::GLuint test_case_index)17410 bool BuiltInAssignmentTest::prepareNextTestCase(glw::GLuint test_case_index)
17411 {
17412 const GLchar* description = 0;
17413
17414 switch (test_case_index)
17415 {
17416 case (glw::GLuint)-1:
17417 case 0:
17418 description = "Testing gl_MinProgramTexelOffset";
17419 break;
17420 case 1:
17421 description = "Testing gl_MaxProgramTexelOffset";
17422 break;
17423 default:
17424 return false;
17425 }
17426
17427 m_case = test_case_index;
17428
17429 m_context.getTestContext().getLog() << tcu::TestLog::Message << description << tcu::TestLog::EndMessage;
17430
17431 return true;
17432 }
17433
17434 /** Prepare source for given shader stage
17435 *
17436 * @param in_stage Shader stage, compute shader will use 430
17437 * @param in_use_version_400 Select if 400 or 420 should be used
17438 * @param out_source Prepared shader source instance
17439 **/
prepareShaderSource(Utils::SHADER_STAGES in_stage,bool in_use_version_400,Utils::shaderSource & out_source)17440 void BuiltInAssignmentTest::prepareShaderSource(Utils::SHADER_STAGES in_stage, bool in_use_version_400,
17441 Utils::shaderSource& out_source)
17442 {
17443 static const GLchar* min_verification_snippet = " gl_MinProgramTexelOffset += gl_MaxProgramTexelOffset\n"
17444 "\n"
17445 " if (expected_value != gl_MinProgramTexelOffset)\n"
17446 " {\n"
17447 " result = vec4(1, 0, 0, 1);\n"
17448 " }\n";
17449
17450 static const GLchar* max_verification_snippet = " gl_MaxProgramTexelOffset += gl_MinProgramTexelOffset\n"
17451 "\n"
17452 " if (expected_value != gl_MaxProgramTexelOffset)\n"
17453 " {\n"
17454 " result = vec4(1, 0, 0, 1);\n"
17455 " }\n";
17456
17457 static const GLchar* compute_shader_template =
17458 "VERSION\n"
17459 "\n"
17460 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
17461 "\n"
17462 "writeonly uniform image2D uni_image;\n"
17463 " uniform ivec2 expected_values;\n"
17464 "\n"
17465 "void main()\n"
17466 "{\n"
17467 " vec4 result = vec4(0, 1, 0, 1);\n"
17468 "\n"
17469 "VERIFICATION"
17470 "\n"
17471 " imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
17472 "}\n"
17473 "\n";
17474
17475 static const GLchar* fragment_shader_template = "VERSION\n"
17476 "\n"
17477 "in vec4 gs_fs_result;\n"
17478 "out vec4 fs_out_result;\n"
17479 "\n"
17480 "uniform ivec2 expected_values;\n"
17481 "\n"
17482 "void main()\n"
17483 "{\n"
17484 " vec4 result = vec4(0, 1, 0, 1);\n"
17485 "\n"
17486 "VERIFICATION"
17487 " else if (vec4(0, 1, 0, 1) != gs_fs_result)\n"
17488 " {\n"
17489 " result = vec4(1, 0, 0, 1);\n"
17490 " }\n"
17491 "\n"
17492 " fs_out_result = result;\n"
17493 "}\n"
17494 "\n";
17495
17496 static const GLchar* geometry_shader_template = "VERSION\n"
17497 "\n"
17498 "layout(points) in;\n"
17499 "layout(triangle_strip, max_vertices = 4) out;\n"
17500 "\n"
17501 "in vec4 tes_gs_result[];\n"
17502 "out vec4 gs_fs_result;\n"
17503 "\n"
17504 "uniform ivec2 expected_values;\n"
17505 "\n"
17506 "void main()\n"
17507 "{\n"
17508 " vec4 result = vec4(0, 1, 0, 1);\n"
17509 "\n"
17510 "VERIFICATION"
17511 " else if (vec4(0, 1, 0, 1) != tes_gs_result[0])\n"
17512 " {\n"
17513 " result = vec4(1, 0, 0, 1);\n"
17514 " }\n"
17515 "\n"
17516 " gs_fs_result = result;\n"
17517 " gl_Position = vec4(-1, -1, 0, 1);\n"
17518 " EmitVertex();\n"
17519 " gs_fs_result = result;\n"
17520 " gl_Position = vec4(-1, 1, 0, 1);\n"
17521 " EmitVertex();\n"
17522 " gs_fs_result = result;\n"
17523 " gl_Position = vec4(1, -1, 0, 1);\n"
17524 " EmitVertex();\n"
17525 " gs_fs_result = result;\n"
17526 " gl_Position = vec4(1, 1, 0, 1);\n"
17527 " EmitVertex();\n"
17528 "}\n"
17529 "\n";
17530
17531 static const GLchar* tess_ctrl_shader_template =
17532 "VERSION\n"
17533 "\n"
17534 "layout(vertices = 1) out;\n"
17535 "\n"
17536 "in vec4 vs_tcs_result[];\n"
17537 "out vec4 tcs_tes_result[];\n"
17538 "\n"
17539 "uniform ivec2 expected_values;\n"
17540 "\n"
17541 "void main()\n"
17542 "{\n"
17543 " vec4 result = vec4(0, 1, 0, 1);\n"
17544 "\n"
17545 "VERIFICATION"
17546 " else if (vec4(0, 1, 0, 1) != vs_tcs_result[gl_InvocationID])\n"
17547 " {\n"
17548 " result = vec4(1, 0, 0, 1);\n"
17549 " }\n"
17550 "\n"
17551 " tcs_tes_result[gl_InvocationID] = result;\n"
17552 "\n"
17553 " gl_TessLevelOuter[0] = 1.0;\n"
17554 " gl_TessLevelOuter[1] = 1.0;\n"
17555 " gl_TessLevelOuter[2] = 1.0;\n"
17556 " gl_TessLevelOuter[3] = 1.0;\n"
17557 " gl_TessLevelInner[0] = 1.0;\n"
17558 " gl_TessLevelInner[1] = 1.0;\n"
17559 "}\n"
17560 "\n";
17561
17562 static const GLchar* tess_eval_shader_template = "VERSION\n"
17563 "\n"
17564 "layout(isolines, point_mode) in;\n"
17565 "\n"
17566 "in vec4 tcs_tes_result[];\n"
17567 "out vec4 tes_gs_result;\n"
17568 "\n"
17569 "uniform ivec2 expected_values;\n"
17570 "\n"
17571 "void main()\n"
17572 "{\n"
17573 " vec4 result = vec4(0, 1, 0, 1);\n"
17574 "\n"
17575 "VERIFICATION"
17576 " else if (vec4(0, 1, 0, 1) != tcs_tes_result[0])\n"
17577 " {\n"
17578 " result = vec4(1, 0, 0, 1);\n"
17579 " }\n"
17580 "\n"
17581 " tes_gs_result = result;\n"
17582 "}\n"
17583 "\n";
17584
17585 static const GLchar* vertex_shader_template = "VERSION\n"
17586 "\n"
17587 "out vec4 vs_tcs_result;\n"
17588 "\n"
17589 "uniform ivec2 expected_values;\n"
17590 "\n"
17591 "void main()\n"
17592 "{\n"
17593 " vec4 result = vec4(0, 1, 0, 1);\n"
17594 "\n"
17595 "VERIFICATION"
17596 "\n"
17597 " vs_tcs_result = result;\n"
17598 "}\n"
17599 "\n";
17600
17601 const GLchar* shader_template = 0;
17602 const GLchar* verification_snippet = 0;
17603
17604 switch (in_stage)
17605 {
17606 case Utils::COMPUTE_SHADER:
17607 shader_template = compute_shader_template;
17608 break;
17609 case Utils::FRAGMENT_SHADER:
17610 shader_template = fragment_shader_template;
17611 break;
17612 case Utils::GEOMETRY_SHADER:
17613 shader_template = geometry_shader_template;
17614 break;
17615 case Utils::TESS_CTRL_SHADER:
17616 shader_template = tess_ctrl_shader_template;
17617 break;
17618 case Utils::TESS_EVAL_SHADER:
17619 shader_template = tess_eval_shader_template;
17620 break;
17621 case Utils::VERTEX_SHADER:
17622 shader_template = vertex_shader_template;
17623 break;
17624 default:
17625 TCU_FAIL("Invalid enum");
17626 }
17627
17628 switch (m_case)
17629 {
17630 case (glw::GLuint)-1:
17631 case 0:
17632 verification_snippet = min_verification_snippet;
17633 break;
17634 case 1:
17635 verification_snippet = max_verification_snippet;
17636 break;
17637 }
17638
17639 out_source.m_parts[0].m_code = shader_template;
17640
17641 size_t position = 0;
17642 Utils::replaceToken("VERSION", position, getVersionString(in_stage, in_use_version_400),
17643 out_source.m_parts[0].m_code);
17644
17645 Utils::replaceToken("VERIFICATION", position, verification_snippet, out_source.m_parts[0].m_code);
17646 }
17647
17648 /** Constructor.
17649 *
17650 * @param context CTS context.
17651 **/
buffer(deqp::Context & context)17652 Utils::buffer::buffer(deqp::Context& context) : m_id(0), m_context(context), m_target(0)
17653 {
17654 }
17655
17656 /** Destructor
17657 *
17658 **/
~buffer()17659 Utils::buffer::~buffer()
17660 {
17661 release();
17662 }
17663
17664 /** Execute BindBuffer
17665 *
17666 **/
bind() const17667 void Utils::buffer::bind() const
17668 {
17669 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17670
17671 gl.bindBuffer(m_target, m_id);
17672 GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
17673 }
17674
17675 /** Execute BindBufferRange
17676 *
17677 * @param index <index> parameter
17678 * @param offset <offset> parameter
17679 * @param size <size> parameter
17680 **/
bindRange(glw::GLuint index,glw::GLintptr offset,glw::GLsizeiptr size)17681 void Utils::buffer::bindRange(glw::GLuint index, glw::GLintptr offset, glw::GLsizeiptr size)
17682 {
17683 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17684
17685 gl.bindBufferRange(m_target, index, m_id, offset, size);
17686 GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
17687 }
17688
17689 /** Execute GenBuffer
17690 *
17691 * @param target Target that will be used by this buffer
17692 **/
generate(glw::GLenum target)17693 void Utils::buffer::generate(glw::GLenum target)
17694 {
17695 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17696
17697 m_target = target;
17698
17699 gl.genBuffers(1, &m_id);
17700 GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
17701 }
17702
17703 /** Maps buffer content
17704 *
17705 * @param access Access rights for mapped region
17706 *
17707 * @return Mapped memory
17708 **/
map(GLenum access) const17709 void* Utils::buffer::map(GLenum access) const
17710 {
17711 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17712
17713 gl.bindBuffer(m_target, m_id);
17714 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17715
17716 void* result = gl.mapBuffer(m_target, access);
17717 GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
17718
17719 return result;
17720 }
17721
17722 /** Unmaps buffer
17723 *
17724 **/
unmap() const17725 void Utils::buffer::unmap() 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 gl.unmapBuffer(m_target);
17733 GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
17734 }
17735
17736 /** Execute BufferData
17737 *
17738 * @param size <size> parameter
17739 * @param data <data> parameter
17740 * @param usage <usage> parameter
17741 **/
update(glw::GLsizeiptr size,glw::GLvoid * data,glw::GLenum usage)17742 void Utils::buffer::update(glw::GLsizeiptr size, glw::GLvoid* data, glw::GLenum usage)
17743 {
17744 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17745
17746 gl.bindBuffer(m_target, m_id);
17747 GLU_EXPECT_NO_ERROR(gl.getError(), "bindBuffer");
17748
17749 gl.bufferData(m_target, size, data, usage);
17750 GLU_EXPECT_NO_ERROR(gl.getError(), "bufferData");
17751 }
17752
17753 /** Release buffer
17754 *
17755 **/
release()17756 void Utils::buffer::release()
17757 {
17758 if (0 != m_id)
17759 {
17760 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17761
17762 gl.deleteBuffers(1, &m_id);
17763 m_id = 0;
17764 }
17765 }
17766
17767 /** Constructor
17768 *
17769 * @param context CTS context
17770 **/
framebuffer(deqp::Context & context)17771 Utils::framebuffer::framebuffer(deqp::Context& context) : m_id(0), m_context(context)
17772 {
17773 /* Nothing to be done here */
17774 }
17775
17776 /** Destructor
17777 *
17778 **/
~framebuffer()17779 Utils::framebuffer::~framebuffer()
17780 {
17781 if (0 != m_id)
17782 {
17783 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17784
17785 gl.deleteFramebuffers(1, &m_id);
17786 m_id = 0;
17787 }
17788 }
17789
17790 /** Attach texture to specified attachment
17791 *
17792 * @param attachment Attachment
17793 * @param texture_id Texture id
17794 * @param width Texture width
17795 * @param height Texture height
17796 **/
attachTexture(glw::GLenum attachment,glw::GLuint texture_id,glw::GLuint width,glw::GLuint height)17797 void Utils::framebuffer::attachTexture(glw::GLenum attachment, glw::GLuint texture_id, glw::GLuint width,
17798 glw::GLuint height)
17799 {
17800 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17801
17802 bind();
17803
17804 gl.bindTexture(GL_TEXTURE_2D, texture_id);
17805 GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
17806
17807 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture_id, 0 /* level */);
17808 GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture2D");
17809
17810 gl.viewport(0 /* x */, 0 /* y */, width, height);
17811 GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
17812 }
17813
17814 /** Binds framebuffer to DRAW_FRAMEBUFFER
17815 *
17816 **/
bind()17817 void Utils::framebuffer::bind()
17818 {
17819 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17820
17821 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_id);
17822 GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
17823 }
17824
17825 /** Clear framebuffer
17826 *
17827 * @param mask <mask> parameter of glClear. Decides which shall be cleared
17828 **/
clear(glw::GLenum mask)17829 void Utils::framebuffer::clear(glw::GLenum mask)
17830 {
17831 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17832
17833 gl.clear(mask);
17834 GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
17835 }
17836
17837 /** Specifies clear color
17838 *
17839 * @param red Red channel
17840 * @param green Green channel
17841 * @param blue Blue channel
17842 * @param alpha Alpha channel
17843 **/
clearColor(GLfloat red,GLfloat green,GLfloat blue,GLfloat alpha)17844 void Utils::framebuffer::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
17845 {
17846 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17847
17848 gl.clearColor(red, green, blue, alpha);
17849 GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
17850 }
17851
17852 /** Generate framebuffer
17853 *
17854 **/
generate()17855 void Utils::framebuffer::generate()
17856 {
17857 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17858
17859 gl.genFramebuffers(1, &m_id);
17860 GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
17861 }
17862
shaderSource()17863 Utils::shaderSource::shaderSource()
17864 {
17865 }
17866
shaderSource(const shaderSource & source)17867 Utils::shaderSource::shaderSource(const shaderSource& source) : m_parts(source.m_parts), m_use_lengths(false)
17868 {
17869 }
17870
shaderSource(const glw::GLchar * source_code)17871 Utils::shaderSource::shaderSource(const glw::GLchar* source_code) : m_use_lengths(false)
17872 {
17873 if (0 != source_code)
17874 {
17875 m_parts.resize(1);
17876
17877 m_parts[0].m_code = source_code;
17878 }
17879 }
17880
shaderCompilationException(const shaderSource & source,const glw::GLchar * message)17881 Utils::shaderCompilationException::shaderCompilationException(const shaderSource& source, const glw::GLchar* message)
17882 : m_shader_source(source), m_error_message(message)
17883 {
17884 /* Nothing to be done */
17885 }
17886
what() const17887 const char* Utils::shaderCompilationException::what() const throw()
17888 {
17889 return "Shader compilation failed";
17890 }
17891
programLinkageException(const glw::GLchar * message)17892 Utils::programLinkageException::programLinkageException(const glw::GLchar* message) : m_error_message(message)
17893 {
17894 /* Nothing to be done */
17895 }
17896
what() const17897 const char* Utils::programLinkageException::what() const throw()
17898 {
17899 return "Program linking failed";
17900 }
17901
17902 const glw::GLenum Utils::program::ARB_COMPUTE_SHADER = 0x91B9;
17903
17904 /** Constructor.
17905 *
17906 * @param context CTS context.
17907 **/
program(deqp::Context & context)17908 Utils::program::program(deqp::Context& context)
17909 : m_compute_shader_id(0)
17910 , m_fragment_shader_id(0)
17911 , m_geometry_shader_id(0)
17912 , m_program_object_id(0)
17913 , m_tesselation_control_shader_id(0)
17914 , m_tesselation_evaluation_shader_id(0)
17915 , m_vertex_shader_id(0)
17916 , m_context(context)
17917 {
17918 /* Nothing to be done here */
17919 }
17920
17921 /** Destructor
17922 *
17923 **/
~program()17924 Utils::program::~program()
17925 {
17926 remove();
17927 }
17928
17929 /** Build program
17930 *
17931 * @param compute_shader_code Compute shader source code
17932 * @param fragment_shader_code Fragment shader source code
17933 * @param geometry_shader_code Geometry shader source code
17934 * @param tesselation_control_shader_code Tesselation control shader source code
17935 * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17936 * @param vertex_shader_code Vertex shader source code
17937 * @param varying_names Array of strings containing names of varyings to be captured with transfrom feedback
17938 * @param n_varying_names Number of varyings to be captured with transfrom feedback
17939 * @param is_separable Selects if monolithis or separable program should be built. Defaults to false
17940 **/
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)17941 void Utils::program::build(const glw::GLchar* compute_shader_code, const glw::GLchar* fragment_shader_code,
17942 const glw::GLchar* geometry_shader_code, const glw::GLchar* tesselation_control_shader_code,
17943 const glw::GLchar* tesselation_evaluation_shader_code, const glw::GLchar* vertex_shader_code,
17944 const glw::GLchar* const* varying_names, glw::GLuint n_varying_names, bool is_separable)
17945 {
17946 const shaderSource compute_shader(compute_shader_code);
17947 const shaderSource fragment_shader(fragment_shader_code);
17948 const shaderSource geometry_shader(geometry_shader_code);
17949 const shaderSource tesselation_control_shader(tesselation_control_shader_code);
17950 const shaderSource tesselation_evaluation_shader(tesselation_evaluation_shader_code);
17951 const shaderSource vertex_shader(vertex_shader_code);
17952
17953 build(compute_shader, fragment_shader, geometry_shader, tesselation_control_shader, tesselation_evaluation_shader,
17954 vertex_shader, varying_names, n_varying_names, is_separable);
17955 }
17956
17957 /** Build program
17958 *
17959 * @param compute_shader_code Compute shader source code
17960 * @param fragment_shader_code Fragment shader source code
17961 * @param geometry_shader_code Geometry shader source code
17962 * @param tesselation_control_shader_code Tesselation control shader source code
17963 * @param tesselation_evaluation_shader_code Tesselation evaluation shader source code
17964 * @param vertex_shader_code Vertex shader source code
17965 * @param varying_names Array of strings containing names of varyings to be captured with transfrom feedback
17966 * @param n_varying_names Number of varyings to be captured with transfrom feedback
17967 * @param is_separable Selects if monolithis or separable program should be built. Defaults to false
17968 **/
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)17969 void Utils::program::build(const shaderSource& compute_shader, const shaderSource& fragment_shader,
17970 const shaderSource& geometry_shader, const shaderSource& tesselation_control_shader,
17971 const shaderSource& tesselation_evaluation_shader, const shaderSource& vertex_shader,
17972 const glw::GLchar* const* varying_names, glw::GLuint n_varying_names, bool is_separable)
17973 {
17974 /* GL entry points */
17975 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
17976
17977 /* Create shader objects and compile */
17978 if (false == compute_shader.m_parts.empty())
17979 {
17980 m_compute_shader_id = gl.createShader(ARB_COMPUTE_SHADER);
17981 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17982
17983 compile(m_compute_shader_id, compute_shader);
17984 }
17985
17986 if (false == fragment_shader.m_parts.empty())
17987 {
17988 m_fragment_shader_id = gl.createShader(GL_FRAGMENT_SHADER);
17989 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17990
17991 compile(m_fragment_shader_id, fragment_shader);
17992 }
17993
17994 if (false == geometry_shader.m_parts.empty())
17995 {
17996 m_geometry_shader_id = gl.createShader(GL_GEOMETRY_SHADER);
17997 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
17998
17999 compile(m_geometry_shader_id, geometry_shader);
18000 }
18001
18002 if (false == tesselation_control_shader.m_parts.empty())
18003 {
18004 m_tesselation_control_shader_id = gl.createShader(GL_TESS_CONTROL_SHADER);
18005 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18006
18007 compile(m_tesselation_control_shader_id, tesselation_control_shader);
18008 }
18009
18010 if (false == tesselation_evaluation_shader.m_parts.empty())
18011 {
18012 m_tesselation_evaluation_shader_id = gl.createShader(GL_TESS_EVALUATION_SHADER);
18013 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18014
18015 compile(m_tesselation_evaluation_shader_id, tesselation_evaluation_shader);
18016 }
18017
18018 if (false == vertex_shader.m_parts.empty())
18019 {
18020 m_vertex_shader_id = gl.createShader(GL_VERTEX_SHADER);
18021 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
18022
18023 compile(m_vertex_shader_id, vertex_shader);
18024 }
18025
18026 /* Create program object */
18027 m_program_object_id = gl.createProgram();
18028 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
18029
18030 /* Set up captyured varyings' names */
18031 if (0 != n_varying_names)
18032 {
18033 gl.transformFeedbackVaryings(m_program_object_id, n_varying_names, varying_names, GL_INTERLEAVED_ATTRIBS);
18034 GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
18035 }
18036
18037 /* Set separable parameter */
18038 if (true == is_separable)
18039 {
18040 gl.programParameteri(m_program_object_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
18041 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
18042 }
18043
18044 /* Link program */
18045 link();
18046 }
18047
compile(glw::GLuint shader_id,const Utils::shaderSource & source) const18048 void Utils::program::compile(glw::GLuint shader_id, const Utils::shaderSource& source) const
18049 {
18050 /* GL entry points */
18051 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18052
18053 /* Compilation status */
18054 glw::GLint status = GL_FALSE;
18055
18056 /* Source parts and lengths vectors */
18057 std::vector<const GLchar*> parts;
18058 std::vector<GLint> lengths_vector;
18059 GLint* lengths = 0;
18060
18061 /* Prepare storage */
18062 parts.resize(source.m_parts.size());
18063
18064 /* Prepare arrays */
18065 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18066 {
18067 parts[i] = source.m_parts[i].m_code.c_str();
18068 }
18069
18070 if (true == source.m_use_lengths)
18071 {
18072 lengths_vector.resize(source.m_parts.size());
18073
18074 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18075 {
18076 lengths_vector[i] = source.m_parts[i].m_length;
18077 }
18078
18079 lengths = &lengths_vector[0];
18080 }
18081
18082 /* Set source code */
18083 gl.shaderSource(shader_id, static_cast<GLsizei>(source.m_parts.size()), &parts[0], lengths);
18084 GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
18085
18086 /* Compile */
18087 gl.compileShader(shader_id);
18088 GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
18089
18090 /* Get compilation status */
18091 gl.getShaderiv(shader_id, GL_COMPILE_STATUS, &status);
18092 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
18093
18094 /* Log compilation error */
18095 if (GL_TRUE != status)
18096 {
18097 glw::GLint length = 0;
18098 std::vector<glw::GLchar> message;
18099
18100 /* Error log length */
18101 gl.getShaderiv(shader_id, GL_INFO_LOG_LENGTH, &length);
18102 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
18103
18104 /* Prepare storage */
18105 message.resize(length);
18106
18107 /* Get error log */
18108 gl.getShaderInfoLog(shader_id, length, 0, &message[0]);
18109 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
18110
18111 throw shaderCompilationException(source, &message[0]);
18112 }
18113 }
18114
18115 /** Create program from provided binary
18116 *
18117 * @param binary Buffer with binary form of program
18118 * @param binary_format Format of <binary> data
18119 **/
createFromBinary(const std::vector<GLubyte> & binary,GLenum binary_format)18120 void Utils::program::createFromBinary(const std::vector<GLubyte>& binary, GLenum binary_format)
18121 {
18122 /* GL entry points */
18123 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18124
18125 /* Create program object */
18126 m_program_object_id = gl.createProgram();
18127 GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
18128
18129 gl.programBinary(m_program_object_id, binary_format, &binary[0], static_cast<GLsizei>(binary.size()));
18130 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramBinary");
18131 }
18132
getAttribLocation(const glw::GLchar * name) const18133 glw::GLint Utils::program::getAttribLocation(const glw::GLchar* name) const
18134 {
18135 /* GL entry points */
18136 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18137
18138 GLint location = gl.getAttribLocation(m_program_object_id, name);
18139 GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
18140
18141 return location;
18142 }
18143
18144 /** Get binary form of program
18145 *
18146 * @param binary Buffer for binary data
18147 * @param binary_format Format of binary data
18148 **/
getBinary(std::vector<GLubyte> & binary,GLenum & binary_format) const18149 void Utils::program::getBinary(std::vector<GLubyte>& binary, GLenum& binary_format) const
18150 {
18151 /* GL entry points */
18152 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18153
18154 /* Get binary size */
18155 GLint length = 0;
18156 gl.getProgramiv(m_program_object_id, GL_PROGRAM_BINARY_LENGTH, &length);
18157 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18158
18159 /* Allocate storage */
18160 binary.resize(length);
18161
18162 /* Get binary */
18163 gl.getProgramBinary(m_program_object_id, static_cast<GLsizei>(binary.size()), &length, &binary_format, &binary[0]);
18164 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramBinary");
18165 }
18166
18167 /** Get subroutine index
18168 *
18169 * @param subroutine_name Subroutine name
18170 *
18171 * @return Index of subroutine
18172 **/
getSubroutineIndex(const glw::GLchar * subroutine_name,glw::GLenum shader_stage) const18173 GLuint Utils::program::getSubroutineIndex(const glw::GLchar* subroutine_name, glw::GLenum shader_stage) const
18174 {
18175 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18176 GLuint index = -1;
18177
18178 index = gl.getSubroutineIndex(m_program_object_id, shader_stage, subroutine_name);
18179 GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineIndex");
18180
18181 if (GL_INVALID_INDEX == index)
18182 {
18183 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine: " << subroutine_name
18184 << " is not available" << tcu::TestLog::EndMessage;
18185
18186 TCU_FAIL("Subroutine is not available");
18187 }
18188
18189 return index;
18190 }
18191
18192 /** Get subroutine uniform location
18193 *
18194 * @param uniform_name Subroutine uniform name
18195 *
18196 * @return Location of subroutine uniform
18197 **/
getSubroutineUniformLocation(const glw::GLchar * uniform_name,glw::GLenum shader_stage) const18198 GLint Utils::program::getSubroutineUniformLocation(const glw::GLchar* uniform_name, glw::GLenum shader_stage) const
18199 {
18200 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18201 GLint location = -1;
18202
18203 location = gl.getSubroutineUniformLocation(m_program_object_id, shader_stage, uniform_name);
18204 GLU_EXPECT_NO_ERROR(gl.getError(), "GetSubroutineUniformLocation");
18205
18206 if (-1 == location)
18207 {
18208 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Subroutine uniform: " << uniform_name
18209 << " is not available" << tcu::TestLog::EndMessage;
18210
18211 TCU_FAIL("Subroutine uniform is not available");
18212 }
18213
18214 return location;
18215 }
18216
18217 /** Get integer uniform at given location
18218 *
18219 * @param location Uniform location
18220 *
18221 * @return Value
18222 **/
getUniform1i(GLuint location) const18223 GLint Utils::program::getUniform1i(GLuint location) const
18224 {
18225 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18226
18227 GLint result;
18228
18229 gl.getUniformiv(m_program_object_id, location, &result);
18230 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformiv");
18231
18232 return result;
18233 }
18234
18235 /** Get uniform location
18236 *
18237 * @param uniform_name Subroutine uniform name
18238 *
18239 * @return Location of uniform
18240 **/
getUniformLocation(const glw::GLchar * uniform_name) const18241 GLint Utils::program::getUniformLocation(const glw::GLchar* uniform_name) const
18242 {
18243 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18244 GLint location = -1;
18245
18246 location = gl.getUniformLocation(m_program_object_id, uniform_name);
18247 GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
18248
18249 if (-1 == location)
18250 {
18251 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Uniform: " << uniform_name
18252 << " is not available" << tcu::TestLog::EndMessage;
18253
18254 TCU_FAIL("Uniform is not available");
18255 }
18256
18257 return location;
18258 }
18259
18260 /** Attach shaders and link program
18261 *
18262 **/
link() const18263 void Utils::program::link() const
18264 {
18265 /* GL entry points */
18266 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18267
18268 /* Link status */
18269 glw::GLint status = GL_FALSE;
18270
18271 /* Attach shaders */
18272 if (0 != m_compute_shader_id)
18273 {
18274 gl.attachShader(m_program_object_id, m_compute_shader_id);
18275 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18276 }
18277
18278 if (0 != m_fragment_shader_id)
18279 {
18280 gl.attachShader(m_program_object_id, m_fragment_shader_id);
18281 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18282 }
18283
18284 if (0 != m_geometry_shader_id)
18285 {
18286 gl.attachShader(m_program_object_id, m_geometry_shader_id);
18287 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18288 }
18289
18290 if (0 != m_tesselation_control_shader_id)
18291 {
18292 gl.attachShader(m_program_object_id, m_tesselation_control_shader_id);
18293 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18294 }
18295
18296 if (0 != m_tesselation_evaluation_shader_id)
18297 {
18298 gl.attachShader(m_program_object_id, m_tesselation_evaluation_shader_id);
18299 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18300 }
18301
18302 if (0 != m_vertex_shader_id)
18303 {
18304 gl.attachShader(m_program_object_id, m_vertex_shader_id);
18305 GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
18306 }
18307
18308 /* Link */
18309 gl.linkProgram(m_program_object_id);
18310 GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
18311
18312 /* Get link status */
18313 gl.getProgramiv(m_program_object_id, GL_LINK_STATUS, &status);
18314 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18315
18316 /* Log link error */
18317 if (GL_TRUE != status)
18318 {
18319 glw::GLint length = 0;
18320 std::vector<glw::GLchar> message;
18321
18322 /* Get error log length */
18323 gl.getProgramiv(m_program_object_id, GL_INFO_LOG_LENGTH, &length);
18324 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
18325
18326 message.resize(length);
18327
18328 /* Get error log */
18329 gl.getProgramInfoLog(m_program_object_id, length, 0, &message[0]);
18330 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
18331
18332 throw programLinkageException(&message[0]);
18333 }
18334 }
18335
18336 /** Delete program object and all attached shaders
18337 *
18338 **/
remove()18339 void Utils::program::remove()
18340 {
18341 /* GL entry points */
18342 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18343
18344 /* Make sure program object is no longer used by GL */
18345 gl.useProgram(0);
18346
18347 /* Clean program object */
18348 if (0 != m_program_object_id)
18349 {
18350 gl.deleteProgram(m_program_object_id);
18351 m_program_object_id = 0;
18352 }
18353
18354 /* Clean shaders */
18355 if (0 != m_compute_shader_id)
18356 {
18357 gl.deleteShader(m_compute_shader_id);
18358 m_compute_shader_id = 0;
18359 }
18360
18361 if (0 != m_fragment_shader_id)
18362 {
18363 gl.deleteShader(m_fragment_shader_id);
18364 m_fragment_shader_id = 0;
18365 }
18366
18367 if (0 != m_geometry_shader_id)
18368 {
18369 gl.deleteShader(m_geometry_shader_id);
18370 m_geometry_shader_id = 0;
18371 }
18372
18373 if (0 != m_tesselation_control_shader_id)
18374 {
18375 gl.deleteShader(m_tesselation_control_shader_id);
18376 m_tesselation_control_shader_id = 0;
18377 }
18378
18379 if (0 != m_tesselation_evaluation_shader_id)
18380 {
18381 gl.deleteShader(m_tesselation_evaluation_shader_id);
18382 m_tesselation_evaluation_shader_id = 0;
18383 }
18384
18385 if (0 != m_vertex_shader_id)
18386 {
18387 gl.deleteShader(m_vertex_shader_id);
18388 m_vertex_shader_id = 0;
18389 }
18390 }
18391
uniform(const glw::GLchar * uniform_name,TYPES type,glw::GLuint n_columns,glw::GLuint n_rows,const void * data) const18392 void Utils::program::uniform(const glw::GLchar* uniform_name, TYPES type, glw::GLuint n_columns, glw::GLuint n_rows,
18393 const void* data) const
18394 {
18395 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18396
18397 GLuint location = getUniformLocation(uniform_name);
18398
18399 if ((glw::GLuint)-1 == location)
18400 {
18401 TCU_FAIL("Uniform is inactive");
18402 }
18403
18404 switch (type)
18405 {
18406 case DOUBLE:
18407 if (1 == n_columns)
18408 {
18409 getUniformNdv(gl, n_rows)(location, 1 /* count */, (const GLdouble*)data);
18410 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
18411 }
18412 else
18413 {
18414 getUniformMatrixNdv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLdouble*)data);
18415 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
18416 }
18417 break;
18418 case FLOAT:
18419 if (1 == n_columns)
18420 {
18421 getUniformNfv(gl, n_rows)(location, 1 /* count */, (const GLfloat*)data);
18422 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
18423 }
18424 else
18425 {
18426 getUniformMatrixNfv(gl, n_columns, n_rows)(location, 1 /* count */, false, (const GLfloat*)data);
18427 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
18428 }
18429 break;
18430 case INT:
18431 getUniformNiv(gl, n_rows)(location, 1 /* count */, (const GLint*)data);
18432 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
18433 break;
18434 case UINT:
18435 getUniformNuiv(gl, n_rows)(location, 1 /* count */, (const GLuint*)data);
18436 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
18437 break;
18438 default:
18439 TCU_FAIL("Invalid enum");
18440 }
18441 }
18442
18443 /** Execute UseProgram
18444 *
18445 **/
use() const18446 void Utils::program::use() const
18447 {
18448 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18449
18450 gl.useProgram(m_program_object_id);
18451 GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
18452 }
18453
printShaderSource(const shaderSource & source,tcu::MessageBuilder & log)18454 void Utils::program::printShaderSource(const shaderSource& source, tcu::MessageBuilder& log)
18455 {
18456 GLuint line_number = 0;
18457
18458 log << "Shader source.";
18459
18460 for (GLuint i = 0; i < source.m_parts.size(); ++i)
18461 {
18462 log << "\nLine||Part: " << (i + 1) << "/" << source.m_parts.size();
18463
18464 if (true == source.m_use_lengths)
18465 {
18466 log << " Length: " << source.m_parts[i].m_length;
18467 }
18468
18469 log << "\n";
18470
18471 const GLchar* part = source.m_parts[i].m_code.c_str();
18472
18473 while (0 != part)
18474 {
18475 std::string line;
18476 const GLchar* next_line = strchr(part, '\n');
18477
18478 if (0 != next_line)
18479 {
18480 next_line += 1;
18481 line.assign(part, next_line - part);
18482 }
18483 else
18484 {
18485 line = part;
18486 }
18487
18488 if (0 != *part)
18489 {
18490 log << std::setw(4) << line_number << "||" << line;
18491 }
18492
18493 part = next_line;
18494 line_number += 1;
18495 }
18496 }
18497 }
18498
18499 /** Constructor.
18500 *
18501 * @param context CTS context.
18502 **/
texture(deqp::Context & context)18503 Utils::texture::texture(deqp::Context& context) : m_id(0), m_buffer_id(0), m_context(context), m_texture_type(TEX_2D)
18504 {
18505 /* Nothing to done here */
18506 }
18507
18508 /** Destructor
18509 *
18510 **/
~texture()18511 Utils::texture::~texture()
18512 {
18513 release();
18514 }
18515
18516 /** Bind texture to GL_TEXTURE_2D
18517 *
18518 **/
bind() const18519 void Utils::texture::bind() const
18520 {
18521 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18522
18523 GLenum target = getTextureTartet(m_texture_type);
18524
18525 gl.bindTexture(target, m_id);
18526 GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
18527 }
18528
18529 /** Create 2d texture
18530 *
18531 * @param width Width of texture
18532 * @param height Height of texture
18533 * @param internal_format Internal format of texture
18534 **/
create(glw::GLuint width,glw::GLuint height,glw::GLenum internal_format)18535 void Utils::texture::create(glw::GLuint width, glw::GLuint height, glw::GLenum internal_format)
18536 {
18537 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18538
18539 release();
18540
18541 m_texture_type = TEX_2D;
18542
18543 gl.genTextures(1, &m_id);
18544 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18545
18546 bind();
18547
18548 gl.texStorage2D(GL_TEXTURE_2D, 1 /* levels */, internal_format, width, height);
18549 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18550 }
18551
18552 /** Create texture of given type
18553 *
18554 * @param width Width of texture
18555 * @param height Height of texture
18556 * @param depth Depth of texture
18557 * @param internal_format Internal format of texture
18558 * @param texture_type Type of texture
18559 **/
create(GLuint width,GLuint height,GLuint depth,GLenum internal_format,TEXTURE_TYPES texture_type)18560 void Utils::texture::create(GLuint width, GLuint height, GLuint depth, GLenum internal_format,
18561 TEXTURE_TYPES texture_type)
18562 {
18563 static const GLuint levels = 1;
18564
18565 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18566
18567 release();
18568
18569 m_texture_type = texture_type;
18570
18571 GLenum target = getTextureTartet(m_texture_type);
18572
18573 gl.genTextures(1, &m_id);
18574 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18575
18576 bind();
18577
18578 switch (m_texture_type)
18579 {
18580 case TEX_1D:
18581 gl.texStorage1D(target, levels, internal_format, width);
18582 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18583 break;
18584 case TEX_2D:
18585 case TEX_1D_ARRAY:
18586 case TEX_2D_RECT:
18587 case TEX_CUBE:
18588 gl.texStorage2D(target, levels, internal_format, width, height);
18589 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18590 break;
18591 case TEX_3D:
18592 case TEX_2D_ARRAY:
18593 gl.texStorage3D(target, levels, internal_format, width, height, depth);
18594 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18595 break;
18596 default:
18597 TCU_FAIL("Invliad enum");
18598 }
18599 }
18600
18601 /** Create buffer texture
18602 *
18603 * @param internal_format Internal format of texture
18604 * @param buffer_id Id of buffer that will be used as data source
18605 **/
createBuffer(GLenum internal_format,GLuint buffer_id)18606 void Utils::texture::createBuffer(GLenum internal_format, GLuint buffer_id)
18607 {
18608 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18609
18610 release();
18611
18612 m_texture_type = TEX_BUFFER;
18613 m_buffer_id = buffer_id;
18614
18615 gl.genTextures(1, &m_id);
18616 GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
18617
18618 bind();
18619
18620 gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
18621 GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
18622 }
18623
18624 /** Get contents of texture
18625 *
18626 * @param format Format of image
18627 * @param type Type of image
18628 * @param out_data Buffer for image
18629 **/
get(glw::GLenum format,glw::GLenum type,glw::GLvoid * out_data) const18630 void Utils::texture::get(glw::GLenum format, glw::GLenum type, glw::GLvoid* out_data) const
18631 {
18632 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18633
18634 GLenum target = getTextureTartet(m_texture_type);
18635
18636 bind();
18637
18638 gl.memoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
18639 GLU_EXPECT_NO_ERROR(gl.getError(), "MemoryBarrier");
18640
18641 if (TEX_CUBE != m_texture_type)
18642 {
18643 gl.getTexImage(target, 0 /* level */, format, type, out_data);
18644 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18645 }
18646 else
18647 {
18648 GLint width;
18649 GLint height;
18650
18651 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
18652 {
18653 TCU_FAIL("Not implemented");
18654 }
18655
18656 GLuint texel_size = 4;
18657
18658 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
18659 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18660
18661 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
18662 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
18663
18664 const GLuint image_size = width * height * texel_size;
18665
18666 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
18667 (GLvoid*)((GLchar*)out_data + (image_size * 0)));
18668 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
18669 (GLvoid*)((GLchar*)out_data + (image_size * 1)));
18670 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
18671 (GLvoid*)((GLchar*)out_data + (image_size * 2)));
18672 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
18673 (GLvoid*)((GLchar*)out_data + (image_size * 3)));
18674 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
18675 (GLvoid*)((GLchar*)out_data + (image_size * 4)));
18676 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
18677 (GLvoid*)((GLchar*)out_data + (image_size * 5)));
18678 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
18679 }
18680 }
18681
18682 /** Delete texture
18683 *
18684 **/
release()18685 void Utils::texture::release()
18686 {
18687 if (0 != m_id)
18688 {
18689 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18690
18691 gl.deleteTextures(1, &m_id);
18692 m_id = 0;
18693
18694 if ((m_texture_type == TEX_BUFFER) && (0 != m_buffer_id))
18695 {
18696 gl.deleteBuffers(1, &m_buffer_id);
18697 m_buffer_id = 0;
18698 }
18699 }
18700 }
18701
18702 /** Update contents of texture
18703 *
18704 * @param width Width of texture
18705 * @param height Height of texture
18706 * @param format Format of data
18707 * @param type Type of data
18708 * @param data Buffer with image
18709 **/
update(glw::GLuint width,glw::GLuint height,glw::GLuint depth,glw::GLenum format,glw::GLenum type,glw::GLvoid * data)18710 void Utils::texture::update(glw::GLuint width, glw::GLuint height, glw::GLuint depth, glw::GLenum format,
18711 glw::GLenum type, glw::GLvoid* data)
18712 {
18713 static const GLuint level = 0;
18714
18715 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18716
18717 GLenum target = getTextureTartet(m_texture_type);
18718
18719 bind();
18720
18721 switch (m_texture_type)
18722 {
18723 case TEX_1D:
18724 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
18725 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
18726 break;
18727 case TEX_2D:
18728 case TEX_1D_ARRAY:
18729 case TEX_2D_RECT:
18730 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
18731 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18732 break;
18733 case TEX_CUBE:
18734 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18735 data);
18736 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
18737 data);
18738 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18739 data);
18740 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
18741 data);
18742 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18743 data);
18744 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
18745 data);
18746 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
18747 break;
18748 case TEX_3D:
18749 case TEX_2D_ARRAY:
18750 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
18751 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
18752 break;
18753 default:
18754 TCU_FAIL("Invliad enum");
18755 }
18756 }
18757
18758 /** Constructor.
18759 *
18760 * @param context CTS context.
18761 **/
vertexArray(deqp::Context & context)18762 Utils::vertexArray::vertexArray(deqp::Context& context) : m_id(0), m_context(context)
18763 {
18764 }
18765
18766 /** Destructor
18767 *
18768 **/
~vertexArray()18769 Utils::vertexArray::~vertexArray()
18770 {
18771 if (0 != m_id)
18772 {
18773 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18774
18775 gl.deleteVertexArrays(1, &m_id);
18776
18777 m_id = 0;
18778 }
18779 }
18780
18781 /** Execute BindVertexArray
18782 *
18783 **/
bind()18784 void Utils::vertexArray::bind()
18785 {
18786 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18787
18788 gl.bindVertexArray(m_id);
18789 GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
18790 }
18791
18792 /** Execute GenVertexArrays
18793 *
18794 **/
generate()18795 void Utils::vertexArray::generate()
18796 {
18797 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
18798
18799 gl.genVertexArrays(1, &m_id);
18800 GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
18801 }
18802 } /* GLSL420Pack namespace */
18803
18804 /** Constructor.
18805 *
18806 * @param context Rendering context.
18807 **/
ShadingLanguage420PackTests(deqp::Context & context)18808 ShadingLanguage420PackTests::ShadingLanguage420PackTests(deqp::Context& context)
18809 : TestCaseGroup(context, "shading_language_420pack", "Verifies \"shading_language_420pack\" functionality")
18810 {
18811 /* Left blank on purpose */
18812 }
18813
18814 /** Initializes a texture_storage_multisample test group.
18815 *
18816 **/
init(void)18817 void ShadingLanguage420PackTests::init(void)
18818 {
18819 addChild(new GLSL420Pack::BindingSamplerSingleTest(m_context));
18820 addChild(new GLSL420Pack::BindingImageSingleTest(m_context));
18821 addChild(new GLSL420Pack::UTF8CharactersTest(m_context));
18822 addChild(new GLSL420Pack::UTF8InSourceTest(m_context));
18823 addChild(new GLSL420Pack::QualifierOrderTest(m_context));
18824 addChild(new GLSL420Pack::QualifierOrderBlockTest(m_context));
18825 addChild(new GLSL420Pack::LineContinuationTest(m_context));
18826 addChild(new GLSL420Pack::LineNumberingTest(m_context));
18827 addChild(new GLSL420Pack::ImplicitConversionsValidTest(m_context));
18828 addChild(new GLSL420Pack::ImplicitConversionsInvalidTest(m_context));
18829 addChild(new GLSL420Pack::ConstDynamicValueTest(m_context));
18830 addChild(new GLSL420Pack::ConstAssignmentTest(m_context));
18831 addChild(new GLSL420Pack::ConstDynamicValueAsConstExprTest(m_context));
18832 addChild(new GLSL420Pack::QualifierOrderUniformTest(m_context));
18833 addChild(new GLSL420Pack::QualifierOrderFunctionInoutTest(m_context));
18834 addChild(new GLSL420Pack::QualifierOrderFunctionInputTest(m_context));
18835 addChild(new GLSL420Pack::QualifierOrderFunctionOutputTest(m_context));
18836 addChild(new GLSL420Pack::QualifierOverrideLayoutTest(m_context));
18837 addChild(new GLSL420Pack::BindingUniformBlocksTest(m_context));
18838 addChild(new GLSL420Pack::BindingUniformSingleBlockTest(m_context));
18839 addChild(new GLSL420Pack::BindingUniformBlockArrayTest(m_context));
18840 addChild(new GLSL420Pack::BindingUniformDefaultTest(m_context));
18841 addChild(new GLSL420Pack::BindingUniformAPIOverirdeTest(m_context));
18842 addChild(new GLSL420Pack::BindingUniformGlobalBlockTest(m_context));
18843 addChild(new GLSL420Pack::BindingUniformInvalidTest(m_context));
18844 addChild(new GLSL420Pack::BindingSamplersTest(m_context));
18845 addChild(new GLSL420Pack::BindingSamplerArrayTest(m_context));
18846 addChild(new GLSL420Pack::BindingSamplerDefaultTest(m_context));
18847 addChild(new GLSL420Pack::BindingSamplerAPIOverrideTest(m_context));
18848 addChild(new GLSL420Pack::BindingSamplerInvalidTest(m_context));
18849 addChild(new GLSL420Pack::BindingImagesTest(m_context));
18850 addChild(new GLSL420Pack::BindingImageArrayTest(m_context));
18851 addChild(new GLSL420Pack::BindingImageDefaultTest(m_context));
18852 addChild(new GLSL420Pack::BindingImageAPIOverrideTest(m_context));
18853 addChild(new GLSL420Pack::BindingImageInvalidTest(m_context));
18854 addChild(new GLSL420Pack::InitializerListTest(m_context));
18855 addChild(new GLSL420Pack::InitializerListNegativeTest(m_context));
18856 addChild(new GLSL420Pack::LengthOfVectorAndMatrixTest(m_context));
18857 addChild(new GLSL420Pack::LengthOfComputeResultTest(m_context));
18858 addChild(new GLSL420Pack::ScalarSwizzlersTest(m_context));
18859 addChild(new GLSL420Pack::ScalarSwizzlersInvalidTest(m_context));
18860 addChild(new GLSL420Pack::BuiltInValuesTest(m_context));
18861 addChild(new GLSL420Pack::BuiltInAssignmentTest(m_context));
18862 }
18863
18864 } /* gl4cts namespace */
18865