Repository navigation
WGSL: describe memory layout rules for buffers - #1215
Conversation
| <tr><td><dfn noexport>`stride`</dfn> | ||
| <td>positive i32 literal | ||
| <td>Applied to an array type.<br> | ||
| The number of bytes between successive elements of the array, |
There was a problem hiding this comment.
At first reading, I take this to mean the space between the elements, not element + space. The number of bytes from the start of one element to the start of the next element of the array?
| The memory layout of a type is significant only when referring to a value in those storage classes. | ||
| This affects evaluation of a variable in one of those storage classes, or of a pointer into one of those storage classes. | ||
| This affects evaluation of a variable in one of those storage classes, | ||
| or of a pointer expression pointing into one of those storage classes. |
There was a problem hiding this comment.
What is the 'This' in this sentence, the buffer variable?
This sentence has too many one of those storage classes.
There was a problem hiding this comment.
Replacing those last two sentences with:
The memory layout of a type is significant only when evaluating an expression with:
- a variable in the uniform or storage storage class, or
- a pointer into the uniform or storage storage class.
| not support the `scalarBlockLayout` feature. | ||
| Therefore, a data value must not be placed in the padding at the end of a structure or matrix, | ||
| nor in the padding at the last element of an array. | ||
| Counting the such padding as part of the allocation extent allows [SHORTNAME] to capture this constraint. |
There was a problem hiding this comment.
nit: Counting the padding or Counting such padding
| </table> | ||
|
|
||
| If |B| is a [=uniform buffer=] variable in a resource interface, | ||
| and |WB| is the WebGPU GPUBuffer bound to |B|, then: |
There was a problem hiding this comment.
Can we link WebGPU GPUBuffer back to the spec?
41555bd to
9603cf6
Compare
|
Rebased, and added 9603cf to reply to most of @dj2's feedback. |
9603cf6 to
5b29556
Compare
|
The parent PR was updated, so I rebased again. |
|
Discussed at 2020-11-17 meeting. |
|
From the meeting:
|
5b29556 to
c8b8764
Compare
|
Hey @kvark please take a look. |
kvark
left a comment
There was a problem hiding this comment.
This is some grand work, thank you for writing it down!
| the host and the GPU, or copied between host and GPU without format translation. | ||
| When used for this purpose, the type must be additionally decorated with layout attributes | ||
| as described in [[#memory-layouts]]. | ||
| In particular, any variable using the `uniform` or `storage` [=storage classes=] must have |
There was a problem hiding this comment.
Are there any other types that need to be host-shareable? If not, then "In particular" sounds a bit misleading. Perhaps, we should more precise.
There was a problem hiding this comment.
This is here to provide context. Really it's a forward reference.
I will change to:
We will see in [[#module-scope-variables]] that the [=store type=] of [=uniform buffer=] and [=storage buffer=]
variables must be host-shareable.
| <td>Applied to a member of a structure type.<br> | ||
| The number of bytes between the start of the structure and the location | ||
| of this member, when a value of this structure is stored in the | ||
| `uniform` or `storage` [=storage classes=]. |
There was a problem hiding this comment.
is this necessary? We are describing the attributes of host-shareable types, so the fact about uniform/storage is specified/implied at the higher level
There was a problem hiding this comment.
Sure. Will remove for both 'stride' and 'offset'.
| See [[#resource-layout-compatibility]]. | ||
|
|
||
| Compared to OpenGL: | ||
| * OpenGL `std140` layout satisfies [SHORTNAME] [=uniform buffer layout=]. |
There was a problem hiding this comment.
is it "satisfies", or is it "exactly matches"?
There was a problem hiding this comment.
Satisfies. WGSL uniform buffer layout can give strides and offsets that are multiples of the ones specified by std140.
Example:
uint arr[3]; // will have stride of 16 in std140.
But
[[stride(32)]] array<u32,3>; // This is perfectly fine to use inside a uniform buffer in WGSL
There was a problem hiding this comment.
Can we instead say something like
For any type |S|, the tightest offset and stride assignments would exactly match both [SHORTNAME] [=uniform buffer layout=] and
std140
There was a problem hiding this comment.
How about:
- For any type |S|, OpenGL std140 layout is the same as using the tightest offset and stride assignments in [SHORTNAME] [=uniform buffer layout=].
There was a problem hiding this comment.
Or remove the quantification by |S|:
- For any type, OpenGL
std140layout is the same as using the tightest offset and stride assignments in WGSL [=uniform buffer layout=].
| = |k| × <var ignore>Align</var>(|T|<sub>|i|</sub>,<var ignore>C</var>), | ||
| for some non-negative integer |k| | ||
| </p> | ||
| * For the `uniform` storage class, members are aligned to 16 byte boundaries: |
There was a problem hiding this comment.
Oof. I think this is wrong. Will remove it.
| <td>Applied to a member of a structure type.<br> | ||
| The number of bytes between the start of the structure and the location | ||
| of this member, when a value of this structure is stored in the | ||
| `uniform` or `storage` [=storage classes=]. |
There was a problem hiding this comment.
Sure. Will remove for both 'stride' and 'offset'.
| the host and the GPU, or copied between host and GPU without format translation. | ||
| When used for this purpose, the type must be additionally decorated with layout attributes | ||
| as described in [[#memory-layouts]]. | ||
| In particular, any variable using the `uniform` or `storage` [=storage classes=] must have |
There was a problem hiding this comment.
This is here to provide context. Really it's a forward reference.
I will change to:
We will see in [[#module-scope-variables]] that the [=store type=] of [=uniform buffer=] and [=storage buffer=]
variables must be host-shareable.
| See [[#resource-layout-compatibility]]. | ||
|
|
||
| Compared to OpenGL: | ||
| * OpenGL `std140` layout satisfies [SHORTNAME] [=uniform buffer layout=]. |
- define 'block' attribute on structure type - text from 'uniform' and 'storage' rows of storage classes table out to resource interface section - define 'set' and 'binding' attribute on structure type - relate resources in WGSL to WebGPU GPUBindingType - Add notations for floor, ceiling, roundUp - define 'stride' and 'offset' attributes - describe byte-by-byte layout of values, based on storage class, and stride and offset - describe constraints on stride and offset, yielding 'uniform buffer layout' and 'storage buffer layout' - Fix alignment of structure in uniform storage class - Uniform buffer layout: 16byte alignment of array elements, and of struct * Clarify array stride as counting from the start of one element to the start of the next * Simplify description of when layout applies, using bullet points. * Remove stray "the" * Add crossreference for WebGPU GPUBuffer * Add internal links to runtime-sized Add notes about relation to OpenGL and Vulkan layout Even in uniform buffers, struct members aren't automatically aligned to 16 Simplify description of stride and offset Clarify forward reference of uniform/storage buffer variables as host-shareable Fix one WGSL -> [SHORTNAME] Clarify that a type can be used in both uniform and storage storage classes
254c2ea to
bf32d5f
Compare
|
Resolved @kvark's issue with std140, std430 (I hope). Then I rebased against main, and fixed up the cross-references for storage classes as mentioned in the new text. |
…uweb#1215) instead of `;`. Spec change: gpuweb#2656
This builds on #1214 (describe resource interface of a shader)
WGSL: describe memory layout rules for buffers