Skip to content

Add pub const fn default() for various types. - #9929

Merged
ErichDonGubler merged 2 commits into
gfx-rs:trunkfrom
kpreid:const
Aug 3, 2026
Merged

Add pub const fn default() for various types.#9929
ErichDonGubler merged 2 commits into
gfx-rs:trunkfrom
kpreid:const

Conversation

@kpreid

@kpreid kpreid commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Connections
Fixes #9923.

Description
Allows use of wgpu’s provided default values for its types in dependents’ constant evaluation.

  • The default functions are generated using a macro_rules_attribute emulated derive macro, just fancy enough to work. It does not support structs with generics, so *Descriptors are left alone for now.

    • When Rust const traits stabilize, we can replace this with real const traits.
    • The new trait ConstDefaultHelper is not part of the public API.
  • Separately, ForceShaderModelToken::{with_shader_model, get} are now const fn.

  • DxcShaderModel now implements Copy.

Testing
Existing tests pass. But perhaps we should also add a test or doctest showing that this constant works. Where?

Squash or Rebase?
Rebase

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

@kpreid
kpreid force-pushed the const branch 3 times, most recently from cf6d79b to ddae7ac Compare July 22, 2026 19:42

@ErichDonGubler ErichDonGubler 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.

This broadly LGTM, and does what it says it does. Just want to ping at least one other @gfx-rs/wgpu member for their thoughts/approval before we merge this API addition (which I don't want to wait longer than a couple of days for, unless you feel strongly, @kpreid).

Comment thread wgpu-types/src/render.rs
Comment thread wgpu-types/src/render.rs
Comment thread wgpu-types/src/macros.rs
Comment thread wgpu-types/src/macros.rs Outdated
Comment thread wgpu-types/src/macros.rs
Comment thread wgpu-hal/src/dx12/shader_compilation.rs
@ErichDonGubler ErichDonGubler added type: enhancement New feature or request area: api Issues related to API surface labels Jul 30, 2026
Comment thread wgpu-types/src/macros.rs

@ErichDonGubler ErichDonGubler 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.

:shipit:

@ErichDonGubler

Copy link
Copy Markdown
Member

Leaving unmerged in case the latest feedback made you want to edit something. Otherwise: fire when ready!

@kpreid

kpreid commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 1 doc edit. Should be good to merge now.

kpreid added 2 commits August 3, 2026 12:11
The default functions are generated using a `macro_rules_attribute`
emulated derive macro, just fancy enough to work. It does not support
structs with generics, so `*Descriptor`s are left alone for now.

When Rust const traits stabilize, we can replace this with real const
traits.
@ErichDonGubler

Copy link
Copy Markdown
Member

Rebased with resolved conflicts in the CHANGELOG. Merging.

@ErichDonGubler
ErichDonGubler enabled auto-merge (rebase) August 3, 2026 10:11
@ErichDonGubler
ErichDonGubler merged commit 9f5c71f into gfx-rs:trunk Aug 3, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: api Issues related to API surface type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Const support for configuration types

2 participants