Skip to content

Bring immediate in line with webgpu spec - #9280

Merged
cwfitzgerald merged 11 commits into
gfx-rs:trunkfrom
atlv24:ad/immediates
Apr 9, 2026
Merged

Bring immediate in line with webgpu spec#9280
cwfitzgerald merged 11 commits into
gfx-rs:trunkfrom
atlv24:ad/immediates

Conversation

@atlv24

@atlv24 atlv24 commented Mar 21, 2026

Copy link
Copy Markdown
Collaborator

Connections
ticks boxes in #8556

Description
Brings immediate validation in line with webgpu spec. Bitmask of immediate slots required for a pipeline, tracks slot writing, removes auto-zeroing, and infers immediate_size for auto pipline layouts

Testing
Theres some tests on the slot bitmask algorithm and some validation tests for set_immediates behavior

Squash or Rebase?

squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@cwfitzgerald cwfitzgerald self-assigned this Mar 23, 2026
@teoxoy

teoxoy commented Mar 23, 2026

Copy link
Copy Markdown
Member

We should probably use a u64 for the bitmask to support at most 256bytes given that's the most almost all Vulkan devices support (https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxPushConstantsSize&platform=all). We also need to cap the max_immediate_size returned by adapters to 256 (in adjust_raw_limits).

@jimblandy jimblandy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this should block landing this, but:

The way this determines immediate_slots_required is not per spec. You need to look at the entry point(s) the pipeline uses, and see which specific fields of the var<immediate> type those entry points and their callees actually touch.

Getting this right will require a new bitmask field in naga::valid::FunctionInfo that gets populated probably by FunctionInfo::process_expression and process_block, and then consulted by wgpu_core.

fn required_limits() -> wgpu::Limits {
wgpu::Limits {
max_immediate_size: 16,
max_immediate_size: 12,

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.

Does this PR fix #4682 (which IIRC is the reason for this)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Maybe! I don't know.

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.

CC @Lichtso & @LPGhatguy since you know how to repro this issue (I personally couldn't).

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.

It only happens on metal with the validation layer on.

@cwfitzgerald cwfitzgerald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this!

A few miscellaneous comments. I think unless you feel really strongly, we should do the move to naga's FunctionInfo first, as it will need to be done no matter what once we hook up the CTS, and means you won't need to churn on this code for the stuff that is going to be replaced anyway.

Comment thread wgpu-core/src/command/bundle.rs Outdated
Comment thread wgpu-core/src/command/compute.rs Outdated
@atlv24
atlv24 force-pushed the ad/immediates branch 2 times, most recently from 0bb654a to a53d7ea Compare April 2, 2026 06:02

@cwfitzgerald cwfitzgerald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some small things, then g2g.

Comment thread naga/src/valid/immediates.rs Outdated
Comment thread naga/src/valid/immediates.rs
@atlv24

atlv24 commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto latest trunk due to merge conflicts, the only new changes are the last "feedback" comment

@cwfitzgerald
cwfitzgerald enabled auto-merge (squash) April 9, 2026 22:23
@cwfitzgerald

Copy link
Copy Markdown
Member

Thanks for spelling the commit situation out it really helps!

@cwfitzgerald
cwfitzgerald merged commit e6e5f52 into gfx-rs:trunk Apr 9, 2026
59 checks passed
@atlv24
atlv24 deleted the ad/immediates branch April 14, 2026 21:15
slyedoc pushed a commit to slyedoc/wgpu that referenced this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants