Skip to content

Expose pipeline constants to materials#24502

Open
Visse wants to merge 3 commits into
bevyengine:mainfrom
Visse:expose-pipeline-constants
Open

Expose pipeline constants to materials#24502
Visse wants to merge 3 commits into
bevyengine:mainfrom
Visse:expose-pipeline-constants

Conversation

@Visse
Copy link
Copy Markdown

@Visse Visse commented May 31, 2026

Objective

Allow materials to use pipeline constants (pipeline-overridable constants).
They are already available in wgpu, but bevy didn't expose them.

Solution

Expose constants in RenderPipelineDescriptor & ComputePipelineDescriptor, allowing materials to specify them in their specilize function.

Note: I had to remove the Eq derive from ComputePipelineDescriptor, VertexState and FragmentState, due to the new f64 field. It was already a bit inconsistent with RenderPipelineDescriptor not having it.

Testing

  • Ran cargo check
  • Created an example & ran it
  • Couldn't run cargo test due to it taking looots of disk space to run, but I have a hard time seeing it break something at runtime

Showcase

See the added example, where pipeline constants are used to change the LEVELS override in WGSL.
Screenshot from 2026-05-31 09-46-05

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

Comment thread crates/bevy_material/src/descriptor.rs Outdated
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 31, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering May 31, 2026
@alice-i-cecile alice-i-cecile added the X-Uncontroversial This work is generally agreed upon label May 31, 2026
@coreh
Copy link
Copy Markdown
Contributor

coreh commented Jun 1, 2026

Is this restricted to just f64 -> f32? Is the f64 there because the WebGPU is made with JS in mind? Is there some sort of internal conversion for other types?

Could we expose some sort of PipelineConstant newtype so you could pass other types, or would that be too silly since they will be coerced to f64 behind the scenes anyway?

@beicause
Copy link
Copy Markdown
Member

beicause commented Jun 1, 2026

Is this restricted to just f64 -> f32? Is the f64 there because the WebGPU is made with JS in mind? Is there some sort of internal conversion for other types?

Could we expose some sort of PipelineConstant newtype so you could pass other types, or would that be too silly since they will be coerced to f64 behind the scenes anyway?

It is f64 like LoadOp::Clear values.The conversion rule is https://gpuweb.github.io/gpuweb/#conversions-to-wgsl

Copy link
Copy Markdown
Member

@beicause beicause left a comment

Choose a reason for hiding this comment

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

Some unnecessary cloning, although it's not big deal since these constants are empty.

Comment thread crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs Outdated
Comment thread crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs Outdated
Comment thread crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs Outdated
Comment thread crates/bevy_pbr/src/meshlet/pipelines.rs Outdated
Comment thread crates/bevy_pbr/src/meshlet/material_pipeline_prepare.rs
Visse added 3 commits June 2, 2026 23:07
Removed Eq derive from VertexState, FragmentState and ComputePipelineDescriptor
as f64 does not implement it.
@Visse Visse force-pushed the expose-pipeline-constants branch from 85c718a to abfe4a7 Compare June 2, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

4 participants