fix(vk): the simulated-turf switch rows sit in name order, so find() finds them #2197

Open
dazemc wants to merge 1 commit from dazemc/Longshot:fix/switch-table-sort into main
Contributor

Summary

gpu/vk/switches.def is sorted by name because gpu/vk/switches.h's find() binary-searches rows[]. #2093 (1885234b) inserted RX_VK_SIM_TURF_ADAPTIVE and RX_VK_SIM_TURF_POOLS around the existing RX_VK_GRASS_DISTANCE row, which leaves two inversions:

  • line 466 RX_VK_SIM_TURF_ADAPTIVE before line 467 RX_VK_GRASS_DISTANCE (G sorts before S);
  • line 468 RX_VK_SIM_TURF_POOLS before line 469 RX_VK_HALF_RATE_SHADING (H sorts before S).

tests/test_switch_table.py reports only the first (it stops at the first inversion), so moving that one row alone would leave the second in place.

This is a product bug, not a lint. With the table unsorted, find() misses four real switches — RX_VK_SIM_TURF_ADAPTIVE, RX_VK_SIM_TURF_POOLS, RX_VK_HALF_RATE_SHADING and RX_VK_HANDLE_TABLES — so report() at start would tell a run that sets one of them that it "is not a switch of this build: a misspelt name, or one from another build", and leave it out of the switches set line.

What changed: the two rows move to their alphabetical place among the S names, after SHOT_W and before SKIP_CODE. Two lines moved; no name, kind, type, unset or summary text changes. An SW row has no ID or index — a switch's identity is its name — and find() is the only consumer of the row order (the program-cache stamp hashes the environment's names and values, find_gone() is a linear scan, and the menu's rows are a table of their own).

Read first: gpu/vk/switches.h (find(), and its "sorted by name" comment), then the two moved rows in gpu/vk/switches.def, then the sortedness check at tests/test_switch_table.py:150.

Testing

Tested: the full suite, --jobs 3 in an 8 GiB memory scope with the pinned headers: here 912 passed, 22 failed, 18 skipped in 620 s against main @ a2dc5385's 911 / 23 / 18 in 635 s. Every failing name here is one of main's 23; the only difference is tests/test_switch_table.py, which this change fixes (main's 23 less that one = this branch's 22), and no name fails here that does not fail on main.

At the check itself: on main @ a2dc5385 it fails with FAIL: the switch table and the source disagree: switches.def is not sorted by name: RX_VK_GRASS_DISTANCE comes after RX_VK_SIM_TURF_ADAPTIVE; here it passes.

In the game (Linux 7.3.4-zen2-2-zen, NVIDIA GeForce RTX 4070 Ti, Vulkan 1.4, driver 620.70.06): Kokiri Forest, 20 s after warm-up, one run each side (record runs/ab/20261121-191618-change-kokiri-forest) — main 1804 frames, 90.2 fps, median 11.11 ms, p99 13.86 ms, 1% low 72.2 fps, 0 cold frames; here 1805 frames, 90.3 fps, median 11.09 ms, p99 13.76 ms, 1% low 72.7 fps, 0 cold frames. The smoke is a boot/play check with the reordered table; the check above, not the smoke, is what proves the four lookups.

Still to test: None (the check and the smoke cover this PC; CI builds both platforms).

Measurements

Verdict: the table is sorted again: find() finds all 788 switches, 4 more than on main, and test_switch_table.py goes from red to green through the check's own find(name) == &rows[i] test. No switch's name, default or behaviour changes.

Before: main @ a2dc5385 After: this PR @ abbc5703
test_switch_table.py FAIL: not sorted by name (line 466 before 467) ok: 788 switches
switches find() finds, of 788 784 788
switches find() misses 4 0
full suite (passed / failed, 18 skipped) 911 / 23 912 / 22
Kokiri Forest, 20 s (fps) 90.2 90.3
median frame time (ms) 11.11 11.09
p99 frame time (ms) 13.86 13.76
1% low (fps) 72.2 72.7
cold frames 0 0

Risks

