⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 246628 in webkit


Ignore:
Timestamp:
Jun 19, 2019, 8:18:37 PM (7 years ago)
Author:
Justin Fan
Message:

[WHLSL] Create a shading language test harness
https://bugs.webkit.org/show_bug.cgi?id=198978

Reviewed by Myles C. Maxfield.

Source/WebCore:

When creating MTLArgumentEncoders for argument buffers, the user's arguments
must match the order that they are declared in the shader. Move back-end information
such as buffer lengths to the end of the argument arrays.

Test: webgpu/whlsl-harness-test.html

  • Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp:

(WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes):

  • platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm:

(WebCore::GPUBindGroupLayout::tryCreate):

LayoutTests:

Introduce a test harness that can be used to test WebGPU shader compilation and functionality.
Currently using MSL.
Will be replaced with WHLSL as it gains the minimum features needed to support.

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

(isVectorType):
(convertTypeToArrayType):
(convertTypeToWHLSLType):
(Data):
(Data.prototype.async.getArrayBuffer):
(Data.prototype.get type):
(Data.prototype.get isPointer):
(Data.prototype.get buffer):
(Data.prototype.get byteLength):
(Harness.prototype._initialize):
(Harness.prototype.async.callTypedFunction):
(Harness.prototype.async.callVoidFunction):
(Harness.prototype._setUpArguments):
(Harness.prototype._callFunction):
(Harness):
(harness._initialize.async):
(makeBool):
(makeInt):
(makeUchar):
(makeUint):
(makeFloat):
(makeFloat4):
(async.callBoolFunction):
(async.callIntFunction):
(async.callUcharFunction):
(async.callUintFunction):
(async.callFloatFunction):
(async.callFloat4Function):
(callVoidFunction):

  • webgpu/whlsl-harness-test-expected.txt: Added.
  • webgpu/whlsl-harness-test.html: Added.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246625 r246628  
     12019-06-19  Justin Fan  <justin_fan@apple.com>
     2
     3        [WHLSL] Create a shading language test harness
     4        https://bugs.webkit.org/show_bug.cgi?id=198978
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Introduce a test harness that can be used to test WebGPU shader compilation and functionality.
     9        Currently using MSL.
     10        Will be replaced with WHLSL as it gains the minimum features needed to support.
     11
     12        * webgpu/js/whlsl-test-harness.js: Added.
     13        (isVectorType):
     14        (convertTypeToArrayType):
     15        (convertTypeToWHLSLType):
     16        (Data):
     17        (Data.prototype.async.getArrayBuffer):
     18        (Data.prototype.get type):
     19        (Data.prototype.get isPointer):
     20        (Data.prototype.get buffer):
     21        (Data.prototype.get byteLength):
     22        (Harness.prototype._initialize):
     23        (Harness.prototype.async.callTypedFunction):
     24        (Harness.prototype.async.callVoidFunction):
     25        (Harness.prototype._setUpArguments):
     26        (Harness.prototype._callFunction):
     27        (Harness):
     28        (harness._initialize.async):
     29        (makeBool):
     30        (makeInt):
     31        (makeUchar):
     32        (makeUint):
     33        (makeFloat):
     34        (makeFloat4):
     35        (async.callBoolFunction):
     36        (async.callIntFunction):
     37        (async.callUcharFunction):
     38        (async.callUintFunction):
     39        (async.callFloatFunction):
     40        (async.callFloat4Function):
     41        (callVoidFunction):
     42        * webgpu/whlsl-harness-test-expected.txt: Added.
     43        * webgpu/whlsl-harness-test.html: Added.
     44
    1452019-06-19  Saam Barati  <sbarati@apple.com>
    246
  • trunk/Source/WebCore/ChangeLog

    r246625 r246628  
     12019-06-19  Justin Fan  <justin_fan@apple.com>
     2
     3        [WHLSL] Create a shading language test harness
     4        https://bugs.webkit.org/show_bug.cgi?id=198978
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        When creating MTLArgumentEncoders for argument buffers, the user's arguments
     9        must match the order that they are declared in the shader. Move back-end information
     10        such as buffer lengths to the end of the argument arrays.
     11
     12        Test: webgpu/whlsl-harness-test.html
     13
     14        * Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp:
     15        (WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes):
     16        * platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm:
     17        (WebCore::GPUBindGroupLayout::tryCreate):
     18
    1192019-06-19  Saam Barati  <sbarati@apple.com>
    220
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp

    r246515 r246628  
    3838#include "WHLSLStructureDefinition.h"
    3939#include "WHLSLTypeNamer.h"
     40#include <algorithm>
    4041#include <wtf/Optional.h>
    4142#include <wtf/text/StringBuilder.h>
     
    144145    for (size_t i = 0; i < m_layout.size(); ++i) {
    145146        stringBuilder.append(makeString("struct ", m_namedBindGroups[i].structName, " {\n"));
     147        Vector<std::pair<unsigned, String>> structItems;
    146148        for (size_t j = 0; j < m_layout[i].bindings.size(); ++j) {
    147149            auto iterator = m_resourceMap.find(&m_layout[i].bindings[j]);
     
    154156            auto elementName = m_namedBindGroups[i].namedBindings[j].elementName;
    155157            auto index = m_namedBindGroups[i].namedBindings[j].index;
    156             stringBuilder.append(makeString("    ", addressSpace, " ", mangledTypeName, "* ", elementName, " [[id(", index, ")]];\n"));
     158            structItems.append(std::make_pair(index, makeString("    ", addressSpace, " ", mangledTypeName, "* ", elementName, " [[id(", index, ")]];\n")));
    157159            if (auto lengthInformation = m_namedBindGroups[i].namedBindings[j].lengthInformation)
    158                 stringBuilder.append(makeString("    uint2 ", lengthInformation->elementName, " [[id(", lengthInformation->index, ")]];\n"));
     160                structItems.append(std::make_pair(lengthInformation->index, makeString("uint2 ", lengthInformation->elementName, " [[id(", lengthInformation->index, ")]];")));
    159161        }
     162        std::sort(structItems.begin(), structItems.end(), [](const std::pair<unsigned, String>& left, const std::pair<unsigned, String>& right) {
     163            return left.first < right.first;
     164        });
     165        for (const auto& structItem : structItems)
     166            stringBuilder.append(makeString("    ", structItem.second, '\n'));
    160167        stringBuilder.append("};\n\n");
    161168    }
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm

    r246394 r246628  
    9797    }
    9898
    99     ArgumentArray vertexArgsArray, fragmentArgsArray, computeArgsArray;
     99    ArgumentArray vertexArgs, fragmentArgs, computeArgs, vertexLengths, fragmentLengths, computeLengths;
    100100    BindingsMapType bindingsMap;
    101101
     
    138138        }
    139139
    140         auto addIndices = [&](ArgumentArray& array) -> bool {
    141             appendArgumentToArray(array, mtlArgument);
     140        auto addIndices = [&](ArgumentArray& args, ArgumentArray& lengths) -> bool {
     141            appendArgumentToArray(args, mtlArgument);
    142142            if (extraIndex) {
    143143                RetainPtr<MTLArgumentDescriptor> mtlArgument = argumentDescriptor(MTLDataTypeUInt2, *extraIndex);
     
    146146                    return false;
    147147                }
    148                 appendArgumentToArray(array, mtlArgument);
     148                appendArgumentToArray(lengths, mtlArgument);
    149149            }
    150150            return true;
    151151        };
    152         if ((binding.visibility & GPUShaderStageBit::Flags::Vertex) && !addIndices(vertexArgsArray))
     152        if ((binding.visibility & GPUShaderStageBit::Flags::Vertex) && !addIndices(vertexArgs, vertexLengths))
    153153            return nullptr;
    154         if ((binding.visibility & GPUShaderStageBit::Flags::Fragment) && !addIndices(fragmentArgsArray))
     154        if ((binding.visibility & GPUShaderStageBit::Flags::Fragment) && !addIndices(fragmentArgs, fragmentLengths))
    155155            return nullptr;
    156         if ((binding.visibility & GPUShaderStageBit::Flags::Compute) && !addIndices(computeArgsArray))
     156        if ((binding.visibility & GPUShaderStageBit::Flags::Compute) && !addIndices(computeArgs, computeLengths))
    157157            return nullptr;
    158158    }
    159159
     160    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     161    [vertexArgs addObjectsFromArray:vertexLengths.get()];
     162    [fragmentArgs addObjectsFromArray:fragmentLengths.get()];
     163    [computeArgs addObjectsFromArray:computeLengths.get()];
     164    END_BLOCK_OBJC_EXCEPTIONS;
     165
    160166    RetainPtr<MTLArgumentEncoder> vertex, fragment, compute;
    161167
    162     if (vertexArgsArray && !(vertex = tryCreateMtlArgumentEncoder(device, vertexArgsArray)))
     168    if (vertexArgs && !(vertex = tryCreateMtlArgumentEncoder(device, vertexArgs)))
    163169        return nullptr;
    164     if (fragmentArgsArray && !(fragment = tryCreateMtlArgumentEncoder(device, fragmentArgsArray)))
     170    if (fragmentArgs && !(fragment = tryCreateMtlArgumentEncoder(device, fragmentArgs)))
    165171        return nullptr;
    166     if (computeArgsArray && !(compute = tryCreateMtlArgumentEncoder(device, computeArgsArray)))
     172    if (computeArgs && !(compute = tryCreateMtlArgumentEncoder(device, computeArgs)))
    167173        return nullptr;
    168174
Note: See TracChangeset for help on using the changeset viewer.