Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WGSL] Add support for multiplication #9043

Conversation

tadeuzagallo
Copy link
Member

@tadeuzagallo tadeuzagallo commented Jan 24, 2023

f10f7a6

[WGSL] Add support for multiplication
https://bugs.webkit.org/show_bug.cgi?id=251088
<rdar://problem/104600637>

Reviewed by Myles C. Maxfield and Dean Jackson.

As the title says: add parsing and a new BinaryOperation for multiplication.
The lexing will have to change as we add support for comments and other operators,
but this will do for now and enables testing more complex shaders.

* Source/WebGPU/WGSL/AST/ASTBinaryExpression.h:
* Source/WebGPU/WGSL/AST/ASTStringDumper.cpp:
(WGSL::AST::StringDumper::visit):
* Source/WebGPU/WGSL/Lexer.cpp:
(WGSL::Lexer<T>::lex):
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
* Source/WebGPU/WGSL/Parser.cpp:
(WGSL::Parser<Lexer>::parseMultiplicativeExpression):
* Source/WebGPU/WGSL/Token.cpp:
(WGSL::toString):
* Source/WebGPU/WGSL/Token.h:

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

879623b

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe   πŸ›  πŸ§ͺ win
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ›  gtk βœ… πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac   πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ webkitpy βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk1   πŸ§ͺ api-gtk
  πŸ›  πŸ§ͺ jsc βœ… πŸ›  tv βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  jsc-armv7
  πŸ›  πŸ§ͺ jsc-arm64 βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ jsc-armv7-tests
βœ… πŸ§ͺ services βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ›  jsc-mips
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch-sim   πŸ§ͺ jsc-mips-tests

@tadeuzagallo tadeuzagallo self-assigned this Jan 24, 2023
@tadeuzagallo tadeuzagallo added the WebGPU For bugs in WebGPU label Jan 24, 2023
@@ -31,6 +31,7 @@ namespace WGSL::AST {

enum class BinaryOperation : uint8_t {
Add,
Times,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really named Times in the spec? otherwise I'd just use Multiply or smtg similar, though Myles might have a different opinion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec doesn't name it AFAICT, but since it's the token and not the operation I was between Times and Asterisk, but I saw times in other places. I don't have a strong opinion, but it's also used for pointer dereference, so neither Times nor Multiply are very accurate πŸ€·β€β™‚οΈ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a related note, we could also move to the model that just uses the character as the token "name", that would avoid having to name tokens, which is probably the hardest part of making these patches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly here fwiw, just a thought that popped in my head. I'm sure one of you will figure out a good name/solution for this :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just realized I also named the operation Times 🀦 I was thinking this was the token. I'll rename before landing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like the "unify all binary operators into a single class, and give that class a char m_operator; model. The different binary operators are not structurally different.

@tadeuzagallo tadeuzagallo force-pushed the eng/WGSL-Add-support-for-multiplication branch from 2a6b81d to 4d9f215 Compare January 24, 2023 16:38
@@ -31,6 +31,7 @@ namespace WGSL::AST {

enum class BinaryOperation : uint8_t {
Add,
Times,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like the "unify all binary operators into a single class, and give that class a char m_operator; model. The different binary operators are not structurally different.

@tadeuzagallo tadeuzagallo force-pushed the eng/WGSL-Add-support-for-multiplication branch from 4d9f215 to 879623b Compare January 25, 2023 10:05
@tadeuzagallo tadeuzagallo added the merge-queue Applied to send a pull request to merge-queue label Jan 25, 2023
https://bugs.webkit.org/show_bug.cgi?id=251088
<rdar://problem/104600637>

Reviewed by Myles C. Maxfield and Dean Jackson.

As the title says: add parsing and a new BinaryOperation for multiplication.
The lexing will have to change as we add support for comments and other operators,
but this will do for now and enables testing more complex shaders.

* Source/WebGPU/WGSL/AST/ASTBinaryExpression.h:
* Source/WebGPU/WGSL/AST/ASTStringDumper.cpp:
(WGSL::AST::StringDumper::visit):
* Source/WebGPU/WGSL/Lexer.cpp:
(WGSL::Lexer<T>::lex):
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
* Source/WebGPU/WGSL/Parser.cpp:
(WGSL::Parser<Lexer>::parseMultiplicativeExpression):
* Source/WebGPU/WGSL/Token.cpp:
(WGSL::toString):
* Source/WebGPU/WGSL/Token.h:

Canonical link: https://commits.webkit.org/259347@main
@webkit-commit-queue
Copy link
Collaborator

Committed 259347@main (f10f7a6): https://commits.webkit.org/259347@main

Reviewed commits have been landed. Closing PR #9043 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit f10f7a6 into WebKit:main Jan 25, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jan 25, 2023
@tadeuzagallo tadeuzagallo deleted the eng/WGSL-Add-support-for-multiplication branch May 17, 2023 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebGPU For bugs in WebGPU
Projects
None yet
6 participants