Subgroups proposal: Consider subgroup_size used in compute stage uniform by jiangzhaoming · Pull Request #4652 · gpuweb/gpuweb · GitHub
Skip to content

Subgroups proposal: Consider subgroup_size used in compute stage uniform#4652

Merged
jiangzhaoming merged 1 commit into
gpuweb:mainfrom
jiangzhaoming:SubgroupSizeUniform
May 27, 2024
Merged

Subgroups proposal: Consider subgroup_size used in compute stage uniform#4652
jiangzhaoming merged 1 commit into
gpuweb:mainfrom
jiangzhaoming:SubgroupSizeUniform

Conversation

@jiangzhaoming

Copy link
Copy Markdown
Contributor

Currently only workgroup_id and num_workgroups built-in values are considered uniform according to spec.

Treating subgroup_size as uniform may help writing flexible kernel that fit to different actual subgroup size, and allow using functions like workgroupBarrier and subgroupBroadcast (if requiring that the subgroup operations only be used in uniform control flow) under condition of subgroup size, like

    if (subgroupSize == 16) {
        ...
        workgroupBarrier();
        let a0 = subgroupBroadcast(a[0], 0u);
        ...
    } else {
        // Fall back path
        ...
    }

The Vulkan spec, in SubgroupSize of 15.9. Built-In Variables section, required that

The value may vary across a single draw call, and for fragment shaders may vary across a single primitive. In compute dispatches, SubgroupSize must be uniform with command scope.

I don't find explicit requirement in MSL/HLSL spec, but I think they should work in the same way for compute kernel.

subgroup_size built-in variable should be considered uniform for uniformity analysis when used in compute stage uniform.
@github-actions

Copy link
Copy Markdown
Contributor

@kainino0x kainino0x added the wgsl WebGPU Shading Language Issues label May 21, 2024

@alan-baker alan-baker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense to me.

@jiangzhaoming

Copy link
Copy Markdown
Contributor Author

@jiangzhaoming jiangzhaoming merged commit 0bfb5ca into gpuweb:main May 27, 2024
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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants