fold: pin the VGPR-base table's round trip #577

Open
qnjk wants to merge 1 commit from qnjk/Darner:fold-vgpr-bases-test into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: nothing. This is a tests-only change (no production line is edited).

  • What it pins: fold appends a VGPR-base table to the folded code — for every copy whose VGPRs are moved, words.push(4 * w as u32); words.push(u32::from(d) | u32::from(s) << 16);, then words.push(bases.len() as u32); words.push(BASES_MAGIC); (crates/darner-shader/src/fold.rs, around :1698) — and vgpr_bases (:241) reads it back from the code's last words for ir::build and oracle64. It has two silent failure modes: if n < 2 || word(n - 1) != Some(BASES_MAGIC) { return Vec::new(); } and if 2 * count + 2 > n { return Vec::new(); }. An empty table makes ir::build treat every upper-half copy as unbased, so a broken writer, a broken reader or a truncated program degrades silently; nothing tested the round trip without a GPU.

  • This change adds two tests: one folds a small program with known moved copies and asserts vgpr_bases returns exactly those bases at exactly those byte offsets; the other pins both empty returns (code without the magic, and code too short to hold the count).

How it was tested

  • Tested revision: 5d48068 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-shader --lib -- fold — 34 passed, 0 failed (the whole fold module).
    • cargo clippy --locked -p darner-shader --all-targets -- -D warnings passes.
    • Fail-before: a tests-only change has no old behaviour to revert, so each side of the round trip was broken in turn and the suite re-run:
      1. writer pushes word offsets instead of byte offsets (4 * w → w):
        a_folded_programs_vgpr_bases_are_read_back_from_its_code ... FAILED
        assertion `left == right` failed
          left:  [(0, (32, 0)), (1, (32, 32)), (3, (32, 32)), ...]
         right: [(0, (32, 0)), (4, (32, 32)), (12, (32, 32)), ...]
        
      2. reader's n < 2 guard dropped: code_that_does_not_end_with_a_table_has_no_vgpr_bases panics with attempt to subtract with overflow.
      3. reader's magic check dropped: the same test fails.
        Each mutation was reverted with git checkout -- (never git stash).
  • Changes a default: no. Tests only.
  • A/B result: not applicable — tests-only change.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; darner-shader's full lib suite takes ~40 minutes on this machine because of emit::waterfall_tests, which also fails on a clean main (#227), so the crate was gated by its fold module (34 passed) plus clippy. darner-shader is the only crate this change touches.
  • Gameplay, when relevant: not applicable — tests-only change.
  • Shader wave sizes tested, when relevant: the folded programs are small synthetic ones; the wave64 pairing is not exercised by these tests.
  • Hardware dependence: none.
  • Coverage gaps: the tests pin the encoding and both empty returns, not a real folded title program; a table with more copies than a 16-bit field can hold is not exercised.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: tests-only change, stated at the top.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 576 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #312 changes crates/darner-shader/src/fold.rs too; this change only adds to the mod tests block. No open or closed issue mentions vgpr_bases, BASES_MAGIC or the VGPR-base table.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: nothing. This is a **tests-only** change (no production line is edited). - What it pins: `fold` appends a VGPR-base table to the folded code — for every copy whose VGPRs are moved, `words.push(4 * w as u32); words.push(u32::from(d) | u32::from(s) << 16);`, then `words.push(bases.len() as u32); words.push(BASES_MAGIC);` (`crates/darner-shader/src/fold.rs`, around :1698) — and `vgpr_bases` (:241) reads it back from the code's last words for `ir::build` and `oracle64`. It has two silent failure modes: `if n < 2 || word(n - 1) != Some(BASES_MAGIC) { return Vec::new(); }` and `if 2 * count + 2 > n { return Vec::new(); }`. An empty table makes `ir::build` treat every upper-half copy as unbased, so a broken writer, a broken reader or a truncated program degrades silently; nothing tested the round trip without a GPU. - This change adds two tests: one folds a small program with known moved copies and asserts `vgpr_bases` returns exactly those bases at exactly those byte offsets; the other pins both empty returns (code without the magic, and code too short to hold the count). ## How it was tested - Tested revision: `5d48068` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-shader --lib -- fold` — 34 passed, 0 failed (the whole `fold` module). - `cargo clippy --locked -p darner-shader --all-targets -- -D warnings` passes. - Fail-before: a tests-only change has no old behaviour to revert, so each side of the round trip was broken in turn and the suite re-run: 1. writer pushes word offsets instead of byte offsets (`4 * w` → `w`): ``` a_folded_programs_vgpr_bases_are_read_back_from_its_code ... FAILED assertion `left == right` failed left: [(0, (32, 0)), (1, (32, 32)), (3, (32, 32)), ...] right: [(0, (32, 0)), (4, (32, 32)), (12, (32, 32)), ...] ``` 2. reader's `n < 2` guard dropped: `code_that_does_not_end_with_a_table_has_no_vgpr_bases` panics with `attempt to subtract with overflow`. 3. reader's magic check dropped: the same test fails. Each mutation was reverted with `git checkout --` (never `git stash`). - Changes a default: no. Tests only. - A/B result: not applicable — tests-only change. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; `darner-shader`'s full lib suite takes ~40 minutes on this machine because of `emit::waterfall_tests`, which also fails on a clean `main` (#227), so the crate was gated by its `fold` module (34 passed) plus clippy. `darner-shader` is the only crate this change touches. - Gameplay, when relevant: not applicable — tests-only change. - Shader wave sizes tested, when relevant: the folded programs are small synthetic ones; the wave64 pairing is not exercised by these tests. - Hardware dependence: none. - Coverage gaps: the tests pin the encoding and both empty returns, not a real folded title program; a table with more copies than a 16-bit field can hold is not exercised. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: tests-only change, stated at the top. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 576 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #312 changes `crates/darner-shader/src/fold.rs` too; this change only adds to the `mod tests` block. No open or closed issue mentions `vgpr_bases`, `BASES_MAGIC` or the VGPR-base table. - Replaces or overlaps: none found
`fold` appends the bases of the upper halves' copies to a folded program's
code, and `vgpr_bases` reads them back for `ir::build`; nothing tested that
round trip without a GPU. The only test that reaches the parser folds and
lowers a program of more than 127 VGPRs, but checks the values only after
`run`, which returns on a bare runner, so a table written in word offsets, a
count that did not fit, or a lost magic word changed no assertion.

The new tests fold a 64-thread program and pin its prologue's seven bases by
byte offset, that each offset is that of an instruction of the folded code,
and that they are in the order `ir::build`'s `binary_search_by_key` needs;
and they pin both silent failure modes — no magic, and code too short for
the count — which give an empty table rather than a panic or a guess.
TrustNo1 changed title from [pr-tests][shaders] fold: pin the VGPR-base table's round trip to fold: pin the VGPR-base table's round trip 2026-12-06 03:26:56 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fold-vgpr-bases-test:qnjk-fold-vgpr-bases-test'
git switch 'qnjk-fold-vgpr-bases-test'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'qnjk-fold-vgpr-bases-test'
git switch 'qnjk-fold-vgpr-bases-test'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-fold-vgpr-bases-test'
git switch 'qnjk-fold-vgpr-bases-test'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-fold-vgpr-bases-test'
git switch 'Main'
git merge --squash 'qnjk-fold-vgpr-bases-test'
git switch 'Main'
git merge --ff-only 'qnjk-fold-vgpr-bases-test'
git switch 'Main'
git merge 'qnjk-fold-vgpr-bases-test'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!577
No description provided.