Skip to content

wgsl: describe builtin variables and how to declare them - #1142

Merged
kvark merged 1 commit into
gpuweb:mainfrom
dneto0:builtin-vars
Oct 27, 2020
Merged

kvark merged 1 commit into
gpuweb:mainfrom
dneto0:builtin-vars

Conversation

@dneto0

@dneto0 dneto0 commented Oct 9, 2020

Copy link
Copy Markdown
Contributor

This builds on #1093

@dneto0 dneto0 added a11y-needs-resolution Issue the Accessibility Group has raised and looks for a response on. wgsl WebGPU Shading Language Issues and removed a11y-needs-resolution Issue the Accessibility Group has raised and looks for a response on. labels Oct 9, 2020
@dneto0 dneto0 added this to the MVP milestone Oct 9, 2020
@dneto0

dneto0 commented Oct 9, 2020

Copy link
Copy Markdown
Contributor Author

@dneto0
dneto0 requested review from dj2, kvark and litherum October 9, 2020 15:58

@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.

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!

Comment thread wgsl/index.bs Outdated
must be a `block`-decorated [=host-shareable=] structure type.
See also [[#memory-layout]].
<br>Used with `uniform-buffer` WebGPU GPUBindingType.
<tr><td>buffer

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.

we should rename this to "storage" for consistency with "uniform"

Comment thread wgsl/index.bs Outdated
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.

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.

would it be cleaner to say "Buffer variables must have a ..."?

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.

"buffer variable" is not yet a defined term at this point in the spec.

I can look at rewording it with more connective tissue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we elaborate certain storage classes into the storage class list uniform and storage classes or something?

Comment thread wgsl/index.bs
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

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's not clear to me what this refers to. Maybe some examples are needed?

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.

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.

Comment thread wgsl/index.bs
<td>[=Module scope=]
<td>[=IO-shareable=]
<td>Output to a downstream pipeline stage.
<tr><td>function

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.

Is this useful? Do we have a situation where this storage class isn't known apriori?

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 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.)

Comment thread wgsl/index.bs
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>

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.

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".

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.

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).

Comment thread wgsl/index.bs Outdated
<td>fragment
<td>in
<td>vec4&lt;f32&gt;
<td width="50%">Coordinate of the current fragment.

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.

maybe "screen-space coordinate of the current fragment"?

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.

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.)

Comment thread wgsl/index.bs Outdated
<td>fragment
<td>in
<td>vec4&lt;f32&gt;
<td width="50%">Coordinate of the current fragment.

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.

we should link to the coordinate system convention of the main spec here and in position: https://gpuweb.github.io/gpuweb/#coordinate-systems

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.

Will do. I learned how to do a cross-reference using an inline biliography.

Comment thread wgsl/index.bs
<tr><td>`front_facing`
<td>fragment
<td>in
<td>u32

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.

why is this not a bool?

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.

I/O can't be bools. That's a Vulkan rule.

Comment thread wgsl/index.bs
<td>fragment
<td>in
<td>u32
<td width="50%">Non-zero when the current fragment is on a front-facing primitive.

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.

Comment thread wgsl/index.bs Outdated
<td>fragment
<td>out
<td>f32
<td width="50%">Updated depth of the fragment.

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.

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.

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.)

Comment thread wgsl/index.bs Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: for a variable

Comment thread wgsl/index.bs Outdated
* [[#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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: if each member is host-sharable and has an [=offset=] attribute (or some other wording, current doesn't read right.

Comment thread wgsl/index.bs Resolved
Comment thread wgsl/index.bs Outdated

<table class='data'>
<thead>
<tr><td>Storage class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These tds should probaby be th's as this is the header

Comment thread wgsl/index.bs Outdated
<table class='data'>
<thead>
<tr><td>Name<td>SPIR-V Storage Class
<tr><td>WGSL storage class<td>SPIR-V storage class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: td ->th

Comment thread wgsl/index.bs Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe note the lack of storage class? not sure.

Comment thread wgsl/index.bs Outdated
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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These storage classes aren't right storage and handle ?

Comment thread wgsl/index.bs Outdated

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: /sahder/shader

Comment thread wgsl/index.bs Outdated
OpDecorate %gl_VertexIdx BuiltIn VertexIndex
<table class='data'>
<thead>
<tr><td>Built-in<td>Stage<td>Input or Output<td>Store type<td>Description

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: td -> th

Comment thread wgsl/index.bs Outdated
<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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: s/firstIstance/firstInstance

@dneto0

dneto0 commented Oct 24, 2020

Copy link
Copy Markdown
Contributor Author

- 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
@dneto0

dneto0 commented Oct 26, 2020

Copy link
Copy Markdown
Contributor Author

Rebased on main, and collapsed into a single commit.

@kvark
kvark merged commit 9e53fb4 into gpuweb:main Oct 27, 2020
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.

3 participants