Changeset 249787 in webkit


Ignore:
Timestamp:
Sep 11, 2019 4:34:42 PM (5 years ago)
Author:
sbarati@apple.com
Message:

[WHLSL] Ensure structs/arrays with pointers as fields are disallowed
https://bugs.webkit.org/show_bug.cgi?id=201525

Reviewed by Robin Morisset.

Source/WebCore:

This patch adds a pass which both ensures that references are always initialized with
concrete values and that we support logical mode validation by disallowing nested references.

Specifically, the pass:

  1. Disallows structs to have fields which are references. This prevents us from having to

figure out how to default initialize such a struct. We could relax this in the future if we
did an analysis on which structs contain reference fields, and ensure such struct variables
always have initializers. This would also require us to create constructors for structs which
initialize each field.

  1. We also do the same for arrays.
  2. References can only be one level deep. So no pointers to pointers. No references to

references, etc. This is to support logical mode validation rules.

Test: webgpu/whlsl/ensure-proper-pointer-usage.html

  • Modules/webgpu/WHLSL/WHLSLCheckReferenceTypes.cpp: Added.

(WebCore::WHLSL::checkReferenceTypes):

  • Modules/webgpu/WHLSL/WHLSLCheckReferenceTypes.h: Added.
  • Modules/webgpu/WHLSL/WHLSLChecker.cpp:

(WebCore::WHLSL::Checker::visit):

  • Modules/webgpu/WHLSL/WHLSLPrepare.cpp:

(WebCore::WHLSL::prepareShared):

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:

LayoutTests:

This patch fixes a bug in our test harness where we forgot to wait for the gpu
device to load before running test harness tests. This patch fixes this oversight
and asserts that we have always finished loading before running a test.

  • webgpu/whlsl/array-spec-tests.html:
  • webgpu/whlsl/ensure-proper-pointer-usage-expected.txt: Added.
  • webgpu/whlsl/ensure-proper-pointer-usage.html: Added.
  • webgpu/whlsl/js/test-harness.js:

(Harness):
(Harness.prototype.async.requestDevice):
(Harness.prototype.async.callTypedFunction):
(Harness.prototype.async.checkCompileFail):

  • webgpu/whlsl/pointer-spec-tests.html:
  • webgpu/whlsl/test-harness-test.html:
