Skip to content

Conversation

alan-baker
Copy link
Contributor

  • Allows vectors and matrices to have abstract components
  • Renames constexpr to creation-time expression and greatly expands
    functionality to include most expressions
    • to be creation-time expressions, all identifiers must be
      creation-time constants or creation-time functions
    • removes const_expression grammar (replacement for it)
  • Add new declaration type: creation-time constant
    • uses const keyword
    • usable at module and function scopes
  • Restrict let to function scope
  • Add @const attribute to declare creation-time constants
    • only usable for built-in functions currently
  • Define override expression in terms of creation-time expressions
  • Update fixed-size array declarations to allow creation-time
    expressions
  • Update texture functions to use creation-time expressions
  • Update builtin functions to specify which are usable with abstract
    types and which are usable with creation-time expressions
  • Update expressions to specify which are usable with abstract types
  • Clarify that let and var are always concrete
  • De-duplicate some builtin function table entries
  • Update some overload resolution examples

This builds on #2227 and implements the consensus on constexpr from #1272. Take a look at the last commit.

Does not add support for specifying arguments as required to be creation-time expressions. Does not add staticAssert yet.

Some of the examples use a grammar ambiguity that was pre-existing (e.g. vec3(...)).

@alan-baker alan-baker added the wgsl WebGPU Shading Language Issues label Mar 15, 2022
@alan-baker alan-baker marked this pull request as draft March 15, 2022 17:30
Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

This is really nice.
I have very minor edits/suggestions.

Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Thanks for the update.
I think two things remain:

  • element_count_expression changes
  • the 's' type parameter issue for matrix arithmetic

Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Thanks!
LGTM. Now we only need W3C WebGPU group agreement.

@alan-baker alan-baker marked this pull request as ready for review March 29, 2022 19:24
@kdashg
Copy link
Contributor

kdashg commented Mar 30, 2022

WGSL meeting minutes 2022-03-29
  • MM: const x = 5; is the type AbstractInt, or in32.
  • AB: In this PR, it’s i32. When you add ‘const’ as a declarator, then it becomes abstract
  • MM: Glad there is an answer. No strong opinion about what the answer should be.
  • MM: Why have @const when authors can’t write it. Why not have an explicit list in the spec.
  • AB: Thinking forward, we can add that feature later. It’s easy to explain it this way.
  • AB: Happy to bikeshed the name like ‘constfn’ vs @const fn.
  • MM: Think user-defined constexpr functions is a big thing, and needs careful consideration about how it’s shaped. So for now want to not add a syntax for it.
  • AB: I want a single place to look in the spec to know about a function, rather than look in two places. As long as it’s inline it’s important.
  • MM: Inline is no problem. Could be a column, or a sentence.
  • KG: Agree with Alan somewhat. When I look at documentation I often just look at a declaration. So it would be cool to see a ‘const’ there, or @const. You could argue it’s just a table with no borders.
  • MM: I view the whole spec as the thing you’re describing. If someone made a list of everything in the std library that info would be in the list.
  • DN: The way AB has it is there’s an @const attrib, but users can’t use it, so this would be something we can harmlessly changed later with no user-visibility. Did we add a note that this is just for explaining, and not “real” syntax?
  • MM: RIght, this is an editorial comment.
  • MM: Confirm you can still make a let at internal function scope.
  • AB: Yes.
  • MM: Not blocking. If I wrote a PR to replace @const with something that is inline next to the function, would that be a harm?
  • AB: would need to see it.
  • KG: Currently prefer @const.
  • MM: Ok, let’s go forward, and I can write a PR.
  • AB: I’ll rebase, convert to non-draft.
  • KG: I’ll review
  • AB: Call attention that some builtin functions now take abstract numeric types, see if you agree with the set. And also abstract types can be for scalars, vectors, and matrices. Not arrays and structs.
  • MM: I’m most interested in the math functions working on these abstract values, and they don’t operate on arrays and structs, generally.
  • AB: An odd case is frexp and modf, which return structs. Decided one way, and open to changing to the other.

@kdashg
Copy link
Contributor

kdashg commented Apr 12, 2022

WGSL meeting minutes 2022-04-05
  • AB: Waiting on more reviews. Keep on rebasing.
  • KG:** I promise to review this week.**

* Allows vectors and matrices to have abstract components
* Renames constexpr to creation-time expression and greatly expands
  functionality to include most expressions
  * to be creation-time expressions, all identifiers must be
    creation-time constants or creation-time functions
  * removes `const_expression` grammar (replacement for it)
* Add new declaration type: creation-time constant
  * uses `const` keyword
  * usable at module and function scopes
* Restrict `let` to function scope
* Add `@const` attribute to declare creation-time constants
  * only usable for built-in functions currently
* Define override expression in terms of creation-time expressions
* Update fixed-size array declarations to allow creation-time
  expressions
* Update texture functions to use creation-time expressions
* Update builtin functions to specify which are usable with abstract
  types and which are usable with creation-time expressions
* Update expressions to specify which are usable with abstract types
* Clarify that `let` and `var` are always concrete
* De-duplicate some builtin function table entries
* Update some overload resolution exmaples
* Clarify formulae for matrix arithmetic
* Change element count expressions for arrays to be shift expresions and
  bitwise expressions
