[webkit-changes] [WebKit/WebKit] f8937a: [WGSL] Rewrite pointer variables

Tadeu Zagallo noreply at github.com
Wed Oct 4 05:41:36 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f8937a35f02f3c64eb02529b413b65c33d65e565
      https://github.com/WebKit/WebKit/commit/f8937a35f02f3c64eb02529b413b65c33d65e565
  Author: Tadeu Zagallo <tzagallo at apple.com>
  Date:   2023-10-04 (Wed, 04 Oct 2023)

  Changed paths:
    M Source/WebGPU/WGSL/AST/ASTExpression.h
    M Source/WebGPU/WGSL/AST/ASTIdentityExpression.h
    M Source/WebGPU/WGSL/AST/ASTParameter.h
    M Source/WebGPU/WGSL/AST/ASTVariable.h
    M Source/WebGPU/WGSL/CallGraph.cpp
    M Source/WebGPU/WGSL/CallGraph.h
    M Source/WebGPU/WGSL/EntryPointRewriter.cpp
    M Source/WebGPU/WGSL/EntryPointRewriter.h
    M Source/WebGPU/WGSL/GlobalVariableRewriter.cpp
    M Source/WebGPU/WGSL/GlobalVariableRewriter.h
    M Source/WebGPU/WGSL/MangleNames.cpp
    A Source/WebGPU/WGSL/PointerRewriter.cpp
    A Source/WebGPU/WGSL/PointerRewriter.h
    M Source/WebGPU/WGSL/WGSL.cpp
    M Source/WebGPU/WGSL/WGSLShaderModule.h
    M Source/WebGPU/WGSL/tests/valid/global-used-by-callee.wgsl
    M Source/WebGPU/WGSL/tests/valid/packing.wgsl
    M Source/WebGPU/WGSL/tests/valid/pointers.wgsl
    M Source/WebGPU/WebGPU.xcodeproj/project.pbxproj
    M Source/WebGPU/WebGPU/ShaderModule.mm
    M Tools/TestWebKitAPI/Tests/WGSL/MetalGenerationTests.cpp

  Log Message:
  -----------
  [WGSL] Rewrite pointer variables
https://bugs.webkit.org/show_bug.cgi?id=262541
rdar://116402059

Reviewed by Mike Wyrzykowski.

Taking the address of resource variables, which have to be packed, generates
invalid code such as `&unpack(...)`, where we try to take the address of an
rvalue. In order to fix this, we eliminate all pointer variables and replace
all references to it with the variable's right-hand side.
This patch also moves the name mangling pass from being the last pass to run
to being the first. This resolves issues shadowing where the right-hand side
of the eliminated variable would be copied into a place where one of the
variables it references has been shadowed. This is fixed since all variables
are given unique names during mangling. It also has the side-effect of generate
more meaningful names in the final program, while still replacing all original
names.

* Source/WebGPU/WGSL/AST/ASTExpression.h:
* Source/WebGPU/WGSL/AST/ASTIdentityExpression.h:
* Source/WebGPU/WGSL/AST/ASTVariable.h:
* Source/WebGPU/WGSL/CallGraph.cpp:
(WGSL::CallGraphBuilder::CallGraphBuilder):
(WGSL::CallGraphBuilder::initializeMappings):
(WGSL::buildCallGraph):
* Source/WebGPU/WGSL/CallGraph.h:
* Source/WebGPU/WGSL/EntryPointRewriter.cpp:
(WGSL::EntryPointRewriter::EntryPointRewriter):
(WGSL::rewriteEntryPoints):
(WGSL::EntryPointRewriter::takeEntryPointInformation): Deleted.
* Source/WebGPU/WGSL/EntryPointRewriter.h:
* Source/WebGPU/WGSL/GlobalVariableRewriter.cpp:
(WGSL::RewriteGlobalVariables::RewriteGlobalVariables):
(WGSL::RewriteGlobalVariables::run):
(WGSL::RewriteGlobalVariables::usesOverride):
(WGSL::rewriteGlobalVariables):
* Source/WebGPU/WGSL/GlobalVariableRewriter.h:
* Source/WebGPU/WGSL/MangleNames.cpp:
(WGSL::MangledName::toString const):
(WGSL::NameManglerVisitor::visit):
(WGSL::NameManglerVisitor::visitVariableDeclaration):
* Source/WebGPU/WGSL/PointerRewriter.cpp: Added.
(WGSL::PointerRewriter::PointerRewriter):
(WGSL::PointerRewriter::run):
(WGSL::PointerRewriter::visit):
(WGSL::rewritePointers):
* Source/WebGPU/WGSL/PointerRewriter.h: Copied from Source/WebGPU/WGSL/EntryPointRewriter.h.
* Source/WebGPU/WGSL/WGSL.cpp:
(WGSL::prepareImpl):
* Source/WebGPU/WGSL/WGSLShaderModule.h:
(WGSL::ShaderModule::replace):
(WGSL::ShaderModule::std::enable_if_t<sizeof):
(WGSL::ShaderModule::remove):
* Source/WebGPU/WGSL/tests/valid/global-used-by-callee.wgsl:
* Source/WebGPU/WGSL/tests/valid/packing.wgsl:
* Source/WebGPU/WGSL/tests/valid/pointers.wgsl:
* Source/WebGPU/WebGPU.xcodeproj/project.pbxproj:
* Source/WebGPU/WebGPU/ShaderModule.mm:
(WebGPU::Device::createShaderModule):

Canonical link: https://commits.webkit.org/268846@main




More information about the webkit-changes mailing list