Repository navigation
wgsl: describe builtin variables and how to declare them - #1142
Conversation
kvark
left a comment
There was a problem hiding this comment.
Amazing work, thank you for specifying this!
Looks like the changes start piling up quickly, so we better resolve this promptly and land in some way, to not impede the progress. Thank you for your patience!
| must be a `block`-decorated [=host-shareable=] structure type. | ||
| See also [[#memory-layout]]. | ||
| <br>Used with `uniform-buffer` WebGPU GPUBindingType. | ||
| <tr><td>buffer |
There was a problem hiding this comment.
we should rename this to "storage" for consistency with "uniform"
| TODO: *The following is a stub* | ||
|
|
||
| Variables in certain storage classes must have host-shareable store type with fully elaborated memory layout. | ||
| Variables in certain storage classes must have a [=host-shareable=] [=store type=] with fully elaborated memory layout. |
There was a problem hiding this comment.
would it be cleaner to say "Buffer variables must have a ..."?
There was a problem hiding this comment.
"buffer variable" is not yet a defined term at this point in the spec.
I can look at rewording it with more connective tissue.
There was a problem hiding this comment.
Can we elaborate certain storage classes into the storage class list uniform and storage classes or something?
| Two types are associated with a variable: its *store type* (the type of value | ||
| that may be placed in the referenced storage) and its *reference type* (the type | ||
| of the variable itself). If a variable has store type *T* and storage class *S*, | ||
| Two types are associated with a variable: its <dfn noexport>store type</dfn> (the type of value |
There was a problem hiding this comment.
it's not clear to me what this refers to. Maybe some examples are needed?
There was a problem hiding this comment.
Intent of this MR was to add cross-links, that's all.
Store-type and reference-type will become significant when description of how pointers are type-checked and evaluated. I'd like to defer that until later.
| <td>[=Module scope=] | ||
| <td>[=IO-shareable=] | ||
| <td>Output to a downstream pipeline stage. | ||
| <tr><td>function |
There was a problem hiding this comment.
Is this useful? Do we have a situation where this storage class isn't known apriori?
There was a problem hiding this comment.
We need a name for the concept. This table introduces the storage classes, so function storage class should exist hee.
Also, we'll be able to form pointer-to-function values. (Note: that part isn't yet written in the spec.)
| Note that being statically accessed is independent of whether an execution of the shader | ||
| will actually evaluate the subexpression, or even execute the enclosing statement. | ||
|
|
||
| More precisely, the <dfn noexport>interface of a shader stage</dfn> |
There was a problem hiding this comment.
Why are we introducing this definition? IIRC nothing on the host side would care about the combined interface of a particular shader stage in a module. It would care about the module as a whole, or particular entry points.
Or maybe this paragraph should talk about "interface of an entry point" rather than "interface of a shader stage".
There was a problem hiding this comment.
The "entry point" is a WGSL function that serves a specific role.
The "shader stage" is the broader thing defined in 8.1 "Shader stages": It's the entry point + all the data objects accessed by the entry point and the static call tree of the entry point, and is executed for a particular pipeline stage.
IIRC nothing on the host side would care about the combined interface of a particular shader stage in a module.
You need to know what needs to be bound (binding points, and attachments). Also the programmer needs to know what data becomes accessible to the shader and when that data is set up (e.g. supplying values to the pipeline inputs).
| <td>fragment | ||
| <td>in | ||
| <td>vec4<f32> | ||
| <td width="50%">Coordinate of the current fragment. |
There was a problem hiding this comment.
maybe "screen-space coordinate of the current fragment"?
There was a problem hiding this comment.
Updating to:
Framebuffer position of the current fragment, using normalized homogeneous
coordinates.
(Normalization means the x, y, and z have already been scaled such that w is now 1.)
| <td>fragment | ||
| <td>in | ||
| <td>vec4<f32> | ||
| <td width="50%">Coordinate of the current fragment. |
There was a problem hiding this comment.
we should link to the coordinate system convention of the main spec here and in position: https://gpuweb.github.io/gpuweb/#coordinate-systems
There was a problem hiding this comment.
Will do. I learned how to do a cross-reference using an inline biliography.
| <tr><td>`front_facing` | ||
| <td>fragment | ||
| <td>in | ||
| <td>u32 |
There was a problem hiding this comment.
I/O can't be bools. That's a Vulkan rule.
| <td>fragment | ||
| <td>in | ||
| <td>u32 | ||
| <td width="50%">Non-zero when the current fragment is on a front-facing primitive. |
There was a problem hiding this comment.
| <td>fragment | ||
| <td>out | ||
| <td>f32 | ||
| <td width="50%">Updated depth of the fragment. |
There was a problem hiding this comment.
also should link to https://gpuweb.github.io/gpuweb/#coordinate-systems (or otherwise indicating that it's between 0 and 1)
There was a problem hiding this comment.
Will link. 0 and 1 are the default. But I think the range is between the viewport minDepth and maxDepth.
(I reviewed D3D rules and Vulkan rules, and they seem the same.)
| Issue: (dneto): Complete description of `Array<E,N>` | ||
| Restrictions on runtime-sized arrays: | ||
| * The last member of the structure type defining the [=store type=] | ||
| for variable in the `buffer` [=storage class=] may be a runtime-sized array. |
| * [[#array-types]] if the array type has a stride attribute and its element type is host-shareable | ||
| * [[#struct-types]] if all its members are host-shareable | ||
| * [[#array-types]] if the array type has a [=stride=] attribute and its element type is host-shareable | ||
| * [[#struct-types]] if each of its members both has an [=offset=] attribute and is host-shareable |
There was a problem hiding this comment.
nit: if each member is host-sharable and has an [=offset=] attribute (or some other wording, current doesn't read right.
|
|
||
| <table class='data'> | ||
| <thead> | ||
| <tr><td>Storage class |
There was a problem hiding this comment.
These tds should probaby be th's as this is the header
| <table class='data'> | ||
| <thead> | ||
| <tr><td>Name<td>SPIR-V Storage Class | ||
| <tr><td>WGSL storage class<td>SPIR-V storage class |
| var<function> count : u32; # A variable in function storage class. | ||
| var delta : i32; # Another variable in the function storage class. | ||
| var sum : f32 = 0.0; # A function storage class variable with initializer. | ||
| const unit : i32 = 1; # A constant. |
There was a problem hiding this comment.
Maybe note the lack of storage class? not sure.
| More precisely, the <dfn noexport>interface of a shader stage</dfn> | ||
| is the set of module-scope variables | ||
| [=statically accessed=] by [=functions in a shader stage|functions in the shader stage=], | ||
| and which are in [=storage classes=] `in`, `out`, `uniform`, `storage_buffer`, or `uniform_constant`. |
There was a problem hiding this comment.
These storage classes aren't right storage and handle ?
|
|
||
| TODO: *Stub* The resource interface of a shader stage is the set of module-scope | ||
| variables statically accessed by functions | ||
| in the sahder and which declare textures, samplers, |
| OpDecorate %gl_VertexIdx BuiltIn VertexIndex | ||
| <table class='data'> | ||
| <thead> | ||
| <tr><td>Built-in<td>Stage<td>Input or Output<td>Store type<td>Description |
| <td>u32 | ||
| <td width="50%">Instance index of the current vertex within the current API-level draw command. | ||
|
|
||
| The first instance has an index equal to the `firstIstance` argument of the draw, |
993bc61 to
ac4230c
Compare
|
I believe I've addressed all feedback. Updated preview is at https://gistpreview.github.io/?9a3ae1bcfaf6d1e4d8a37bca274ec13d |
- Finish renaming output input - Fix another 'input' -> 'in' storage class - Strengthen note on statically-accessed - Add short examples of declaring builtin variables - Define "buffer variable", in memory layout intro - Add issue for builtin-variables uniquely determining storage class - Fix TODO about interface matching - Describe local invocation index with an expression rather than prose - Clarify vertex position and fragment coordinate builtins - Add cross-reference to WebGPU Coordinate Systems section, using an inline bibliography - Clarify frag_depth uses framebuffer/viewport depth range - Also reference the WebGPU Coordinate Systems section - Fix typos and wording problems. - Fix table rendering for WGSL storage class and builtin variables
|
Rebased on main, and collapsed into a single commit. |
This builds on #1093