* Add creation-time constants to uniformity analysis
* Change texture built-in function parameters to remove references to
  module-scope let declarations
* Clarify shift operations
* Add unsigned conversion from abstract integer
  * Fixes gpuweb#2719
  * Add conversion to u32 scalar and vector types from abstract integer
  scalar and vector respectively
Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Thanks!

<td>Reinterpretation of bits.<br>
The result is the unique value in [=u32=] that is equal to (|e| mod 2<sup>32</sup>).
<tr algorithm="scalar conversion from binary32 floating point to unsigned integer">
The result is the unique value in [=u32=] that has the same bit pattern as |e|.
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess AbstractInt values have a bit pattern, because we define bitwise operations on them.

This rephrasing would make it an error to try to stuff a too-big AbstractInt value into a u32. It would be overflow. Similarly for a negative abstract-int value. That makes sense to me.

@@ -4371,8 +4433,8 @@ For details on conversion to and from floating point types, see [[#floating-poin
<tr algorithm="scalar reinterpretation from unsigned to signed">
<td>|e|: u32<td>`i32(`|e|`)`: i32
<td>Reinterpretation of bits.<br>
The result is the unique value in [=i32=] that is equal to (|e| mod 2<sup>32</sup>).
<tr algorithm="scalar conversion from binary32 floating point to signed integer">
The result is the unique value in [=i32=] that has the same bit pattern as |e|.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing AbstractInt here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, discussed offline: The AbstractInt -> i32 conversion is already the default. So writing i32( ... ) around an AbstractInt already just works as intended.

Cool

@dneto0 dneto0 merged commit 83f4b92 into gpuweb:main Apr 12, 2022
github-actions bot added a commit that referenced this pull request Apr 12, 2022
SHA: 83f4b92
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 12, 2022
SHA: 83f4b92
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 12, 2022
SHA: 83f4b92
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@alan-baker alan-baker deleted the constexpr branch April 12, 2022 20:14
@kdashg
Copy link
Contributor

kdashg commented Apr 13, 2022

WGSL meeting minutes 2022-04-12
  • Previously:
    • KG: I promise to review this week.
  • KG**: **Think we should land this. Progress
  • AB to resolve conflicts, then David to land.

toji pushed a commit that referenced this pull request Apr 28, 2022
* Allows vectors and matrices to have abstract components
* Renames constexpr to creation-time expression and greatly expands
  functionality to include most expressions
  * to be creation-time expressions, all identifiers must be
    creation-time constants or creation-time functions
  * removes `const_expression` grammar (replacement for it)
* Add new declaration type: creation-time constant
  * uses `const` keyword
  * usable at module and function scopes
* Restrict `let` to function scope
* Add `@const` attribute to declare creation-time constants
  * only usable for built-in functions currently
* Define override expression in terms of creation-time expressions
* Update fixed-size array declarations to allow creation-time
  expressions
* Update texture functions to use creation-time expressions
* Update builtin functions to specify which are usable with abstract
  types and which are usable with creation-time expressions
* Update expressions to specify which are usable with abstract types
* Clarify that `let` and `var` are always concrete
* De-duplicate some builtin function table entries
* Update some overload resolution exmaples
* Clarify formulae for matrix arithmetic
* Change element count expressions for arrays to be shift expresions and
  bitwise expressions
* Add creation-time constants to uniformity analysis
* Change texture built-in function parameters to remove references to
  module-scope let declarations
* Clarify shift operations
* Add unsigned conversion from abstract integer
  * Fixes #2719
  * Add conversion to u32 scalar and vector types from abstract integer
  scalar and vector respectively
jdarpinian pushed a commit to jdarpinian/gpuweb that referenced this pull request Aug 12, 2022
* Allows vectors and matrices to have abstract components
* Renames constexpr to creation-time expression and greatly expands
  functionality to include most expressions
  * to be creation-time expressions, all identifiers must be
    creation-time constants or creation-time functions
  * removes `const_expression` grammar (replacement for it)
* Add new declaration type: creation-time constant
  * uses `const` keyword
  * usable at module and function scopes
* Restrict `let` to function scope
* Add `@const` attribute to declare creation-time constants
  * only usable for built-in functions currently
* Define override expression in terms of creation-time expressions
* Update fixed-size array declarations to allow creation-time
  expressions
* Update texture functions to use creation-time expressions
* Update builtin functions to specify which are usable with abstract
  types and which are usable with creation-time expressions
* Update expressions to specify which are usable with abstract types
* Clarify that `let` and `var` are always concrete
* De-duplicate some builtin function table entries
* Update some overload resolution exmaples
* Clarify formulae for matrix arithmetic
* Change element count expressions for arrays to be shift expresions and
  bitwise expressions
* Add creation-time constants to uniformity analysis
* Change texture built-in function parameters to remove references to
  module-scope let declarations
* Clarify shift operations
* Add unsigned conversion from abstract integer
  * Fixes gpuweb#2719
  * Add conversion to u32 scalar and vector types from abstract integer
  scalar and vector respectively
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wgsl WebGPU Shading Language Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants