Skip to content

Bring immediate in line with webgpu spec#9280

Open
atlv24 wants to merge 8 commits intogfx-rs:trunkfrom
atlv24:ad/immediates
Open

Bring immediate in line with webgpu spec#9280
atlv24 wants to merge 8 commits intogfx-rs:trunkfrom
atlv24:ad/immediates

Conversation

@atlv24
Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 commented Mar 21, 2026

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?

Either, commits are clean

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
Copy link
Copy Markdown
Member

teoxoy commented Mar 23, 2026

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).

Copy link
Copy Markdown
Member

@jimblandy jimblandy left a comment

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
Member

@cwfitzgerald cwfitzgerald left a comment

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.

texture_memory_init_actions: Vec<TextureInitTrackerAction>,
next_dynamic_offset: usize,
binder: Binder,
immediate_slots_set: u64,
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.

We should document what this is and that it's a bitflags and not a count.

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.

suggestion(optional): Might consider putting this in a wrapper type so you can easily define helper methods on it (and added type safety)

InvalidGroupSize { current: [u32; 3], limit: u32 },
#[error(transparent)]
BindingSizeTooSmall(#[from] LateMinBufferBindingSizeMismatch),
#[error("Not all immediate data slots required by the pipeline have been set (required: 0x{required:016X}, set: 0x{set:016X})")]
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.

This error isn't really going to be very actionable for users. Once we determine we're in the error state, we should build a vector of byte ranges that aren't specified, will be much better UX.

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.

5 participants