Hash :
fcec6904
Author :
Date :
2022-04-13T14:18:06
Generate feature variable names from display names The json file now only contains the feature display name. The variable name is automaticaly derived. For consistence with Chromium and other Chromium-based projects, the display name is now always snake_case, and that's what's specified in the json files. This also makes camelCase variable name generation trivial (as opposed to the other way around). Feature overrides now accept both snake_case and camelCase names to ensure compatibility with existing scripts. This is done by removing _ and comparing override names with feature names in lower case. Bug: angleproject:6435 Change-Id: I0b6ed2bbf5c312bc4f4be7b3c7d55dbaca2a9886 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3584630 Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@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 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// renderer_utils:
// Helper methods pertaining to most or all back-ends.
//
#include "libANGLE/renderer/renderer_utils.h"
#include "common/string_utils.h"
#include "common/system_utils.h"
#include "common/utilities.h"
#include "image_util/copyimage.h"
#include "image_util/imageformats.h"
#include "libANGLE/AttributeMap.h"
#include "libANGLE/Context.h"
#include "libANGLE/Context.inl.h"
#include "libANGLE/Display.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/ContextImpl.h"
#include "libANGLE/renderer/Format.h"
#include "platform/Feature.h"
#include <string.h>
#include <cctype>
namespace angle
{
namespace
{
// For the sake of feature name matching, underscore is ignored, and the names are matched
// case-insensitive. This allows feature names to be overriden both in snake_case (previously used
// by ANGLE) and camelCase.
bool FeatureNameMatch(const std::string &a, const std::string &b)
{
size_t ai = 0;
size_t bi = 0;
while (ai < a.size() && bi < b.size())
{
if (a[ai] == '_')
{
++ai;
}
if (b[bi] == '_')
{
++bi;
}
if (std::tolower(a[ai++]) != std::tolower(b[bi++]))
{
return false;
}
}
return ai == a.size() && bi == b.size();
}
// Search for a feature by name, matching it loosely so that both snake_case and camelCase names are
// matched.
FeatureInfo *FindFeatureByName(FeatureMap *features, const std::string &name)
{
for (auto iter : *features)
{
if (FeatureNameMatch(iter.first, name))
{
return iter.second;
}
}
return nullptr;
}
} // anonymous namespace
// FeatureSetBase implementation
void FeatureSetBase::overrideFeatures(const std::vector<std::string> &featureNames, bool enabled)
{
for (const std::string &name : featureNames)
{
FeatureInfo *feature = FindFeatureByName(&members, name);
if (feature != nullptr)
{
feature->enabled = enabled;
}
}
}
void FeatureSetBase::populateFeatureList(FeatureList *features) const
{
for (FeatureMap::const_iterator it = members.begin(); it != members.end(); it++)
{
features->push_back(it->second);
}
}
} // namespace angle
namespace rx
{
namespace
{
// Both D3D and Vulkan support the same set of standard sample positions for 1, 2, 4, 8, and 16
// samples. See:
//
// - https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218.aspx
//
// -
// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#primsrast-multisampling
using SamplePositionsArray = std::array<float, 32>;
constexpr std::array<SamplePositionsArray, 5> kSamplePositions = {
{{{0.5f, 0.5f}},
{{0.75f, 0.75f, 0.25f, 0.25f}},
{{0.375f, 0.125f, 0.875f, 0.375f, 0.125f, 0.625f, 0.625f, 0.875f}},
{{0.5625f, 0.3125f, 0.4375f, 0.6875f, 0.8125f, 0.5625f, 0.3125f, 0.1875f, 0.1875f, 0.8125f,
0.0625f, 0.4375f, 0.6875f, 0.9375f, 0.9375f, 0.0625f}},
{{0.5625f, 0.5625f, 0.4375f, 0.3125f, 0.3125f, 0.625f, 0.75f, 0.4375f,
0.1875f, 0.375f, 0.625f, 0.8125f, 0.8125f, 0.6875f, 0.6875f, 0.1875f,
0.375f, 0.875f, 0.5f, 0.0625f, 0.25f, 0.125f, 0.125f, 0.75f,
0.0f, 0.5f, 0.9375f, 0.25f, 0.875f, 0.9375f, 0.0625f, 0.0f}}}};
struct IncompleteTextureParameters
{
GLenum sizedInternalFormat;
GLenum format;
GLenum type;
GLubyte clearColor[4];
};
// Note that for gl::SamplerFormat::Shadow, the clearColor datatype needs to be GLushort and as such
// we will reinterpret GLubyte[4] as GLushort[2].
constexpr angle::PackedEnumMap<gl::SamplerFormat, IncompleteTextureParameters>
kIncompleteTextureParameters = {
{gl::SamplerFormat::Float, {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, {0, 0, 0, 255}}},
{gl::SamplerFormat::Unsigned,
{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, {0, 0, 0, 255}}},
{gl::SamplerFormat::Signed, {GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, {0, 0, 0, 127}}},
{gl::SamplerFormat::Shadow,
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, {0, 0, 0, 0}}}};
void CopyColor(gl::ColorF *color)
{
// No-op
}
void PremultiplyAlpha(gl::ColorF *color)
{
color->red *= color->alpha;
color->green *= color->alpha;
color->blue *= color->alpha;
}
void UnmultiplyAlpha(gl::ColorF *color)
{
if (color->alpha != 0.0f)
{
float invAlpha = 1.0f / color->alpha;
color->red *= invAlpha;
color->green *= invAlpha;
color->blue *= invAlpha;
}
}
void ClipChannelsR(gl::ColorF *color)
{
color->green = 0.0f;
color->blue = 0.0f;
color->alpha = 1.0f;
}
void ClipChannelsRG(gl::ColorF *color)
{
color->blue = 0.0f;
color->alpha = 1.0f;
}
void ClipChannelsRGB(gl::ColorF *color)
{
color->alpha = 1.0f;
}
void ClipChannelsLuminance(gl::ColorF *color)
{
color->alpha = 1.0f;
}
void ClipChannelsAlpha(gl::ColorF *color)
{
color->red = 0.0f;
color->green = 0.0f;
color->blue = 0.0f;
}
void ClipChannelsNoOp(gl::ColorF *color) {}
void WriteUintColor(const gl::ColorF &color,
PixelWriteFunction colorWriteFunction,
uint8_t *destPixelData)
{
gl::ColorUI destColor(
static_cast<unsigned int>(color.red * 255), static_cast<unsigned int>(color.green * 255),
static_cast<unsigned int>(color.blue * 255), static_cast<unsigned int>(color.alpha * 255));
colorWriteFunction(reinterpret_cast<const uint8_t *>(&destColor), destPixelData);
}
void WriteFloatColor(const gl::ColorF &color,
PixelWriteFunction colorWriteFunction,
uint8_t *destPixelData)
{
colorWriteFunction(reinterpret_cast<const uint8_t *>(&color), destPixelData);
}
template <int cols, int rows, bool IsColumnMajor>
inline int GetFlattenedIndex(int col, int row)
{
if (IsColumnMajor)
{
return col * rows + row;
}
else
{
return row * cols + col;
}
}
template <typename T,
bool IsSrcColumnMajor,
int colsSrc,
int rowsSrc,
bool IsDstColumnMajor,
int colsDst,
int rowsDst>
void ExpandMatrix(T *target, const GLfloat *value)
{
static_assert(colsSrc <= colsDst && rowsSrc <= rowsDst, "Can only expand!");
constexpr int kDstFlatSize = colsDst * rowsDst;
T staging[kDstFlatSize] = {0};
for (int r = 0; r < rowsSrc; r++)
{
for (int c = 0; c < colsSrc; c++)
{
int srcIndex = GetFlattenedIndex<colsSrc, rowsSrc, IsSrcColumnMajor>(c, r);
int dstIndex = GetFlattenedIndex<colsDst, rowsDst, IsDstColumnMajor>(c, r);
staging[dstIndex] = static_cast<T>(value[srcIndex]);
}
}
memcpy(target, staging, kDstFlatSize * sizeof(T));
}
template <bool IsSrcColumMajor,
int colsSrc,
int rowsSrc,
bool IsDstColumnMajor,
int colsDst,
int rowsDst>
void SetFloatUniformMatrix(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
const GLfloat *value,
uint8_t *targetData)
{
unsigned int count =
std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
const unsigned int targetMatrixStride = colsDst * rowsDst;
GLfloat *target = reinterpret_cast<GLfloat *>(
targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride);
for (unsigned int i = 0; i < count; i++)
{
ExpandMatrix<GLfloat, IsSrcColumMajor, colsSrc, rowsSrc, IsDstColumnMajor, colsDst,
rowsDst>(target, value);
target += targetMatrixStride;
value += colsSrc * rowsSrc;
}
}
void SetFloatUniformMatrixFast(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
size_t matrixSize,
const GLfloat *value,
uint8_t *targetData)
{
const unsigned int count =
std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
const uint8_t *valueData = reinterpret_cast<const uint8_t *>(value);
targetData = targetData + arrayElementOffset * matrixSize;
memcpy(targetData, valueData, matrixSize * count);
}
} // anonymous namespace
void RotateRectangle(const SurfaceRotation rotation,
const bool flipY,
const int framebufferWidth,
const int framebufferHeight,
const gl::Rectangle &incoming,
gl::Rectangle *outgoing)
{
// GLES's y-axis points up; Vulkan's points down.
switch (rotation)
{
case SurfaceRotation::Identity:
// Do not rotate gl_Position (surface matches the device's orientation):
outgoing->x = incoming.x;
outgoing->y = flipY ? framebufferHeight - incoming.y - incoming.height : incoming.y;
outgoing->width = incoming.width;
outgoing->height = incoming.height;
break;
case SurfaceRotation::Rotated90Degrees:
// Rotate gl_Position 90 degrees:
outgoing->x = incoming.y;
outgoing->y = flipY ? incoming.x : framebufferWidth - incoming.x - incoming.width;
outgoing->width = incoming.height;
outgoing->height = incoming.width;
break;
case SurfaceRotation::Rotated180Degrees:
// Rotate gl_Position 180 degrees:
outgoing->x = framebufferWidth - incoming.x - incoming.width;
outgoing->y = flipY ? incoming.y : framebufferHeight - incoming.y - incoming.height;
outgoing->width = incoming.width;
outgoing->height = incoming.height;
break;
case SurfaceRotation::Rotated270Degrees:
// Rotate gl_Position 270 degrees:
outgoing->x = framebufferHeight - incoming.y - incoming.height;
outgoing->y = flipY ? framebufferWidth - incoming.x - incoming.width : incoming.x;
outgoing->width = incoming.height;
outgoing->height = incoming.width;
break;
default:
UNREACHABLE();
break;
}
}
PackPixelsParams::PackPixelsParams()
: destFormat(nullptr),
outputPitch(0),
packBuffer(nullptr),
offset(0),
rotation(SurfaceRotation::Identity)
{}
PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
const angle::Format &destFormat,
GLuint outputPitchIn,
bool reverseRowOrderIn,
gl::Buffer *packBufferIn,
ptrdiff_t offsetIn)
: area(areaIn),
destFormat(&destFormat),
outputPitch(outputPitchIn),
packBuffer(packBufferIn),
reverseRowOrder(reverseRowOrderIn),
offset(offsetIn),
rotation(SurfaceRotation::Identity)
{}
void PackPixels(const PackPixelsParams ¶ms,
const angle::Format &sourceFormat,
int inputPitchIn,
const uint8_t *sourceIn,
uint8_t *destWithoutOffset)
{
uint8_t *destWithOffset = destWithoutOffset + params.offset;
const uint8_t *source = sourceIn;
int inputPitch = inputPitchIn;
int destWidth = params.area.width;
int destHeight = params.area.height;
int xAxisPitch = 0;
int yAxisPitch = 0;
switch (params.rotation)
{
case SurfaceRotation::Identity:
// The source image is not rotated (i.e. matches the device's orientation), and may or
// may not be y-flipped. The image is row-major. Each source row (one step along the
// y-axis for each step in the dest y-axis) is inputPitch past the previous row. Along
// a row, each source pixel (one step along the x-axis for each step in the dest
// x-axis) is sourceFormat.pixelBytes past the previous pixel.
xAxisPitch = sourceFormat.pixelBytes;
if (params.reverseRowOrder)
{
// The source image is y-flipped, which means we start at the last row, and each
// source row is BEFORE the previous row.
source += inputPitchIn * (params.area.height - 1);
inputPitch = -inputPitch;
yAxisPitch = -inputPitchIn;
}
else
{
yAxisPitch = inputPitchIn;
}
break;
case SurfaceRotation::Rotated90Degrees:
// The source image is rotated 90 degrees counter-clockwise. Y-flip is always applied
// to rotated images. The image is column-major. Each source column (one step along
// the source x-axis for each step in the dest y-axis) is inputPitch past the previous
// column. Along a column, each source pixel (one step along the y-axis for each step
// in the dest x-axis) is sourceFormat.pixelBytes past the previous pixel.
xAxisPitch = inputPitchIn;
yAxisPitch = sourceFormat.pixelBytes;
destWidth = params.area.height;
destHeight = params.area.width;
break;
case SurfaceRotation::Rotated180Degrees:
// The source image is rotated 180 degrees. Y-flip is always applied to rotated
// images. The image is row-major, but upside down. Each source row (one step along
// the y-axis for each step in the dest y-axis) is inputPitch after the previous row.
// Along a row, each source pixel (one step along the x-axis for each step in the dest
// x-axis) is sourceFormat.pixelBytes BEFORE the previous pixel.
xAxisPitch = -static_cast<int>(sourceFormat.pixelBytes);
yAxisPitch = inputPitchIn;
source += sourceFormat.pixelBytes * (params.area.width - 1);
break;
case SurfaceRotation::Rotated270Degrees:
// The source image is rotated 270 degrees counter-clockwise (or 90 degrees clockwise).
// Y-flip is always applied to rotated images. The image is column-major, where each
// column (one step in the source x-axis for one step in the dest y-axis) is inputPitch
// BEFORE the previous column. Along a column, each source pixel (one step along the
// y-axis for each step in the dest x-axis) is sourceFormat.pixelBytes BEFORE the
// previous pixel. The first pixel is at the end of the source.
xAxisPitch = -inputPitchIn;
yAxisPitch = -static_cast<int>(sourceFormat.pixelBytes);
destWidth = params.area.height;
destHeight = params.area.width;
source += inputPitch * (params.area.height - 1) +
sourceFormat.pixelBytes * (params.area.width - 1);
break;
default:
UNREACHABLE();
break;
}
if (params.rotation == SurfaceRotation::Identity && sourceFormat == *params.destFormat)
{
// Direct copy possible
for (int y = 0; y < params.area.height; ++y)
{
memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch,
params.area.width * sourceFormat.pixelBytes);
}
return;
}
FastCopyFunction fastCopyFunc = sourceFormat.fastCopyFunctions.get(params.destFormat->id);
if (fastCopyFunc)
{
// Fast copy is possible through some special function
fastCopyFunc(source, xAxisPitch, yAxisPitch, destWithOffset, params.destFormat->pixelBytes,
params.outputPitch, destWidth, destHeight);
return;
}
PixelWriteFunction pixelWriteFunction = params.destFormat->pixelWriteFunction;
ASSERT(pixelWriteFunction != nullptr);
// Maximum size of any Color<T> type used.
uint8_t temp[16];
static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) &&
sizeof(temp) >= sizeof(gl::ColorI) &&
sizeof(temp) >= sizeof(angle::DepthStencil),
"Unexpected size of pixel struct.");
PixelReadFunction pixelReadFunction = sourceFormat.pixelReadFunction;
ASSERT(pixelReadFunction != nullptr);
for (int y = 0; y < destHeight; ++y)
{
for (int x = 0; x < destWidth; ++x)
{
uint8_t *dest =
destWithOffset + y * params.outputPitch + x * params.destFormat->pixelBytes;
const uint8_t *src = source + y * yAxisPitch + x * xAxisPitch;
// readFunc and writeFunc will be using the same type of color, CopyTexImage
// will not allow the copy otherwise.
pixelReadFunction(src, temp);
pixelWriteFunction(temp, dest);
}
}
}
bool FastCopyFunctionMap::has(angle::FormatID formatID) const
{
return (get(formatID) != nullptr);
}
namespace
{
const FastCopyFunctionMap::Entry *getEntry(const FastCopyFunctionMap::Entry *entry,
size_t numEntries,
angle::FormatID formatID)
{
const FastCopyFunctionMap::Entry *end = entry + numEntries;
while (entry != end)
{
if (entry->formatID == formatID)
{
return entry;
}
++entry;
}
return nullptr;
}
} // namespace
FastCopyFunction FastCopyFunctionMap::get(angle::FormatID formatID) const
{
const FastCopyFunctionMap::Entry *entry = getEntry(mData, mSize, formatID);
return entry ? entry->func : nullptr;
}
bool ShouldUseDebugLayers(const egl::AttributeMap &attribs)
{
EGLAttrib debugSetting =
attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE);
// Prefer to enable debug layers when available.
#if defined(ANGLE_ENABLE_ASSERTS)
return (debugSetting != EGL_FALSE);
#else
return (debugSetting == EGL_TRUE);
#endif // defined(ANGLE_ENABLE_ASSERTS)
}
void CopyImageCHROMIUM(const uint8_t *sourceData,
size_t sourceRowPitch,
size_t sourcePixelBytes,
size_t sourceDepthPitch,
PixelReadFunction pixelReadFunction,
uint8_t *destData,
size_t destRowPitch,
size_t destPixelBytes,
size_t destDepthPitch,
PixelWriteFunction pixelWriteFunction,
GLenum destUnsizedFormat,
GLenum destComponentType,
size_t width,
size_t height,
size_t depth,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha)
{
using ConversionFunction = void (*)(gl::ColorF *);
ConversionFunction conversionFunction = CopyColor;
if (unpackPremultiplyAlpha != unpackUnmultiplyAlpha)
{
if (unpackPremultiplyAlpha)
{
conversionFunction = PremultiplyAlpha;
}
else
{
conversionFunction = UnmultiplyAlpha;
}
}
auto clipChannelsFunction = ClipChannelsNoOp;
switch (destUnsizedFormat)
{
case GL_RED:
clipChannelsFunction = ClipChannelsR;
break;
case GL_RG:
clipChannelsFunction = ClipChannelsRG;
break;
case GL_RGB:
clipChannelsFunction = ClipChannelsRGB;
break;
case GL_LUMINANCE:
clipChannelsFunction = ClipChannelsLuminance;
break;
case GL_ALPHA:
clipChannelsFunction = ClipChannelsAlpha;
break;
}
auto writeFunction = (destComponentType == GL_UNSIGNED_INT) ? WriteUintColor : WriteFloatColor;
for (size_t z = 0; z < depth; z++)
{
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
{
const uint8_t *sourcePixelData =
sourceData + y * sourceRowPitch + x * sourcePixelBytes + z * sourceDepthPitch;
gl::ColorF sourceColor;
pixelReadFunction(sourcePixelData, reinterpret_cast<uint8_t *>(&sourceColor));
conversionFunction(&sourceColor);
clipChannelsFunction(&sourceColor);
size_t destY = 0;
if (unpackFlipY)
{
destY += (height - 1);
destY -= y;
}
else
{
destY += y;
}
uint8_t *destPixelData =
destData + destY * destRowPitch + x * destPixelBytes + z * destDepthPitch;
writeFunction(sourceColor, pixelWriteFunction, destPixelData);
}
}
}
}
// IncompleteTextureSet implementation.
IncompleteTextureSet::IncompleteTextureSet() : mIncompleteTextureBufferAttachment(nullptr) {}
IncompleteTextureSet::~IncompleteTextureSet() {}
void IncompleteTextureSet::onDestroy(const gl::Context *context)
{
// Clear incomplete textures.
for (auto &incompleteTextures : mIncompleteTextures)
{
for (auto &incompleteTexture : incompleteTextures)
{
if (incompleteTexture.get() != nullptr)
{
incompleteTexture->onDestroy(context);
incompleteTexture.set(context, nullptr);
}
}
}
if (mIncompleteTextureBufferAttachment != nullptr)
{
mIncompleteTextureBufferAttachment->onDestroy(context);
mIncompleteTextureBufferAttachment = nullptr;
}
}
angle::Result IncompleteTextureSet::getIncompleteTexture(
const gl::Context *context,
gl::TextureType type,
gl::SamplerFormat format,
MultisampleTextureInitializer *multisampleInitializer,
gl::Texture **textureOut)
{
*textureOut = mIncompleteTextures[format][type].get();
if (*textureOut != nullptr)
{
return angle::Result::Continue;
}
ContextImpl *implFactory = context->getImplementation();
gl::Extents colorSize(1, 1, 1);
gl::PixelUnpackState unpack;
unpack.alignment = 1;
gl::Box area(0, 0, 0, 1, 1, 1);
const IncompleteTextureParameters &incompleteTextureParam =
kIncompleteTextureParameters[format];
// Cube map arrays are expected to have layer counts that are multiples of 6
constexpr int kCubeMapArraySize = 6;
if (type == gl::TextureType::CubeMapArray)
{
// From the GLES 3.2 spec:
// 8.18. IMMUTABLE-FORMAT TEXTURE IMAGES
// TexStorage3D Errors
// An INVALID_OPERATION error is generated if any of the following conditions hold:
// * target is TEXTURE_CUBE_MAP_ARRAY and depth is not a multiple of 6
// Since ANGLE treats incomplete textures as immutable, respect that here.
colorSize.depth = kCubeMapArraySize;
area.depth = kCubeMapArraySize;
}
// If a texture is external use a 2D texture for the incomplete texture
gl::TextureType createType = (type == gl::TextureType::External) ? gl::TextureType::_2D : type;
gl::Texture *tex =
new gl::Texture(implFactory, {std::numeric_limits<GLuint>::max()}, createType);
angle::UniqueObjectPointer<gl::Texture, gl::Context> t(tex, context);
// This is a bit of a kludge but is necessary to consume the error.
gl::Context *mutableContext = const_cast<gl::Context *>(context);
if (createType == gl::TextureType::Buffer)
{
constexpr uint32_t kBufferInitData = 0;
mIncompleteTextureBufferAttachment =
new gl::Buffer(implFactory, {std::numeric_limits<GLuint>::max()});
ANGLE_TRY(mIncompleteTextureBufferAttachment->bufferData(
mutableContext, gl::BufferBinding::Texture, &kBufferInitData, sizeof(kBufferInitData),
gl::BufferUsage::StaticDraw));
}
else if (createType == gl::TextureType::_2DMultisample)
{
ANGLE_TRY(t->setStorageMultisample(mutableContext, createType, 1,
incompleteTextureParam.sizedInternalFormat, colorSize,
true));
}
else
{
ANGLE_TRY(t->setStorage(mutableContext, createType, 1,
incompleteTextureParam.sizedInternalFormat, colorSize));
}
if (type == gl::TextureType::CubeMap)
{
for (gl::TextureTarget face : gl::AllCubeFaceTextureTargets())
{
ANGLE_TRY(t->setSubImage(mutableContext, unpack, nullptr, face, 0, area,
incompleteTextureParam.format, incompleteTextureParam.type,
incompleteTextureParam.clearColor));
}
}
else if (type == gl::TextureType::CubeMapArray)
{
// We need to provide enough pixel data to fill the array of six faces
GLubyte incompleteCubeArrayPixels[kCubeMapArraySize][4];
for (int i = 0; i < kCubeMapArraySize; ++i)
{
incompleteCubeArrayPixels[i][0] = incompleteTextureParam.clearColor[0];
incompleteCubeArrayPixels[i][1] = incompleteTextureParam.clearColor[1];
incompleteCubeArrayPixels[i][2] = incompleteTextureParam.clearColor[2];
incompleteCubeArrayPixels[i][3] = incompleteTextureParam.clearColor[3];
}
ANGLE_TRY(t->setSubImage(mutableContext, unpack, nullptr,
gl::NonCubeTextureTypeToTarget(createType), 0, area,
incompleteTextureParam.format, incompleteTextureParam.type,
*incompleteCubeArrayPixels));
}
else if (type == gl::TextureType::_2DMultisample)
{
// Call a specialized clear function to init a multisample texture.
ANGLE_TRY(multisampleInitializer->initializeMultisampleTextureToBlack(context, t.get()));
}
else if (type == gl::TextureType::Buffer)
{
ANGLE_TRY(t->setBuffer(context, mIncompleteTextureBufferAttachment,
incompleteTextureParam.sizedInternalFormat));
}
else
{
ANGLE_TRY(t->setSubImage(mutableContext, unpack, nullptr,
gl::NonCubeTextureTypeToTarget(createType), 0, area,
incompleteTextureParam.format, incompleteTextureParam.type,
incompleteTextureParam.clearColor));
}
if (format == gl::SamplerFormat::Shadow)
{
// To avoid the undefined spec behavior for shadow samplers with a depth texture, we set the
// compare mode to GL_COMPARE_REF_TO_TEXTURE
ASSERT(!t->hasObservers());
t->setCompareMode(context, GL_COMPARE_REF_TO_TEXTURE);
}
ANGLE_TRY(t->syncState(context, gl::Command::Other));
mIncompleteTextures[format][type].set(context, t.release());
*textureOut = mIncompleteTextures[format][type].get();
return angle::Result::Continue;
}
#define ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \
template void SetFloatUniformMatrix##api<cols, rows>::Run( \
unsigned int, unsigned int, GLsizei, GLboolean, const GLfloat *, uint8_t *)
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 2, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 3, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 2, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 3, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 4, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(GLSL, 4, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 2, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 3, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 2, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 3, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 2, 4);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(HLSL, 3, 4);
#undef ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC
#define ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \
template void SetFloatUniformMatrix##api<cols, 4>::Run(unsigned int, unsigned int, GLsizei, \
GLboolean, const GLfloat *, uint8_t *)
template <int cols>
struct SetFloatUniformMatrixGLSL<cols, 4>
{
static void Run(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData);
};
ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(GLSL, 2, 4);
ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(GLSL, 3, 4);
ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC(GLSL, 4, 4);
#undef ANGLE_SPECIALIZATION_ROWS_SET_UNIFORM_MATRIX_FUNC
#define ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(api, cols, rows) \
template void SetFloatUniformMatrix##api<4, rows>::Run(unsigned int, unsigned int, GLsizei, \
GLboolean, const GLfloat *, uint8_t *)
template <int rows>
struct SetFloatUniformMatrixHLSL<4, rows>
{
static void Run(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData);
};
ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(HLSL, 4, 2);
ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(HLSL, 4, 3);
ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC(HLSL, 4, 4);
#undef ANGLE_SPECIALIZATION_COLS_SET_UNIFORM_MATRIX_FUNC
template <int cols>
void SetFloatUniformMatrixGLSL<cols, 4>::Run(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData)
{
const bool isSrcColumnMajor = !transpose;
if (isSrcColumnMajor)
{
// Both src and dst matrixs are has same layout,
// a single memcpy updates all the matrices
constexpr size_t srcMatrixSize = sizeof(GLfloat) * cols * 4;
SetFloatUniformMatrixFast(arrayElementOffset, elementCount, countIn, srcMatrixSize, value,
targetData);
}
else
{
// fallback to general cases
SetFloatUniformMatrix<false, cols, 4, true, cols, 4>(arrayElementOffset, elementCount,
countIn, value, targetData);
}
}
template <int cols, int rows>
void SetFloatUniformMatrixGLSL<cols, rows>::Run(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData)
{
const bool isSrcColumnMajor = !transpose;
// GLSL expects matrix uniforms to be column-major, and each column is padded to 4 rows.
if (isSrcColumnMajor)
{
SetFloatUniformMatrix<true, cols, rows, true, cols, 4>(arrayElementOffset, elementCount,
countIn, value, targetData);
}
else
{
SetFloatUniformMatrix<false, cols, rows, true, cols, 4>(arrayElementOffset, elementCount,
countIn, value, targetData);
}
}
template <int rows>
void SetFloatUniformMatrixHLSL<4, rows>::Run(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData)
{
const bool isSrcColumnMajor = !transpose;
if (!isSrcColumnMajor)
{
// Both src and dst matrixs are has same layout,
// a single memcpy updates all the matrices
constexpr size_t srcMatrixSize = sizeof(GLfloat) * 4 * rows;
SetFloatUniformMatrixFast(arrayElementOffset, elementCount, countIn, srcMatrixSize, value,
targetData);
}
else
{
// fallback to general cases
SetFloatUniformMatrix<true, 4, rows, false, 4, rows>(arrayElementOffset, elementCount,
countIn, value, targetData);
}
}
template <int cols, int rows>
void SetFloatUniformMatrixHLSL<cols, rows>::Run(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData)
{
const bool isSrcColumnMajor = !transpose;
// Internally store matrices as row-major to accomodate HLSL matrix indexing. Each row is
// padded to 4 columns.
if (!isSrcColumnMajor)
{
SetFloatUniformMatrix<false, cols, rows, false, 4, rows>(arrayElementOffset, elementCount,
countIn, value, targetData);
}
else
{
SetFloatUniformMatrix<true, cols, rows, false, 4, rows>(arrayElementOffset, elementCount,
countIn, value, targetData);
}
}
template void GetMatrixUniform<GLint>(GLenum, GLint *, const GLint *, bool);
template void GetMatrixUniform<GLuint>(GLenum, GLuint *, const GLuint *, bool);
void GetMatrixUniform(GLenum type, GLfloat *dataOut, const GLfloat *source, bool transpose)
{
int columns = gl::VariableColumnCount(type);
int rows = gl::VariableRowCount(type);
for (GLint col = 0; col < columns; ++col)
{
for (GLint row = 0; row < rows; ++row)
{
GLfloat *outptr = dataOut + ((col * rows) + row);
const GLfloat *inptr =
transpose ? source + ((row * 4) + col) : source + ((col * 4) + row);
*outptr = *inptr;
}
}
}
template <typename NonFloatT>
void GetMatrixUniform(GLenum type, NonFloatT *dataOut, const NonFloatT *source, bool transpose)
{
UNREACHABLE();
}
const angle::Format &GetFormatFromFormatType(GLenum format, GLenum type)
{
GLenum sizedInternalFormat = gl::GetInternalFormatInfo(format, type).sizedInternalFormat;
angle::FormatID angleFormatID = angle::Format::InternalFormatToID(sizedInternalFormat);
return angle::Format::Get(angleFormatID);
}
angle::Result ComputeStartVertex(ContextImpl *contextImpl,
const gl::IndexRange &indexRange,
GLint baseVertex,
GLint *firstVertexOut)
{
// The entire index range should be within the limits of a 32-bit uint because the largest
// GL index type is GL_UNSIGNED_INT.
ASSERT(indexRange.start <= std::numeric_limits<uint32_t>::max() &&
indexRange.end <= std::numeric_limits<uint32_t>::max());
// The base vertex is only used in DrawElementsIndirect. Given the assertion above and the
// type of mBaseVertex (GLint), adding them both as 64-bit ints is safe.
int64_t startVertexInt64 =
static_cast<int64_t>(baseVertex) + static_cast<int64_t>(indexRange.start);
// OpenGL ES 3.2 spec section 10.5: "Behavior of DrawElementsOneInstance is undefined if the
// vertex ID is negative for any element"
ANGLE_CHECK_GL_MATH(contextImpl, startVertexInt64 >= 0);
// OpenGL ES 3.2 spec section 10.5: "If the vertex ID is larger than the maximum value
// representable by type, it should behave as if the calculation were upconverted to 32-bit
// unsigned integers(with wrapping on overflow conditions)." ANGLE does not fully handle
// these rules, an overflow error is returned if the start vertex cannot be stored in a
// 32-bit signed integer.
ANGLE_CHECK_GL_MATH(contextImpl, startVertexInt64 <= std::numeric_limits<GLint>::max());
*firstVertexOut = static_cast<GLint>(startVertexInt64);
return angle::Result::Continue;
}
angle::Result GetVertexRangeInfo(const gl::Context *context,
GLint firstVertex,
GLsizei vertexOrIndexCount,
gl::DrawElementsType indexTypeOrInvalid,
const void *indices,
GLint baseVertex,
GLint *startVertexOut,
size_t *vertexCountOut)
{
if (indexTypeOrInvalid != gl::DrawElementsType::InvalidEnum)
{
gl::IndexRange indexRange;
ANGLE_TRY(context->getState().getVertexArray()->getIndexRange(
context, indexTypeOrInvalid, vertexOrIndexCount, indices, &indexRange));
ANGLE_TRY(ComputeStartVertex(context->getImplementation(), indexRange, baseVertex,
startVertexOut));
*vertexCountOut = indexRange.vertexCount();
}
else
{
*startVertexOut = firstVertex;
*vertexCountOut = vertexOrIndexCount;
}
return angle::Result::Continue;
}
gl::Rectangle ClipRectToScissor(const gl::State &glState, const gl::Rectangle &rect, bool invertY)
{
// If the scissor test isn't enabled, assume it has infinite size. Its intersection with the
// rect would be the rect itself.
//
// Note that on Vulkan, returning this (as opposed to a fixed max-int-sized rect) could lead to
// unnecessary pipeline creations if two otherwise identical pipelines are used on framebuffers
// with different sizes. If such usage is observed in an application, we should investigate
// possible optimizations.
if (!glState.isScissorTestEnabled())
{
return rect;
}
gl::Rectangle clippedRect;
if (!gl::ClipRectangle(glState.getScissor(), rect, &clippedRect))
{
return gl::Rectangle();
}
if (invertY)
{
clippedRect.y = rect.height - clippedRect.y - clippedRect.height;
}
return clippedRect;
}
void LogFeatureStatus(const angle::FeatureSetBase &features,
const std::vector<std::string> &featureNames,
bool enabled)
{
for (const std::string &name : featureNames)
{
if (features.getFeatures().find(name) != features.getFeatures().end())
{
INFO() << "Feature: " << name << (enabled ? " enabled" : " disabled");
}
}
}
void ApplyFeatureOverrides(angle::FeatureSetBase *features, const egl::DisplayState &state)
{
features->overrideFeatures(state.featureOverridesEnabled, true);
features->overrideFeatures(state.featureOverridesDisabled, false);
// Override with environment as well.
constexpr char kAngleFeatureOverridesEnabledEnvName[] = "ANGLE_FEATURE_OVERRIDES_ENABLED";
constexpr char kAngleFeatureOverridesDisabledEnvName[] = "ANGLE_FEATURE_OVERRIDES_DISABLED";
constexpr char kAngleFeatureOverridesEnabledPropertyName[] =
"debug.angle.feature_overrides_enabled";
constexpr char kAngleFeatureOverridesDisabledPropertyName[] =
"debug.angle.feature_overrides_disabled";
std::vector<std::string> overridesEnabled =
angle::GetCachedStringsFromEnvironmentVarOrAndroidProperty(
kAngleFeatureOverridesEnabledEnvName, kAngleFeatureOverridesEnabledPropertyName, ":");
std::vector<std::string> overridesDisabled =
angle::GetCachedStringsFromEnvironmentVarOrAndroidProperty(
kAngleFeatureOverridesDisabledEnvName, kAngleFeatureOverridesDisabledPropertyName, ":");
features->overrideFeatures(overridesEnabled, true);
LogFeatureStatus(*features, overridesEnabled, true);
features->overrideFeatures(overridesDisabled, false);
LogFeatureStatus(*features, overridesDisabled, false);
}
void GetSamplePosition(GLsizei sampleCount, size_t index, GLfloat *xy)
{
ASSERT(gl::isPow2(sampleCount));
if (sampleCount > 16)
{
// Vulkan (and D3D11) doesn't have standard sample positions for 32 and 64 samples (and no
// drivers are known to support that many samples)
xy[0] = 0.5f;
xy[1] = 0.5f;
}
else
{
size_t indexKey = static_cast<size_t>(gl::log2(sampleCount));
ASSERT(indexKey < kSamplePositions.size() &&
(2 * index + 1) < kSamplePositions[indexKey].size());
xy[0] = kSamplePositions[indexKey][2 * index];
xy[1] = kSamplePositions[indexKey][2 * index + 1];
}
}
// These macros are to avoid code too much duplication for variations of multi draw types
#define DRAW_ARRAYS__ contextImpl->drawArrays(context, mode, firsts[drawID], counts[drawID])
#define DRAW_ARRAYS_INSTANCED_ \
contextImpl->drawArraysInstanced(context, mode, firsts[drawID], counts[drawID], \
instanceCounts[drawID])
#define DRAW_ELEMENTS__ \
contextImpl->drawElements(context, mode, counts[drawID], type, indices[drawID])
#define DRAW_ELEMENTS_INSTANCED_ \
contextImpl->drawElementsInstanced(context, mode, counts[drawID], type, indices[drawID], \
instanceCounts[drawID])
#define DRAW_ARRAYS_INSTANCED_BASE_INSTANCE \
contextImpl->drawArraysInstancedBaseInstance(context, mode, firsts[drawID], counts[drawID], \
instanceCounts[drawID], baseInstances[drawID])
#define DRAW_ELEMENTS_INSTANCED_BASE_VERTEX_BASE_INSTANCE \
contextImpl->drawElementsInstancedBaseVertexBaseInstance( \
context, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID], \
baseVertices[drawID], baseInstances[drawID])
#define DRAW_CALL(drawType, instanced, bvbi) DRAW_##drawType##instanced##bvbi
#define MULTI_DRAW_BLOCK(drawType, instanced, bvbi, hasDrawID, hasBaseVertex, hasBaseInstance) \
for (GLsizei drawID = 0; drawID < drawcount; ++drawID) \
{ \
if (ANGLE_NOOP_DRAW(instanced)) \
{ \
ANGLE_TRY(contextImpl->handleNoopDrawEvent()); \
continue; \
} \
ANGLE_SET_DRAW_ID_UNIFORM(hasDrawID)(drawID); \
ANGLE_SET_BASE_VERTEX_UNIFORM(hasBaseVertex)(baseVertices[drawID]); \
ANGLE_SET_BASE_INSTANCE_UNIFORM(hasBaseInstance)(baseInstances[drawID]); \
ANGLE_TRY(DRAW_CALL(drawType, instanced, bvbi)); \
ANGLE_MARK_TRANSFORM_FEEDBACK_USAGE(instanced); \
gl::MarkShaderStorageUsage(context); \
}
angle::Result MultiDrawArraysGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
GLsizei drawcount)
{
gl::Program *programObject = context->getState().getLinkedProgram(context);
const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
if (hasDrawID)
{
MULTI_DRAW_BLOCK(ARRAYS, _, _, 1, 0, 0)
}
else
{
MULTI_DRAW_BLOCK(ARRAYS, _, _, 0, 0, 0)
}
return angle::Result::Continue;
}
angle::Result MultiDrawArraysIndirectGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect,
GLsizei drawcount,
GLsizei stride)
{
const GLubyte *indirectPtr = static_cast<const GLubyte *>(indirect);
for (auto count = 0; count < drawcount; count++)
{
ANGLE_TRY(contextImpl->drawArraysIndirect(
context, mode, reinterpret_cast<const gl::DrawArraysIndirectCommand *>(indirectPtr)));
if (stride == 0)
{
indirectPtr += sizeof(gl::DrawArraysIndirectCommand);
}
else
{
indirectPtr += stride;
}
}
return angle::Result::Continue;
}
angle::Result MultiDrawArraysInstancedGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
gl::Program *programObject = context->getState().getLinkedProgram(context);
const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
if (hasDrawID)
{
MULTI_DRAW_BLOCK(ARRAYS, _INSTANCED, _, 1, 0, 0)
}
else
{
MULTI_DRAW_BLOCK(ARRAYS, _INSTANCED, _, 0, 0, 0)
}
return angle::Result::Continue;
}
angle::Result MultiDrawElementsGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
GLsizei drawcount)
{
gl::Program *programObject = context->getState().getLinkedProgram(context);
const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
if (hasDrawID)
{
MULTI_DRAW_BLOCK(ELEMENTS, _, _, 1, 0, 0)
}
else
{
MULTI_DRAW_BLOCK(ELEMENTS, _, _, 0, 0, 0)
}
return angle::Result::Continue;
}
angle::Result MultiDrawElementsIndirectGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
gl::DrawElementsType type,
const void *indirect,
GLsizei drawcount,
GLsizei stride)
{
const GLubyte *indirectPtr = static_cast<const GLubyte *>(indirect);
for (auto count = 0; count < drawcount; count++)
{
ANGLE_TRY(contextImpl->drawElementsIndirect(
context, mode, type,
reinterpret_cast<const gl::DrawElementsIndirectCommand *>(indirectPtr)));
if (stride == 0)
{
indirectPtr += sizeof(gl::DrawElementsIndirectCommand);
}
else
{
indirectPtr += stride;
}
}
return angle::Result::Continue;
}
angle::Result MultiDrawElementsInstancedGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
gl::Program *programObject = context->getState().getLinkedProgram(context);
const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
if (hasDrawID)
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _, 1, 0, 0)
}
else
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _, 0, 0, 0)
}
return angle::Result::Continue;
}
angle::Result MultiDrawArraysInstancedBaseInstanceGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
const GLsizei *instanceCounts,
const GLuint *baseInstances,
GLsizei drawcount)
{
gl::Program *programObject = context->getState().getLinkedProgram(context);
const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
const bool hasBaseInstance = programObject && programObject->hasBaseInstanceUniform();
ResetBaseVertexBaseInstance resetUniforms(programObject, false, hasBaseInstance);
if (hasDrawID && hasBaseInstance)
{
MULTI_DRAW_BLOCK(ARRAYS, _INSTANCED, _BASE_INSTANCE, 1, 0, 1)
}
else if (hasDrawID)
{
MULTI_DRAW_BLOCK(ARRAYS, _INSTANCED, _BASE_INSTANCE, 1, 0, 0)
}
else if (hasBaseInstance)
{
MULTI_DRAW_BLOCK(ARRAYS, _INSTANCED, _BASE_INSTANCE, 0, 0, 1)
}
else
{
MULTI_DRAW_BLOCK(ARRAYS, _INSTANCED, _BASE_INSTANCE, 0, 0, 0)
}
return angle::Result::Continue;
}
angle::Result MultiDrawElementsInstancedBaseVertexBaseInstanceGeneral(ContextImpl *contextImpl,
const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
const GLsizei *instanceCounts,
const GLint *baseVertices,
const GLuint *baseInstances,
GLsizei drawcount)
{
gl::Program *programObject = context->getState().getLinkedProgram(context);
const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
const bool hasBaseVertex = programObject && programObject->hasBaseVertexUniform();
const bool hasBaseInstance = programObject && programObject->hasBaseInstanceUniform();
ResetBaseVertexBaseInstance resetUniforms(programObject, hasBaseVertex, hasBaseInstance);
if (hasDrawID)
{
if (hasBaseVertex)
{
if (hasBaseInstance)
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 1, 1, 1)
}
else
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 1, 1, 0)
}
}
else
{
if (hasBaseInstance)
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 1, 0, 1)
}
else
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 1, 0, 0)
}
}
}
else
{
if (hasBaseVertex)
{
if (hasBaseInstance)
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 0, 1, 1)
}
else
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 0, 1, 0)
}
}
else
{
if (hasBaseInstance)
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 0, 0, 1)
}
else
{
MULTI_DRAW_BLOCK(ELEMENTS, _INSTANCED, _BASE_VERTEX_BASE_INSTANCE, 0, 0, 0)
}
}
}
return angle::Result::Continue;
}
ResetBaseVertexBaseInstance::ResetBaseVertexBaseInstance(gl::Program *programObject,
bool resetBaseVertex,
bool resetBaseInstance)
: mProgramObject(programObject),
mResetBaseVertex(resetBaseVertex),
mResetBaseInstance(resetBaseInstance)
{}
ResetBaseVertexBaseInstance::~ResetBaseVertexBaseInstance()
{
if (mProgramObject)
{
// Reset emulated uniforms to zero to avoid affecting other draw calls
if (mResetBaseVertex)
{
mProgramObject->setBaseVertexUniform(0);
}
if (mResetBaseInstance)
{
mProgramObject->setBaseInstanceUniform(0);
}
}
}
angle::FormatID ConvertToSRGB(angle::FormatID formatID)
{
switch (formatID)
{
case angle::FormatID::R8_UNORM:
return angle::FormatID::R8_UNORM_SRGB;
case angle::FormatID::R8G8_UNORM:
return angle::FormatID::R8G8_UNORM_SRGB;
case angle::FormatID::R8G8B8_UNORM:
return angle::FormatID::R8G8B8_UNORM_SRGB;
case angle::FormatID::R8G8B8A8_UNORM:
return angle::FormatID::R8G8B8A8_UNORM_SRGB;
case angle::FormatID::B8G8R8A8_UNORM:
return angle::FormatID::B8G8R8A8_UNORM_SRGB;
case angle::FormatID::BC1_RGB_UNORM_BLOCK:
return angle::FormatID::BC1_RGB_UNORM_SRGB_BLOCK;
case angle::FormatID::BC1_RGBA_UNORM_BLOCK:
return angle::FormatID::BC1_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::BC2_RGBA_UNORM_BLOCK:
return angle::FormatID::BC2_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::BC3_RGBA_UNORM_BLOCK:
return angle::FormatID::BC3_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::BC7_RGBA_UNORM_BLOCK:
return angle::FormatID::BC7_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::ETC2_R8G8B8_UNORM_BLOCK:
return angle::FormatID::ETC2_R8G8B8_SRGB_BLOCK;
case angle::FormatID::ETC2_R8G8B8A1_UNORM_BLOCK:
return angle::FormatID::ETC2_R8G8B8A1_SRGB_BLOCK;
case angle::FormatID::ETC2_R8G8B8A8_UNORM_BLOCK:
return angle::FormatID::ETC2_R8G8B8A8_SRGB_BLOCK;
case angle::FormatID::ASTC_4x4_UNORM_BLOCK:
return angle::FormatID::ASTC_4x4_SRGB_BLOCK;
case angle::FormatID::ASTC_5x4_UNORM_BLOCK:
return angle::FormatID::ASTC_5x4_SRGB_BLOCK;
case angle::FormatID::ASTC_5x5_UNORM_BLOCK:
return angle::FormatID::ASTC_5x5_SRGB_BLOCK;
case angle::FormatID::ASTC_6x5_UNORM_BLOCK:
return angle::FormatID::ASTC_6x5_SRGB_BLOCK;
case angle::FormatID::ASTC_6x6_UNORM_BLOCK:
return angle::FormatID::ASTC_6x6_SRGB_BLOCK;
case angle::FormatID::ASTC_8x5_UNORM_BLOCK:
return angle::FormatID::ASTC_8x5_SRGB_BLOCK;
case angle::FormatID::ASTC_8x6_UNORM_BLOCK:
return angle::FormatID::ASTC_8x6_SRGB_BLOCK;
case angle::FormatID::ASTC_8x8_UNORM_BLOCK:
return angle::FormatID::ASTC_8x8_SRGB_BLOCK;
case angle::FormatID::ASTC_10x5_UNORM_BLOCK:
return angle::FormatID::ASTC_10x5_SRGB_BLOCK;
case angle::FormatID::ASTC_10x6_UNORM_BLOCK:
return angle::FormatID::ASTC_10x6_SRGB_BLOCK;
case angle::FormatID::ASTC_10x8_UNORM_BLOCK:
return angle::FormatID::ASTC_10x8_SRGB_BLOCK;
case angle::FormatID::ASTC_10x10_UNORM_BLOCK:
return angle::FormatID::ASTC_10x10_SRGB_BLOCK;
case angle::FormatID::ASTC_12x10_UNORM_BLOCK:
return angle::FormatID::ASTC_12x10_SRGB_BLOCK;
case angle::FormatID::ASTC_12x12_UNORM_BLOCK:
return angle::FormatID::ASTC_12x12_SRGB_BLOCK;
default:
return angle::FormatID::NONE;
}
}
angle::FormatID ConvertToLinear(angle::FormatID formatID)
{
switch (formatID)
{
case angle::FormatID::R8_UNORM_SRGB:
return angle::FormatID::R8_UNORM;
case angle::FormatID::R8G8_UNORM_SRGB:
return angle::FormatID::R8G8_UNORM;
case angle::FormatID::R8G8B8_UNORM_SRGB:
return angle::FormatID::R8G8B8_UNORM;
case angle::FormatID::R8G8B8A8_UNORM_SRGB:
return angle::FormatID::R8G8B8A8_UNORM;
case angle::FormatID::B8G8R8A8_UNORM_SRGB:
return angle::FormatID::B8G8R8A8_UNORM;
case angle::FormatID::BC1_RGB_UNORM_SRGB_BLOCK:
return angle::FormatID::BC1_RGB_UNORM_BLOCK;
case angle::FormatID::BC1_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC1_RGBA_UNORM_BLOCK;
case angle::FormatID::BC2_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC2_RGBA_UNORM_BLOCK;
case angle::FormatID::BC3_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC3_RGBA_UNORM_BLOCK;
case angle::FormatID::BC7_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC7_RGBA_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8_SRGB_BLOCK:
return angle::FormatID::ETC2_R8G8B8_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8A1_SRGB_BLOCK:
return angle::FormatID::ETC2_R8G8B8A1_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8A8_SRGB_BLOCK:
return angle::FormatID::ETC2_R8G8B8A8_UNORM_BLOCK;
case angle::FormatID::ASTC_4x4_SRGB_BLOCK:
return angle::FormatID::ASTC_4x4_UNORM_BLOCK;
case angle::FormatID::ASTC_5x4_SRGB_BLOCK:
return angle::FormatID::ASTC_5x4_UNORM_BLOCK;
case angle::FormatID::ASTC_5x5_SRGB_BLOCK:
return angle::FormatID::ASTC_5x5_UNORM_BLOCK;
case angle::FormatID::ASTC_6x5_SRGB_BLOCK:
return angle::FormatID::ASTC_6x5_UNORM_BLOCK;
case angle::FormatID::ASTC_6x6_SRGB_BLOCK:
return angle::FormatID::ASTC_6x6_UNORM_BLOCK;
case angle::FormatID::ASTC_8x5_SRGB_BLOCK:
return angle::FormatID::ASTC_8x5_UNORM_BLOCK;
case angle::FormatID::ASTC_8x6_SRGB_BLOCK:
return angle::FormatID::ASTC_8x6_UNORM_BLOCK;
case angle::FormatID::ASTC_8x8_SRGB_BLOCK:
return angle::FormatID::ASTC_8x8_UNORM_BLOCK;
case angle::FormatID::ASTC_10x5_SRGB_BLOCK:
return angle::FormatID::ASTC_10x5_UNORM_BLOCK;
case angle::FormatID::ASTC_10x6_SRGB_BLOCK:
return angle::FormatID::ASTC_10x6_UNORM_BLOCK;
case angle::FormatID::ASTC_10x8_SRGB_BLOCK:
return angle::FormatID::ASTC_10x8_UNORM_BLOCK;
case angle::FormatID::ASTC_10x10_SRGB_BLOCK:
return angle::FormatID::ASTC_10x10_UNORM_BLOCK;
case angle::FormatID::ASTC_12x10_SRGB_BLOCK:
return angle::FormatID::ASTC_12x10_UNORM_BLOCK;
case angle::FormatID::ASTC_12x12_SRGB_BLOCK:
return angle::FormatID::ASTC_12x12_UNORM_BLOCK;
default:
return angle::FormatID::NONE;
}
}
bool IsOverridableLinearFormat(angle::FormatID formatID)
{
return ConvertToSRGB(formatID) != angle::FormatID::NONE;
}
} // namespace rx