commit | 2a9466967e0208400dfe7d41a3bad3ae947e9532 | [log] [tgz] |
---|---|---|
author | mmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Thu Jun 13 05:38:28 2019 +0000 |
committer | mmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Thu Jun 13 05:38:28 2019 +0000 |
tree | 4364c4008dd0d12be5aeaa206d2aa4685e0a065f | |
parent | fa4ac89ea1243bcacb8f89609ba8e27a0c8b0dd4 [diff] |
[WHLSL] Implement array references https://bugs.webkit.org/show_bug.cgi?id=198163 Reviewed by Saam Barati. Source/WebCore: The compiler automatically generates anders for every array reference. Luckily, the infrastructure to generate those anders and emit Metal code to represent them already exists in the compiler. There are two pieces remaining (which this patch implements): 1. The JavaScript compiler has a behavior where anders that are called with an array reference as an argument don't wrap the argument in a MakePointerExpression. This is because the array reference is already a reference type, so it's silly to operate on a pointer to a reference. This patch implements this by teaching the type checker about which types should be passed to the ander call, and by actually constructing those types in the property resolver. The property resolver does this by placing the logic to construct an ander argument in a single function which also has logic to save the argument in a temporary if the thread ander will be called. The semantics about which functions are called in which situations are not changed; instead, we just simply don't wrap array references with MakePointerExpressions. 2. Creating a bind group from the WebGPU API has to retain information about buffer lengths for each buffer so the shader can properly perform bounds checks. This can be broken down into a few pieces: - Creating a bind group layout has to assign extra id indexes for each buffer which will be filled in to represent the buffer's length - Creating the bind group itself needs to fill in the buffer length into the Metal argument buffer - The shader compiler needs to emit code at the beginning of entry point to find the buffer lengths and pack them together into the array reference (array references correspond to a Metal struct with two fields: a pointer and a length). This patch doesn't actually implement bounds checks themselves; it just hooks up the buffer lengths so https://bugs.webkit.org/show_bug.cgi?id=198600 can implement it. The shader compiler's API is modified to allow for this extra buffer length information to be passed in from the WebGPU implementation. Unfortunately, I don't think I could split this patch up into two pieces because both are required to test the compiler with buffers. Tests: webgpu/whlsl-buffer-fragment.html webgpu/whlsl-buffer-vertex.html * Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h: (WebCore::WHLSL::AST::PropertyAccessExpression::baseReference): * Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp: (WebCore::WHLSL::AST::ResourceSemantic::isAcceptableType const): Arrays can't be resources because the compiler has no way of guaranteeing if the resource is long enough to hold the array at compile time. * Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp: (WebCore::WHLSL::Metal::EntryPointScaffolding::EntryPointScaffolding): Generate an extra variable name to represent the buffer length. Only do it for resources which have lengths. (WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes): (WebCore::WHLSL::Metal::EntryPointScaffolding::unpackResourcesAndNamedBuiltIns): Perform the appropriate math to turn byte lengths into element counts and store the element count in the array reference. * Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h: * Modules/webgpu/WHLSL/WHLSLChecker.cpp: (WebCore::WHLSL::resolveWithOperatorAnderIndexer): Refactor. (WebCore::WHLSL::resolveWithOperatorLength): Ditto. (WebCore::WHLSL::resolveWithReferenceComparator): Ditto. (WebCore::WHLSL::resolveByInstantiation): Ditto. (WebCore::WHLSL::argumentTypeForAndOverload): Given an ander, what should the type of the argument be? (WebCore::WHLSL::Checker::finishVisiting): Call argumentTypeForAndOverload(). Also, if we couldn't find an ander, try automatically generating it, the same way that function calls do. (This is how array references get their anders.) (WebCore::WHLSL::Checker::visit): * Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h: New WHLSL API to provide the length information. * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp: (WebCore::WHLSL::PropertyResolver::visit): SimplifyRightValue() can't fail any more. (WebCore::WHLSL::wrapAnderCallArgument): If the ander argument should be wrapped in a MakePointer or a MakeArrayReference, do that. Also, if the ander is a thread ander, save the argument in a local variable and use that. (WebCore::WHLSL::anderCallArgument): The equivalent of argumentTypeForAndOverload(). (WebCore::WHLSL::setterCall): Call anderCallArgument(). (WebCore::WHLSL::getterCall): Ditto. (WebCore::WHLSL::modify): We used to have special-case code for handling pointer-to-argument values as distinct from just the argument values themselves. However, emitting chains of &* operators is valid and won't even make it through the Metal code generator after https://bugs.webkit.org/show_bug.cgi?id=198600 is fixed. So, in order to simplify wrapAnderCallArgument(), don't special case these values and just create &* chains instead. (WebCore::WHLSL::PropertyResolver::simplifyRightValue): (WebCore::WHLSL::LeftValueSimplifier::finishVisiting): Call anderCallArgument(). * Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp: Update to support the new compiler API. (WebCore::WHLSL::matchMode): (WebCore::WHLSL::matchResources): * Modules/webgpu/WebGPUBindGroupDescriptor.cpp: Ditto. (WebCore::WebGPUBindGroupDescriptor::tryCreateGPUBindGroupDescriptor const): * platform/graphics/gpu/GPUBindGroupLayout.h: Add some internal implementation data inside the bindings object. Use a Variant to differentiate between the various bindings types, and put the extra length field on just those members of the variant that represent buffers. * platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm: Update to support the new compiler API. (WebCore::argumentDescriptor): (WebCore::GPUBindGroupLayout::tryCreate): * platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm: Ditto. (WebCore::setBufferOnEncoder): (WebCore::GPUBindGroup::tryCreate): * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm: Ditto. (WebCore::convertBindingType): (WebCore::convertLayout): LayoutTests: * webgpu/buffer-resource-triangles-expected.html: Deleted. This test doens't make any sense and triggers Metal to read out-of-bounds of a vertex buffer. * webgpu/buffer-resource-triangles.html: Deleted. * webgpu/whlsl-buffer-fragment-expected.html: Added. * webgpu/whlsl-buffer-fragment.html: Added. * webgpu/whlsl-buffer-vertex-expected.html: Added. * webgpu/whlsl-buffer-vertex.html: Added. * webgpu/whlsl-dont-crash-parsing-enum.html: * webgpu/whlsl.html: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@246394 268f45cc-cd09-0410-ab3c-d52691b4dbfc
WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.
Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.
On macOS, download Safari Technology Preview to test the latest version of WebKit. On Linux, download Epiphany Technology Preview. On Windows, you'll have to build it yourself.
Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.
On Windows, follow the instructions on our website.
Run the following command to clone WebKit's Git SVN repository:
git clone git://git.webkit.org/WebKit.git WebKit
or
git clone https://git.webkit.org/git/WebKit.git WebKit
If you want to be able to commit changes to the repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track WebKit's Subversion repository. You can run the following command to configure this and other options of the new Git clone for WebKit development.
Tools/Scripts/webkit-patch setup-git-clone
For information about this, and other aspects of using Git with WebKit, read the wiki page.
If you don‘t want to use Git, run the following command to check out WebKit’s Subversion repository:
svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit
Install Xcode and its command line tools if you haven't done so already:
xcode-select --install
Run the following command to build a debug build with debugging symbols and assertions:
Tools/Scripts/build-webkit --debug
For performance testing, and other purposes, use --release
instead.
You can open WebKit.xcworkspace
to build and debug WebKit within Xcode.
If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild
directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild
for both Products and Intermediates.
The first time after you install a new Xcode, you will need to run the following command to enable Xcode to build command line tools for iOS Simulator:
sudo Tools/Scripts/configure-xcode-for-ios-development
Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.
” when building target JSCLLIntOffsetsExtractor
of project JavaScriptCore
.
Run the following command to build a debug build with debugging symbols and assertions for iOS:
Tools/Scripts/build-webkit --debug --ios-simulator
For production builds:
cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/gtk/install-dependencies Tools/Scripts/update-webkitgtk-libs Tools/Scripts/build-webkit --gtk --debug
For more information on building WebKitGTK+, see the wiki page.
For production builds:
cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/wpe/install-dependencies Tools/Scripts/update-webkitwpe-libs Tools/Scripts/build-webkit --wpe --debug
For building WebKit on Windows, see the wiki page.
Run the following command to launch Safari with your local build of WebKit:
Tools/Scripts/run-safari --debug
The run-safari
script sets the DYLD_FRAMEWORK_PATH
environment variable to point to your build products, and then launches /Applications/Safari.app
. DYLD_FRAMEWORK_PATH
tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks
.
To run other applications with your local build of WebKit, run the following command:
Tools/Scripts/run-webkit-app <application-path>
Run the following command to launch iOS simulator with your local build of WebKit:
run-safari --debug --ios-simulator
In both cases, if you have built release builds instead, use --release
instead of --debug
.
If you have a development build, you can use the run-minibrowser script, e.g.:
run-minibrowser --debug --wpe
Pass one of --gtk
, --jsc-only
, or --wpe
to indicate the port to use.
Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.