Describe module constants, including pipeline-overrideable#886
Describe module constants, including pipeline-overrideable#886dj2 merged 4 commits intogpuweb:mainfrom
Conversation
|
Notes:
-- |
dj2
left a comment
There was a problem hiding this comment.
How will these work when we translate to HLSL?
wgsl/index.bs
Outdated
|
|
||
| A *module constant* declares a name for a value, outside of all function declarations. | ||
| The name is available for use after the end of the declaration, | ||
| until the end of the WGSL program. |
wgsl/index.bs
Outdated
| The name is available for use after the end of the declaration, | ||
| until the end of the WGSL program. | ||
|
|
||
| When the declaration has no attributes, the value is the expression in the declaration. |
There was a problem hiding this comment.
Should we note that the initializer is required?
There was a problem hiding this comment.
Well, the grammar requires there to be an initializer expression. So I don't think we need to say extra here.
wgsl/index.bs
Outdated
| to a value of the constant's type. | ||
| If the mapping does not have an entry for the pipeline constant ID, then the expression | ||
| in the declaration is used as the value. | ||
| * Pipeline constant IDs must be unique within the WGSL program: Two module constants |
| * The type must one of the [[#scalar-types]]. | ||
| * The attribute's literal operand is known as the *pipeline constant ID*, | ||
| and must be a non-negative integer value representable in 32 bits. | ||
| * The application can specify its own value for the name at pipeline-creation time. |
There was a problem hiding this comment.
What happens if the application provides a value for an ID which doesn't exist in the shader?
There was a problem hiding this comment.
I would say that's an application error. I would lean toward the requiring the pipeline creation API to fail.
The downside to that is it may cause more bookkeeping in the API.
There was a problem hiding this comment.
Added this as an issue
| : CONSTANT_ID INT_LITERAL | ||
| </pre> | ||
|
|
||
| Issue(dneto): The WebGPU pipeline creation API must specify how API-supplied values are mapped to |
There was a problem hiding this comment.
We have the concept of host-accessible types in the spec, right? Can we just say the type of a constant has to be a host-accessible scalar?
There was a problem hiding this comment.
Hmm. That removes the ability to set booleans. It's just as easy to say that when setting a bool constant, supply a 32-bit integer value, with 0 mapping to false, and true otherwise. It depends on the shape of the API whether we even need that detail or not.
|
Discussed at the 2020-07-07 meeting. |
wgsl/index.bs
Outdated
|
|
||
| <pre class='def'> | ||
| global_constant_decl | ||
| : global_const_decoration_list? CONST variable_ident_decl EQUAL const_expr |
There was a problem hiding this comment.
It should be possible for an author to omit the EQUAL const_expr
There was a problem hiding this comment.
That changes the grammar for a 'const' declaration. The rule would be to require an initializer on the const if and only if not having the attribute.
For me that elevates the status of the attribute quite a bit. I'm tempted to use new keyword other than 'const', e.g. 'spec_const'. I have to think that over.
There was a problem hiding this comment.
I went with making the expression optional. It didn't make things too complex.
9b01e81 to
ef525bc
Compare
|
(rebased against latest main) |
3b59c33 to
ef525bc
Compare
|
(removed an accidental commit meant for another PR) |
| The pipeline creation API accepts a mapping from the pipeline constant ID | ||
| to a value of the constant's type. | ||
| If the mapping has an entry for the ID, the value in the mapping is used. | ||
| Otherwise, the initializer expression must be present, and its value is used. |
There was a problem hiding this comment.
This was the simplest way to say it.
But the implementation detects the error at pipeline creation time, not at shader module creation time. It's pipeline creation that fails, no earlier.
|
What about constants where the value isn't supplied by the WGSL source, and also isn't supplied by the API? Do they get filled by 0s? Or compiler error? |
|
Discussed at the 2020-07-14 meeting. Resolution was to accept the PR, but open an issue changing the numbers into strings. |
From the PR:
So that case should result in failure of pipeline creation. |
Fixes gpuweb#572 Includes a strict "static use" rule. It allows for a very simple implementation (no assumed smarts for dead code elimination), and shifts the burden to the application to cleanup for interface matching. This features corresponds roughly to: - SPIR-V specialization constants, except you can't use them in all the same places. For example, in SPIR-V an array size may be a specialization constant scalar, but no in WGSL. - MSL function constants, except: - MSL allows vector values - MSL has a facility for excluding an entry point interface parameter based on the value of a boolean function constant.
1e5c29a to
766ec76
Compare
|
Rebased to avoid the merge conflict. |
Fixes #572
Includes a strict "static use" rule. It allows for a very
simple implementation (no assumed smarts for dead code elimination),
and shifts the burden to the application to cleanup for interface matching.
This features corresponds roughly to:
in all the same places. For example, in SPIR-V an array
size may be a specialization constant scalar, but no in WGSL.
parameter based on the value of a boolean function constant.