Changeset 246649 in webkit


Ignore:
Timestamp:
Jun 20, 2019 1:10:06 PM (5 years ago)
Author:
sbarati@apple.com
Message:

[WHLSL] Property resolver needs to recurse on newValueExpression for RMW operations
https://bugs.webkit.org/show_bug.cgi?id=199037

Reviewed by Myles C. Maxfield.

Source/WebCore:

When we had an expression like <e1> += <e2>, we weren't running the property
resolver on <e2>. If <e2> was something like mat[1][2], we wouldn't end up
simplifying that into the needed getter calls. This patch fixes this by having
the property resolver recurse on <e2>.

This patch also fixes a bug in the property resolver where we weren't marking some
dereference expressions as LValues. This was causing bugs in the metal code generator.

This patch also adds a way to dump the AST between passes that are
guaranteed to not fail.

Test: webgpu/whlsl-read-modify-write-high-zombies.html

  • Modules/webgpu/WHLSL/WHLSLPrepare.cpp:

(WebCore::WHLSL::prepareShared):

  • Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:

(WebCore::WHLSL::PropertyResolver::visit):

  • Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:

LayoutTests:

  • webgpu/whlsl-read-modify-write-high-zombies-expected.txt: Added.
  • webgpu/whlsl-read-modify-write-high-zombies.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246646 r246649  
     12019-06-20  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Property resolver needs to recurse on newValueExpression for RMW operations
     4        https://bugs.webkit.org/show_bug.cgi?id=199037
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        * webgpu/whlsl-read-modify-write-high-zombies-expected.txt: Added.
     9        * webgpu/whlsl-read-modify-write-high-zombies.html: Added.
     10
    1112019-06-20  Justin Fan  <justin_fan@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r246647 r246649  
     12019-06-20  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Property resolver needs to recurse on newValueExpression for RMW operations
     4        https://bugs.webkit.org/show_bug.cgi?id=199037
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        When we had an expression like `<e1> += <e2>`, we weren't running the property
     9        resolver on <e2>. If <e2> was something like `mat[1][2]`, we wouldn't end up
     10        simplifying that into the needed getter calls. This patch fixes this by having
     11        the property resolver recurse on <e2>.
     12       
     13        This patch also fixes a bug in the property resolver where we weren't marking some
     14        dereference expressions as LValues. This was causing bugs in the metal code generator.
     15       
     16        This patch also adds a way to dump the AST between passes that are
     17        guaranteed to not fail.
     18
     19        Test: webgpu/whlsl-read-modify-write-high-zombies.html
     20
     21        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
     22        (WebCore::WHLSL::prepareShared):
     23        * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
     24        (WebCore::WHLSL::PropertyResolver::visit):
     25        * Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:
     26
    1272019-06-20  John Wilander  <wilander@apple.com>
    228
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp

    r246631 r246649  
    9191}
    9292
    93 #define RUN_PASS(pass, ...) \
     93#define CHECK_PASS(pass, ...) \
    9494    do { \
    9595        dumpASTBetweenEachPassIfNeeded(program, "AST before " # pass); \
     
    100100        } \
    101101    } while (0)
    102    
     102
     103#define RUN_PASS(pass, ...) \
     104    do { \
     105        dumpASTBetweenEachPassIfNeeded(program, "AST before " # pass); \
     106        pass(__VA_ARGS__); \
     107    } while (0)
    103108
    104109static Optional<Program> prepareShared(String& whlslSource)
     
    122127
    123128    NameResolver nameResolver(program.nameContext());
    124     RUN_PASS(resolveNamesInTypes, program, nameResolver);
    125     RUN_PASS(checkRecursiveTypes, program);
    126     RUN_PASS(synthesizeStructureAccessors, program);
    127     RUN_PASS(synthesizeEnumerationFunctions, program);
    128     RUN_PASS(synthesizeArrayOperatorLength, program);
    129     RUN_PASS(resolveTypeNamesInFunctions, program, nameResolver);
    130     RUN_PASS(synthesizeConstructors, program);
    131     RUN_PASS(resolveCallsInFunctions, program, nameResolver);
    132     RUN_PASS(checkDuplicateFunctions, program);
     129    CHECK_PASS(resolveNamesInTypes, program, nameResolver);
     130    CHECK_PASS(checkRecursiveTypes, program);
     131    CHECK_PASS(synthesizeStructureAccessors, program);
     132    CHECK_PASS(synthesizeEnumerationFunctions, program);
     133    CHECK_PASS(synthesizeArrayOperatorLength, program);
     134    CHECK_PASS(resolveTypeNamesInFunctions, program, nameResolver);
     135    CHECK_PASS(synthesizeConstructors, program);
     136    CHECK_PASS(resolveCallsInFunctions, program, nameResolver);
     137    CHECK_PASS(checkDuplicateFunctions, program);
    133138
    134     RUN_PASS(check, program);
     139    CHECK_PASS(check, program);
    135140
    136     checkLiteralTypes(program);
    137     RUN_PASS(checkTextureReferences, program);
    138     RUN_PASS(autoInitializeVariables, program);
    139     resolveProperties(program);
    140     findHighZombies(program);
    141     RUN_PASS(checkStatementBehavior, program);
    142     RUN_PASS(checkRecursion, program);
    143     RUN_PASS(checkFunctionStages, program);
    144     preserveVariableLifetimes(program);
     141    RUN_PASS(checkLiteralTypes, program);
     142    CHECK_PASS(checkTextureReferences, program);
     143    CHECK_PASS(autoInitializeVariables, program);
     144    RUN_PASS(resolveProperties, program);
     145    RUN_PASS(findHighZombies, program);
     146    CHECK_PASS(checkStatementBehavior, program);
     147    CHECK_PASS(checkRecursion, program);
     148    CHECK_PASS(checkFunctionStages, program);
     149    RUN_PASS(preserveVariableLifetimes, program);
    145150
    146151    dumpASTAtEndIfNeeded(program);
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp

    r246515 r246649  
    547547void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpression)
    548548{
     549    checkErrorAndVisit(readModifyWriteExpression.newValueExpression());
     550    if (error())
     551        return;
     552
    549553    if (readModifyWriteExpression.leftValue().typeAnnotation().leftAddressSpace()) {
    550554        // Consider a++;
     
    589593            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference1));
    590594            dereferenceExpression->setType(baseType->clone());
    591             dereferenceExpression->setTypeAnnotation(AST::RightValue());
     595            dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
    592596
    593597            auto variableReference2 = readModifyWriteExpression.oldVariableReference();
     
    622626            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference1));
    623627            dereferenceExpression->setType(baseType->clone());
    624             dereferenceExpression->setTypeAnnotation(AST::RightValue());
     628            dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
    625629
    626630            auto variableReference2 = readModifyWriteExpression.newVariableReference();
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt

    r246631 r246649  
    620620    float4 result;
    621621    result[0] = 0;
    622     result[0] = result[0] + x[0][0] * y[0];
    623     result[0] = result[0] + x[0][1] * y[1];
    624     result[0] = result[0] + x[0][2] * y[2];
    625     result[0] = result[0] + x[0][3] * y[3];
     622    result[0] += x[0][0] * y[0];
     623    result[0] += x[0][1] * y[1];
     624    result[0] += x[0][2] * y[2];
     625    result[0] += x[0][3] * y[3];
    626626    result[1] = 0;
    627     result[1] = result[1] + x[1][0] * y[0];
    628     result[1] = result[1] + x[1][1] * y[1];
    629     result[1] = result[1] + x[1][2] * y[2];
    630     result[1] = result[1] + x[1][3] * y[3];
     627    result[1] += x[1][0] * y[0];
     628    result[1] += x[1][1] * y[1];
     629    result[1] += x[1][2] * y[2];
     630    result[1] += x[1][3] * y[3];
    631631    result[2] = 0;
    632     result[2] = result[2] + x[2][0] * y[0];
    633     result[2] = result[2] + x[2][1] * y[1];
    634     result[2] = result[2] + x[2][2] * y[2];
    635     result[2] = result[2] + x[2][3] * y[3];
     632    result[2] += x[2][0] * y[0];
     633    result[2] += x[2][1] * y[1];
     634    result[2] += x[2][2] * y[2];
     635    result[2] += x[2][3] * y[3];
    636636    result[3] = 0;
    637     result[3] = result[3] + x[3][0] * y[0];
    638     result[3] = result[3] + x[3][1] * y[1];
    639     result[3] = result[3] + x[3][2] * y[2];
    640     result[3] = result[3] + x[3][3] * y[3];
     637    result[3] += x[3][0] * y[0];
     638    result[3] += x[3][1] * y[1];
     639    result[3] += x[3][2] * y[2];
     640    result[3] += x[3][3] * y[3];
    641641    return result;
    642642}
     
    645645    float4x4 result;
    646646    result[0][0] = 0;
    647     result[0][0] = result[0][0] + x[0][0] * y[0][0];
    648     result[0][0] = result[0][0] + x[0][1] * y[1][0];
    649     result[0][0] = result[0][0] + x[0][2] * y[2][0];
    650     result[0][0] = result[0][0] + x[0][3] * y[3][0];
     647    result[0][0] += x[0][0] * y[0][0];
     648    result[0][0] += x[0][1] * y[1][0];
     649    result[0][0] += x[0][2] * y[2][0];
     650    result[0][0] += x[0][3] * y[3][0];
    651651    result[0][1] = 0;
    652     result[0][1] = result[0][1] + x[0][0] * y[0][1];
    653     result[0][1] = result[0][1] + x[0][1] * y[1][1];
    654     result[0][1] = result[0][1] + x[0][2] * y[2][1];
    655     result[0][1] = result[0][1] + x[0][3] * y[3][1];
     652    result[0][1] += x[0][0] * y[0][1];
     653    result[0][1] += x[0][1] * y[1][1];
     654    result[0][1] += x[0][2] * y[2][1];
     655    result[0][1] += x[0][3] * y[3][1];
    656656    result[0][2] = 0;
    657     result[0][2] = result[0][2] + x[0][0] * y[0][2];
    658     result[0][2] = result[0][2] + x[0][1] * y[1][2];
    659     result[0][2] = result[0][2] + x[0][2] * y[2][2];
    660     result[0][2] = result[0][2] + x[0][3] * y[3][2];
     657    result[0][2] += x[0][0] * y[0][2];
     658    result[0][2] += x[0][1] * y[1][2];
     659    result[0][2] += x[0][2] * y[2][2];
     660    result[0][2] += x[0][3] * y[3][2];
    661661    result[0][3] = 0;
    662     result[0][3] = result[0][3] + x[0][0] * y[0][3];
    663     result[0][3] = result[0][3] + x[0][1] * y[1][3];
    664     result[0][3] = result[0][3] + x[0][2] * y[2][3];
    665     result[0][3] = result[0][3] + x[0][3] * y[3][3];
     662    result[0][3] += x[0][0] * y[0][3];
     663    result[0][3] += x[0][1] * y[1][3];
     664    result[0][3] += x[0][2] * y[2][3];
     665    result[0][3] += x[0][3] * y[3][3];
    666666    result[1][0] = 0;
    667     result[1][0] = result[1][0] + x[1][0] * y[0][0];
    668     result[1][0] = result[1][0] + x[1][1] * y[1][0];
    669     result[1][0] = result[1][0] + x[1][2] * y[2][0];
    670     result[1][0] = result[1][0] + x[1][3] * y[3][0];
     667    result[1][0] += x[1][0] * y[0][0];
     668    result[1][0] += x[1][1] * y[1][0];
     669    result[1][0] += x[1][2] * y[2][0];
     670    result[1][0] += x[1][3] * y[3][0];
    671671    result[1][1] = 0;
    672     result[1][1] = result[1][1] + x[1][0] * y[0][1];
    673     result[1][1] = result[1][1] + x[1][1] * y[1][1];
    674     result[1][1] = result[1][1] + x[1][2] * y[2][1];
    675     result[1][1] = result[1][1] + x[1][3] * y[3][1];
     672    result[1][1] += x[1][0] * y[0][1];
     673    result[1][1] += x[1][1] * y[1][1];
     674    result[1][1] += x[1][2] * y[2][1];
     675    result[1][1] += x[1][3] * y[3][1];
    676676    result[1][2] = 0;
    677     result[1][2] = result[1][2] + x[1][0] * y[0][2];
    678     result[1][2] = result[1][2] + x[1][1] * y[1][2];
    679     result[1][2] = result[1][2] + x[1][2] * y[2][2];
    680     result[1][2] = result[1][2] + x[1][3] * y[3][2];
     677    result[1][2] += x[1][0] * y[0][2];
     678    result[1][2] += x[1][1] * y[1][2];
     679    result[1][2] += x[1][2] * y[2][2];
     680    result[1][2] += x[1][3] * y[3][2];
    681681    result[1][3] = 0;
    682     result[1][3] = result[1][3] + x[1][0] * y[0][3];
    683     result[1][3] = result[1][3] + x[1][1] * y[1][3];
    684     result[1][3] = result[1][3] + x[1][2] * y[2][3];
    685     result[1][3] = result[1][3] + x[1][3] * y[3][3];
     682    result[1][3] += x[1][0] * y[0][3];
     683    result[1][3] += x[1][1] * y[1][3];
     684    result[1][3] += x[1][2] * y[2][3];
     685    result[1][3] += x[1][3] * y[3][3];
    686686    result[2][0] = 0;
    687     result[2][0] = result[2][0] + x[2][0] * y[0][0];
    688     result[2][0] = result[2][0] + x[2][1] * y[1][0];
    689     result[2][0] = result[2][0] + x[2][2] * y[2][0];
    690     result[2][0] = result[2][0] + x[2][3] * y[3][0];
     687    result[2][0] += x[2][0] * y[0][0];
     688    result[2][0] += x[2][1] * y[1][0];
     689    result[2][0] += x[2][2] * y[2][0];
     690    result[2][0] += x[2][3] * y[3][0];
    691691    result[2][1] = 0;
    692     result[2][1] = result[2][1] + x[2][0] * y[0][1];
    693     result[2][1] = result[2][1] + x[2][1] * y[1][1];
    694     result[2][1] = result[2][1] + x[2][2] * y[2][1];
    695     result[2][1] = result[2][1] + x[2][3] * y[3][1];
     692    result[2][1] += x[2][0] * y[0][1];
     693    result[2][1] += x[2][1] * y[1][1];
     694    result[2][1] += x[2][2] * y[2][1];
     695    result[2][1] += x[2][3] * y[3][1];
    696696    result[2][2] = 0;
    697     result[2][2] = result[2][2] + x[2][0] * y[0][2];
    698     result[2][2] = result[2][2] + x[2][1] * y[1][2];
    699     result[2][2] = result[2][2] + x[2][2] * y[2][2];
    700     result[2][2] = result[2][2] + x[2][3] * y[3][2];
     697    result[2][2] += x[2][0] * y[0][2];
     698    result[2][2] += x[2][1] * y[1][2];
     699    result[2][2] += x[2][2] * y[2][2];
     700    result[2][2] += x[2][3] * y[3][2];
    701701    result[2][3] = 0;
    702     result[2][3] = result[2][3] + x[2][0] * y[0][3];
    703     result[2][3] = result[2][3] + x[2][1] * y[1][3];
    704     result[2][3] = result[2][3] + x[2][2] * y[2][3];
    705     result[2][3] = result[2][3] + x[2][3] * y[3][3];
     702    result[2][3] += x[2][0] * y[0][3];
     703    result[2][3] += x[2][1] * y[1][3];
     704    result[2][3] += x[2][2] * y[2][3];
     705    result[2][3] += x[2][3] * y[3][3];
    706706    result[3][0] = 0;
    707     result[3][0] = result[3][0] + x[3][0] * y[0][0];
    708     result[3][0] = result[3][0] + x[3][1] * y[1][0];
    709     result[3][0] = result[3][0] + x[3][2] * y[2][0];
    710     result[3][0] = result[3][0] + x[3][3] * y[3][0];
     707    result[3][0] += x[3][0] * y[0][0];
     708    result[3][0] += x[3][1] * y[1][0];
     709    result[3][0] += x[3][2] * y[2][0];
     710    result[3][0] += x[3][3] * y[3][0];
    711711    result[3][1] = 0;
    712     result[3][1] = result[3][1] + x[3][0] * y[0][1];
    713     result[3][1] = result[3][1] + x[3][1] * y[1][1];
    714     result[3][1] = result[3][1] + x[3][2] * y[2][1];
    715     result[3][1] = result[3][1] + x[3][3] * y[3][1];
     712    result[3][1] += x[3][0] * y[0][1];
     713    result[3][1] += x[3][1] * y[1][1];
     714    result[3][1] += x[3][2] * y[2][1];
     715    result[3][1] += x[3][3] * y[3][1];
    716716    result[3][2] = 0;
    717     result[3][2] = result[3][2] + x[3][0] * y[0][2];
    718     result[3][2] = result[3][2] + x[3][1] * y[1][2];
    719     result[3][2] = result[3][2] + x[3][2] * y[2][2];
    720     result[3][2] = result[3][2] + x[3][3] * y[3][2];
     717    result[3][2] += x[3][0] * y[0][2];
     718    result[3][2] += x[3][1] * y[1][2];
     719    result[3][2] += x[3][2] * y[2][2];
     720    result[3][2] += x[3][3] * y[3][2];
    721721    result[3][3] = 0;
    722     result[3][3] = result[3][3] + x[3][0] * y[0][3];
    723     result[3][3] = result[3][3] + x[3][1] * y[1][3];
    724     result[3][3] = result[3][3] + x[3][2] * y[2][3];
    725     result[3][3] = result[3][3] + x[3][3] * y[3][3];
     722    result[3][3] += x[3][0] * y[0][3];
     723    result[3][3] += x[3][1] * y[1][3];
     724    result[3][3] += x[3][2] * y[2][3];
     725    result[3][3] += x[3][3] * y[3][3];
    726726    return result;
    727727}
Note: See TracChangeset for help on using the changeset viewer.