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

[WebGPU] Control Access Barriers #28525

Closed
cmhhelgeson opened this issue May 29, 2024 · 4 comments
Closed

[WebGPU] Control Access Barriers #28525

cmhhelgeson opened this issue May 29, 2024 · 4 comments
Labels
Milestone

Comments

@cmhhelgeson
Copy link
Contributor

Description

At some point, I think it would be great to have the ability to set control access barriers and access more of the WGSL specific functionality within a TSL function. I've tried implementing some of these access barriers myself in a personal branch, using an approach similar to that of the 'vec2', 'vec3', 'etc' ConvertTypes in ShaderNode.js. However, it seems like the node system is heavily weighted towards nodes that explicitly represent some kind of mathematical operation, so, at least from my end, it's not as simple as just adding another node type.

Solution

export const workgroupBarrier = new BarrierType('workgroup');

And then be accessed from a tslFn like so...

tslFn( () => {
	...
	workgroupBarrier()
	...
})

I'm not sure if there's currently a relevant use case for these barriers, but once subgroups become stable, I imagine commands like workgroupBarrier() or subgroupBarrier() would be very useful for things like prefix sums for spatial hash grids.

Alternatives

No response

Additional context

No response

@sunag
Copy link
Collaborator

sunag commented May 29, 2024

I think the code below can work for a tslFn() using as your example?

export const workgroupBarrier = () => expression( 'workgroupBarrier()' ).append();

@Mugen87 Mugen87 added the WebGPU label May 30, 2024
@skywolf829
Copy link

Also posting to see if barriers are possible for subsets of the compute shader? I.e. workers in a smaller workgroup subset all wait at a barrier together, but don't wait for other subsets. Ex:

tslFn( () => {
	const workgroup_idx = instanceIndex.mod(4); // 4 workers per group
        ...
	workgroupBarrier(workgroup_idx); // Only waits for the (4) workers in this group
	...
});

@cmhhelgeson
Copy link
Contributor Author

The workgroupBarrier() function does not take any arguments. As far as I know, there's also no way to directly specify the size of a subgroup in current implementations of WebGPU.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 10, 2025

I think the feature request has been implemented via #29192 🎉 .

@Mugen87 Mugen87 closed this as completed Feb 10, 2025
@Mugen87 Mugen87 added this to the r174 milestone Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants