Hash :
54d4bfe5
Author :
Date :
2021-09-28T17:27:57
Update ANGLE Metal to Webkit at Sept 29 2021
This commit merges changes from Webkit into ANGLE upstream.
The following commits were used:
Current:
https://git.webkit.org/?p=WebKit.git;a=commit;h=e01d0bda8f4b7dc2fd834b92802d15d8c15735f
Previous:
https://git.webkit.org/?p=WebKit.git;a=commit;h=492f078198748e8ff248eea0bb979cf79e5f5adfj
The following commits were merged in from the Webkit Repository:
(Hashes from git://git.webkit.org/WebKit-https.git)
03ea44c78ce5665d4ec9add271260121cbc7bc6c
Problems with drawElements in some conditions
https://bugs.webkit.org/show_bug.cgi?id=230107
c8dc8e0c4d1109d39a62eb197b45e95132380290
ANGLE Metal: single-component swizzles do not compile
https://bugs.webkit.org/show_bug.cgi?id=230472
7285dbaaf5af15877d6c332b30ef7a4d67225460
webgl-compressed-texture-s3tc-srgb.html fails on Intel+AMD Metal
https://bugs.webkit.org/show_bug.cgi?id=229941
4c72f92967ecd2a095666fef431384c4f5f60fb4
fragcolor-fragdata-invariant.html fails
https://bugs.webkit.org/show_bug.cgi?id=223317
cd943145467f54e5928793c0dd3dfa2313c007dd
ANGLE Metal index buffer restart range cache could be maintained..
https://bugs.webkit.org/show_bug.cgi?id=227451
f075ff77e592eabd54dd659a8e13617cc5faedc8
ANGLE Metal infinities and NaNs generated with incorrect syntax
https://bugs.webkit.org/show_bug.cgi?id=229439
5862073269122f4b2d43d96d3922757557755e86
[Metal ANGLE] Fix over-autorelease of
rx::DisplayMtl::getMetalDeviceMatchingAttribute()...
<https://webkit.org/b/229128>
85f797ad31db048cb82cbafd428ef77f0b839312 ANGLE Cocoa compiles....
https://bugs.webkit.org/show_bug.cgi?id=228987
a67918ba279ad4842b6ae84a79c3f1c0cdc35ace Avoid infinite recursion...
https://bugs.webkit.org/show_bug.cgi?id=228978
d341f67de0033adcf1ec6373ace6a54b06c4a031
Cherry-pick ANGLE: Revise WebGL's shaderSource validation
https://bugs.webkit.org/show_bug.cgi?id=228951
1e2714d981e97de8234ba055570dfdf56e8b6944
3.5 MB system-wide footprint impact due to thread-locals...
https://bugs.webkit.org/show_bug.cgi?id=228240
d32e5cca34081997d32504b0b56c18b9703ff3be
Build Default Metal library offline
https://bugs.webkit.org/show_bug.cgi?id=227333
33702279faccfd4c8d1c8a6d549925f9ca9a4e8f
WebGL2 demo doesn't work due to failing compilation....
https://bugs.webkit.org/show_bug.cgi?id=226865
0a075885d242db38c4e435a6597173dc3b082173
rAF driven WebGL submits excessive amount of GPU work...
https://bugs.webkit.org/show_bug.cgi?id=227059
f38a92b3e7c17efda269caa7066e7ffe2f828e72
WebGL shader link error in iOS 15 beta: "Internal error..."
https://bugs.webkit.org/show_bug.cgi?id=227723
98d48f011d561531470d97f26a022767b5452fb7
REGRESSION (r279466): [Big Sur] webgl/1.0.3/conformance &...
https://bugs.webkit.org/show_bug.cgi?id=227596
Bug: angleproject:6471
Change-Id: I07166d0dc4b5c3579d98353485b3245b81c7b882
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3194322
Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
Commit-Queue: Kyle Piddington <kpiddington@apple.com>
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
//
// Copyright 2020 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.
//
#include <unordered_map>
#include "common/system_utils.h"
#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h"
#include "compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.h"
#include "compiler/translator/tree_ops/SimplifyLoopConditions.h"
#include "compiler/translator/tree_util/IntermRebuild.h"
using namespace sh;
////////////////////////////////////////////////////////////////////////////////
namespace
{
bool IsIndex(TOperator op)
{
switch (op)
{
case TOperator::EOpIndexDirect:
case TOperator::EOpIndexDirectInterfaceBlock:
case TOperator::EOpIndexDirectStruct:
case TOperator::EOpIndexIndirect:
return true;
default:
return false;
}
}
bool IsIndex(TIntermTyped &expr)
{
if (auto *binary = expr.getAsBinaryNode())
{
return IsIndex(binary->getOp());
}
return expr.getAsSwizzleNode();
}
bool ViewBinaryChain(TOperator op, TIntermTyped &node, std::vector<TIntermTyped *> &out)
{
TIntermBinary *binary = node.getAsBinaryNode();
if (!binary || binary->getOp() != op)
{
return false;
}
TIntermTyped *left = binary->getLeft();
TIntermTyped *right = binary->getRight();
if (!ViewBinaryChain(op, *left, out))
{
out.push_back(left);
}
if (!ViewBinaryChain(op, *right, out))
{
out.push_back(right);
}
return true;
}
std::vector<TIntermTyped *> ViewBinaryChain(TIntermBinary &node)
{
std::vector<TIntermTyped *> chain;
ViewBinaryChain(node.getOp(), node, chain);
ASSERT(chain.size() >= 2);
return chain;
}
class PrePass : public TIntermRebuild
{
public:
PrePass(TCompiler &compiler) : TIntermRebuild(compiler, true, true) {}
private:
// Change chains of
// x OP y OP z
// to
// x OP (y OP z)
// regardless of original parenthesization.
TIntermTyped &reassociateRight(TIntermBinary &node)
{
const TOperator op = node.getOp();
std::vector<TIntermTyped *> chain = ViewBinaryChain(node);
TIntermTyped *result = chain.back();
chain.pop_back();
ASSERT(result);
const auto begin = chain.rbegin();
const auto end = chain.rend();
for (auto iter = begin; iter != end; ++iter)
{
TIntermTyped *part = *iter;
ASSERT(part);
TIntermNode *temp = rebuild(*part).single();
ASSERT(temp);
part = temp->getAsTyped();
ASSERT(part);
result = new TIntermBinary(op, part, result);
}
return *result;
}
private:
PreResult visitBinaryPre(TIntermBinary &node) override
{
const TOperator op = node.getOp();
if (op == TOperator::EOpLogicalAnd || op == TOperator::EOpLogicalOr)
{
return {reassociateRight(node), VisitBits::Neither};
}
return node;
}
};
class Separator : public TIntermRebuild
{
IdGen &mIdGen;
std::vector<std::vector<TIntermNode *>> mStmtsStack;
std::vector<std::unordered_map<const TVariable *, TIntermDeclaration *>> mBindingMapStack;
std::unordered_map<TIntermTyped *, TIntermTyped *> mExprMap;
std::unordered_set<TIntermDeclaration *> mMaskedDecls;
public:
Separator(TCompiler &compiler, SymbolEnv &symbolEnv, IdGen &idGen)
: TIntermRebuild(compiler, true, true), mIdGen(idGen)
{}
~Separator() override
{
ASSERT(mStmtsStack.empty());
ASSERT(mExprMap.empty());
ASSERT(mBindingMapStack.empty());
}
private:
std::vector<TIntermNode *> &getCurrStmts()
{
ASSERT(!mStmtsStack.empty());
return mStmtsStack.back();
}
std::unordered_map<const TVariable *, TIntermDeclaration *> &getCurrBindingMap()
{
ASSERT(!mBindingMapStack.empty());
return mBindingMapStack.back();
}
void pushStmt(TIntermNode &node) { getCurrStmts().push_back(&node); }
bool isTerminalExpr(TIntermNode &node)
{
NodeType nodeType = getNodeType(node);
switch (nodeType)
{
case NodeType::Symbol:
case NodeType::ConstantUnion:
return true;
default:
return false;
}
}
TIntermTyped *pullMappedExpr(TIntermTyped *node, bool allowBacktrack)
{
TIntermTyped *expr;
{
auto iter = mExprMap.find(node);
if (iter == mExprMap.end())
{
return node;
}
ASSERT(node);
expr = iter->second;
ASSERT(expr);
mExprMap.erase(iter);
}
if (allowBacktrack)
{
auto &bindingMap = getCurrBindingMap();
while (TIntermSymbol *symbol = expr->getAsSymbolNode())
{
const TVariable &var = symbol->variable();
auto iter = bindingMap.find(&var);
if (iter == bindingMap.end())
{
return expr;
}
ASSERT(var.symbolType() == SymbolType::AngleInternal);
TIntermDeclaration *decl = iter->second;
ASSERT(decl);
expr = ViewDeclaration(*decl).initExpr;
ASSERT(expr);
bindingMap.erase(iter);
mMaskedDecls.insert(decl);
}
}
return expr;
}
bool isStandaloneExpr(TIntermTyped &expr)
{
if (getParentNode()->getAsBlock())
{
return true;
}
// https://bugs.webkit.org/show_bug.cgi?id=227723: Fix for sequence operator.
if ((expr.getType().getBasicType() == TBasicType::EbtVoid))
{
return true;
}
return false;
}
void pushBinding(TIntermTyped &oldExpr, TIntermTyped &newExpr)
{
if (isStandaloneExpr(newExpr))
{
pushStmt(newExpr);
return;
}
if (IsIndex(newExpr))
{
mExprMap[&oldExpr] = &newExpr;
return;
}
auto &bindingMap = getCurrBindingMap();
const Name name = mIdGen.createNewName();
auto *var =
new TVariable(&mSymbolTable, name.rawName(), &newExpr.getType(), name.symbolType());
auto *decl = new TIntermDeclaration(var, &newExpr);
pushStmt(*decl);
mExprMap[&oldExpr] = new TIntermSymbol(var);
bindingMap[var] = decl;
}
void pushStacks()
{
mStmtsStack.emplace_back();
mBindingMapStack.emplace_back();
}
void popStacks()
{
ASSERT(!mBindingMapStack.empty());
ASSERT(!mStmtsStack.empty());
ASSERT(mStmtsStack.back().empty());
mBindingMapStack.pop_back();
mStmtsStack.pop_back();
}
void pushStmtsIntoBlock(TIntermBlock &block, std::vector<TIntermNode *> &stmts)
{
TIntermSequence &seq = *block.getSequence();
for (TIntermNode *stmt : stmts)
{
if (TIntermDeclaration *decl = stmt->getAsDeclarationNode())
{
auto iter = mMaskedDecls.find(decl);
if (iter != mMaskedDecls.end())
{
mMaskedDecls.erase(iter);
continue;
}
}
seq.push_back(stmt);
}
}
TIntermBlock &buildBlockWithTailAssign(const TVariable &var, TIntermTyped &newExpr)
{
std::vector<TIntermNode *> stmts = std::move(getCurrStmts());
popStacks();
auto &block = *new TIntermBlock();
auto &seq = *block.getSequence();
seq.reserve(1 + stmts.size());
pushStmtsIntoBlock(block, stmts);
seq.push_back(new TIntermBinary(TOperator::EOpAssign, new TIntermSymbol(&var), &newExpr));
return block;
}
private:
PreResult visitBlockPre(TIntermBlock &node) override
{
pushStacks();
return node;
}
PostResult visitBlockPost(TIntermBlock &node) override
{
std::vector<TIntermNode *> stmts = std::move(getCurrStmts());
popStacks();
TIntermSequence &seq = *node.getSequence();
seq.clear();
seq.reserve(stmts.size());
pushStmtsIntoBlock(node, stmts);
TIntermNode *parent = getParentNode();
if (parent && parent->getAsBlock())
{
pushStmt(node);
}
return node;
}
PreResult visitDeclarationPre(TIntermDeclaration &node) override
{
Declaration decl = ViewDeclaration(node);
if (!decl.initExpr || isTerminalExpr(*decl.initExpr))
{
pushStmt(node);
return {node, VisitBits::Neither};
}
return node;
}
PostResult visitDeclarationPost(TIntermDeclaration &node) override
{
Declaration decl = ViewDeclaration(node);
ASSERT(decl.symbol.variable().symbolType() != SymbolType::Empty);
ASSERT(!decl.symbol.variable().getType().isStructSpecifier());
TIntermTyped *newInitExpr = pullMappedExpr(decl.initExpr, true);
if (decl.initExpr == newInitExpr)
{
pushStmt(node);
}
else
{
auto &newNode = *new TIntermDeclaration();
newNode.appendDeclarator(
new TIntermBinary(TOperator::EOpInitialize, &decl.symbol, newInitExpr));
pushStmt(newNode);
}
return node;
}
PostResult visitUnaryPost(TIntermUnary &node) override
{
TIntermTyped *expr = node.getOperand();
TIntermTyped *newExpr = pullMappedExpr(expr, false);
if (expr == newExpr)
{
pushBinding(node, node);
}
else
{
pushBinding(node, *new TIntermUnary(node.getOp(), newExpr, node.getFunction()));
}
return node;
}
PreResult visitBinaryPre(TIntermBinary &node) override
{
const TOperator op = node.getOp();
if (op == TOperator::EOpLogicalAnd || op == TOperator::EOpLogicalOr)
{
TIntermTyped *left = node.getLeft();
TIntermTyped *right = node.getRight();
PostResult leftResult = rebuild(*left);
ASSERT(leftResult.single());
pushStacks();
PostResult rightResult = rebuild(*right);
ASSERT(rightResult.single());
return {node, VisitBits::Post};
}
return node;
}
PostResult visitBinaryPost(TIntermBinary &node) override
{
const TOperator op = node.getOp();
if (op == TOperator::EOpInitialize && getParentNode()->getAsDeclarationNode())
{
// Special case is handled by visitDeclarationPost
return node;
}
TIntermTyped *left = node.getLeft();
TIntermTyped *right = node.getRight();
if (op == TOperator::EOpLogicalAnd || op == TOperator::EOpLogicalOr)
{
const Name name = mIdGen.createNewName();
auto *var = new TVariable(&mSymbolTable, name.rawName(), new TType(TBasicType::EbtBool),
name.symbolType());
TIntermTyped *newRight = pullMappedExpr(right, true);
TIntermBlock *rightBlock = &buildBlockWithTailAssign(*var, *newRight);
TIntermTyped *newLeft = pullMappedExpr(left, true);
TIntermTyped *cond = new TIntermSymbol(var);
if (op == TOperator::EOpLogicalOr)
{
cond = new TIntermUnary(TOperator::EOpLogicalNot, cond, nullptr);
}
pushStmt(*new TIntermDeclaration(var, newLeft));
pushStmt(*new TIntermIfElse(cond, rightBlock, nullptr));
if (!isStandaloneExpr(node))
{
mExprMap[&node] = new TIntermSymbol(var);
}
return node;
}
const bool isAssign = IsAssignment(op);
TIntermTyped *newLeft = pullMappedExpr(left, false);
TIntermTyped *newRight = pullMappedExpr(right, isAssign);
if (op == TOperator::EOpComma)
{
pushBinding(node, *newRight);
return node;
}
else
{
TIntermBinary *newNode;
if (left == newLeft && right == newRight)
{
newNode = &node;
}
else
{
newNode = new TIntermBinary(op, newLeft, newRight);
}
pushBinding(node, *newNode);
return node;
}
}
PreResult visitTernaryPre(TIntermTernary &node) override
{
PostResult condResult = rebuild(*node.getCondition());
ASSERT(condResult.single());
pushStacks();
PostResult thenResult = rebuild(*node.getTrueExpression());
ASSERT(thenResult.single());
pushStacks();
PostResult elseResult = rebuild(*node.getFalseExpression());
ASSERT(elseResult.single());
return {node, VisitBits::Post};
}
PostResult visitTernaryPost(TIntermTernary &node) override
{
TIntermTyped *cond = node.getCondition();
TIntermTyped *then = node.getTrueExpression();
TIntermTyped *else_ = node.getFalseExpression();
const Name name = mIdGen.createNewName();
auto *var =
new TVariable(&mSymbolTable, name.rawName(), &node.getType(), name.symbolType());
TIntermTyped *newElse = pullMappedExpr(else_, false);
TIntermBlock *elseBlock = &buildBlockWithTailAssign(*var, *newElse);
TIntermTyped *newThen = pullMappedExpr(then, true);
TIntermBlock *thenBlock = &buildBlockWithTailAssign(*var, *newThen);
TIntermTyped *newCond = pullMappedExpr(cond, true);
pushStmt(*new TIntermDeclaration{var});
pushStmt(*new TIntermIfElse(newCond, thenBlock, elseBlock));
if (!isStandaloneExpr(node))
{
mExprMap[&node] = new TIntermSymbol(var);
}
return node;
}
PostResult visitSwizzlePost(TIntermSwizzle &node) override
{
TIntermTyped *expr = node.getOperand();
TIntermTyped *newExpr = pullMappedExpr(expr, false);
if (expr == newExpr)
{
pushBinding(node, node);
}
else
{
pushBinding(node, *new TIntermSwizzle(newExpr, node.getSwizzleOffsets()));
}
return node;
}
PostResult visitAggregatePost(TIntermAggregate &node) override
{
TIntermSequence &args = *node.getSequence();
for (TIntermNode *&arg : args)
{
TIntermTyped *targ = arg->getAsTyped();
ASSERT(targ);
arg = pullMappedExpr(targ, false);
}
pushBinding(node, node);
return node;
}
PostResult visitPreprocessorDirectivePost(TIntermPreprocessorDirective &node) override
{
pushStmt(node);
return node;
}
PostResult visitFunctionPrototypePost(TIntermFunctionPrototype &node) override
{
if (!getParentFunction())
{
pushStmt(node);
}
return node;
}
PreResult visitCasePre(TIntermCase &node) override
{
if (TIntermTyped *cond = node.getCondition())
{
ASSERT(isTerminalExpr(*cond));
}
pushStmt(node);
return {node, VisitBits::Neither};
}
PostResult visitSwitchPost(TIntermSwitch &node) override
{
TIntermTyped *init = node.getInit();
TIntermTyped *newInit = pullMappedExpr(init, false);
if (init == newInit)
{
pushStmt(node);
}
else
{
pushStmt(*new TIntermSwitch(newInit, node.getStatementList()));
}
return node;
}
PostResult visitFunctionDefinitionPost(TIntermFunctionDefinition &node) override
{
pushStmt(node);
return node;
}
PostResult visitIfElsePost(TIntermIfElse &node) override
{
TIntermTyped *cond = node.getCondition();
TIntermTyped *newCond = pullMappedExpr(cond, false);
if (cond == newCond)
{
pushStmt(node);
}
else
{
pushStmt(*new TIntermIfElse(newCond, node.getTrueBlock(), node.getFalseBlock()));
}
return node;
}
PostResult visitBranchPost(TIntermBranch &node) override
{
TIntermTyped *expr = node.getExpression();
TIntermTyped *newExpr = pullMappedExpr(expr, false);
if (expr == newExpr)
{
pushStmt(node);
}
else
{
pushStmt(*new TIntermBranch(node.getFlowOp(), newExpr));
}
return node;
}
PreResult visitLoopPre(TIntermLoop &node) override
{
if (!rebuildInPlace(*node.getBody()))
{
UNREACHABLE();
}
pushStmt(node);
return {node, VisitBits::Neither};
}
PostResult visitConstantUnionPost(TIntermConstantUnion &node) override
{
const TType &type = node.getType();
if (!type.isScalar())
{
pushBinding(node, node);
}
return node;
}
PostResult visitGlobalQualifierDeclarationPost(TIntermGlobalQualifierDeclaration &node) override
{
// With the removal of RewriteGlobalQualifierDecls, we may encounter globals while
// seperating compound expressions.
pushStmt(node);
return node;
}
};
} // anonymous namespace
////////////////////////////////////////////////////////////////////////////////
bool sh::SeparateCompoundExpressions(TCompiler &compiler,
SymbolEnv &symbolEnv,
IdGen &idGen,
TIntermBlock &root)
{
if (angle::GetBoolEnvironmentVar("GMT_DISABLE_SEPARATE_COMPOUND_EXPRESSIONS"))
{
return true;
}
if (!SimplifyLoopConditions(&compiler, &root, &compiler.getSymbolTable()))
{
return false;
}
if (!PrePass(compiler).rebuildRoot(root))
{
return false;
}
if (!Separator(compiler, symbolEnv, idGen).rebuildRoot(root))
{
return false;
}
return true;
}