Skip to content

Entry point fix, describe workgroups - #1046

Merged
dj2 merged 7 commits into
gpuweb:mainfrom
dneto0:entry-point
Sep 18, 2020
Merged

dj2 merged 7 commits into
gpuweb:mainfrom
dneto0:entry-point

Conversation

@dneto0

@dneto0 dneto0 commented Sep 2, 2020

Copy link
Copy Markdown
Contributor

Fixes #662 : Declare an entry point by decorating the function declaration

  • Adds ability to add attributes to an entry point declaration
  • Adds the workgroup_size attribute
  • Describes compute shader dispatch, in a new "Compute shaders and
    workgroups" section

@dneto0 dneto0 added the wgsl WebGPU Shading Language Issues label Sep 2, 2020
@dneto0

dneto0 commented Sep 2, 2020

Copy link
Copy Markdown
Contributor Author

Preview of contents: https://gistpreview.github.io/?38fee9b1c324bd449a65a06fe476594e#entry-point-decl

See "Entry point declaration" section and "Compute shaders and workgroups"

@dneto0
dneto0 force-pushed the entry-point branch 2 times, most recently from 8ac6f24 to b240900 Compare September 2, 2020 20:33
@dneto0
dneto0 requested review from kvark and litherum September 2, 2020 20:34
@dneto0 dneto0 self-assigned this Sep 2, 2020
@dneto0 dneto0 added this to the MVP milestone Sep 2, 2020
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Outdated
<xmp>
entry_point vertex = main
OpEntryPoint Vertex %vtx_main "vtx_main" %gl_FragColor
vertex fn vtx_main() -> void { gl_Position = vec4<f32>(); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did we consider making the stage selection more... regular in terms of syntax?
E.g. fn<vertex> vtx_main() -> void {... }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We didn't discuss it much.
I didn't even know if the stage name should go before or after fn.

I like the template syntax you suggested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is some rework of the grammar, so I'd like to agree on this in the group before making this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolution in 2020-09-15 meeting is to use syntax like this:

    [[stage(fragment)]]  fn main()....

Comment thread wgsl/index.bs Resolved
@kainino0x

Copy link
Copy Markdown
Contributor

Whatever the resolution here is, I'd like to consider doing the same thing for bindings. [[binding 0, set 1]] -> [[binding (1, 0)]]

@kdashg

kdashg commented Sep 8, 2020

Copy link
Copy Markdown
Contributor

I have a bunch of sometimes-opposing/contradictory feelings on this, but here's the signal I have dredged out of them.

I think my prefs are:

  • [[workgroup_size N N N]] [[foo bar]] "LISPish"
  • [[workgroup_size N N N, foo bar]] "comma-delimited list"
  • [[workgroup_size (N N N), foo bar]] "paren-tuples"
    • Is [[foo (bar)]] valid?
  • [[workgroup_size [N N N], foo bar]] "square-bracket-tuples"
    • [N,N,N] feels like an array, but what if it were [N, cw|ccw]? Paren-tuples are more flexible, even if we don't have them elsewhere in the language yet.
    • Also [[workgroup_size [N N N]]] is gross, even if we can manage to parse it.
  • [[workgroup size(N N N), foo bar]] "pseudo-function attribute values"

@dneto0

dneto0 commented Sep 8, 2020

Copy link
Copy Markdown
Contributor Author

Discussed in the 2020-09-08 WGSL meeting

  • An entry point is now declared by using a 'stage' attribute on a function declaration
  • We argued over various options on how to spell the workgroup_size parameters. The MR uses [[stage compute, workgroup_size 1 2 3]] syntax.

I have refreshed the HTML in the gist. https://gistpreview.github.io/?38fee9b1c324bd449a65a06fe476594e#entry-point-decl

On the "how to I write many attributes" front, early on we at Google decided that [[attr, attr2]] was better than [[attr]] [[attr2]]. It was less fussy and less typing.

@kainino0x

kainino0x commented Sep 8, 2020 •

Copy link
Copy Markdown
Contributor

While we're bikeshedding (EDIT: oops, posted at the same time as the comment above):

I think a lot of people don't like this, but I personally like:

[[workgroup_size somesyntaxhere]]
[[foo bar]]
vertex fn main() -> void {
}

mainly because in practice I would probably put these on separate lines, and IMO this syntax makes that a bit cleaner than:

[[
  workgroup_size somesyntaxhere,
  foo bar,
]] vertex fn main() -> void {
}

. I would also support something like this (looks like a function)

[[workgroup_size(x, y, z), foo(bar)]] vertex fn main() -> void {
}

or even

@workgroup_size(x, y, z)
@foo(bar)
vertex fn main() -> void {
}

like in Python or Java.

@johnkslang

Copy link
Copy Markdown

I recommend reading through https://en.cppreference.com/w/cpp/language/attributes and fully understanding its power before spending time trying to invent new syntax that might not work as well. Especially where both space and parenthesis have their own meaning.

For HLSL, we discussed this and chose [[vk::binding(3, 2)]], where the arguments are required binding followed by optional set.

Really seems worth following precedence here in C++, GLSL, HLSL, probably many others, and saving time as well.

@dneto0

dneto0 commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

Attribute syntax is a larger topic that we haven't addressed in a focused way.
I've done this MR with workgroup_size attribute syntax two ways, once as workgroup_size(1,2,3) and now as workgroup_size 1 2 3.

If the attribute syntax is truly the only sticking point, and it is orthogonal to content being proposed here I suggest we land this and start a separate focused issue for attribute syntax.

@kainino0x

Copy link
Copy Markdown
Contributor

I'm in favor of using the C++ style (or a similar style from another language) and making it work nicely for what we have already (e.g. [[position]] or [[builtin::position]], but not [[builtin(position)]]).

@kainino0x

Copy link
Copy Markdown
Contributor

We can continue this topic here: #1067

@kainino0x

Copy link
Copy Markdown
Contributor

And an issue for the [[binding(n,m)]] issue: #1068

@dj2

dj2 commented Sep 14, 2020

Copy link
Copy Markdown
Member

My vote is for the [[workgroup_size N N N, foo bar]] "comma-delimited list" option. Do we expect to have a large number of these in any given case? It seems like it's a fairly limited set.

Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Resolved
@grorg

grorg commented Sep 15, 2020

Copy link
Copy Markdown
Contributor

Moved this to resolved. Review continues here, and the follow-up issues #1067 and #1068

Fixes gpuweb#662 : Declare an entry point by decorating the function declaration

- Adds ability to add attributes to an entry point declaration
- Adds the workgroup_size attribute
- Describes compute shader dispatch, in a new "Compute shaders and
  workgroups" section
Instead, assert the existince of a dispatch command of some sort,
without saying how it was created.
- use space-separated literals, instead of function-style parameter list
- the y and z dimensions are optional, defaulting to 1.
- Functions can now have attributes
  - So far the only attributes are for entry points.
- Add 'stage' attribute
- Remove 'entry_point' as a statement.
- Other uses of attribues should be updated in another MR.

Also:
- Add an example of a compute shader declared without workgroup_size
attirbute. In this case it defaults to a workgroup size of (1,1,1), and
we show this in the sample translation snippit to SPIR-V.
- Fix grammar when explaining how invocations are organized into
workgroups.
@dneto0

dneto0 commented Sep 15, 2020

Copy link
Copy Markdown
Contributor Author

I've addressed all feedback now. PTAL.

@kvark kvark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

loots of good material in here!

Comment thread wgsl/index.bs

* The entry point function for the stage.
* The targets of function calls from within the body of a function
in the shader stage, whether or not that call is executed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it would be useful to define "statically reachable" somewhere and refer to it in places like this instead of redefining

@dj2
dj2 merged commit 9cc8d59 into gpuweb:main Sep 18, 2020
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
* Update canvas_complex_bgra8unorm_copy.https.html

Adding fuzzyness

* Update canvas_complex_bgra8unorm_draw.https.html

* Update canvas_composite_alpha_bgra8unorm_opaque_copy.https.html

* Update canvas_composite_alpha_bgra8unorm_opaque_draw.https.html

* Update canvas_composite_alpha_bgra8unorm_premultiplied_copy.https.html

* Update canvas_composite_alpha_bgra8unorm_premultiplied_draw.https.html

* Update canvas_complex_bgra8unorm_copy.https.html

* Update canvas_complex_bgra8unorm_draw.https.html
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.

entry_point_decl should be an annotation on the function

8 participants