Location:
trunk
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249786 r249787  
     12019-09-11  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Ensure structs/arrays with pointers as fields are disallowed
     4        https://bugs.webkit.org/show_bug.cgi?id=201525
     5
     6        Reviewed by Robin Morisset.
     7
     8        This patch fixes a bug in our test harness where we forgot to wait for the gpu
     9        device to load before running test harness tests. This patch fixes this oversight
     10        and asserts that we have always finished loading before running a test.
     11
     12        * webgpu/whlsl/array-spec-tests.html:
     13        * webgpu/whlsl/ensure-proper-pointer-usage-expected.txt: Added.
     14        * webgpu/whlsl/ensure-proper-pointer-usage.html: Added.
     15        * webgpu/whlsl/js/test-harness.js:
     16        (Harness):
     17        (Harness.prototype.async.requestDevice):
     18        (Harness.prototype.async.callTypedFunction):
     19        (Harness.prototype.async.checkCompileFail):
     20        * webgpu/whlsl/pointer-spec-tests.html:
     21        * webgpu/whlsl/test-harness-test.html:
     22
    1232019-09-11  Devin Rousso  <drousso@apple.com>
    224
  • trunk/LayoutTests/webgpu/whlsl/array-spec-tests.html

    r249765 r249787  
    3030        }
    3131    `;
    32     assert_equals(await callIntFunction(program, "foo", []), 76 + 39 + 83);
     32    await checkFail(program);
    3333}
    3434
  • trunk/LayoutTests/webgpu/whlsl/js/test-harness.js

    r249765 r249787  
    159159    constructor ()
    160160    {
     161        this._loaded = false;
    161162    }
    162163
     
    170171            // FIXME: Add support for GPUAdapterRequestOptions and GPUDeviceDescriptor,
    171172            // and differentiate between descriptor validation errors and no WebGPU support.
     173        } finally {
     174            this._loaded = true;
    172175        }
    173176    }
     
    183186    async callTypedFunction(type, functions, name, args)
    184187    {   
     188        if (!this._loaded)
     189            throw new Error("GPU device not loaded.");
     190
    185191        if (this._device === undefined)
    186192            throw new WebGPUUnsupportedError();
     
    264270    async checkCompileFail(source)
    265271    {
     272        if (!this._loaded)
     273            throw new Error("GPU device not loaded.");
     274
    266275        if (this._device === undefined)
    267             return;
     276            throw new WebGPUUnsupportedError();
    268277       
    269278        let entryPointCode = `
     
    520529function runTests(obj) {
    521530    window.addEventListener("load", async () => {
     531        await harness.requestDevice();
    522532        try {
    523533            for (const name in obj) {
  • trunk/LayoutTests/webgpu/whlsl/pointer-spec-tests.html

    r249765 r249787  
    3030            return result;
    3131        }
    32     `;;
    33     assert_equals(await callIntFunction(program, "foo", []), 76 + 39 + 83);
     32    `;
     33    await checkFail(program);
    3434}
    3535
  • trunk/LayoutTests/webgpu/whlsl/test-harness-test.html

    r249765 r249787  
    187187};
    188188
    189 window.addEventListener("load", () => {
     189window.addEventListener("load", async () => {
    190190    try {
     191        await harness.requestDevice();
    191192        for (const name in whlslTests) {
    192193            if (!name.startsWith("_"))
  • trunk/Source/WebCore/ChangeLog

    r249786 r249787  
     12019-09-11  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Ensure structs/arrays with pointers as fields are disallowed
     4        https://bugs.webkit.org/show_bug.cgi?id=201525
     5
     6        Reviewed by Robin Morisset.
     7
     8        This patch adds a pass which both ensures that references are always initialized with
     9        concrete values and that we support logical mode validation by disallowing nested references.
     10       
     11        Specifically, the pass:
     12       
     13        1. Disallows structs to have fields which are references. This prevents us from having to
     14        figure out how to default initialize such a struct. We could relax this in the future if we
     15        did an analysis on which structs contain reference fields, and ensure such struct variables
     16        always have initializers. This would also require us to create constructors for structs which
     17        initialize each field.
     18        2. We also do the same for arrays.
     19        3. References can only be one level deep. So no pointers to pointers. No references to
     20        references, etc. This is to support logical mode validation rules.
     21
     22        Test: webgpu/whlsl/ensure-proper-pointer-usage.html
     23
     24        * Modules/webgpu/WHLSL/WHLSLCheckReferenceTypes.cpp: Added.
     25        (WebCore::WHLSL::checkReferenceTypes):
     26        * Modules/webgpu/WHLSL/WHLSLCheckReferenceTypes.h: Added.
     27        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
     28        (WebCore::WHLSL::Checker::visit):
     29        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
     30        (WebCore::WHLSL::prepareShared):
     31        * Sources.txt:
     32        * WebCore.xcodeproj/project.pbxproj:
     33
    1342019-09-11  Devin Rousso  <drousso@apple.com>
    235
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp

    r249765 r249787  
    937937        if (is<AST::PointerType>(unnamedType)) {
    938938            auto& pointerType = downcast<AST::PointerType>(unnamedType);
    939             // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198163 Save the fact that we're not targetting the item; we're targetting the item's inner element.
    940939            assignConcreteType(makeArrayReferenceExpression, AST::ArrayReferenceType::create(makeArrayReferenceExpression.codeLocation(), pointerType.addressSpace(), pointerType.elementType()));
    941940            return;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp

    r249765 r249787  
    3131#include "WHLSLASTDumper.h"
    3232#include "WHLSLCheckDuplicateFunctions.h"
     33#include "WHLSLCheckReferenceTypes.h"
    3334#include "WHLSLCheckTextureReferences.h"
    3435#include "WHLSLChecker.h"
     
    232233    RUN_PASS(checkLiteralTypes, program);
    233234    CHECK_PASS(checkTextureReferences, program);
     235    CHECK_PASS(checkReferenceTypes, program);
    234236    RUN_PASS(resolveProperties, program);
    235237    RUN_PASS(findHighZombies, program);
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp

    r249351 r249787  
    3131#include "WHLSLAST.h"
    3232#include "WHLSLProgram.h"
     33#include "WHLSLVisitor.h"
    3334
    3435namespace WebCore {
  • trunk/Source/WebCore/Sources.txt

    r249765 r249787  
    314314Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp
    315315Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp
     316Modules/webgpu/WHLSL/WHLSLCheckReferenceTypes.cpp
    316317Modules/webgpu/WHLSL/WHLSLChecker.cpp
    317318Modules/webgpu/WHLSL/WHLSLGatherEntryPointItems.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r249765 r249787  
    83328332                522E1A172297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLPreserveVariableLifetimes.cpp; sourceTree = "<group>"; };
    83338333                522E1A192297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLPreserveVariableLifetimes.h; sourceTree = "<group>"; };
     8334                524BD47E23277E15008F56C1 /* WHLSLCheckReferenceTypes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLCheckReferenceTypes.cpp; sourceTree = "<group>"; };
     8335                524BD48023277E16008F56C1 /* WHLSLCheckReferenceTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLCheckReferenceTypes.h; sourceTree = "<group>"; };
    83348336                526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextTrackRepresentationCocoa.mm; sourceTree = "<group>"; };
    83358337                526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentationCocoa.h; sourceTree = "<group>"; };
     
    2558025582                                1C281C6D22B87B9800691C00 /* WHLSLCheckTextureReferences.cpp */,
    2558125583                                1C281C6E22B87B9800691C00 /* WHLSLCheckTextureReferences.h */,
     25584                                524BD47E23277E15008F56C1 /* WHLSLCheckReferenceTypes.cpp */,
     25585                                524BD48023277E16008F56C1 /* WHLSLCheckReferenceTypes.h */,
    2558225586                                522BAB9622E6A36200C54CE9 /* WHLSLCodeLocation.h */,
    2558325587                                1C86CA4B22AA19FF001BF961 /* WHLSLComputeDimensions.cpp */,
Note: See TracChangeset for help on using the changeset viewer.