Changeset 247067 in webkit


Ignore:
Timestamp:
Jul 2, 2019 12:06:44 PM (5 years ago)
Author:
sbarati@apple.com
Message:

[WHLSL] Import bitwise bool tests
https://bugs.webkit.org/show_bug.cgi?id=199093

Reviewed by Myles C. Maxfield.

Source/WebCore:

Add standard library functions for:

  • bool bit ops
  • converting from bool to number
  • converting from number to bool

Test: webgpu/whlsl-bitwise-bool-ops.html

  • Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:

LayoutTests:

This patch makes it so that we can mark bools as input and output types in the
WHLSL harness. Since bool is not something WHLSL itself allows as an entrypoint
input/output type (because we don't specify its bit pattern), we convert between
bool and int in the input and output of the function. For now, we don't support
a buffer of bools for the input type as a simplification, so we don't have to worry
about dynamically converting an int buffer to a bool buffer. We could add this
in the future if we found it helpful, but we don't have a strong reason for supporting
it right now.

This patch also starts the process of importing the WHLSL test suite by importing bool
bit op tests.

  • webgpu/js/whlsl-test-harness.js:

(convertTypeToArrayType):
(whlslArgumentType):
(convertToWHLSLOutputType):
(convertToWHLSLInputType):
(Data):
(Harness.prototype.get isWHLSL):
(Harness.prototype.async.callTypedFunction):
(Harness.prototype._setUpArguments):
(callVoidFunction):

  • webgpu/whlsl-bitwise-bool-ops-expected.txt: Added.
  • webgpu/whlsl-bitwise-bool-ops.html: Added.
  • webgpu/whlsl-test-harness-test-expected.txt:
  • webgpu/whlsl-test-harness-test.html:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r247064 r247067  
     12019-07-02  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Import bitwise bool tests
     4        https://bugs.webkit.org/show_bug.cgi?id=199093
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        This patch makes it so that we can mark bools as input and output types in the
     9        WHLSL harness. Since bool is not something WHLSL itself allows as an entrypoint
     10        input/output type (because we don't specify its bit pattern), we convert between
     11        bool and int in the input and output of the function. For now,  we don't support
     12        a buffer of bools for the input type as a simplification, so we don't have to worry
     13        about dynamically converting an int buffer to a bool buffer. We could add this
     14        in the future if we found it helpful, but we don't have a strong reason for supporting
     15        it right now.
     16       
     17        This patch also starts the process of importing the WHLSL test suite by importing bool
     18        bit op tests.
     19
     20        * webgpu/js/whlsl-test-harness.js:
     21        (convertTypeToArrayType):
     22        (whlslArgumentType):
     23        (convertToWHLSLOutputType):
     24        (convertToWHLSLInputType):
     25        (Data):
     26        (Harness.prototype.get isWHLSL):
     27        (Harness.prototype.async.callTypedFunction):
     28        (Harness.prototype._setUpArguments):
     29        (callVoidFunction):
     30        * webgpu/whlsl-bitwise-bool-ops-expected.txt: Added.
     31        * webgpu/whlsl-bitwise-bool-ops.html: Added.
     32        * webgpu/whlsl-test-harness-test-expected.txt:
     33        * webgpu/whlsl-test-harness-test.html:
     34
    1352019-07-02  Takashi Komori  <Takashi.Komori@sony.com>
    236
  • trunk/LayoutTests/webgpu/js/whlsl-test-harness.js

    r246824 r247067  
    2323}
    2424
    25 function convertTypeToArrayType(type)
     25function convertTypeToArrayType(isWHLSL, type)
    2626{
    2727    switch(type) {
    2828        case Types.BOOL:
     29            if (isWHLSL)
     30                return Int32Array;
    2931            return Uint8Array;
    3032        case Types.INT:
     
    6264}
    6365
     66function whlslArgumentType(type)
     67{
     68    if (type === Types.BOOL)
     69        return "int";
     70    return convertTypeToWHLSLType(type);
     71}
     72
     73function convertToWHLSLOutputType(code, type)
     74{
     75    if (type !== Types.BOOL)
     76        return code;
     77    return `int(${code})`;
     78}
     79
     80function convertToWHLSLInputType(code, type)
     81{
     82    if (type !== Types.BOOL)
     83        return code;
     84    return `bool(${code})`;
     85}
     86
    6487/* Harness Classes */
    6588
     
    92115
    93116        this._type = type;
    94         this._byteLength = (convertTypeToArrayType(type)).BYTES_PER_ELEMENT * values.length;
     117        this._byteLength = (convertTypeToArrayType(harness.isWHLSL, type)).BYTES_PER_ELEMENT * values.length;
    95118
    96119        const [buffer, arrayBuffer] = harness.device.createBufferMapped({
     
    99122        });
    100123
    101         const typedArray = new (convertTypeToArrayType(type))(arrayBuffer);
     124        const typedArray = new (convertTypeToArrayType(harness.isWHLSL, type))(arrayBuffer);
    102125        typedArray.set(values);
    103126        buffer.unmap();
     
    156179using namespace metal;
    157180        `;
     181    }
     182
     183    get isWHLSL()
     184    {
     185        return this._isWHLSL;
    158186    }
    159187
     
    197225        let entryPointCode;
    198226        if (this._isWHLSL) {
    199             argsDeclarations.unshift(`device ${convertTypeToWHLSLType(type)}[] result : register(u0)`);
     227            argsDeclarations.unshift(`device ${whlslArgumentType(type)}[] result : register(u0)`);
     228            let callCode = `${name}(${functionCallArgs.join(", ")})`;
     229            callCode = convertToWHLSLOutputType(callCode, type);
    200230            entryPointCode = `
    201231[numthreads(1, 1, 1)]
    202232compute void _compute_main(${argsDeclarations.join(", ")})
    203233{
    204     result[0] = ${name}(${functionCallArgs.join(", ")});
     234    result[0] = ${callCode};
    205235}
    206236`;
     
    226256            throw new Error("Harness error: Unable to read results!");
    227257        }
    228         const array = new (convertTypeToArrayType(type))(result);
     258        const array = new (convertTypeToArrayType(this._isWHLSL, type))(result);
    229259        this._resultBuffer.unmap();
    230260
     
    302332            const arg = args[i - 1];
    303333            if (this._isWHLSL) {
    304                 argsDeclarations.push(`device ${convertTypeToWHLSLType(arg.type)}[] arg${i} : register(u${i})`);
    305                 functionCallArgs.push(`arg${i}` + (arg.isBuffer ? "" : "[0]"));
     334                argsDeclarations.push(`device ${whlslArgumentType(arg.type)}[] arg${i} : register(u${i})`);
     335                functionCallArgs.push(convertToWHLSLInputType(`arg${i}` + (arg.isBuffer ? "" : "[0]"), arg.type));
    306336            } else {
    307337                argsDeclarations.push(`device ${convertTypeToWHLSLType(arg.type)}* arg${i} [[id(${i})]];`);
  • trunk/LayoutTests/webgpu/whlsl-test-harness-test-expected.txt

    r246824 r247067  
    11
     2PASS Return a literal of type bool.
    23PASS Return an expected float4 value.
    34PASS Return an expected int value.
    45PASS Return an expected uint value.
    56PASS Return an expected float value.
     7PASS Upload and return a bool value.
    68PASS Return an expected float4 value.
    79PASS Return an expected int value.
    810PASS Return an expected uint value.
    911PASS Return an expected float value.
     12PASS Upload many bool values and return a calculated result.
    1013PASS Return an expected float4 value.
    1114PASS Return an expected int value.
  • trunk/LayoutTests/webgpu/whlsl-test-harness-test.html

    r246824 r247067  
    5959whlslTests.buffersWithOneValue = () => {
    6060    const body = `return in0[0];`
    61     checkBools("Access and return a single bool through a bool[].", body, [[true]]);
    6261    checkFloat4s(body, [[[0, 1, 2, 3]]]);
    6362    checkNumericScalars(body, [[42]], 42);
     
    6564
    6665whlslTests.multipleBufferArguments = () => {
    67     checkBools("Access multiple bools through various buffers and return a bool.",
    68         "return in0[0] & in0[1] & in0[2] & in1 & in2[0];",
    69         [[true, true, true], true, [true]]);
    70 
    7166    let body = `
    7267    float x = in0[0].x + in0[1].x + in0[2].x + in1.x + in2[0].x;
     
    169164
    170165const checkBools = (msg = "Return an expected bool value.", body, argValues = [], expected = true) => {
    171     // FIXME (https://webkit.org/b/199093): Bool[] functions don't compile, so no-op for now.
    172     return;
    173 
    174166    const [src, name, values] = appendScalarFunctionToSource("", "bool", body, argValues);
    175167
  • trunk/Source/WebCore/ChangeLog

    r247064 r247067  
     12019-07-02  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Import bitwise bool tests
     4        https://bugs.webkit.org/show_bug.cgi?id=199093
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Add standard library functions for:
     9        - bool bit ops
     10        - converting from bool to number
     11        - converting from number to bool
     12
     13        Test: webgpu/whlsl-bitwise-bool-ops.html
     14
     15        * Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:
     16
    1172019-07-02  Takashi Komori  <Takashi.Komori@sony.com>
    218
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt

    r246875 r247067  
    744744    return result;
    745745}
     746
     747native bool operator==(uchar, uchar);
     748native bool operator==(ushort, ushort);
     749native bool operator==(char, char);
     750native bool operator==(short, short);
     751native bool operator==(half, half);
    746752
    747753native int operator+(int, int);
     
    11731179native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, threadgroup uint* Height, threadgroup uint* NumberOfLevels);
    11741180
     1181
     1182native bool operator==(bool, bool);
     1183native bool operator&&(bool, bool);
     1184native bool operator||(bool, bool);
     1185bool operator&(bool a, bool b) {
     1186    return a && b;
     1187}
     1188bool operator|(bool a, bool b) {
     1189    return a || b;
     1190}
     1191bool operator^(bool a, bool b) {
     1192    if (a)
     1193        return !b;
     1194    return b;
     1195}
     1196bool operator~(bool value) {
     1197    return !value;
     1198}
     1199
     1200operator bool(uchar x) {
     1201    return x != 0;
     1202}
     1203operator bool(ushort x) {
     1204    return x != 0;
     1205}
     1206operator bool(uint x) {
     1207    return x != 0;
     1208}
     1209operator bool(char x) {
     1210    return x != 0;
     1211}
     1212operator bool(short x) {
     1213    return x != 0;
     1214}
     1215operator bool(int x) {
     1216    return x != 0;
     1217}
     1218operator bool(half x) {
     1219    return x != 0;
     1220}
     1221operator bool(float x) {
     1222    return x != 0;
     1223}
     1224
     1225operator int(bool x) {
     1226    return x ? 1 : 0;
     1227}
     1228
    11751229// FIXME: https://bugs.webkit.org/show_bug.cgi?id=192890 Insert the rest of the standard library once the parser is fast enough
Note: See TracChangeset for help on using the changeset viewer.