-
Notifications
You must be signed in to change notification settings - Fork 329
Closed
Labels
uniformityIssues / discussions around uniformity analysisIssues / discussions around uniformity analysiswgslWebGPU Shading Language IssuesWebGPU Shading Language Issues
Milestone
Description
As discussed in the February VF2F, WGSL should get a built-in function workgroupBroadcast
. This would allow users to branch uniformly on reads from storage buffers for example.
Proposal
Workgroup broadcast is a new collective operation (i.e. must be called only in uniform control flow). It would be compute stage only. The function would return a uniform value (i.e. the same value for each invocation in the workgroup). Uniformity analysis would understand the built-in function and consider the result uniform regardless of the uniformity of the input value.
// Returns "value" for linear local invocation index 0 to all workgroup invocations.
fn workgroupBroadcastFirst(value : T) -> T
// Local invocation index 0 loads p and returns the value to all workgroup invocations.
fn workgroupBroadcastFirst(p : ptr<T, S>) -> T
// Possible, generic broadcast. Takes the local invocation index to broadcast (must be const expression).
fn workgroupBroadcast(value : T, linear_id : i32/u32) -> T
fn workgroupBroadcast(p : ptr<T, S>, linear_id : i32/u32) -> T
A possible implementation in pseudo-WGSL would look like:
var<workgroup> wg_storage : T;
fn workgroupBroadcastFirst(p : ptr<T, S>) -> T {
workgroupBarrier();
if (local_invocation_index == 0) {
wg_storage = *p;
}
workgroupBarrier();
return wg_storage;
}
Depending on the underlying implementation the polyfill could be improved to use subgroup broadcasts to reduce workgroup memory reads.
mehmetoguzderinmehmetoguzderin
Metadata
Metadata
Assignees
Labels
uniformityIssues / discussions around uniformity analysisIssues / discussions around uniformity analysiswgslWebGPU Shading Language IssuesWebGPU Shading Language Issues