Skip to content

d3d12-shader: make chains() and loop-counter lowering deterministic (D3D12-SHADER-DETERMINISTIC-EMIT, carry of #2872) - #3059

Open
MoonEyes wants to merge 3 commits into
ProjectLeonida:mainfrom
MoonEyes:carry/2872
Open

MoonEyes wants to merge 3 commits into
ProjectLeonida:mainfrom
MoonEyes:carry/2872

Conversation

@MoonEyes

@MoonEyes MoonEyes commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue as: D3D12-SHADER-DETERMINISTIC-EMIT (the claim of the original author, #2570 (comment))

What and why

Carry of #2872 (kirigayakazima), in conflict with main since both sides appended a test at the end of the same module in d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs. This branch is main merged with the head of #2872, so the author's commit is kept. My only change is the merge: both tests stay.

The change itself is #2872's: chains() builds its per-block plans in tree.order instead of iterating a HashMap, and the loop counters in lower.rs use a BTreeMap, so the emitted instruction IDs no longer depend on the run (chains_emits_deterministic_instruction_ids_across_blocks pins it).

Tested

Windows 11, no GPU, no game files, on current main plus this branch:

  • cargo test -p leonida-shader --lib: 421 passed, 0 failed, 5 ignored.
  • cargo clippy --locked -p leonida-shader -- -D warnings: clean.
  • Not run: the full translator suite, CI.

GPUs tested: n/a (translator unit tests only)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md. (n/a: no new rule, an ordering fix)

Supersedes #2872 once merged; the original stays open until a maintainer decides.

AI-assisted (Claude Code)

🤖 Generated with Claude Code

@Kal0s-design

Copy link
Copy Markdown
Contributor

A red/green and the full suite on a card, since the description has neither. Windows 11, MSVC toolchain 1.98.1. Head 5d47d4f57 merged into current main 229d352ee: the merge is clean.

  • Red/green. I took main's opt.rs and added only the new test, chains_emits_deterministic_instruction_ids_across_blocks. It fails 5 runs of 5, and the block order differs every run:

    [[34, 35], [30, 31], [32, 33], [36, 37], [38, 39], [40, 41]]
    [[38, 39], [34, 35], [30, 31], [40, 41], [36, 37], [32, 33]]
    [[32, 33], [30, 31], [40, 41], [34, 35], [36, 37], [38, 39]]
    [[36, 37], [30, 31], [34, 35], [38, 39], [32, 33], [40, 41]]
    [[40, 41], [36, 37], [38, 39], [30, 31], [32, 33], [34, 35]]
    

    That is the HashMap order changing from one process to the next. With the change it passes 5 runs of 5.

  • cargo test -p leonida-shader --lib, with an NVIDIA card present, so the card-backed tests ran too: 428 passed, 0 failed, 6 ignored. I touched build.rs first so the translator's source hash was fresh.

  • cargo clippy -p leonida-shader --lib --tests: no warning in opt.rs or lower.rs.

A note on lower.rs: main already sorted the counter headers before walking them (headers.sort_unstable()), so the BTreeMap there keeps the same order rather than fixing one. The nondeterminism this fixes is the one in chains().

Not checked: the game, and AMD hardware.

GPUs tested: one NVIDIA desktop card.

AI-assisted: yes (Claude Code).

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