Sitelet https://github.com/gpuweb/gpuweb/issues/2586
Skip to content

Workgroup Broadcast #2586

Description

@alan-baker

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    uniformityIssues / discussions around uniformity analysiswgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions