6 $ Comment line starts with dollar sign and white space.
8 $ $program <name> starts a new test program section called <name>. Contains all other sections.
10 $ $attrib <name> starts vertex data input section for attrib called <name>. Each line consists of
11 $ four values that form single vertex attrib.
13 $ $vertex starts vertex shader section. Contains $code and &output sections.
15 $ $code starts source code section. All text in this section gets compiled into appropriate
18 $ $output starts shader execution results section. These are compared, value-by-value,
19 $ with results of executing printMESA() functions within a shader.
24 $ --------------------------------------------------------------------------------------------------
25 $ Test printMESA() function.
36 #extension MESA_shader_debug: require
39 gl_Position = gl_ModelViewMatrix * gl_Vertex;
40 gl_FrontColor = vec4 (1.0);
46 printMESA (vec2 (22.1, 22.2));
47 printMESA (vec3 (33.1, 33.2, 33.3));
48 printMESA (vec4 (44.1, 44.2, 44.3, 44.4));
50 printMESA (ivec2 (221, 222));
51 printMESA (ivec3 (331, 332, 333));
52 printMESA (ivec4 (441, 442, 443, 444));
54 printMESA (bvec2 (false, true));
55 printMESA (bvec3 (true, true, false));
56 printMESA (bvec4 (true, false, true, false));
58 printMESA (mat2 (55.11, 55.12, 55.21, 55.22));
59 printMESA (mat3 (66.11, 66.12, 66.13,
61 66.31, 66.32, 66.33));
62 printMESA (mat4 (77.11, 77.12, 77.13, 77.14,
63 77.21, 77.22, 77.23, 77.24,
64 77.31, 77.32, 77.33, 77.34,
65 77.41, 77.42, 77.43, 77.44));
138 $ --------------------------------------------------------------------------------------------------
142 $program TYPE CAST TEST
165 #extension MESA_shader_debug: require
167 attribute float _Zero;
168 attribute float _One;
169 attribute float _Two;
170 attribute float _MinusThree;
173 gl_Position = gl_ModelViewMatrix * gl_Vertex;
174 gl_FrontColor = vec4 (1.0);
179 printMESA (_MinusThree);
181 printMESA (float (_Zero));
182 printMESA (float (_One));
183 printMESA (float (_Two));
184 printMESA (float (_MinusThree));
185 printMESA (float (45.99));
186 printMESA (float (-6.17));
188 printMESA (bool (_Zero));
189 printMESA (bool (_One));
190 printMESA (bool (_Two));
191 printMESA (bool (_MinusThree));
192 printMESA (bool (45.99));
193 printMESA (bool (-6.17));
194 printMESA (bool (0.0001));
195 printMESA (bool (0.0));
197 printMESA (int (_Zero));
198 printMESA (int (_One));
199 printMESA (int (_Two));
200 printMESA (int (_MinusThree));
201 printMESA (int (45.99));
202 printMESA (int (45.22));
203 printMESA (int (-6.17));
204 printMESA (int (-6.87));
240 $ --------------------------------------------------------------------------------------------------
241 $ Test vector swizzles.
244 $program SWIZZLE TEST
261 #extension MESA_shader_debug: require
266 void assign5678 (out vec4 v)
275 gl_Position = gl_ModelViewMatrix * gl_Vertex;
276 gl_FrontColor = vec4 (1.0);
297 printMESA (_One.xyz);
298 printMESA (_One.yzx);
299 printMESA (_One.zxy);
300 printMESA (_One.xzy);
301 printMESA (_One.yzw);
302 printMESA (_One.zwx);
304 printMESA (_Two.xyzw);
305 printMESA (_Two.yzwx);
306 printMESA (_Two.wzyx);
307 printMESA (_Two.zwyx);
313 printMESA (_Two.xxx);
314 printMESA (_Two.yyy);
315 printMESA (_Two.www);
317 printMESA (_One.xxxx);
318 printMESA (_One.zzzz);
320 printMESA (_Two.xxyy);
321 printMESA (_Two.wwxx);
322 printMESA (_Two.zxxw);
326 v.zxwy = vec4 (5.5, 6.6, 7.7, 8.8);
457 $ --------------------------------------------------------------------------------------------------
458 $ Test relational operators.
461 $program RELATIONAL OPERATOR TEST
481 #extension MESA_shader_debug: require
483 attribute float _Two;
484 attribute float _Two2;
485 attribute float _MinusThree;
497 void printMESA (const in foo bar)
508 gl_Position = gl_ModelViewMatrix * gl_Vertex;
509 gl_FrontColor = vec4 (1.0);
511 int iTwo = int (_Two);
512 int iTwo2 = int (_Two2);
513 int iMinusThree = int (_MinusThree);
515 printMESA (_Two <= _Two);
516 printMESA (_Two <= _Two2);
517 printMESA (_Two <= _MinusThree);
518 printMESA (_MinusThree <= _Two);
519 printMESA (iTwo <= iTwo);
520 printMESA (iTwo <= iTwo2);
521 printMESA (iTwo <= iMinusThree);
522 printMESA (iMinusThree <= iTwo);
524 printMESA (_Two >= _Two);
525 printMESA (_Two >= _Two2);
526 printMESA (_Two >= _MinusThree);
527 printMESA (_MinusThree >= _Two);
528 printMESA (iTwo >= iTwo);
529 printMESA (iTwo >= iTwo2);
530 printMESA (iTwo >= iMinusThree);
531 printMESA (iMinusThree >= iTwo);
533 printMESA (_Two < _Two);
534 printMESA (_Two < _Two2);
535 printMESA (_Two < _MinusThree);
536 printMESA (_MinusThree < _Two);
537 printMESA (iTwo < iTwo);
538 printMESA (iTwo < iTwo2);
539 printMESA (iTwo < iMinusThree);
540 printMESA (iMinusThree < iTwo);
542 printMESA (_Two > _Two);
543 printMESA (_Two > _Two2);
544 printMESA (_Two > _MinusThree);
545 printMESA (_MinusThree > _Two);
546 printMESA (iTwo > iTwo);
547 printMESA (iTwo > iTwo2);
548 printMESA (iTwo > iMinusThree);
549 printMESA (iMinusThree > iTwo);
551 printMESA (_Two == _Two);
552 printMESA (_Two == _Two2);
553 printMESA (_Two == _MinusThree);
554 printMESA (_MinusThree == _MinusThree);
555 printMESA (iTwo == iTwo);
556 printMESA (iTwo == iTwo2);
557 printMESA (iTwo == iMinusThree);
558 printMESA (iMinusThree == iMinusThree);
560 printMESA (_Two != _Two);
561 printMESA (_Two != _Two2);
562 printMESA (_Two != _MinusThree);
563 printMESA (_MinusThree != _MinusThree);
564 printMESA (iTwo != iTwo);
565 printMESA (iTwo != iTwo2);
566 printMESA (iTwo != iMinusThree);
567 printMESA (iMinusThree != iMinusThree);
571 foo1.v4 = vec4 (44.11, 44.22, 44.33, 44.44);
572 foo1.v3 = vec3 (33.11, 33.22, 33.33);
573 foo1.m4 = mat4 (17.88);
578 // make foo2 the same as foo1
581 foo2.v4 = vec4 (44.11, 44.22, 44.33, 44.44);
582 foo2.v3 = vec3 (33.11, 33.22, 33.33);
583 foo2.m4 = mat4 (17.88);
587 printMESA (foo1 == foo2);
588 printMESA (foo1 != foo2);
590 // make them a little bit different
591 foo2.m4[2].y = 333.333;
594 printMESA (foo1 == foo2);
595 printMESA (foo1 != foo2);
716 $ --------------------------------------------------------------------------------------------------
717 $ Test logical operators.
720 $program LOGICAL OPERATOR TEST
743 #extension MESA_shader_debug: require
745 attribute float _False;
746 attribute float _True;
747 attribute float _False2;
748 attribute float _True2;
751 gl_Position = gl_ModelViewMatrix * gl_Vertex;
752 gl_FrontColor = vec4 (1.0);
759 bool False = bool (_False);
760 bool True = bool (_True);
761 bool False2 = bool (_False2);
762 bool True2 = bool (_True2);
765 // It is important to test each operator with the following argument types:
766 // * Both arguments are different variables, even if they have the same values.
767 // False and False2 are distinct attributes, but are the same in value.
768 // * Both arguments may be the same variables. This case tests possible
769 // optimizations, e.g. X && X --> X.
770 // * Both arguments are constant. This tests constant folding.
778 printMESA (False ^^ False2);
779 printMESA (False ^^ True2);
780 printMESA (True ^^ False2);
781 printMESA (True ^^ True2);
782 printMESA (False ^^ False);
783 printMESA (False ^^ True);
784 printMESA (True ^^ False);
785 printMESA (True ^^ True);
786 printMESA (false ^^ false);
787 printMESA (false ^^ true);
788 printMESA (true ^^ false);
789 printMESA (true ^^ true);
791 printMESA (False && False2);
792 printMESA (False && True2);
793 printMESA (True && False2);
794 printMESA (True && True2);
795 printMESA (False && False);
796 printMESA (False && True);
797 printMESA (True && False);
798 printMESA (True && True);
799 printMESA (false && false);
800 printMESA (false && true);
801 printMESA (true && false);
802 printMESA (true && true);
804 printMESA (False || False2);
805 printMESA (False || True2);
806 printMESA (True || False2);
807 printMESA (True || True2);
808 printMESA (False || False);
809 printMESA (False || True);
810 printMESA (True || False);
811 printMESA (True || True);
812 printMESA (false || false);
813 printMESA (false || true);
814 printMESA (true || false);
815 printMESA (true || true);
818 // Test short-circuit evaluation of && and ||. The right expression evaluation depends
819 // on the value of the left expression. If the right expression has side effects, we
820 // can easily test if it happened.
827 printMESA (False && (x = true));
832 printMESA (false && (x = true));
837 printMESA (True || (x = false));
842 printMESA (true || (x = false));
915 $ --------------------------------------------------------------------------------------------------
916 $ Test subscript operator/array access.
919 $program ARRAY ACCESS TEST
934 11.11 22.22 33.33 44.44
942 #extension MESA_shader_debug: require
944 attribute float _Zero;
945 attribute float _One;
946 attribute float _Two;
950 gl_Position = gl_ModelViewMatrix * gl_Vertex;
951 gl_FrontColor = vec4 (1.0);
963 printMESA (_Vec[int (_Zero)]);
964 printMESA (_Vec[int (_One)]);
965 printMESA (_Vec[int (_Two)]);
989 $ --------------------------------------------------------------------------------------------------
990 $ Test pre/post-increment/decrement operators.
991 $ Note: assumes relational operators being correct.
994 $program PRE/POST-INC/DEC OPERATOR TEST
1014 #extension MESA_shader_debug: require
1016 attribute float _Zero;
1017 attribute float _One;
1018 attribute vec4 _Two4;
1029 iZero = int (_Zero);
1031 iTwo4 = ivec4 (_Two4);
1035 gl_Position = gl_ModelViewMatrix * gl_Vertex;
1036 gl_FrontColor = vec4 (1.0);
1044 printMESA (++fZero);
1046 printMESA (++iZero);
1052 printMESA (++fTwo4 == _Two4 + 1.0);
1053 printMESA (++iTwo4 == ivec4 (_Two4) + 1);
1057 printMESA (--fZero);
1059 printMESA (--iZero);
1065 printMESA (--fTwo4 == _Two4 - 1.0);
1066 printMESA (--iTwo4 == ivec4 (_Two4) - 1);
1070 printMESA (fZero++);
1072 printMESA (iZero++);
1078 printMESA (fTwo4++ == _Two4);
1079 printMESA (iTwo4++ == ivec4 (_Two4));
1083 printMESA (fZero--);
1085 printMESA (iZero--);
1091 printMESA (fTwo4-- == _Two4);
1092 printMESA (iTwo4-- == ivec4 (_Two4));
1150 $ --------------------------------------------------------------------------------------------------
1151 $ Test arithmetical operators.
1154 $program ARITHMETICAL OPERATOR TEST
1174 #extension MESA_shader_debug: require
1176 attribute float _Zero;
1177 attribute float _One;
1178 attribute vec4 _Two4;
1181 gl_Position = gl_ModelViewMatrix * gl_Vertex;
1182 gl_FrontColor = vec4 (1.0);
1188 int iZero = int (_Zero);
1189 int iOne = int (_One);
1190 ivec4 iTwo4 = ivec4 (_Two4);
1195 printMESA (-_Two4.z);
1197 printMESA (_Zero + 0.0);
1198 printMESA (_One + 0.0);
1199 printMESA (_Two4 + 0.0);
1200 printMESA (_Two4.y + 0.0);
1202 printMESA (_Zero + _Zero);
1203 printMESA (_Zero + _One);
1204 printMESA (_Zero + _Two4);
1205 printMESA (_One + _Zero);
1206 printMESA (_One + _Two4);
1207 printMESA (_Two4 + _Two4);
1209 printMESA (_Zero - 0.0);
1210 printMESA (_One - 0.0);
1211 printMESA (_Two4 - 0.0);
1212 printMESA (_Two4.y - 0.0);
1214 printMESA (_Zero - _Zero);
1215 printMESA (_Zero - _One);
1216 printMESA (_Zero - _Two4);
1217 printMESA (_One - _Zero);
1218 printMESA (_One - _Two4);
1219 printMESA (_Two4 - _Two4);
1221 printMESA (_Zero * 1.0);
1222 printMESA (_One * 1.0);
1223 printMESA (_Two4 * 1.0);
1224 printMESA (_Two4.x * 1.0);
1226 printMESA (_Zero * _Zero);
1227 printMESA (_Zero * _One);
1228 printMESA (_Zero * _Two4);
1229 printMESA (_One * _Zero);
1230 printMESA (_One * _One);
1231 printMESA (_One * _Two4);
1232 printMESA (_Two4 * _Two4);
1234 printMESA (_Zero / 1.0);
1235 printMESA (_One / 1.0);
1236 printMESA (_Two4 / 1.0);
1237 printMESA (_Two4.x / 1.0);
1239 printMESA (_Zero / _One);
1240 printMESA (_Zero / _Two4);
1241 printMESA (_One / _One);
1242 printMESA (_One / _Two4);
1243 printMESA (_Two4 / _Two4);
1361 $ --------------------------------------------------------------------------------------------------
1362 $ Test matrix operations.
1363 $ Note: assumes relational operators being correct.
1366 $program MATRIX TEST
1386 #extension MESA_shader_debug: require
1388 attribute vec4 _Zero;
1389 attribute vec4 _One;
1390 attribute vec4 _Two;
1393 gl_Position = gl_ModelViewMatrix * gl_Vertex;
1394 gl_FrontColor = vec4 (1.0);
1400 mat4 Identity = mat4 (_One.x);
1402 printMESA (Identity == mat4 (1.0, 0.0, 0.0, 0.0,
1405 0.0, 0.0, 0.0, 1.0));
1406 printMESA (Identity * _Two == _Two);
1408 mat4 Matrix = mat4 (1.1, 1.2, 1.3, 1.4,
1411 4.1, 4.2, 4.3, 4.4);
1413 printMESA (Matrix[2].y);
1414 printMESA (Matrix[1]);
1441 $ --------------------------------------------------------------------------------------------------
1442 $ Test vec4 extension operations.
1445 $program VEC4 EXTENSION OPERATIONS
1465 #extension MESA_shader_debug: require
1467 attribute float _One;
1468 attribute vec4 _Two4;
1469 attribute vec4 _Three4;
1472 gl_Position = gl_ModelViewMatrix * gl_Vertex;
1473 gl_FrontColor = vec4 (1.0);
1477 printMESA (_Three4);
1479 printMESA (vec4 (_One));
1481 printMESA (_Two4 + _Three4);
1482 printMESA (_Two4 - _Three4);
1483 printMESA (_Two4 * _Three4);
1484 printMESA (_Two4 / _Three4);
1486 printMESA (_Two4 + _One);
1487 printMESA (_Two4 - _One);
1488 printMESA (_Two4 * _One);
1489 printMESA (_Two4 / _One);
1491 printMESA (_One + _Two4);
1492 printMESA (_One - _Two4);
1493 printMESA (_One * _Two4);
1494 printMESA (_One / _Two4);
1496 printMESA (-_Three4);
1498 printMESA (dot (_Two4.xyz, _Three4.xyz));
1499 printMESA (dot (_Two4, _Three4));
1501 printMESA (length (_Two4.xyz));
1502 printMESA (length (_Three4));
1504 printMESA (normalize (_Two4.xyz));
1505 printMESA (normalize (_Three4));
1510 printMESA (_Two4 == _Three4);
1511 printMESA (_Two4 != _Three4);
1512 printMESA (_Two4 == _Two4);
1513 printMESA (_Three4 != _Three4);
1514 printMESA (_Two4 != vec4 (_Two4.xyz, 999.0));
1515 printMESA (_Two4 != vec4 (999.0, _Two4.yzw));