Skip to content

Conversation

@dneto0
Copy link
Contributor

@dneto0 dneto0 commented May 17, 2021

  • Delete 'access' as an attribute.
  • Add "Memory Access Mode" section
  • Storage classes table gets a "Supported access modes" and "Default
    access mode"
    NOTE: This is the minimally flexible set of options; only 'storage'
    has any flexibility.
  • Add "Access Modes Defaults" section, among "Memory View Types"
  • Each memory view has an access mode.
  • Access modes are inherited by most reference-handling operations.
  • LHS of assignment must be write or read-write
  • Load Rule applies only if the reference is read or read-write.
  • Storage texture types are parameterized by 'read' or 'write' access
    mode.
  • Formal parameters that are pointers must match in access type with
    the call site's pointer argument.
  • Fix the description of modf and frexp to properly parameterize
    the pointer types.

Fixes: #1604

@dneto0 dneto0 added the wgsl resolved Resolved - waiting for a change to the WGSL specification label May 17, 2021
@dneto0 dneto0 added this to the MVP milestone May 17, 2021
@dneto0 dneto0 requested review from alan-baker, kvark and litherum May 17, 2021 21:55
@dneto0
Copy link
Contributor Author

dneto0 commented May 17, 2021

Note: With this PR, the storage classes have minimum flexibility. Only the 'storage' storage class allows more than one access mode. (You can't create a read-only variable in function storage class, for example. )

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (3f71d6b):
WebGPU | IDL
WGSL
Explainer

@dneto0 dneto0 added wgsl WebGPU Shading Language Issues wgsl resolved Resolved - waiting for a change to the WGSL specification and removed wgsl resolved Resolved - waiting for a change to the WGSL specification labels May 17, 2021
Copy link
Contributor

@alan-baker alan-baker left a comment

Choose a reason for hiding this comment

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

I would merge both access modes into a single grammar.

// 'ptr<function,i32>' is the type of a pointer value that references storage
// for keeping an 'i32' value, using memory locations in the 'function' storage
// class. Here 'i32' is the pointee type.
// 'ptr<function,i32,read_write>' is the type of a pointer value that references
Copy link
Contributor

Choose a reason for hiding this comment

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

are we forced to write read_write for all the pointers with this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Only for storage buffers. Line 1806 effectively says if there is only one valid mode, then that is the default and it must not be specified. So this comment is for exposition only as it is invalid WGSL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With type inference for let-declarations, you never have to write this pointer type. (At least while pointer-to-storage is disallowed as in the baseline. And afterward you only need to write it for formal parameter declaration.)

Copy link
Contributor

Choose a reason for hiding this comment

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

This just mentions ptr<function,i32,read_write>, which confused me. Is this a valid type to write, given that the access should only be seen on storage and workgroup classes?

textureLoad(t: [[access(read)]] texture_storage_2d<F>, coords: vec2<i32>) -> vec4<T>
textureLoad(t: [[access(read)]] texture_storage_2d_array<F>, coords: vec2<i32>, array_index: i32) -> vec4<T>
textureLoad(t: [[access(read)]] texture_storage_3d<F>, coords: vec3<i32>) -> vec4<T>
textureLoad(t: texture_storage_1d<F,read>, coords: i32) -> vec4<T>
Copy link
Contributor

Choose a reason for hiding this comment

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

what's going to happen with read-write textures? are we going to provide overloads for read-write for all of the builtin functions on storage textures?

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the proposal for coercing read_write pointers to read pointers, we could do the same thing with textures when read_write textures are added to WGSL. Or, yes, we could just provide overloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say we add overloads for read_write. We don't need to add coercion for this.

@dneto0
Copy link
Contributor Author

dneto0 commented May 19, 2021

I've addressed actionable feedback. PTAL.

dneto0 added 4 commits May 21, 2021 16:22
- Delete 'access' as an attribute.
- Add "Memory Access Mode" section
- Storage classes table gets a "Supported access modes" and "Default
  access mode"
   NOTE: This is the minimally flexible set of options; only 'storage'
   has any flexibility.
- Add "Access Modes Defaults" section, among "Memory View Types"
- Each memory view has an access mode.
- Access modes are inherited by most reference-handling operations.
- LHS of assignment must be write or read-write
- Load Rule applies only if the reference is read or read-write.
- Storage texture types are parameterized by 'read' or 'write' access
  mode.
- Formal parameters that are pointers must match in access type with
  the call site's pointer argument.
- Fix the description of modf and frexp to properly parameterize
  the pointer types.

Fixes: gpuweb#1604
Mark 'read' as the default in the 'storage' row.

The default-ness is already fully explained in its own
section 'Memory Access Defaults'.
Instead of storage_textures_access and variable_access_mode,
use a single access_mode and rely on external validation
to catch the invalid combinations.
Move the grammar rule to the "Memory Access Mode" section.
@dneto0 dneto0 force-pushed the access-attribute branch from 08e6178 to 3e4dfcd Compare May 21, 2021 20:23
@dneto0
Copy link
Contributor Author

dneto0 commented May 21, 2021

Rebased and resolved conflicts. PTAL

Copy link
Contributor

@kvark kvark left a comment

Choose a reason for hiding this comment

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

If I have a pointer, do I need to specify the storage access with this PR?

  1. always
  2. only for storage and workgroup classes

// 'ptr<function,i32>' is the type of a pointer value that references storage
// for keeping an 'i32' value, using memory locations in the 'function' storage
// class. Here 'i32' is the pointee type.
// 'ptr<function,i32,read_write>' is the type of a pointer value that references
Copy link
Contributor

Choose a reason for hiding this comment

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

This just mentions ptr<function,i32,read_write>, which confused me. Is this a valid type to write, given that the access should only be seen on storage and workgroup classes?

@dneto0
Copy link
Contributor Author

dneto0 commented May 26, 2021

If I have a pointer, do I need to specify the storage access with this PR?

  1. always
  2. only for storage and workgroup classes

(Edit to fix the answer.)

Only for storage storage class. The comments in this PR show the fully elaborated type for analysis, but not for spelling it in the shader source. I'll call that out explicitly after defining the ref and ptr types.

@dneto0
Copy link
Contributor Author

dneto0 commented May 27, 2021

Checked again with @kvark, acceptable to merge.

@dneto0 dneto0 merged commit 7da3482 into gpuweb:main May 27, 2021
github-actions bot added a commit that referenced this pull request May 27, 2021
SHA: 7da3482
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request May 27, 2021
SHA: 7da3482
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request May 27, 2021
SHA: 7da3482
Reason: push, by @dneto0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@kdashg
Copy link
Contributor

kdashg commented Jun 1, 2021

WGSL meeting minutes 2021-05-25
  • (wgsl: access mode is no longer an attribute)
  • (Had one round of review, and addressed.)
  • (Can we land this?)
  • DM: When do we specify access quals for pointers. Spec has it for function. I will follow up offline.

ben-clayton added a commit to ben-clayton/webgpu-samples that referenced this pull request Jun 11, 2021
Remove access control decorations.
See gpuweb/gpuweb#1735

arrayLength() now takes a pointer to the array.
See gpuweb/gpuweb#1619
austinEng pushed a commit to webgpu/webgpu-samples that referenced this pull request Jun 11, 2021
Remove access control decorations.
See gpuweb/gpuweb#1735

arrayLength() now takes a pointer to the array.
See gpuweb/gpuweb#1619
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wgsl resolved Resolved - waiting for a change to the WGSL specification wgsl WebGPU Shading Language Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

consider pulling 'access' into the type of a pointer/reference

4 participants