In #2999 and #2505 it was decided that author-provided alignments in WGSL shaders do not incur alignment restrictions on the buffer binding attached to the shader. However, for performance reasons, a shader author may want to guarantee the physical alignment of a WGSL buffer access (constraint 2 in https://github.com/gpuweb/gpuweb/issues/2999#issuecomment-1148913857). @dneto0 describes some examples:
I pointed out that a system author can have a legitimate desire to constrain the divisor on the machine address that goes beyond things known by a WebGPU implementation about primitive shader data types:
E.g. system cache line size (want to avoid false sharing)
E.g. system page size
E.g. interfacing with an external accelerator (e.g. DMA, another hardware block)
In order to guarantee the physical alignment of a WGSL load, we need to guarantee the physical alignment of a binding, that is, the (physical address of the GPUBuffer + static offset + dynamic offset) must be aligned. All of this is currently in the control of the author except for the alignment of the GPUBuffer, but we also don't provide any help with maintaining the guarantee.
Some rough options follow. Please point out if anything doesn't make sense.
Decision A: Alignment of GPUBuffers
Add an alignment to GPUBufferDescriptor.
If there is some smallish maximum alignment that an application "would ever" need, say 1024, we could simply always align GPUBuffer allocations to this alignment. I don't understand the requirements fully enough to know if this is an option.
Decision B: Alignment of bindings
Add no extra validation for this. Applications must simply "get it right" so their loads are aligned the way they want.
Add a new GPUBufferBindingLayout.alignment member. All three of the GPUBuffer alignment, static GPUBufferBinding.offset, and dynamic offset must be multiples of this.
2, plus add a new WGSL attribute like @binding_alignment(1024) @group(0) @binding(0) var<storage> buffer: B;. GPUBufferBindingLayout.alignment must be a multiple of this. Its value is independent of AlignOf(B) (may be smaller or larger).
In #2999 and #2505 it was decided that author-provided alignments in WGSL shaders do not incur alignment restrictions on the buffer binding attached to the shader. However, for performance reasons, a shader author may want to guarantee the physical alignment of a WGSL buffer access (constraint 2 in https://github.com/gpuweb/gpuweb/issues/2999#issuecomment-1148913857). @dneto0 describes some examples:
In order to guarantee the physical alignment of a WGSL load, we need to guarantee the physical alignment of a binding, that is, the (physical address of the GPUBuffer + static offset + dynamic offset) must be aligned. All of this is currently in the control of the author except for the alignment of the GPUBuffer, but we also don't provide any help with maintaining the guarantee.
Some rough options follow. Please point out if anything doesn't make sense.
Decision A: Alignment of
GPUBuffer
salignment
toGPUBufferDescriptor
.Decision B: Alignment of bindings
GPUBufferBindingLayout.alignment
member. All three of theGPUBuffer
alignment, staticGPUBufferBinding.offset
, and dynamic offset must be multiples of this.@binding_alignment(1024) @group(0) @binding(0) var<storage> buffer: B;
.GPUBufferBindingLayout.alignment
must be a multiple of this. Its value is independent ofAlignOf(B)
(may be smaller or larger).Tentatively marking v1 for initial surfacing, but this is a definite candidate for post-v1.