Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workgroupBarrier to WGSL #1449

Merged
merged 5 commits into from
Mar 16, 2021
Merged

Add workgroupBarrier to WGSL #1449

merged 5 commits into from
Mar 16, 2021

Conversation

alan-baker
Copy link
Contributor

Fixes #1374

  • Adds workgroupBarrier as a control barrier templated on affected
    storage classes
  • Modifies func_call_statement grammar to allow limited templates

Fixes gpuweb#1374

* Adds workgroupBarrier as a control barrier templated on affected
  storage classes
* Modifies func_call_statement grammar to allow limited templates
@github-actions
Copy link
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
cf9d260

@github-actions
Copy link
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
6b317d8

wgsl/index.bs Outdated Show resolved Hide resolved
wgsl/index.bs Outdated
atomic operation program ordered after the workgroupBarrier is executed by a
member of the workgroup.

A memory, atomic or workgroupBarrier operation is an afftected operation if it
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a description of what a "memory" operation is? I.e. is loading from a storage texture a memory operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If read_write textures are eventually added, then barriers would need to be updated to allow the handle storage class, and yes, would be considered memory operations. To me, the right place to describe memory operations would be in the memory model section which is still TODO; however, we could say that memory operations are a read or write to a variable (or through a pointer) in an affected storage class if that is preferable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hold on. So today without read/write textures, if I do two different textureStore operations, there are no barriers I could use to ensure that one is done after the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Metal doesn't add image barriers widely until Metal 2.0 so I didn't want to force that requirement on WGSL. I think that without read_write textures, the problem you describe isn't that relevant. It would mean you're overwriting the same pixel from multiple invocations without any interim reads. I don't think that's the common case.

I'd be happy to add texture coverage if we knew only Metal 2.0 or later was being targeted with WGSL.

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 we are to add "handle" here, then it will be only place in the grammar where "handle" is recognized, which is somewhat strange/inelegant. We'll need to eithe:

  • consider handle storage class being optional on textures/samplers (to make the spec consistent)
  • switch this workgroupBarrier to not work with the storage classes directly but instead have another way of specifying the mask, i.e. it could be even something as:
struct MemoryBarrier {
  storage: bool,
  handle: bool,
  workgroup: bool,
};
fn workgroupBarrier(barrier: MemoryBarrier) {..}

I think there is still value in trying to keep the existing grammar rules for this operation rather than inventing an entirely new syntax...

@alan-baker
Copy link
Contributor Author

I'm happy to iterate on barriers if there is a better alternative syntax. I personally don't want pre-defined structs. Constexprs would be ideal, but even without them we could potentially require literal u32 value that acted as a bitmask.

@kdashg kdashg added this to Needs Action in WGSL Feb 23, 2021
* Remove templated function and replace with two control barriers
  * workgroupBarrier - affects memory and atomics in workgroup
  * storageBarrier - affects memory and atomics in storage
  * both barriers synchroize with each other
@github-actions
Copy link
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
6e0d1f2

@alan-baker
Copy link
Contributor Author

The latest commit implements the changes discussed in the VF2F 2021-02-23 (my commit message has the wrong date).

@kainino0x kainino0x added the wgsl WebGPU Shading Language Issues label Mar 8, 2021
wgsl/index.bs Outdated Show resolved Hide resolved
memory ordering. That is, all synchronization functions, and affected memory
and atomic operations are ordered in [[#program-order]] relative to the
synchronization function. Additionally, the affected memory and atomic
operations program-ordered before the synchronization function must be visible
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll followup with a rewording for editorial purposes.

@dneto0 dneto0 merged commit 866b700 into gpuweb:main Mar 16, 2021
WGSL automation moved this from Needs Action to Done Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wgsl WebGPU Shading Language Issues
Projects
WGSL
Done
Development

Successfully merging this pull request may close these issues.

Barriers proposal
4 participants