-
Notifications
You must be signed in to change notification settings - Fork 329
wgsl: @align(n) must divide required-align-of, for all structs #4978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e5bb03e
to
29c76b0
Compare
Previews, as seen when this build job started (f059fe6): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that both Naga and WebKit also check it evenly divides align-of too. Should that be an additional constraint?
@@ -10594,7 +10605,7 @@ used in address space |C|. | |||
<tr algorithm="alignment of an runtime-sized array"> | |||
<td>array<T> | |||
<td>[=AlignOf=](|S|) | |||
<td>[=roundUp=](16, [=AlignOf=](|S|)) | |||
<td>not applicable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch.
I think with this rule change, |
Here is some sample code showing differences between Tint, Naga, and WebKit compilers.
|
then |n| [=shader-creation error|must=] satisfy: | ||
|n| = |k| × [=RequiredAlignOf=](|T|,|C|) | ||
<blockquote> | ||
|n| = |k| × [=RequiredAlignOf=](|T|,|AS|) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we not just use AlignOf()
here instead of RequiredAlignOf()
, to make this rule address-space agnostic? Then you wouldn't need the !uniform
condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, that works. It works because it recurses to a nested type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, because we should plan for a future when we do scalar block layout.
We need to keep Align(..) only about setting layouts, and use RequiredAlignOf to be the constraints the environment places on memory accesses.
WGSL 2024-11-19 Minutes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved by WG in meeting.
Reverses: gpuweb#3756 - The previous phrasing was a note that was "implied" by other rules. It wasn't actually perfectly implied. - Avoids a silly and confusing case with the first element of a struct. - Brings the spec more in line with Naga and WebKit. - More clearly applies the rule for *all* structs, no matter if it is actually instantiated by a variable.
29c76b0
to
077b1b8
Compare
wgsl/index.bs
Outdated
then |n| [=shader-creation error|must=] satisfy: | ||
<blockquote> | ||
|n| = |k| × [=RequiredAlignOf=](|T|,|AS|) | ||
|n| = |k| × [=AlignOf=](|T|) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this again. Not sure this is the right change.
Does this still leave open the ability to do scalar block layout, by lowering the alignment of vec4u to that of u32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, talked this through with @dj2
I will revert this change because:
- right now the two phrasings are the same.
- but in future when we want to introduce something like scalar block layout, we need a path to doing that.
- if we only have Align as a knob, then we have to change Align(vec4u) to be 4.
- But then that is also the default alignment used to set the layout. And then that changes the layout of structs that *don't have annotations: e.g.
{ a:u32, b:vec4u}
would then place b at offset 8 instead of 16.
077b1b8
to
1962a00
Compare
Here's some separating cases, looking forward to scalar-block-layout #4040
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo
Co-authored-by: alan-baker <alanbaker@google.com>
Builds on #4974
Reverses: #3756