Hash :
63490943
Author :
Date :
2017-09-15T23:03:14
Work around VS 2017 compiler bug in dEQP. We should upstream this fix to dEQP once we have the chance. BUG=chromium:759402 Change-Id: I64e5df9bc6552e6fabe2b4b60c877fa30fd4c1f2 Reviewed-on: https://chromium-review.googlesource.com/670101 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
/*-------------------------------------------------------------------------
* drawElements Quality Program OpenGL ES 2.0 Module
* -------------------------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief Shader matrix arithmetic tests.
*
* Variables:
* + operation
* - mat OP mat
* - mat OP vec
* - vec OP mat
* - mat OP scalar
* - OP mat
* + matrix source
* - constant (ctor)
* - uniform
* - vertex input
* - fragment input
* + other operand: always dynamic data?
* + how to reduce to vec3?
*//*--------------------------------------------------------------------*/
#include "es2fShaderMatrixTests.hpp"
#include "glsShaderRenderCase.hpp"
#include "gluShaderUtil.hpp"
#include "tcuVector.hpp"
#include "tcuMatrix.hpp"
#include "tcuMatrixUtil.hpp"
#include "deStringUtil.hpp"
#include "glwEnums.hpp"
#include "glwFunctions.hpp"
namespace deqp
{
namespace gles2
{
namespace Functional
{
using std::string;
using std::vector;
using namespace glu;
using namespace deqp::gls;
using tcu::Vec2;
using tcu::Vec3;
using tcu::Vec4;
using tcu::Mat2;
using tcu::Mat3;
using tcu::Mat4;
// Uniform / constant values for tests.
// \note Input1 should not contain 0 components as it is used as divisor in div cases.
// \todo [2012-02-14 pyry] Make these dynamic.
static const float s_constInFloat[2] = { 0.5f, -0.2f };
static const Vec2 s_constInVec2[2] = { Vec2(1.2f, 0.5f), Vec2(0.5f, 1.0f) };
static const Vec3 s_constInVec3[2] = { Vec3(1.1f, 0.1f, 0.5f), Vec3(-0.2f, 0.5f, 0.8f) };
static const Vec4 s_constInVec4[2] = { Vec4(1.4f, 0.2f, -0.5f, 0.7f), Vec4(0.2f, -1.0f, 0.5f, 0.8f) };
static const float s_constInMat20[] = { 0.6f, -1.0f, 0.7f, 0.4f };
static const float s_constInMat21[] = { -0.5f, -0.4f, 0.7f, -0.8f };
static const float s_constInMat31[] =
{
1.2f, 0.1f, -0.1f,
0.1f, 0.9f, 0.2f,
0.2f, -0.1f, 0.7f
};
static const float s_constInMat41[] =
{
1.2f, -0.2f, 0.4f, 0.1f,
0.1f, 0.8f, -0.1f, -0.2f,
-0.2f, 0.1f, -1.1f, 0.3f,
0.1f, 0.2f, 0.3f, 0.9f
};
static const Mat2 s_constInMat2[2] = { tcu::Mat2(s_constInMat20), tcu::Mat2(s_constInMat21) };
static const Mat3 s_constInMat3[2] = { tcu::translationMatrix(tcu::Vec2(0.2f, -0.3f)), tcu::Mat3(s_constInMat31) };
static const Mat4 s_constInMat4[2] = { tcu::translationMatrix(tcu::Vec3(0.2f, -0.3f, 0.15f)), tcu::Mat4(s_constInMat41) };
namespace MatrixCaseUtils
{
enum InputType
{
INPUTTYPE_CONST = 0,
INPUTTYPE_UNIFORM,
INPUTTYPE_DYNAMIC,
INPUTTYPE_LAST
};
struct ShaderInput
{
ShaderInput (InputType inputType_, DataType dataType_, Precision precision_)
: inputType (inputType_)
, dataType (dataType_)
, precision (precision_)
{
}
InputType inputType;
DataType dataType;
Precision precision;
};
enum MatrixOp
{
OP_ADD = 0,
OP_SUB,
OP_MUL,
OP_DIV,
OP_COMP_MUL,
OP_UNARY_PLUS,
OP_NEGATION,
OP_PRE_INCREMENT,
OP_PRE_DECREMENT,
OP_POST_INCREMENT,
OP_POST_DECREMENT,
OP_ADD_INTO,
OP_SUBTRACT_FROM,
OP_MULTIPLY_INTO,
OP_DIVIDE_INTO,
OP_LAST
};
// Type traits.
template <int DataT>
struct TypeTraits;
#define DECLARE_TYPE_TRAIT(DATATYPE, TYPE) \
template<> \
struct TypeTraits<DATATYPE> { \
typedef TYPE Type; \
}
DECLARE_TYPE_TRAIT(TYPE_FLOAT, float);
DECLARE_TYPE_TRAIT(TYPE_FLOAT_VEC2, tcu::Vec2);
DECLARE_TYPE_TRAIT(TYPE_FLOAT_VEC3, tcu::Vec3);
DECLARE_TYPE_TRAIT(TYPE_FLOAT_VEC4, tcu::Vec4);
DECLARE_TYPE_TRAIT(TYPE_FLOAT_MAT2, tcu::Mat2);
DECLARE_TYPE_TRAIT(TYPE_FLOAT_MAT3, tcu::Mat3);
DECLARE_TYPE_TRAIT(TYPE_FLOAT_MAT4, tcu::Mat4);
// Operation info
enum OperationType
{
OPERATIONTYPE_BINARY_OPERATOR = 0,
OPERATIONTYPE_BINARY_FUNCTION,
OPERATIONTYPE_UNARY_PREFIX_OPERATOR,
OPERATIONTYPE_UNARY_POSTFIX_OPERATOR,
OPERATIONTYPE_ASSIGNMENT,
OPERATIONTYPE_LAST
};
static const char* getOperationName (MatrixOp op)
{
switch (op)
{
case OP_ADD: return "+";
case OP_SUB: return "-";
case OP_MUL: return "*";
case OP_DIV: return "/";
case OP_COMP_MUL: return "matrixCompMult";
case OP_UNARY_PLUS: return "+";
case OP_NEGATION: return "-";
case OP_PRE_INCREMENT: return "++";
case OP_PRE_DECREMENT: return "--";
case OP_POST_INCREMENT: return "++";
case OP_POST_DECREMENT: return "--";
case OP_ADD_INTO: return "+=";
case OP_SUBTRACT_FROM: return "-=";
case OP_MULTIPLY_INTO: return "*=";
case OP_DIVIDE_INTO: return "/=";
default:
DE_ASSERT(DE_FALSE);
return "";
}
}
static OperationType getOperationType (MatrixOp op)
{
switch (op)
{
case OP_ADD: return OPERATIONTYPE_BINARY_OPERATOR;
case OP_SUB: return OPERATIONTYPE_BINARY_OPERATOR;
case OP_MUL: return OPERATIONTYPE_BINARY_OPERATOR;
case OP_DIV: return OPERATIONTYPE_BINARY_OPERATOR;
case OP_COMP_MUL: return OPERATIONTYPE_BINARY_FUNCTION;
case OP_UNARY_PLUS: return OPERATIONTYPE_UNARY_PREFIX_OPERATOR;
case OP_NEGATION: return OPERATIONTYPE_UNARY_PREFIX_OPERATOR;
case OP_PRE_INCREMENT: return OPERATIONTYPE_UNARY_PREFIX_OPERATOR;
case OP_PRE_DECREMENT: return OPERATIONTYPE_UNARY_PREFIX_OPERATOR;
case OP_POST_INCREMENT: return OPERATIONTYPE_UNARY_POSTFIX_OPERATOR;
case OP_POST_DECREMENT: return OPERATIONTYPE_UNARY_POSTFIX_OPERATOR;
case OP_ADD_INTO: return OPERATIONTYPE_ASSIGNMENT;
case OP_SUBTRACT_FROM: return OPERATIONTYPE_ASSIGNMENT;
case OP_MULTIPLY_INTO: return OPERATIONTYPE_ASSIGNMENT;
case OP_DIVIDE_INTO: return OPERATIONTYPE_ASSIGNMENT;
default:
DE_ASSERT(DE_FALSE);
return OPERATIONTYPE_LAST;
}
}
enum TestMatrixType
{
TESTMATRIXTYPE_DEFAULT = 0,
TESTMATRIXTYPE_NEGATED,
TESTMATRIXTYPE_INCREMENTED,
TESTMATRIXTYPE_DECREMENTED,
TESTMATRIXTYPE_LAST
};
static TestMatrixType getOperationTestMatrixType (MatrixOp op)
{
switch(op)
{
case OP_ADD: return TESTMATRIXTYPE_DEFAULT;
case OP_SUB: return TESTMATRIXTYPE_DEFAULT;
case OP_MUL: return TESTMATRIXTYPE_DEFAULT;
case OP_DIV: return TESTMATRIXTYPE_DEFAULT;
case OP_COMP_MUL: return TESTMATRIXTYPE_DEFAULT;
case OP_UNARY_PLUS: return TESTMATRIXTYPE_DEFAULT;
case OP_NEGATION: return TESTMATRIXTYPE_NEGATED;
case OP_PRE_INCREMENT: return TESTMATRIXTYPE_NEGATED;
case OP_PRE_DECREMENT: return TESTMATRIXTYPE_INCREMENTED;
case OP_POST_INCREMENT: return TESTMATRIXTYPE_NEGATED;
case OP_POST_DECREMENT: return TESTMATRIXTYPE_DEFAULT;
case OP_ADD_INTO: return TESTMATRIXTYPE_DECREMENTED;
case OP_SUBTRACT_FROM: return TESTMATRIXTYPE_DEFAULT;
case OP_MULTIPLY_INTO: return TESTMATRIXTYPE_DEFAULT;
case OP_DIVIDE_INTO: return TESTMATRIXTYPE_DEFAULT;
default:
DE_ASSERT(DE_FALSE);
return TESTMATRIXTYPE_LAST;
}
}
static bool isOperationBinary (MatrixOp op)
{
return getOperationType(op) == OPERATIONTYPE_BINARY_OPERATOR ||
getOperationType(op) == OPERATIONTYPE_BINARY_FUNCTION ||
getOperationType(op) == OPERATIONTYPE_ASSIGNMENT;
}
static bool isOperationMatrixScalar (MatrixOp op)
{
return op == OP_ADD || op == OP_SUB || op == OP_MUL || op == OP_DIV;
}
static bool isOperationMatrixVector (MatrixOp op)
{
return op == OP_MUL;
}
static bool isOperationMatrixMatrix (MatrixOp op)
{
return op == OP_ADD || op == OP_SUB || op == OP_MUL || op == OP_DIV || op == OP_COMP_MUL;
}
static bool isOperationUnary (MatrixOp op)
{
return op == OP_UNARY_PLUS ||
op == OP_NEGATION ||
op == OP_PRE_INCREMENT ||
op == OP_PRE_DECREMENT ||
op == OP_POST_INCREMENT ||
op == OP_POST_DECREMENT;
}
static bool isOperationValueModifying (MatrixOp op)
{
return op == OP_PRE_INCREMENT ||
op == OP_PRE_DECREMENT ||
op == OP_POST_INCREMENT ||
op == OP_POST_DECREMENT;
}
static bool isOperationAssignment (MatrixOp op)
{
return op == OP_ADD_INTO ||
op == OP_SUBTRACT_FROM ||
op == OP_MULTIPLY_INTO ||
op == OP_DIVIDE_INTO;
}
// Operation nature
enum OperationNature
{
OPERATIONNATURE_PURE = 0,
OPERATIONNATURE_MUTATING,
OPERATIONNATURE_ASSIGNMENT,
OPERATIONNATURE_LAST
};
static OperationNature getOperationNature (MatrixOp op)
{
if (isOperationAssignment(op))
return OPERATIONNATURE_ASSIGNMENT;
if (isOperationValueModifying(op))
return OPERATIONNATURE_MUTATING;
return OPERATIONNATURE_PURE;
}
// Input value loader.
template <int InputT, int DataT>
typename TypeTraits<DataT>::Type getInputValue (const ShaderEvalContext& evalCtx, int inputNdx);
template <> inline float getInputValue<INPUTTYPE_CONST, TYPE_FLOAT> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInFloat[inputNdx]; }
template <> inline tcu::Vec2 getInputValue<INPUTTYPE_CONST, TYPE_FLOAT_VEC2> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInVec2[inputNdx]; }
template <> inline tcu::Vec3 getInputValue<INPUTTYPE_CONST, TYPE_FLOAT_VEC3> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInVec3[inputNdx]; }
template <> inline tcu::Vec4 getInputValue<INPUTTYPE_CONST, TYPE_FLOAT_VEC4> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInVec4[inputNdx]; }
template <> inline tcu::Mat2 getInputValue<INPUTTYPE_CONST, TYPE_FLOAT_MAT2> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInMat2[inputNdx]; }
template <> inline tcu::Mat3 getInputValue<INPUTTYPE_CONST, TYPE_FLOAT_MAT3> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInMat3[inputNdx]; }
template <> inline tcu::Mat4 getInputValue<INPUTTYPE_CONST, TYPE_FLOAT_MAT4> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(evalCtx); return s_constInMat4[inputNdx]; }
template <> inline float getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(inputNdx); return evalCtx.coords.x(); }
template <> inline tcu::Vec2 getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT_VEC2> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(inputNdx); return evalCtx.coords.swizzle(0, 1); }
template <> inline tcu::Vec3 getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT_VEC3> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(inputNdx); return evalCtx.coords.swizzle(0, 1, 2); }
template <> inline tcu::Vec4 getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT_VEC4> (const ShaderEvalContext& evalCtx, int inputNdx) { DE_UNREF(inputNdx); return evalCtx.coords.swizzle(0, 1, 2, 3); }
template <> inline tcu::Mat2 getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT_MAT2> (const ShaderEvalContext& evalCtx, int inputNdx)
{
DE_UNREF(inputNdx); // Not used.
tcu::Mat2 m;
m.setColumn(0, evalCtx.in[0].swizzle(0,1));
m.setColumn(1, evalCtx.in[1].swizzle(0,1));
return m;
}
template <> inline tcu::Mat3 getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT_MAT3> (const ShaderEvalContext& evalCtx, int inputNdx)
{
DE_UNREF(inputNdx); // Not used.
tcu::Mat3 m;
m.setColumn(0, evalCtx.in[0].swizzle(0,1,2));
m.setColumn(1, evalCtx.in[1].swizzle(0,1,2));
m.setColumn(2, evalCtx.in[2].swizzle(0,1,2));
return m;
}
template <> inline tcu::Mat4 getInputValue<INPUTTYPE_DYNAMIC, TYPE_FLOAT_MAT4> (const ShaderEvalContext& evalCtx, int inputNdx)
{
DE_UNREF(inputNdx); // Not used.
tcu::Mat4 m;
m.setColumn(0, evalCtx.in[0]);
m.setColumn(1, evalCtx.in[1]);
m.setColumn(2, evalCtx.in[2]);
m.setColumn(3, evalCtx.in[3]);
return m;
}
// Reduction from expression result to vec3.
inline tcu::Vec3 reduceToVec3 (const tcu::Vec2& value) { return value.swizzle(0,1,0); }
inline tcu::Vec3 reduceToVec3 (const tcu::Vec3& value) { return value; }
inline tcu::Vec3 reduceToVec3 (const tcu::Vec4& value) { return tcu::Vec3(value.x(), value.y(), value.z()+value.w()); }
inline tcu::Vec3 reduceToVec3 (const tcu::Mat2& value) { return tcu::Vec3(value(0, 0), value(0, 1), value(1, 0)+value(1, 1)); }
inline tcu::Vec3 reduceToVec3 (const tcu::Mat3& value) { return value.getColumn(0) + value.getColumn(1) + value.getColumn(2); }
inline tcu::Vec3 reduceToVec3 (const tcu::Mat4& value) { return value.getColumn(0).swizzle(0,1,2) + value.getColumn(1).swizzle(1,2,3) + value.getColumn(2).swizzle(2,3,0) + value.getColumn(3).swizzle(3,0,1); }
// matrixCompMult
template <typename T, int Rows, int Cols>
tcu::Matrix<T, Rows, Cols> matrixCompMult (const tcu::Matrix<T, Rows, Cols>& a, const tcu::Matrix<T, Rows, Cols>& b)
{
tcu::Matrix<T, Rows, Cols> retVal;
for (int r = 0; r < Rows; ++r)
for (int c = 0; c < Cols; ++c)
retVal(r,c) = a(r,c) * b(r, c);
return retVal;
}
// negate
template <typename T, int Rows, int Cols>
tcu::Matrix<T, Rows, Cols> negate (const tcu::Matrix<T, Rows, Cols>& mat)
{
tcu::Matrix<T, Rows, Cols> retVal;
for (int r = 0; r < Rows; ++r)
for (int c = 0; c < Cols; ++c)
retVal(r,c) = -mat(r, c);
return retVal;
}
// increment/decrement
template <typename T, int Rows, int Cols>
tcu::Matrix<T, Rows, Cols> increment (const tcu::Matrix<T, Rows, Cols>& mat)
{
tcu::Matrix<T, Rows, Cols> retVal;
for (int r = 0; r < Rows; ++r)
for (int c = 0; c < Cols; ++c)
retVal(r,c) = mat(r, c) + 1.0f;
return retVal;
}
template <typename T, int Rows, int Cols>
tcu::Matrix<T, Rows, Cols> decrement (const tcu::Matrix<T, Rows, Cols>& mat)
{
tcu::Matrix<T, Rows, Cols> retVal;
for (int r = 0; r < Rows; ++r)
for (int c = 0; c < Cols; ++c)
retVal(r,c) = mat(r, c) - 1.0f;
return retVal;
}
// Evaluator template.
template <int Op, int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator;
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_ADD, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) + getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_SUB, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) - getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_MUL, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) * getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_DIV, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) / getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_COMP_MUL, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(matrixCompMult(getInputValue<In0Type, In0DataType>(evalCtx, 0), getInputValue<In1Type, In1DataType>(evalCtx, 1)));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_UNARY_PLUS, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_NEGATION, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(negate(getInputValue<In0Type, In0DataType>(evalCtx, 0)));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_PRE_INCREMENT, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
// modifying reduction: sum modified value too
evalCtx.color.xyz() = reduceToVec3(increment(getInputValue<In0Type, In0DataType>(evalCtx, 0))) + reduceToVec3(increment(getInputValue<In0Type, In0DataType>(evalCtx, 0)));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_PRE_DECREMENT, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
// modifying reduction: sum modified value too
evalCtx.color.xyz() = reduceToVec3(decrement(getInputValue<In0Type, In0DataType>(evalCtx, 0))) + reduceToVec3(decrement(getInputValue<In0Type, In0DataType>(evalCtx, 0)));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_POST_INCREMENT, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
// modifying reduction: sum modified value too
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0)) + reduceToVec3(increment(getInputValue<In0Type, In0DataType>(evalCtx, 0)));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_POST_DECREMENT, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
// modifying reduction: sum modified value too
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0)) + reduceToVec3(decrement(getInputValue<In0Type, In0DataType>(evalCtx, 0)));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_ADD_INTO, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) + getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_SUBTRACT_FROM, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) - getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_MULTIPLY_INTO, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) * getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
template <int In0Type, int In0DataType, int In1Type, int In1DataType>
struct Evaluator<OP_DIVIDE_INTO, In0Type, In0DataType, In1Type, In1DataType>
{
static void evaluate (ShaderEvalContext& evalCtx)
{
evalCtx.color.xyz() = reduceToVec3(getInputValue<In0Type, In0DataType>(evalCtx, 0) / getInputValue<In1Type, In1DataType>(evalCtx, 1));
}
};
ShaderEvalFunc getEvalFunc (const ShaderInput& in0, const ShaderInput& in1, MatrixOp op)
{
DE_STATIC_ASSERT(TYPE_LAST <= (1<<7));
DE_STATIC_ASSERT(OP_LAST <= (1<<4));
DE_STATIC_ASSERT(INPUTTYPE_LAST <= (1<<2));
#define PACK_EVAL_CASE(OP, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE) (((OP) << 18) | ((IN0TYPE) << 16) | ((IN0DATATYPE) << 9) | ((IN1TYPE) << 7) | (IN1DATATYPE))
#define MAKE_EVAL_CASE(OP, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE) \
case PACK_EVAL_CASE(OP, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE): \
return Evaluator<OP, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE>::evaluate
#define SCALAR_OPS(IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE) \
MAKE_EVAL_CASE(OP_ADD, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_SUB, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_MUL, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_DIV, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE)
#define ALL_OPS(IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE) \
MAKE_EVAL_CASE(OP_ADD, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_SUB, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_MUL, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_DIV, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_COMP_MUL, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE);
#define MUL_OP(IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE) \
MAKE_EVAL_CASE(OP_MUL, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE)
#define MAKE_MAT_SCALAR_VEC_CASES(OP, TYPE0, TYPE1) \
OP(INPUTTYPE_CONST, TYPE0, INPUTTYPE_CONST, TYPE1); \
OP(INPUTTYPE_DYNAMIC, TYPE0, INPUTTYPE_CONST, TYPE1); \
OP(INPUTTYPE_CONST, TYPE0, INPUTTYPE_DYNAMIC, TYPE1); \
OP(INPUTTYPE_DYNAMIC, TYPE0, INPUTTYPE_DYNAMIC, TYPE1)
#define MAKE_MAT_MAT_CASES(OP, MATTYPE) \
OP(INPUTTYPE_CONST, MATTYPE, INPUTTYPE_CONST, MATTYPE); \
OP(INPUTTYPE_DYNAMIC, MATTYPE, INPUTTYPE_CONST, MATTYPE)
#define UNARY_OP(IN0TYPE, IN0DATATYPE) \
MAKE_EVAL_CASE(OP_UNARY_PLUS, IN0TYPE, IN0DATATYPE, INPUTTYPE_CONST, TYPE_LAST); \
MAKE_EVAL_CASE(OP_NEGATION, IN0TYPE, IN0DATATYPE, INPUTTYPE_CONST, TYPE_LAST); \
MAKE_EVAL_CASE(OP_PRE_INCREMENT, IN0TYPE, IN0DATATYPE, INPUTTYPE_CONST, TYPE_LAST); \
MAKE_EVAL_CASE(OP_PRE_DECREMENT, IN0TYPE, IN0DATATYPE, INPUTTYPE_CONST, TYPE_LAST); \
MAKE_EVAL_CASE(OP_POST_INCREMENT, IN0TYPE, IN0DATATYPE, INPUTTYPE_CONST, TYPE_LAST); \
MAKE_EVAL_CASE(OP_POST_DECREMENT, IN0TYPE, IN0DATATYPE, INPUTTYPE_CONST, TYPE_LAST)
#define MAKE_UNARY_CASES(OP, MATTYPE) \
OP(INPUTTYPE_CONST, MATTYPE); \
OP(INPUTTYPE_DYNAMIC, MATTYPE)
#define ASSIGN_OP(IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE) \
MAKE_EVAL_CASE(OP_ADD_INTO, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_SUBTRACT_FROM, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_MULTIPLY_INTO, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE); \
MAKE_EVAL_CASE(OP_DIVIDE_INTO, IN0TYPE, IN0DATATYPE, IN1TYPE, IN1DATATYPE)
#define MAKE_ASSIGNMENT_CASES(OP, MATTYPE) \
OP(INPUTTYPE_CONST, MATTYPE, INPUTTYPE_CONST, MATTYPE); \
OP(INPUTTYPE_DYNAMIC, MATTYPE, INPUTTYPE_CONST, MATTYPE); \
OP(INPUTTYPE_CONST, MATTYPE, INPUTTYPE_DYNAMIC, MATTYPE); \
OP(INPUTTYPE_DYNAMIC, MATTYPE, INPUTTYPE_DYNAMIC, MATTYPE)
// \note At the moment there is no difference between uniform and const inputs. This saves binary size.
InputType in0Type = in0.inputType == INPUTTYPE_DYNAMIC ? INPUTTYPE_DYNAMIC : INPUTTYPE_CONST;
InputType in1Type = in1.inputType == INPUTTYPE_DYNAMIC ? INPUTTYPE_DYNAMIC : INPUTTYPE_CONST;
switch (PACK_EVAL_CASE(op, in0Type, in0.dataType, in1Type, in1.dataType))
{
// Matrix-scalar.
MAKE_MAT_SCALAR_VEC_CASES(SCALAR_OPS, TYPE_FLOAT_MAT2, TYPE_FLOAT);
MAKE_MAT_SCALAR_VEC_CASES(SCALAR_OPS, TYPE_FLOAT_MAT3, TYPE_FLOAT);
MAKE_MAT_SCALAR_VEC_CASES(SCALAR_OPS, TYPE_FLOAT_MAT4, TYPE_FLOAT);
// Matrix-vector.
MAKE_MAT_SCALAR_VEC_CASES(MUL_OP, TYPE_FLOAT_MAT2, TYPE_FLOAT_VEC2);
MAKE_MAT_SCALAR_VEC_CASES(MUL_OP, TYPE_FLOAT_MAT3, TYPE_FLOAT_VEC3);
MAKE_MAT_SCALAR_VEC_CASES(MUL_OP, TYPE_FLOAT_MAT4, TYPE_FLOAT_VEC4);
// Vector-matrix.
MAKE_MAT_SCALAR_VEC_CASES(MUL_OP, TYPE_FLOAT_VEC2, TYPE_FLOAT_MAT2);
MAKE_MAT_SCALAR_VEC_CASES(MUL_OP, TYPE_FLOAT_VEC3, TYPE_FLOAT_MAT3);
MAKE_MAT_SCALAR_VEC_CASES(MUL_OP, TYPE_FLOAT_VEC4, TYPE_FLOAT_MAT4);
// Matrix-matrix.
MAKE_MAT_MAT_CASES(ALL_OPS, TYPE_FLOAT_MAT2);
MAKE_MAT_MAT_CASES(ALL_OPS, TYPE_FLOAT_MAT3);
MAKE_MAT_MAT_CASES(ALL_OPS, TYPE_FLOAT_MAT4);
// Unary matrix
MAKE_UNARY_CASES(UNARY_OP, TYPE_FLOAT_MAT2);
MAKE_UNARY_CASES(UNARY_OP, TYPE_FLOAT_MAT3);
MAKE_UNARY_CASES(UNARY_OP, TYPE_FLOAT_MAT4);
// Assignment matrix
MAKE_ASSIGNMENT_CASES(ASSIGN_OP, TYPE_FLOAT_MAT2);
MAKE_ASSIGNMENT_CASES(ASSIGN_OP, TYPE_FLOAT_MAT3);
MAKE_ASSIGNMENT_CASES(ASSIGN_OP, TYPE_FLOAT_MAT4);
default:
DE_ASSERT(DE_FALSE);
return DE_NULL;
}
#undef PACK_EVAL_CASE
#undef MAKE_EVAL_CASE
#undef MUL_OP
#undef ALL_OPS
#undef MAKE_MAT_SCALAR_VEC_CASES
#undef MAKE_MAT_MAT_CASES
}
// Shader source format utilities.
template <int Size>
void writeVectorConstructor (std::ostream& str, const tcu::Vector<float, Size>& v)
{
str << "vec" << Size << "(";
for (int ndx = 0; ndx < Size; ndx++)
{
if (ndx != 0)
str << ", ";
str << de::floatToString(v[ndx], 1);
}
str << ")";
}
template <int Cols, int Rows>
void writeMatrixConstructor (std::ostream& str, const tcu::Matrix<float, Rows, Cols>& m)
{
if (Rows == Cols)
str << "mat" << Cols;
else
str << "mat" << Cols << "x" << Rows;
str << "(";
for (int colNdx = 0; colNdx < Cols; colNdx++)
{
for (int rowNdx = 0; rowNdx < Rows; rowNdx++)
{
if (rowNdx > 0 || colNdx > 0)
str << ", ";
str << de::floatToString(m(rowNdx, colNdx), 1);
}
}
str << ")";
}
} // MatrixCaseUtils
using namespace MatrixCaseUtils;
class ShaderMatrixCase : public ShaderRenderCase
{
public:
ShaderMatrixCase (Context& context, const char* name, const char* desc, const ShaderInput& in0, const ShaderInput& in1, MatrixOp op, bool isVertexCase);
~ShaderMatrixCase (void);
void init (void);
protected:
std::string genGLSLMatToVec3Reduction (const glu::DataType& matType, const char* varName);
void setupUniforms (int programID, const tcu::Vec4& constCoords);
private:
ShaderInput m_in0;
ShaderInput m_in1;
MatrixOp m_op;
};
ShaderMatrixCase::ShaderMatrixCase (Context& context, const char* name, const char* desc, const ShaderInput& in0, const ShaderInput& in1, MatrixOp op, bool isVertexCase)
: ShaderRenderCase (context.getTestContext(), context.getRenderContext(), context.getContextInfo(), name, desc, isVertexCase, getEvalFunc(in0, in1, op))
, m_in0 (in0)
, m_in1 (in1)
, m_op (op)
{
}
ShaderMatrixCase::~ShaderMatrixCase (void)
{
}
void ShaderMatrixCase::init (void)
{
std::ostringstream vtx;
std::ostringstream frag;
std::ostringstream& op = m_isVertexCase ? vtx : frag;
bool isInDynMat0 = isDataTypeMatrix(m_in0.dataType) && m_in0.inputType == INPUTTYPE_DYNAMIC;
bool isInDynMat1 = isDataTypeMatrix(m_in1.dataType) && m_in1.inputType == INPUTTYPE_DYNAMIC;
string inValue0;
string inValue1;
DataType resultType = TYPE_LAST;
Precision resultPrec = m_in0.precision;
vector<string> passVars;
int numInputs = (isOperationBinary(m_op)) ? (2) : (1);
std::string operationValue0;
std::string operationValue1;
DE_ASSERT(!isInDynMat0 || !isInDynMat1); // Only single dynamic matrix input is allowed.
DE_UNREF(isInDynMat0 && isInDynMat1);
// Compute result type.
if (isDataTypeMatrix(m_in0.dataType) && isDataTypeMatrix(m_in1.dataType))
{
DE_ASSERT(m_in0.dataType == m_in1.dataType);
resultType = m_in0.dataType;
}
else if (getOperationType(m_op) == OPERATIONTYPE_UNARY_PREFIX_OPERATOR ||
getOperationType(m_op) == OPERATIONTYPE_UNARY_POSTFIX_OPERATOR)
{
resultType = m_in0.dataType;
}
else
{
int matNdx = isDataTypeMatrix(m_in0.dataType) ? 0 : 1;
DataType matrixType = matNdx == 0 ? m_in0.dataType : m_in1.dataType;
DataType otherType = matNdx == 0 ? m_in1.dataType : m_in0.dataType;
if (otherType == TYPE_FLOAT)
resultType = matrixType;
else
{
DE_ASSERT(isDataTypeVector(otherType));
resultType = otherType;
}
}
vtx << "attribute highp vec4 a_position;\n";
if (m_isVertexCase)
{
vtx << "varying mediump vec4 v_color;\n";
frag << "varying mediump vec4 v_color;\n";
}
// Input declarations.
for (int inNdx = 0; inNdx < numInputs; inNdx++)
{
const ShaderInput& in = inNdx > 0 ? m_in1 : m_in0;
const char* precName = getPrecisionName(in.precision);
const char* typeName = getDataTypeName(in.dataType);
string& inValue = inNdx > 0 ? inValue1 : inValue0;
if (in.inputType == INPUTTYPE_DYNAMIC)
{
vtx << "attribute " << precName << " " << typeName << " a_";
if (isDataTypeMatrix(in.dataType))
{
// a_matN, v_matN
vtx << typeName << ";\n";
if (!m_isVertexCase)
{
vtx << "varying " << precName << " " << typeName << " v_" << typeName << ";\n";
frag << "varying " << precName << " " << typeName << " v_" << typeName << ";\n";
passVars.push_back(typeName);
}
inValue = string(m_isVertexCase ? "a_" : "v_") + getDataTypeName(in.dataType);
}
else
{
// a_coords, v_coords
vtx << "coords;\n";
if (!m_isVertexCase)
{
vtx << "varying " << precName << " " << typeName << " v_coords;\n";
frag << "varying " << precName << " " << typeName << " v_coords;\n";
passVars.push_back("coords");
}
inValue = m_isVertexCase ? "a_coords" : "v_coords";
}
}
else if (in.inputType == INPUTTYPE_UNIFORM)
{
op << "uniform " << precName << " " << typeName << " u_in" << inNdx << ";\n";
inValue = string("u_in") + de::toString(inNdx);
}
else if (in.inputType == INPUTTYPE_CONST)
{
op << "const " << precName << " " << typeName << " in" << inNdx << " = ";
// Generate declaration.
switch (in.dataType)
{
case TYPE_FLOAT: op << de::floatToString(s_constInFloat[inNdx], 1); break;
case TYPE_FLOAT_VEC2: writeVectorConstructor<2>(op, s_constInVec2[inNdx]); break;
case TYPE_FLOAT_VEC3: writeVectorConstructor<3>(op, s_constInVec3[inNdx]); break;
case TYPE_FLOAT_VEC4: writeVectorConstructor<4>(op, s_constInVec4[inNdx]); break;
case TYPE_FLOAT_MAT2: writeMatrixConstructor<2, 2>(op, Mat2(s_constInMat2[inNdx])); break;
case TYPE_FLOAT_MAT3: writeMatrixConstructor<3, 3>(op, Mat3(s_constInMat3[inNdx])); break;
case TYPE_FLOAT_MAT4: writeMatrixConstructor<4, 4>(op, Mat4(s_constInMat4[inNdx])); break;
default:
DE_ASSERT(DE_FALSE);
}
op << ";\n";
inValue = string("in") + de::toString(inNdx);
}
}
vtx << "\n"
<< "void main (void)\n"
<< "{\n"
<< " gl_Position = a_position;\n";
frag << "\n"
<< "void main (void)\n"
<< "{\n";
if (m_isVertexCase)
{
frag << " gl_FragColor = v_color;\n";
}
else
{
for (vector<string>::const_iterator copyIter = passVars.begin(); copyIter != passVars.end(); copyIter++)
vtx << " v_" << *copyIter << " = " << "a_" << *copyIter << ";\n";
}
// Operation.
switch (getOperationNature(m_op))
{
case OPERATIONNATURE_PURE:
DE_ASSERT(getOperationType(m_op) != OPERATIONTYPE_ASSIGNMENT);
operationValue0 = inValue0;
operationValue1 = inValue1;
break;
case OPERATIONNATURE_MUTATING:
DE_ASSERT(getOperationType(m_op) != OPERATIONTYPE_ASSIGNMENT);
op << " " << getPrecisionName(resultPrec) << " " << getDataTypeName(resultType) << " tmpValue = " << inValue0 << ";\n";
operationValue0 = "tmpValue";
operationValue1 = inValue1;
break;
case OPERATIONNATURE_ASSIGNMENT:
DE_ASSERT(getOperationType(m_op) == OPERATIONTYPE_ASSIGNMENT);
operationValue0 = inValue0;
operationValue1 = inValue1;
break;
default:
DE_ASSERT(DE_FALSE);
}
switch (getOperationType(m_op))
{
case OPERATIONTYPE_BINARY_OPERATOR:
op << " " << getPrecisionName(resultPrec) << " " << getDataTypeName(resultType) << " res = " << operationValue0 << " " << getOperationName(m_op) << " " << operationValue1 << ";\n";
break;
case OPERATIONTYPE_UNARY_PREFIX_OPERATOR:
op << " " << getPrecisionName(resultPrec) << " " << getDataTypeName(resultType) << " res = " << getOperationName(m_op) << operationValue0 << ";\n";
break;
case OPERATIONTYPE_UNARY_POSTFIX_OPERATOR:
op << " " << getPrecisionName(resultPrec) << " " << getDataTypeName(resultType) << " res = " << operationValue0 << getOperationName(m_op) << ";\n";
break;
case OPERATIONTYPE_BINARY_FUNCTION:
op << " " << getPrecisionName(resultPrec) << " " << getDataTypeName(resultType) << " res = " << getOperationName(m_op) << "(" << operationValue0 << ", " << operationValue1 << ");\n";
break;
case OPERATIONTYPE_ASSIGNMENT:
op << " " << getPrecisionName(resultPrec) << " " << getDataTypeName(resultType) << " res = " << operationValue0 << ";\n";
op << " res " << getOperationName(m_op) << " " << operationValue1 << ";\n";
break;
default:
DE_ASSERT(DE_FALSE);
}
// Reduction to vec3 (rgb). Check the used value too if it was modified.
op << " " << (m_isVertexCase ? "v_color" : "gl_FragColor") << " = ";
if (isOperationValueModifying(m_op))
op << "vec4(" << genGLSLMatToVec3Reduction(resultType, "res") << ", 1.0) + vec4(" << genGLSLMatToVec3Reduction(resultType, "tmpValue") << ", 0.0);\n";
else
op << "vec4(" << genGLSLMatToVec3Reduction(resultType, "res") << ", 1.0);\n";
vtx << "}\n";
frag << "}\n";
m_vertShaderSource = vtx.str();
m_fragShaderSource = frag.str();
// \todo [2012-02-14 pyry] Compute better values for matrix tests.
m_userAttribTransforms.resize(4);
for (int attribNdx = 0; attribNdx < 4; attribNdx++)
{
m_userAttribTransforms[attribNdx] = Mat4(0.0f);
m_userAttribTransforms[attribNdx]((0 + attribNdx) % 4, 0) = 1.0f;
m_userAttribTransforms[attribNdx]((1 + attribNdx) % 4, 1) = 1.0f;
m_userAttribTransforms[attribNdx]((2 + attribNdx) % 4, 2) = 1.0f;
m_userAttribTransforms[attribNdx]((3 + attribNdx) % 4, 3) = 1.0f;
}
// prevent bad reference cases such as black result images by fine-tuning used matrices
if (getOperationTestMatrixType(m_op) != TESTMATRIXTYPE_DEFAULT)
{
for (int attribNdx = 0; attribNdx < 4; attribNdx++)
{
for (int row = 0; row < 4; row++)
for (int col = 0; col < 4; col++)
{
switch (getOperationTestMatrixType(m_op))
{
case TESTMATRIXTYPE_NEGATED:
m_userAttribTransforms[attribNdx](row, col) = -m_userAttribTransforms[attribNdx](row, col);
break;
case TESTMATRIXTYPE_INCREMENTED:
m_userAttribTransforms[attribNdx](row, col) += 0.3f;
break;
case TESTMATRIXTYPE_DECREMENTED:
m_userAttribTransforms[attribNdx](row, col) -= 0.1f;
break;
default:
DE_ASSERT(DE_FALSE);
break;
}
}
}
}
ShaderRenderCase::init();
}
std::string ShaderMatrixCase::genGLSLMatToVec3Reduction (const glu::DataType& matType, const char* varName)
{
std::ostringstream op;
switch (matType)
{
case TYPE_FLOAT: op << varName << ", " << varName << ", " << varName << ""; break;
case TYPE_FLOAT_VEC2: op << varName << ".x, " << varName << ".y, " << varName << ".x"; break;
case TYPE_FLOAT_VEC3: op << varName << ""; break;
case TYPE_FLOAT_VEC4: op << varName << ".x, " << varName << ".y, " << varName << ".z+" << varName << ".w"; break;
case TYPE_FLOAT_MAT2: op << varName << "[0][0], " << varName << "[1][0], " << varName << "[0][1]+" << varName << "[1][1]"; break;
case TYPE_FLOAT_MAT3: op << varName << "[0]+" << varName << "[1]+" << varName << "[2]"; break;
case TYPE_FLOAT_MAT4: op << varName << "[0].xyz+" << varName << "[1].yzw+" << varName << "[2].zwx+" << varName << "[3].wxy"; break;
default:
DE_ASSERT(DE_FALSE);
}
return op.str();
}
void ShaderMatrixCase::setupUniforms (int programID, const tcu::Vec4& constCoords)
{
const glw::Functions& gl = m_renderCtx.getFunctions();
DE_UNREF(constCoords);
for (int inNdx = 0; inNdx < 2; inNdx++)
{
const ShaderInput& in = inNdx > 0 ? m_in1 : m_in0;
if (in.inputType == INPUTTYPE_UNIFORM)
{
int loc = gl.getUniformLocation(programID, (string("u_in") + de::toString(inNdx)).c_str());
if (loc < 0)
continue;
switch (in.dataType)
{
case TYPE_FLOAT: gl.uniform1f(loc, s_constInFloat[inNdx]); break;
case TYPE_FLOAT_VEC2: gl.uniform2fv(loc, 1, s_constInVec2[inNdx].getPtr()); break;
case TYPE_FLOAT_VEC3: gl.uniform3fv(loc, 1, s_constInVec3[inNdx].getPtr()); break;
case TYPE_FLOAT_VEC4: gl.uniform4fv(loc, 1, s_constInVec4[inNdx].getPtr()); break;
case TYPE_FLOAT_MAT2: gl.uniformMatrix2fv(loc, 1, GL_FALSE, s_constInMat2[inNdx].getColumnMajorData().getPtr()); break;
case TYPE_FLOAT_MAT3: gl.uniformMatrix3fv(loc, 1, GL_FALSE, s_constInMat3[inNdx].getColumnMajorData().getPtr()); break;
case TYPE_FLOAT_MAT4: gl.uniformMatrix4fv(loc, 1, GL_FALSE, s_constInMat4[inNdx].getColumnMajorData().getPtr()); break;
default:
DE_ASSERT(false);
}
}
}
}
ShaderMatrixTests::ShaderMatrixTests (Context& context)
: TestCaseGroup(context, "matrix", "Matrix Tests")
{
}
ShaderMatrixTests::~ShaderMatrixTests (void)
{
}
void ShaderMatrixTests::init (void)
{
static const struct
{
const char* name;
const char* desc;
MatrixOp op;
bool extendedInputTypeCases; // !< test with const and uniform types too
} ops[] =
{
{ "add", "Matrix addition tests", OP_ADD, true },
{ "sub", "Matrix subtraction tests", OP_SUB, true },
{ "mul", "Matrix multiplication tests", OP_MUL, true },
{ "div", "Matrix division tests", OP_DIV, true },
{ "matrixcompmult", "Matrix component-wise multiplication tests", OP_COMP_MUL, false },
{ "unary_addition", "Matrix unary addition tests", OP_UNARY_PLUS, false },
{ "negation", "Matrix negation tests", OP_NEGATION, false },
{ "pre_increment", "Matrix prefix increment tests", OP_PRE_INCREMENT, false },
{ "pre_decrement", "Matrix prefix decrement tests", OP_PRE_DECREMENT, false },
{ "post_increment", "Matrix postfix increment tests", OP_POST_INCREMENT, false },
{ "post_decrement", "Matrix postfix decrement tests", OP_POST_DECREMENT, false },
{ "add_assign", "Matrix add into tests", OP_ADD_INTO, false },
{ "sub_assign", "Matrix subtract from tests", OP_SUBTRACT_FROM, false },
{ "mul_assign", "Matrix multiply into tests", OP_MULTIPLY_INTO, false },
{ "div_assign", "Matrix divide into tests", OP_DIVIDE_INTO, false },
};
struct InputTypeSpec
{
const char* name;
const char* desc;
InputType type;
};
static const InputTypeSpec extendedInputTypes[] =
{
{ "const", "Constant matrix input", INPUTTYPE_CONST },
{ "uniform", "Uniform matrix input", INPUTTYPE_UNIFORM },
{ "dynamic", "Dynamic matrix input", INPUTTYPE_DYNAMIC }
};
static const InputTypeSpec reducedInputTypes[] =
{
{ "dynamic", "Dynamic matrix input", INPUTTYPE_DYNAMIC }
};
static const DataType matrixTypes[] =
{
TYPE_FLOAT_MAT2,
TYPE_FLOAT_MAT3,
TYPE_FLOAT_MAT4
};
static const Precision precisions[] =
{
PRECISION_LOWP,
PRECISION_MEDIUMP,
PRECISION_HIGHP
};
for (int opNdx = 0; opNdx < DE_LENGTH_OF_ARRAY(ops); opNdx++)
{
const InputTypeSpec* inTypeList = (ops[opNdx].extendedInputTypeCases) ? (extendedInputTypes) : (reducedInputTypes);
const int inTypeListSize = (ops[opNdx].extendedInputTypeCases) ? (DE_LENGTH_OF_ARRAY(extendedInputTypes)) : (DE_LENGTH_OF_ARRAY(reducedInputTypes));
const MatrixOp op = ops[opNdx].op;
tcu::TestCaseGroup* opGroup = new tcu::TestCaseGroup(m_testCtx, ops[opNdx].name, ops[opNdx].desc);
addChild(opGroup);
for (int inTypeNdx = 0; inTypeNdx < inTypeListSize; inTypeNdx++)
{
const InputType inputType = inTypeList[inTypeNdx].type;
for (int matTypeNdx = 0; matTypeNdx < DE_LENGTH_OF_ARRAY(matrixTypes); matTypeNdx++)
{
DataType matType = matrixTypes[matTypeNdx];
const char* matTypeName = getDataTypeName(matType);
for (int precNdx = 0; precNdx < DE_LENGTH_OF_ARRAY(precisions); precNdx++)
{
Precision precision = precisions[precNdx];
const char* precName = getPrecisionName(precision);
string baseName = string(inTypeList[inTypeNdx].name) + "_" + precName + "_" + matTypeName + "_";
ShaderInput matIn (inputType, matType, precision);
if (isOperationMatrixScalar(op))
{
// Matrix-scalar \note For div cases we use uniform input.
ShaderInput scalarIn(op == OP_DIV ? INPUTTYPE_UNIFORM : INPUTTYPE_DYNAMIC, TYPE_FLOAT, precision);
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + "float_vertex").c_str(), "Matrix-scalar case", matIn, scalarIn, op, true));
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + "float_fragment").c_str(), "Matrix-scalar case", matIn, scalarIn, op, false));
}
if (isOperationMatrixVector(op))
{
// Matrix-vector.
DataType vecType = getDataTypeFloatVec(getDataTypeMatrixNumColumns(matType));
ShaderInput vecIn (op == OP_DIV ? INPUTTYPE_UNIFORM : INPUTTYPE_DYNAMIC, vecType, precision);
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + getDataTypeName(vecType) + "_vertex").c_str(), "Matrix-vector case", matIn, vecIn, op, true));
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + getDataTypeName(vecType) + "_fragment").c_str(), "Matrix-vector case", matIn, vecIn, op, false));
// Vector-matrix.
string vecMatName = string(inTypeList[inTypeNdx].name) + "_" + precName + "_" + getDataTypeName(vecType) + "_" + matTypeName;
opGroup->addChild(new ShaderMatrixCase(m_context, (vecMatName + "_vertex").c_str(), "Vector-matrix case", vecIn, matIn, op, true));
opGroup->addChild(new ShaderMatrixCase(m_context, (vecMatName + "_fragment").c_str(), "Vector-matrix case", vecIn, matIn, op, false));
}
if (isOperationMatrixMatrix(op))
{
// Matrix-matrix.
ShaderInput otherMatIn(inputType == INPUTTYPE_DYNAMIC ? INPUTTYPE_UNIFORM : inputType, matType, precision);
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + matTypeName + "_vertex").c_str(), "Matrix-matrix case", matIn, otherMatIn, op, true));
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + matTypeName + "_fragment").c_str(), "Matrix-matrix case", matIn, otherMatIn, op, false));
}
if (isOperationUnary(op))
{
// op matrix
ShaderInput voidInput(INPUTTYPE_LAST, TYPE_LAST, PRECISION_LAST);
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + "vertex").c_str(), "Matrix case", matIn, voidInput, op, true));
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + "fragment").c_str(), "Matrix case", matIn, voidInput, op, false));
}
if (isOperationAssignment(op))
{
ShaderInput otherMatIn(inputType == INPUTTYPE_DYNAMIC ? INPUTTYPE_UNIFORM : inputType, matType, precision);
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + "vertex").c_str(), "Matrix assignment case", matIn, otherMatIn, op, true));
opGroup->addChild(new ShaderMatrixCase(m_context, (baseName + "fragment").c_str(), "Matrix assignment case", matIn, otherMatIn, op, false));
}
}
}
}
}
}
} // Functional
} // gles2
} // deqp
#if defined(_MSC_VER) && _MSC_FULL_VER == 191125507
// Work around crbug.com/759402 which is a code-gen bug in VC++ 2017, version
// 15.3.2.
#pragma optimize("", off)
#endif