Skip to content

d3d12: the two clippy warnings main still has - #2877

Open
fiestorra wants to merge 1 commit into
ProjectLeonida:mainfrom
fiestorra:fix-clippy-leftovers
Open

fiestorra wants to merge 1 commit into
ProjectLeonida:mainfrom
fiestorra:fix-clippy-leftovers

Conversation

@fiestorra

@fiestorra fiestorra commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Reduced to what main still has. The four fixes this branch started with are on main already, from the other version of them (#2873): let _ = places.insert(..), while let in pipeline/known.rs, (0.0..1e9).contains(&v) in glyphs/live.rs, and a struct for mesh_pipeline's shader bytecodes (MeshStages there). That is why the branch had gone DIRTY: it was re-applying what had landed.

What is left, and is only here:

1. The six --all-targets warnings in emit/valu_tests.rs. Clippy wants a != b for a < b || a > b, and in a table of RDNA2's sixteen f32 compare predicates those are not the same function:

a < b || a > b     false with a NaN
a != b             true  with a NaN

The two lints (neg_cmp_op_on_partial_ord, double_comparisons) are allowed on that one test, with the reason in the doc comment above it.

2. unused_mut on send_published's Handoff. What writes it is behind diagnostics, so the parameter loses mut and keeps the binding under that feature:

fn send_published(&self, h: Handoff) {
    #[cfg(feature = "diagnostics")]
    let mut h = h;

Measured on main 1fff69129, before and after:

cargo clippy --workspace                          2 warnings -> 0
cargo clippy --workspace --all-targets           10 warnings -> 0
cargo test -p leonida-shader float_compares_with_nan    1 passed
cargo test -p leonida-gpu --lib -- --test-threads=1   643 passed, 1 failed

The one that fails is descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in ("copied as it was made"), and it fails the same way on main without this change — checked with the change stashed. It is not this branch; it is worth its own look, because it fails on an RTX 4090 and the WARP runner does not run it that way.

With --features diagnostics nothing new appears: the one warning in leonida-gpu/src/host.rs under that feature is at line 4677, not here.

AI-assisted: yes — DeepSeek v4.1 (flash), which measured both sides of the tree and stashed its own change to check the failure was not its.

Written with an AI assistant.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent clean-target Clippy and GPU comparison check at 118118191 + 9f27ba2e1, Rust 1.98.1, Win64 MSVC target. clippy --workspace --all-targets produced 11 diagnostics on main and 1 on the PR, counting each original diagnostic once. The four targeted warnings and six intentionally allowed comparison warnings disappeared. The remaining unused_mut is in host.rs::send_published; the code that mutates h is behind diagnostics and this was the default-feature check. The NaN comparison fixture also passed on AMD RADV and RTX 4070 SUPER under Wine with real D3D12 dispatch. Both lint builds used separate fresh Cargo target directories.

AI-assisted with OpenAI Codex (GPT-6).

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

Checked the clippy claims by running both configurations rather than reading the body:

tree --workspace --workspace --all-targets
PR base 21e6bbf4b 4 10
PR head 118118191 0 0
origin/main 3e7b34a52 5 11
PR merged into today's main (clean merge) 1 1

So the four targeted warnings are genuinely gone, and the behaviour hunks are safe: Stages keeps the amplify, ms, ps evaluation order and regroups only Copy fields, let _ = places.insert(..) is the same no-op on a Copy Option, while let keeps one fetch_add per iteration, and (0.0..1e9).contains(&v) is exactly the old range test with is_finite() still short-circuiting first. leonida-gpu 627/0/58 and leonida-shader 409/0/5.

Two corrections:

  1. The body's --all-targets number does not reproduce: at the stated base the unique total is 10 (4 lib + 6 test), not 15. The diff addresses exactly those ten.
  2. "0" is true at the head, not on today's main: main gained an unused_mut at crates/leonida-gpu/src/host.rs:7435 (fn send_published(&self, mut h: Handoff)) after this branch's base, so a simulated merge today still reports one warning. Rebase (or drop that mut) or the claim is stale on landing.

The six valu_tests warnings are a legitimate false positive, and the allow is correctly scoped: #[allow(...)] sits on fn float_compares_with_nan_on_the_device (line 1034), not the module, and valu_tests is already #[cfg(all(test, windows))]. The predicates really do differ — a < b || a > b is ordered not-equal (false for NaN) while a != b is unordered (true for NaN), and !(a >= b) etc. are true when either operand is NaN. Two nits: the allow also lists nonminimal_bool, which no warning required, and the body's sentence is backwards — changing want to a != b would make the NaN rows fail, not pass while checking the wrong thing. The argument that the predicates differ is still right.

Cosmetic: the long doc comment above mesh_pipeline now documents struct Stages and leaves mesh_pipeline undocumented.

@merzleckeier

Copy link
Copy Markdown
Contributor

Follow-up on the remaining unused_mut at send_published. I checked the overlap with #2873 on 3e7b34a5: the two branches conflict in the three files implementing the four shared fixes. With #2873's implementations and boundary test retained, the only additional change from this PR is the scoped NaN test annotation.

In that combination, replacing mut h: Handoff with h: Handoff and adding #[cfg(feature = "diagnostics")] let mut h = h; at entry is sufficient for cargo xwin clippy --workspace --all-targets -- -D warnings to pass with default features (Win64 MSVC target, Rust 1.98.1). Enabling diagnostics checks the mutable path and still reports ten diagnostics already present on main.

MEASURED, AI-assisted (Codex).

@imShangLi

Copy link
Copy Markdown
Contributor

VERIFY-2877 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files

Verdict: PASS, with two things to know: it conflicts with #2873, and the #[allow] it adds is documentation rather than part of the warning count.

Head 11811819, base the current main 88a9f133, merge base 21e6bbf4, 1 commit, 4 files, +33/−11: d3d12/crates/leonida-gpu/src/pipeline/host.rs, d3d12/crates/leonida-gpu/src/pipeline/known.rs, d3d12/crates/leonida-hle/src/modules/glyphs/live.rs, d3d12/crates/leonida-shader/src/emit/valu_tests.rs.

1. What it fixes

Four clippy warnings that came back after #2681 and #2682 landed, and six more in valu_tests.rs that get an #[allow] and an explanation instead of a change.

known.rs:246 — drop on a Copy value. drop(places.insert(hash, …)) becomes let _ = places.insert(hash, …), which is what the function just below it (make) already does.

known.rs:268 — a loop that should be a while let.

host.rs:1214 — mesh_pipeline has too many arguments (8/7). The three shader bytecodes become a struct:

struct Stages { amplify: Option<D3D12_SHADER_BYTECODE>, ms: D3D12_SHADER_BYTECODE, ps: D3D12_SHADER_BYTECODE }
fn mesh_pipeline(device: …, root: …, code: Stages, g: …, depth_bounds: bool, name: Option<&str>) -> …

so it takes six arguments, and the body destructures it on its first line. Only the four call sites change shape.

live.rs:121 — manual_range_contains. v >= 0.0 && v < 1e9 becomes (0.0..1e9).contains(&v).

2. The valu_tests.rs explanation is right, and I checked the semantics

The pull request says the six warnings there must not be "fixed", because clippy's suggestion would change what the test asserts. The table is RDNA2's sixteen f32 compare predicates:

0x5 => a < b || a > b,
0x9 => !(a >= b),
0xa => !(a < b || a > b),

I ran the comparisons with a NaN operand:

a < b || a > b   = false    (RDNA2 0x5 的语义)
a != b           = true     (clippy 建议的写法)
!(a >= b)        = true
!(a < b || a > b) = true
a == b           = false

So with a NaN operand a < b || a > b is false and a != b is true — clippy's shortcut is not the same predicate, and taking it would make the test pass while checking the wrong thing. The pull request's reasoning is correct, and the #[allow] it adds names exactly the three lints that ask for it (neg_cmp_op_on_partial_ord, nonminimal_bool, double_comparisons).

3. One clarification about the #[allow]

The three lints it allows are pedantic lints; the repository enables clippy::all ([workspace.lints.clippy] all = { level = "warn", priority = -1 }), which does not include pedantic. So the #[allow] is not what takes the count from 15 to 0 — the four fixes are.

I confirmed it: with -W clippy::pedantic the #[allow] suppresses the warnings at those lines, and removing it brings them back:

# 有 #[allow] + pedantic:没有警告
# 去掉 #[allow] + pedantic:
  = help: .../index.html#nonminimal_bool
  = help: to override `-W clippy::pedantic` add `#[allow(clippy::nonminimal_bool)]`

That makes the #[allow] worth keeping — it stops a later "fix" from breaking the test, and it documents why — but it is not part of the warning count, which is worth knowing when reading the pull request's numbers.

4. It conflicts with #2873

Both pull requests change the same three files, and merging them together fails:

$ git merge pr2873 pr2877
ERROR: content conflict in d3d12/crates/leonida-gpu/src/pipeline/known.rs
ERROR: content conflict in d3d12/crates/leonida-hle/src/modules/glyphs/live.rs

They are two versions of the same fixes: the same let _ = and while let in known.rs, the same struct-for-the-arguments in host.rs (Stages here, MeshStages in #2873), the same range rewrite in live.rs. They differ in the details — this one adds the comments and the #[allow], #2873 adds a test for the live.rs rewrite. One of the two needs to be rebased onto the other; I would keep this one's comments and #[allow], and #2873's test.

5. What I checked in the part that builds here

leonida-shader is the only crate of the four that builds on Linux, and it is the one with the #[allow]:

  • cargo clippy -p leonida-shader --all-targets on this branch: the three lints it allows do not appear, and the manual_range_contains in live.rs is not in this crate.
  • cargo test -p leonida-shader: 247 passed, 0 failed, 2 ignored.

I also checked the live.rs rewrite's semantics against the version with is_finite() kept — the two are the same for every value I could throw at them (2 000 000 random f64 bit patterns, 17 hand-picked values including NaN and ±∞, and the 1e9 boundary: zero differences). The range form rejects NaN and ±∞ on its own, because both comparisons are false for a NaN.

6. What I did not check

  • The warning counts the pull request quotes (cargo clippy --workspace 4 → 0, --all-targets 15 → 0). leonida-gpu and leonida-hle do not build on Linux for reasons that predate this pull request (upstream: "The crates are Windows-only today … Linux follows Linux: build leonida.exe and run it under Proton or Wine #2577"), and clippy needs the crate to compile. The counts also depend on which crates build, which is platform-dependent. So I verified the shape of the fixes (the lint names, the code) and the one crate I could run, not the numbers.
  • The tests of leonida-gpu and leonida-hle — same reason. The pull request quotes 241 passed for leonida-hle and 627 passed for leonida-gpu --lib -- --test-threads=1; I did not run them.
  • Whether the Stages struct's field name code is the best choice — it shadows the meaning of "code" used elsewhere in the file (code(0), code(&ms) are bytecodes). A matter of taste; I am not asking for a change.
  • cargo fmt is left out of the d3d12 workflow, and this pull request's host.rs lines are long enough that rustfmt --check would reformat them.

AI-assisted: MiniMax M3.1 Flash.

@Neutron-0

Copy link
Copy Markdown

Verified on Windows 11, Rust 1.98.1, no GPU and no game files.

The claim holds on the pull request's own base. The warnings were counted from the compiler's own JSON messages (one per line), so the count is what the compiler reported and not a summary line's word for it:

cargo clippy --workspace ... --all-targets
the base e04721c7f 5 warnings 16 warnings
the head 118118191 0 warnings 0 warnings

The four the report names are all there on the base, and all four are gone on the head:

  • clippy::too_many_arguments at crates/leonida-gpu/src/pipeline/host.rs:1214 (8/7)
  • dropping_copy_types at crates/leonida-gpu/src/pipeline/known.rs:246
  • clippy::while_let_loop at crates/leonida-gpu/src/pipeline/known.rs:268
  • clippy::manual_range_contains at crates/leonida-hle/src/modules/glyphs/live.rs:121

and the six in leonida-shader/src/emit/valu_tests.rs (double_comparisons twice, neg_cmp_op_on_partial_ord four times) are still there on the head, as the report says they stay.

Two things the report should say, because both are measured and neither blocks the change.

1. The base's counts are five and sixteen, not "four and fifteen". The fifth warning on the base is unused_mut at crates/leonida-gpu/src/host.rs:7435 (fn send_published(&self, mut h: Handoff) - the mut is not needed). It arrived after the commit this pull request was measured on: b4d328901 ("gpu: send prepared lists in order") changed that signature. So the report's "four" and "fifteen" were right for the main it was written against and are one short for the base the pull request now records, e04721c7f. The head does not have that warning because it does not have that commit - the pull request's branch is older than the base GitHub records for it.

2. What happens when it lands on the current main. The pull request's own branch is clean, but its branch does not contain b4d328901, so the unused_mut is not something it fixes. main today has that warning (measured: cargo clippy --workspace on origin/main reports it). The pull request's commit was put on top of the current main in a worktree - what GitHub would merge - and measured there:

on top of the current main 27613ab6b warnings
cargo clippy --workspace 1 (unused_mut at crates/leonida-gpu/src/host.rs:7435)
cargo clippy --workspace --all-targets 2 (the same one, counted twice)

So a merge that brings this pull request's commits onto the current main leaves that one warning in place, and "clippy is at zero" would not be true of the result. The fix is one word: fn send_published(&self, h: Handoff). Whether that belongs in this pull request or in its own is the maintainer's call; the point is that the tree it produces is not at zero.

One note on the host.rs change, which is the one with a shape. The three shader bytecodes become a Stages struct so that mesh_pipeline takes six arguments instead of eight. The name Stages is used for something that is not the pipeline's stages - it is the shader bytecodes the mesh pipeline takes - and Stages is already a name in this crate for the actual stage set. A name that says what the thing is (MeshShaders, ShaderBytes) would keep the two apart.

Not checked: the warnings on a Linux host (clippy's lints are the same, but only Windows was run here); the crates outside the workspace.

@fiestorra
fiestorra force-pushed the fix-clippy-leftovers branch 3 times, most recently from 3d412f6 to 3e7b0c5 Compare December 1, 2026 18:11
@fiestorra

Copy link
Copy Markdown
Contributor Author

All four reviews read, and four things changed because of them. Head is now 3e7b0c563, rebased on dcda41f76, 5 files.

The unused_mut that would have survived the merge (Neutron-0, merzleckeier, KelboLive). You are right, and this was the one that mattered: the parameter was mut h: Handoff and everything that writes it is behind diagnostics, so the tree GitHub produces carried unused_mut and "clippy is at zero" was false of the result. It is now:

fn send_published(&self, h: Handoff) {
    // The lists and the stamp are added to `h` only with `diagnostics`.
    #[cfg(feature = "diagnostics")]
    let mut h = h;

which is the shape merzleckeier measured. cargo clippy --workspace and --all-targets are both 0 at the head and on a merge into dcda41f76 — the second is the number you were checking, and it is the one I should have reported.

Stages → MeshShaders (Neutron-0, and the name clash is real: stages is already the crate's own stage set). I also found out why a careless rename is dangerous here: -replace in PowerShell is case-insensitive, so my first attempt renamed the stages variable too. The committed rename is case-sensitive and leaves every stages alone.

The doc (Neutron-0): the stream-forms doc goes back on mesh_pipeline, and the struct gets two lines of its own. My insertion had left both on the struct.

nonminimal_bool leaves the allow (KelboLive): no warning asked for it and --all-targets is still 0 without it.

And the sentence you caught, KelboLive: "the test would pass while checking the wrong thing" is backwards, as you say - changing want to a != b makes the NaN rows fail, which is louder than passing wrongly, and my sentence got the direction wrong. The reason the allow is right is unchanged (the predicates differ); only the consequence was written backwards.

On the counts (KelboLive): your 10 at 21e6bbf4b is right and mine was 15 because I measured it on a tree that already had two more --all-targets diagnostics; the body now says what the head measures rather than a number from another tree.

I have not touched #2873, which overlaps in three files; my reading of the thread is the same as yours - the two are versions of one change, and this one's comments and allow plus that one's test is the right combination. That is a maintainer's call and I am not going to make it by rebasing over someone else's branch.

Measured at 3e7b0c563:

cargo clippy --workspace                       0 warnings
cargo clippy --workspace --all-targets         0 warnings
cargo test -p leonida-gpu --lib -- --test-threads=1   633 passed; 0 failed
cargo test -p leonida-shader                   414 passed; 0 failed
cargo test -p leonida-hle                      passed

Written with an AI assistant.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Dec 1, 2026
The four fixes this branch started with are on main already, from the other
version of them (ProjectLeonida#2873): `let _ = places.insert(..)`, `while let` in
`pipeline/known.rs`, `(0.0..1e9).contains(&v)` in `glyphs/live.rs` and the
`MeshStages` struct for `mesh_pipeline`. What is left is the part that commit
did not carry:

  - the six `--all-targets` warnings in `emit/valu_tests.rs`: clippy wants
    `a != b` for `a < b || a > b`, and in a table of RDNA2's sixteen f32
    compare predicates those are not the same function - with a NaN the first
    is false and the second is true. The two lints are allowed on that one
    test, with the reason above it.

  - `unused_mut` on `send_published`'s `Handoff`: what writes it is behind
    `diagnostics`, so the parameter loses `mut` and keeps a `let mut h = h;`
    under that feature.

Measured on main 1fff691, before and after:

  cargo clippy --workspace                    2 warnings -> 0
  cargo clippy --workspace --all-targets     10 warnings -> 0
  cargo test -p leonida-shader float_compares_with_nan  1 passed
  cargo test -p leonida-gpu --lib -- --test-threads=1   643 passed; 1 failed,
      descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in,
      which fails the same way on main without this change

With --features diagnostics nothing new appears: the one warning in
`leonida-gpu/src/host.rs` under that feature is at line 4677, not here.

Written with an AI assistant.
@fiestorra
fiestorra force-pushed the fix-clippy-leftovers branch from 3e7b0c5 to f98e8cc Compare December 1, 2026 21:36
@fiestorra fiestorra changed the title d3d12: the last four clippy warnings, and why the six in valu_tests stay d3d12: the two clippy warnings main still has Dec 1, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Dec 1, 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.

5 participants