Skip to content

gpu/pipeline: reject empty descriptor source joins in bound_view_stores (D3D12-GPU-BOUND-STORES-EMPTY-LEAVES) - #2892

Open
djrolfes wants to merge 1 commit into
ProjectLeonida:mainfrom
djrolfes:djrolfes/gpu-pipeline-empty-leaves-soundness
Open

djrolfes wants to merge 1 commit into
ProjectLeonida:mainfrom
djrolfes:djrolfes/gpu-pipeline-empty-leaves-soundness

Conversation

@djrolfes

@djrolfes djrolfes commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-GPU-BOUND-STORES-EMPTY-LEAVES.

What and why

Close a vacuous-truth soundness bug in stores_in_bound_views (d3d12/crates/leonida-gpu/src/pipeline.rs): require at least one leaf descriptor source (!leaves.is_empty()) before declaring a buffer store or atomic bound.

  • Why: On main, stores_in_bound_views checks:
    found.all(|d| d.source.leaves().into_iter().all(declared))
    Because Rust's Iterator::all returns true on an empty iterator, any descriptor whose tracked source has zero leaves — such as Source::LanePhi { args: [] }, Source::LanePhi { args: [None, None] }, Source::Phi { args: [] }, or Source::Select { args: [] } — vacuously evaluated to true and was misclassified as provably bound for LEONIDA_INDIRECT_BATCH=4.
  • Change:
    • Extracts bound_view_stores(program, &p, &res) from stores_in_bound_views so tracked IR edge cases can be unit-tested directly.
    • Checks let leaves = d.source.leaves(); !leaves.is_empty() && leaves.into_iter().all(declared).
  • Orthogonality check: Touches ONLY d3d12/crates/leonida-gpu/src/pipeline.rs and keeps stores_bound() -> bool signature unchanged — zero overlap with enlight3d's #2868 (D3D12-BATCH-HEAP-READS, which touches draw.rs + indirect/batch.rs) or #2569.
  • Evidence classification: READ IN CODE (d3d12/crates/leonida-gpu/src/pipeline.rs) + red→green unit test + MEASURED 300 s in-world Option-A roam gate.

Tested

  • python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/pipeline.rs → exit 0.
  • Cross-compiled leonida-gpu unit test binary (x86_64-pc-windows-msvc) and ran under Wine:
    • RED on origin/main (with bound_view_stores extracted preserving origin/main's .all(declared) logic and the new test bound_view_stores_rejects_empty_joins_and_missing_descriptors):
      running 1 test
      thread 'pipeline::bound_tests::bound_view_stores_rejects_empty_joins_and_missing_descriptors' panicked:
      unproven descriptor: LanePhi { block: 0, args: [] }
      test result: FAILED. 0 passed; 1 failed; 0 ignored
      
    • GREEN on PR head 2e7c3467d (rebased onto 3e7b34a52):
      test pipeline::bound_tests::bound_view_stores_rejects_empty_joins_and_missing_descriptors ... ok
      test pipeline::bound_tests::stores_through_bound_views_are_told_from_the_others ... ok
      test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 689 filtered out
      
      (Plus pipeline::tests:: 3 passed; 0 failed.)
  • 300 s in-world game gate (MEASURED on exact PR head 2e7c3467d, Series S + DLSS Quality 1280×720 → 1920×1080, LEONIDA_INDIRECT_BATCH=4, Option A mods/gate_driver mode = roam):
    • Verdict: PASS (310.70 s in-world after world entry at 66.99 s; also passed an earlier cold-cache 310.19 s run with 0 errors).
    • Frames & pacing: 1,708 frames after +60 s (1,796 total world presents), 10.52 median FPS (12.26 end median FPS), 394.52 ms p95 frame time, 4.022 s longest present gap (<= 10.0 s).
    • Memory & stability: 6,759 MiB peak VRAM (<= 7,400 MiB), 0 device losses (0x887A0005), 0 crashes, 0 panics, 0 faults before stop, 0 kernel NVRM: Xid errors.
    • Option A roam control: GATE CONTROL reached at t = 70.0 s (moved = 7.63 m, mode = roam), 32 GATE MARK roam ticks, 0 GATE FAIL.

GPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).

AI-assisted: yes (authored by Gemini 4 Neon; reviewed in a separate independent review pass by Gemini 4 Neon).

Checklist

  • Based on current main (3e7b34a52) and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (check_no_game_data.py clean on both source and PR description).
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — GPU bound-store proof soundness fix)

@Kal0s-design

Copy link
Copy Markdown
Contributor

Verified on native Windows 11 (MSVC target, rustc 1.98.1), since the runs in the description are under Wine.

Head 2e7c3467d merged with main d2a564b66 (clean merge):

  • cargo test -p leonida-gpu --lib pipeline::: 39 passed, 0 failed, 8 ignored. Both bound_tests pass.
  • cargo clippy -p leonida-gpu --all-targets: nothing in pipeline.rs.

The test catches the change. With !leaves.is_empty() && removed (the main logic in the extracted function), bound_view_stores_rejects_empty_joins_and_missing_descriptors fails at pipeline.rs:1382 with unproven descriptor: LanePhi { block: 0, args: [] }. That matches the red in the description.

Not checked: the full leonida-gpu suite and the game.

GPUs tested: n/a (CPU unit tests only).

AI-assisted: yes (Claude Code).

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The guard is sound and minimal: leaves() is non-empty for Loaded/Built (resource.rs:101-110), so single-source descriptors still pass, while empty Phi/Select/LanePhi joins now fail closed — and the loss is visible through BOUND_SAID, undeclared_why and batch closure rather than silently dropped. Extracting bound_view_stores (pipeline.rs:599-650) so the proof can be tested directly is the right move, and deleting !leaves.is_empty() && fails the new test exactly at pipeline.rs:1382 (unproven descriptor: LanePhi { block: 0, args: [] }). 632/0/59 on the crate, merge clean against current main.

Two follow-ups worth doing in this PR or a note:

  1. Make the test case reachable in practice. per_lane really can emit LanePhi with every arg None (resource.rs:1954-1976), so a captured real shader/pipeline would be stronger than only the synthetic overwrite — the test currently proves the predicate, not that the tracker produces such a join.
  2. The same vacuous .all() over leaves() sits at emit/lower.rs:9185 and :9771. If empty joins are reachable there, the class is only half closed; either audit those two sites or reject empty joins where they are built.

One correction to the body: #2868 is not zero-overlap at file level — it also edits pipeline.rs (+199), and the two conflict textually where both append tests to bound_tests (merge-tree against its head exits 1). Semantically orthogonal and trivial to resolve by keeping both, but "zero overlap" will mislead whoever merges second. Against current main alone, this is clean.

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.

3 participants