Only which row find() returns can change, and the order is now correct, so every name maps to its own row. No switch's value, default, read or log text changes; nothing changes for saves, longshot_options.ini, the game folder's caches, or the program-cache stamp. A revert is enough; no switch.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. (Kokiri Forest, 20 s a side, 0 cold frames on both; the record is named in Testing)
  • mise run test passes (any failure that also fails on main is named). (912 / 22 / 18 here against main's 911 / 23 / 18; the 22 are main's 23 less test_switch_table.py, which this fixes, and no name here is absent from main's list)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened (test_switch_table.py already reads switches.def and is unchanged; its sortedness check is the guard).

Ready to merge

  • Everything in Still to test has run, its results in Tested. (Still to test is None; the check and the smoke are in Tested — ticked at merge)
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). (the smoke is one Linux RTX 4070 Ti; Tier 1's Windows half has not run)
  • Approved in review, every comment answered. (no review yet)
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold. (CI has not run on this head)
## Summary `gpu/vk/switches.def` is sorted by name because `gpu/vk/switches.h`'s `find()` binary-searches `rows[]`. #2093 (`1885234b`) inserted `RX_VK_SIM_TURF_ADAPTIVE` and `RX_VK_SIM_TURF_POOLS` around the existing `RX_VK_GRASS_DISTANCE` row, which leaves two inversions: - line 466 `RX_VK_SIM_TURF_ADAPTIVE` before line 467 `RX_VK_GRASS_DISTANCE` (`G` sorts before `S`); - line 468 `RX_VK_SIM_TURF_POOLS` before line 469 `RX_VK_HALF_RATE_SHADING` (`H` sorts before `S`). `tests/test_switch_table.py` reports only the first (it stops at the first inversion), so moving that one row alone would leave the second in place. This is a product bug, not a lint. With the table unsorted, `find()` misses four real switches — `RX_VK_SIM_TURF_ADAPTIVE`, `RX_VK_SIM_TURF_POOLS`, `RX_VK_HALF_RATE_SHADING` and `RX_VK_HANDLE_TABLES` — so `report()` at start would tell a run that sets one of them that it "is not a switch of this build: a misspelt name, or one from another build", and leave it out of the `switches set` line. What changed: the two rows move to their alphabetical place among the `S` names, after `SHOT_W` and before `SKIP_CODE`. Two lines moved; no name, kind, type, unset or summary text changes. An `SW` row has no ID or index — a switch's identity is its name — and `find()` is the only consumer of the row order (the program-cache stamp hashes the environment's names and values, `find_gone()` is a linear scan, and the menu's rows are a table of their own). Read first: `gpu/vk/switches.h` (`find()`, and its "sorted by name" comment), then the two moved rows in `gpu/vk/switches.def`, then the sortedness check at `tests/test_switch_table.py:150`. ## Testing **Tested:** the full suite, `--jobs 3` in an 8 GiB memory scope with the pinned headers: here **912 passed, 22 failed, 18 skipped in 620 s** against `main @ a2dc5385`'s **911 / 23 / 18 in 635 s**. Every failing name here is one of main's 23; the only difference is `tests/test_switch_table.py`, which this change fixes (main's 23 less that one = this branch's 22), and no name fails here that does not fail on main. At the check itself: on `main @ a2dc5385` it fails with `FAIL: the switch table and the source disagree: switches.def is not sorted by name: RX_VK_GRASS_DISTANCE comes after RX_VK_SIM_TURF_ADAPTIVE`; here it passes. In the game (Linux `7.3.4-zen2-2-zen`, NVIDIA GeForce RTX 4070 Ti, Vulkan 1.4, driver `620.70.06`): Kokiri Forest, 20 s after warm-up, one run each side (record `runs/ab/20261121-191618-change-kokiri-forest`) — main 1804 frames, 90.2 fps, median 11.11 ms, p99 13.86 ms, 1% low 72.2 fps, 0 cold frames; here 1805 frames, 90.3 fps, median 11.09 ms, p99 13.76 ms, 1% low 72.7 fps, 0 cold frames. The smoke is a boot/play check with the reordered table; the check above, not the smoke, is what proves the four lookups. **Still to test:** None (the check and the smoke cover this PC; CI builds both platforms). ## Measurements **Verdict:** the table is sorted again: `find()` finds all 788 switches, 4 more than on `main`, and `test_switch_table.py` goes from red to green through the check's own `find(name) == &rows[i]` test. No switch's name, default or behaviour changes. | | Before: main @ a2dc5385 | After: this PR @ abbc5703 | |---|---|---| | `test_switch_table.py` | FAIL: not sorted by name (line 466 before 467) | ok: 788 switches | | switches `find()` finds, of 788 | 784 | 788 | | switches `find()` misses | 4 | 0 | | full suite (passed / failed, 18 skipped) | 911 / 23 | 912 / 22 | | Kokiri Forest, 20 s (fps) | 90.2 | 90.3 | | median frame time (ms) | 11.11 | 11.09 | | p99 frame time (ms) | 13.86 | 13.76 | | 1% low (fps) | 72.2 | 72.7 | | cold frames | 0 | 0 | ## Risks Only which row `find()` returns can change, and the order is now correct, so every name maps to its own row. No switch's value, default, read or log text changes; nothing changes for saves, `longshot_options.ini`, the game folder's caches, or the program-cache stamp. A revert is enough; no switch. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. (Kokiri Forest, 20 s a side, 0 cold frames on both; the record is named in Testing) - [x] `mise run test` passes (any failure that also fails on `main` is named). (912 / 22 / 18 here against main's 911 / 23 / 18; the 22 are main's 23 less `test_switch_table.py`, which this fixes, and no name here is absent from main's list) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened (`test_switch_table.py` already reads `switches.def` and is unchanged; its sortedness check is the guard). ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. (Still to test is None; the check and the smoke are in Tested — ticked at merge) - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). (the smoke is one Linux RTX 4070 Ti; Tier 1's Windows half has not run) - [ ] Approved in review, every comment answered. (no review yet) - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. (CI has not run on this head)
fix(vk): the simulated-turf switch rows sit in name order, so find() finds them
Some checks are pending
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
abbc570364
#2093 inserted RX_VK_SIM_TURF_ADAPTIVE and RX_VK_SIM_TURF_POOLS around an
existing RX_VK_GRASS_DISTANCE row, so two rows came after one whose name sorts
later. switches.h's find() binary-searches rows[], which needs the table sorted:
with it unsorted, four real switches are unfindable (both SIM_TURF ones,
HALF_RATE_SHADING and HANDLE_TABLES), so report() would call a set switch "not a
switch of this build" and leave it out of the "switches set" line.

tests/test_switch_table.py reported only the first inversion ("GRASS_DISTANCE
comes after SIM_TURF_ADAPTIVE"); moving that row alone would leave the second
(SIM_TURF_POOLS before HALF_RATE_SHADING) in place. Both rows move to their
place among the S names, after SHOT_W. No name, kind, type or value changes,
and no switch identity is a row's index.

Check: tests/test_switch_table.py (game-free; red on main for the reason).
Author
Contributor

Tested in game: Linux 7.3.4-zen2-2-zen, NVIDIA GeForce RTX 4070 Ti (Vulkan 1.4, driver 620.70.06): Kokiri Forest, 20 s after warm-up, one run each side — main 1804 frames / 90.2 fps / 11.11 ms median / 0 cold frames; this branch 1805 frames / 90.3 fps / 11.09 ms / 0 cold frames.

Tested in game: Linux 7.3.4-zen2-2-zen, NVIDIA GeForce RTX 4070 Ti (Vulkan 1.4, driver 620.70.06): Kokiri Forest, 20 s after warm-up, one run each side — main 1804 frames / 90.2 fps / 11.11 ms median / 0 cold frames; this branch 1805 frames / 90.3 fps / 11.09 ms / 0 cold frames.
Member

Possibly related, for context:

  • PR #2143 WIP: fix(vk): the switch table has a row for every switch the game reads, the translator's EDEN_ ones and four more — Open switch-table work touches switches.def and the switch coverage check
Possibly related, for context: - PR #2143 WIP: fix(vk): the switch table has a row for every switch the game reads, the translator's EDEN_ ones and four more — Open switch-table work touches switches.def and the switch coverage check
Some checks are pending
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
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 'fix/switch-table-sort:dazemc-fix/switch-table-sort'
git switch 'dazemc-fix/switch-table-sort'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!2197
No description provided.