Add buffer_view language feature by alan-baker · Pull Request #6291 · gpuweb/gpuweb · GitHub
Skip to content

Add buffer_view language feature#6291

Open
alan-baker wants to merge 8 commits into
gpuweb:mainfrom
alan-baker:buffer-view-spec
Open

Add buffer_view language feature#6291
alan-baker wants to merge 8 commits into
gpuweb:mainfrom
alan-baker:buffer-view-spec

Conversation

@alan-baker

Copy link
Copy Markdown
Contributor
  • API and WGSL changes to support buffer_view

@alan-baker

Copy link
Copy Markdown
Contributor Author

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (e4bdbd4):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

Comment thread wgsl/index.bs
Comment thread wgsl/index.bs Outdated

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

very nice, careful work!

i have a bunch of refinements below, and also updates to other parts of the spec

14.4.5

"The storage and uniform address spaces have different buffer layout constraints which are described in this section."

Replace "buffer" with "memory" ?? Or delete "buffer" entirely?

14.4

"AlignOf(T) is the alignment of T", when T is not a a buffer type.

14.4 AccessibleBytes

AccessibleBytes(T) is not defined otherwise. (other than the listed cases)

14.4.1 Alignment and size.

"Each host-shareable or fixed footprint data type T has an alignment and size."

Suggest splitting cases, to make the exception clear:

Each host-shareable or fixed footprint type has a size.

Except for [=buffer=] types, each host-shareable or fixed footprint type has an alignment.

14.4.4 Internal layout of values.

"These layouts depend on the value’s type, and the align and size attributes on structure members."

Append. "These rule apply to non-opaque types as described below; values of [=buffer=] type do not
have an internal structure, and are not contrained by these rules."

interaction with "valid pointer"

bufferView, bufferArrayView built-ins yield invalid pointer if the original pointer is invalid.
Is that possible?

What does bufferLength return on an invalid pointer? (Is that even possible after type checking?)

6.5.8

"A pointer value is formed in one of the following ways"

  • add a case for bufferView

6.5.4

"a bufferView or bufferArrayView built-in function requires a larger size than the buffer’s memory view contains."

The "requires a larger size" is confusing?

This rule belongs in a new set of paragraphs for how to make an invalid pointer rather than invalid reference.

Suggest?:

An invalid pointer is formed by:

  • Applying the address-of operator (&) to an invalid memory reference.
  • Calling the bufferView or bufferArrayView built-in functions, but the memory view of
    the resulting pointer would otherwise include memory locations outside the memory view of the
    pointer argument.

Comment thread spec/index.bs Outdated
Comment thread spec/index.bs Outdated
Comment thread wgsl/index.bs
Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs
Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs Outdated
* API and WGSL changes to support buffer_view
@alan-baker

Copy link
Copy Markdown
Contributor Author

bufferView, bufferArrayView built-ins yield invalid pointer if the original pointer is invalid.
Is that possible?

Given the API validation around minimum binding size, I don't believe there can ever be an invalid buffer pointer.

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thanks!

Two typos.

Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs
Comment thread wgsl/index.bs Outdated
Comment thread wgsl/index.bs
Comment thread wgsl/index.bs Outdated
@jimblandy

Copy link
Copy Markdown
Contributor
minutes from WGSL committee meeting 2026-6-23

@jimblandy jimblandy added this to WGSL Jun 23, 2026
@jimblandy jimblandy moved this to Waiting for PR approval in WGSL Jun 23, 2026
alan-baker and others added 2 commits June 23, 2026 15:44
Co-authored-by: Jim Blandy <jimb@red-bean.com>
Comment thread spec/index.bs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this use the size parameter only if the parameter is an override expression?
That's the only time validation-time has a value for it.

And spelling it out, if size is a runtime value then still use MinTypeSize.

I think that's right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably this could be simplifed to use MinTypeSize always. Clamping would be possible if we guarantee at least 1 array element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting for PR approval

Development

Successfully merging this pull request may close these issues.

5 participants