Skip to content

Conversation

@dj2
Copy link
Member

@dj2 dj2 commented Jan 7, 2021

This CL removes the offset decoration from struct members and adds a
span decoration instead. The span reduces the amount of action at a
distance required when adding data members as each line is self
contained. This also reduces the amount of typing required as the span
is only required when the memory size does not patch the type size for a
member.

Fixes #1303

This CL removes the offset decoration from struct members and adds a
`span` decoration instead. The span reduces the amount of action at a
distance required when adding data members as each line is self
contained. This also reduces the amount of typing required as the span
is only required when the memory size does not patch the type size for a
member.

Fixes #1303
@dj2 dj2 added the wgsl WebGPU Shading Language Issues label Jan 7, 2021
@dj2 dj2 added this to the MVP milestone Jan 7, 2021
@dj2 dj2 requested review from dneto0 and kvark January 7, 2021 21:31
@dj2 dj2 self-assigned this Jan 7, 2021
@dj2
Copy link
Member Author

dj2 commented Jan 7, 2021

First pass at converting over to span. The change itself is already approved by the group, so once the text is good we should be good to land.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2021

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
8c962bb

wgsl/index.bs Outdated
* [[#matrix-types]]
* [[#array-types]] if the array type has a [=stride=] attribute and its element type is host-shareable
* [[#struct-types]] if each member is host-shareable and has an [=offset=] attribute
* [[#struct-types]] if each member is host-shareable and, if the size of the member isn't the same as the size of the type, has a [=span=] attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little bit confusing: "the size of the member isn't the same as the size of the type". Are we really talking about the size of the member here? Or maybe about it's memory span?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we should have a separate definition somewhere, defining a set of types that match this description

Copy link
Member Author

Choose a reason for hiding this comment

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

Memory span. Number of bytes taken up by the thing in memory. Will attempt to clarify.

Copy link
Member Author

Choose a reason for hiding this comment

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

Better?

The number of bytes between the start of the structure and the location
of this member.
In the case where the memory size of a member does not match the size of the member type, a
`span` is required. The `span` must be the byte size of memory taken up by the current member and no larger.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we mention somewhere what values of the span are expected? This text says it must be "the byte size of memory taken up by the current member" but doesn't explain how to get that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe? I think we can skip it for now, but this maybe an output from the compilers, or a table to show when needed?

@litherum
Copy link
Contributor

litherum commented Jan 9, 2021

This CL removes the offset decoration

Why not make it optional instead? If an author for some reason wants to tell us the offset they expect stuff to be at, we ought to be receptive of that information.

If we make it optional, we'd have to make offset and span not conflict. E.g. you should be able to do

...
[[offset(16) span(16)]] metallicRoughnessFactor : vec2<f32>;
emissiveFactor : vec2<f32>;
...

@dj2
Copy link
Member Author

dj2 commented Jan 11, 2021

I think we should leave offset out of the MVP and revisit if there is call for it afterwards. It's more spec work and more implementation work to add it in, and we don't know if it will be necessary.

@github-actions
Copy link
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
9339d41

@kainino0x
Copy link
Contributor

kainino0x commented Jan 12, 2021

Comment from meeting: Instruct { a: vec2<f32>; b: vec4<f32>; }, vec2 has a "natural size" of 8 bytes, but would require a span of 16 in order to align the vec4, so it would have to be explicit ([[span(16)]] a: vec2, b: vec4). I don't think we want to add automatic alignment rules so that vec2 implicitly gets a span of 16. If there were an explicit annotation to align (a: vec2, [[align(16)]] b: vec4), required any time that implicit padding would be inserted due to alignment rules, then maybe it would be okay. (Autogenerated code could unconditionally add [[align()]] annotations and then would never break due to the order of fields changing.)
This also means span info is context dependent and so it makes most sense to have it on the member, not on the type.

@kvark
Copy link
Contributor

kvark commented Jan 20, 2021

Doing my share of work to help this case, I tried to crystallize the debate we had so far. Here are the plain and graph views. I'm definitely missing a lot of arguments here (was reconstructing from memory, need to re-read all the discussions, ideally, to populate it), since it appears to me that just slapping [[layout(general)]] or [[layout(storage)]] on textures (related to #621) is the simplest solution. Any help is appreciated!

@dj2
Copy link
Member Author

dj2 commented Jan 20, 2021

I think the concern with add the layout is the number of possible entries getting large? layout(140), layout(430), layout(scalar), layout(relaxed) ....

@kvark
Copy link
Contributor

kvark commented Jan 20, 2021

@dj2 right, but it's not like these layouts are magically going away if we aren't explicit about them. If we support "scalar" at any point, we'd still have to specify it in terms of constraints on the offsets/spans/whatever, i.e. it will technically be a part of the spec, so it might as well be just layout(scalar). This is probably not the best place to have this discussion, sorry for de-railing! I suppose we can chat in #621 if there is any follow-up, instead.

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.

Replace [[offset]] with [[span]]?

4 participants