[webkit-changes] [WebKit/WebKit] 535788: [WGSL] Add a pass to rewrite globals
Tadeu Zagallo
noreply at github.com
Fri Jan 27 03:40:55 PST 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 5357882f7ca7dfe24290ebfd8611dca74bd46246
https://github.com/WebKit/WebKit/commit/5357882f7ca7dfe24290ebfd8611dca74bd46246
Author: Tadeu Zagallo <tzagallo at apple.com>
Date: 2023-01-27 (Fri, 27 Jan 2023)
Changed paths:
M Source/WebGPU/WGSL/AST/ASTFunctionDecl.h
M Source/WebGPU/WGSL/AST/ASTIdentifierExpression.h
M Source/WebGPU/WGSL/AST/ASTStructureDecl.h
A Source/WebGPU/WGSL/GlobalVariableRewriter.cpp
A Source/WebGPU/WGSL/GlobalVariableRewriter.h
M Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
M Source/WebGPU/WGSL/WGSL.cpp
M Source/WebGPU/WebGPU.xcodeproj/project.pbxproj
Log Message:
-----------
[WGSL] Add a pass to rewrite globals
https://bugs.webkit.org/show_bug.cgi?id=251205
<rdar://problem/104691861>
Reviewed by Myles C. Maxfield.
Add a new pass that removes global variables and creates structs compatible
with Metal argument buffers. For now, the pass only generates the structs based
on the globals available in the source program, but we should use the pipeline
layout in the future. Fow now what it does is:
1. Find all the globals in the source and remove them
2. Creates a struct per bind group to receive the globals
3. Traverse the call graph and identify which functions use which globals
4. Insert parameters in the functions that need to receive the globals
5. Rewrite the global accesses with struct accesses to load the globals from
the structs received via the parameters.
In order for this patch to work correct, GlobalVariableRewriter needs to be updated
to use a ReferenceType, which is being introduce in PR #9174.
This PR also includes a fair amount of FIXMEs, but it was getting pretty large so I
paused here and will upload follow up patches shortly.
* Source/WebGPU/WGSL/AST/ASTFunctionDecl.h:
* Source/WebGPU/WGSL/AST/ASTIdentifierExpression.h:
* Source/WebGPU/WGSL/AST/ASTStructureDecl.h:
* Source/WebGPU/WGSL/GlobalVariableRewriter.cpp: Added.
(WGSL::RewriteGlobalVariables::RewriteGlobalVariables):
(WGSL::RewriteGlobalVariables::run):
(WGSL::RewriteGlobalVariables::visit):
(WGSL::replace):
(WGSL::RewriteGlobalVariables::collectGlobals):
(WGSL::RewriteGlobalVariables::visitEntryPoint):
(WGSL::RewriteGlobalVariables::requiredGroups):
(WGSL::RewriteGlobalVariables::insertStructs):
(WGSL::RewriteGlobalVariables::insertParameters):
(WGSL::RewriteGlobalVariables::def):
(WGSL::RewriteGlobalVariables::read):
(WGSL::RewriteGlobalVariables::argumentBufferParameterName):
(WGSL::RewriteGlobalVariables::argumentBufferStructName):
(WGSL::rewriteGlobalVariables):
* Source/WebGPU/WGSL/GlobalVariableRewriter.h: Added.
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::FunctionDefinitionWriter::visitArgumentBufferParameter):
* Source/WebGPU/WGSL/WGSL.cpp:
(WGSL::prepare):
* Source/WebGPU/WebGPU.xcodeproj/project.pbxproj:
Canonical link: https://commits.webkit.org/259477@main
More information about the webkit-changes
mailing list