Repository navigation
Replies: 2 comments
|
Because buffer views are something else in WebGPU, maybe the API should be |
0 replies
|
Let's warn if the offset doesn't comply with the device's requirements during binding, so that we can skip that check in production |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Covers #1612 (dynamic and static offsets for buffers in pipelines) and #2236 (binding sub-regions, writeAt)
Buffer views
TgpuBufferView<TData>: a typed window into a region of a buffer, usable everywhere a buffer is, implementation based on existingmemoryLayoutOfinfrastructure (or raw byte escape-hatch)IO
Views carry the full IO surface (
write,patch,read,clear,copyFrom), scoped to the region. Region writes are nothing new,patchon the parent buffer already works. The actual additions:read()on a region, today reads are whole-buffer only (arguably the most useful one)clear()/copyFrom()on a regionBinding
Bind group entry wherever buffers are accepted, emits
{ buffer, offset, size }(today we always emit{ buffer }). Same for.as('uniform' | 'readonly' | 'mutable')fixed usages.Count change = new view + new bind group, the allocation stays. No destroy/recreate/re-upload
Vertex and index buffers
setVertexBuffer/setIndexBuffer/ pipeline.with(vertexLayout, ...)/withIndexBuffertake views, extra offset/size args are view-relative.firstVertex/baseVertexalready do most of the things this enables and better. Views enable some more advanced usage, like when regions of one allocation differ in format:Interop
root.unwrap(view)returns aGPUBufferBindingCaveats:
min*BufferOffsetAlignment. 256 is only the guaranteed max, my phone reports 32. Vertex/index views need 4b, IO doesn't care. We don't really need to validate any of it, WebGPU doesDynamic offsets
Layout opt-in mirrors WebGPU naming:
Offsets are a named record, converted to WebGPU's positional array by binding order internally. Keys are enforced exactly at the type level, and the parameter is required iff the layout has dynamic entries (spec requires the exact count at every setBindGroup, so a dynamic bind group can never be set without offsets):
unwrap(layout)emitshasDynamicOffsetand, for dynamic entries,minBindingSizefrom the schema, so out-of-range offsets fail at setBindGroup instead of draw.Example: 256-stride slot arena (stride falls out of the schema), one slot-sized view, one bind group, offsets pick the slot per draw:
Note the arena buffer itself never typechecks against the
Transformentry, the slot-sized view is what makes it legalLimitations:
hasDynamicOffset: falseis not a thing, the property istrueor absentAll reactions