BVH builder: FIRSTLANE_OWN makes all 53 builder programs translate; the check needs a wave-uniform proof instead #101

Open
opened 2026-11-26 03:32:11 +00:00 by github-bot · 1 comment
Owner

@⁠kalijerry on GitHub · 2026-11-26 03:25 UTC · original

Follow-up to #37, with the prefix-scan half of it measured end to end on hardware.

What happens with the shortcut on

VICTORY_FIRSTLANE_OWN=1 (the existing shortcut in emit/lower.rs, written for exactly this scan) makes all three refused stages translate:

INFO pipeline: the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53

So nothing new is needed in lowering to get the builder on - it needs this shortcut to be correct for these shaders, or the shortcut promoted to the default.

Why it is plausible, and where it can be wrong

The three stages are the builder's prefix scans (39321a95223001ed, 77360df21e12ea43, 9fc111d3be79364f). They read a sum of scalars with v_readfirstlane inside a loop whose exit is per console wave. The value is the same in every lane of the console wave, so the host wave's own first lane holds the answer and the exchange pair is unnecessary.

The shortcut is not exact in general. It returns the host wave's own first lane without checking that the console's first live lane is in it, so it is only right while the value is wave-uniform. lower.rs accepts it as a static switch with that caveat in the comment; under VICTORY_FIRSTLANE_OWN=1 a divergent non-uniform first-lane read yields the wrong lane rather than failing to build.

The right fix

Keep the own_bits.alike fast path (already there, one line above) and extend it to values proved uniform by the scan's own loop shape, or make the fallback exact for the single-wave case: exchange only the has-lane bitmask and the value where a half actually holds a live lane, instead of two full exchange pairs. Then the shortcut can be retired.

Effect on the picture (this is the point)

Builder on is not a small visual change. With the builder off an interior is a flat black frame; with it on, the same interior has bounce light and a bar's shadow across the face. Builder off is the wrong picture, not a cheaper one.

Cost

Builder on currently drops an RTX 3080 to 6.7 / 3.8 fps (149 / 260 ms), dominated by guard lock waits (636 calls, 141 ms a frame) and 3,125 page faults a frame with no copy left in budget. PR #96 removes the descriptor half of that; the guard and fault work is still open.

Verification

  • RTX 3080 10 GB, 0a43566 + VICTORY_BVH_BUILDER=1,VICTORY_FIRSTLANE_OWN=1: all 53 builder programs get host pipelines, no device removal, VICTORY_BVH_QUARANTINE=1 also stable.
  • The same scene with the builder off reproduces the black interior.
**@⁠kalijerry** on GitHub · 2026-11-26 03:25 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/101) Follow-up to #37, with the prefix-scan half of it measured end to end on hardware. ## What happens with the shortcut on VICTORY_FIRSTLANE_OWN=1 (the existing shortcut in emit/lower.rs, written for exactly this scan) makes all three refused stages translate: ```text INFO pipeline: the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53 ``` So nothing new is needed in lowering to get the builder on - it needs this shortcut to be correct for these shaders, or the shortcut promoted to the default. ## Why it is plausible, and where it can be wrong The three stages are the builder's prefix scans (39321a95223001ed, 77360df21e12ea43, 9fc111d3be79364f). They read a sum of scalars with v_readfirstlane inside a loop whose exit is per console wave. The value is the same in every lane of the console wave, so the host wave's own first lane holds the answer and the exchange pair is unnecessary. The shortcut is not exact in general. It returns the host wave's own first lane without checking that the console's first live lane is in it, so it is only right while the value is wave-uniform. lower.rs accepts it as a static switch with that caveat in the comment; under VICTORY_FIRSTLANE_OWN=1 a divergent non-uniform first-lane read yields the wrong lane rather than failing to build. ## The right fix Keep the own_bits.alike fast path (already there, one line above) and extend it to values proved uniform by the scan's own loop shape, or make the fallback exact for the single-wave case: exchange only the has-lane bitmask and the value where a half actually holds a live lane, instead of two full exchange pairs. Then the shortcut can be retired. ## Effect on the picture (this is the point) Builder on is not a small visual change. With the builder off an interior is a flat black frame; with it on, the same interior has bounce light and a bar's shadow across the face. Builder off is the wrong picture, not a cheaper one. ## Cost Builder on currently drops an RTX 3080 to 6.7 / 3.8 fps (149 / 260 ms), dominated by guard lock waits (636 calls, 141 ms a frame) and 3,125 page faults a frame with no copy left in budget. PR #96 removes the descriptor half of that; the guard and fault work is still open. ## Verification - RTX 3080 10 GB, 0a43566 + VICTORY_BVH_BUILDER=1,VICTORY_FIRSTLANE_OWN=1: all 53 builder programs get host pipelines, no device removal, VICTORY_BVH_QUARANTINE=1 also stable. - The same scene with the builder off reproduces the black interior.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:32:11 +00:00
Author
Owner

@⁠bordersky on GitHub · 2026-11-26 04:55 UTC · original · edited 2026-11-26 06:07 UTC

Correction (later): the faces were not lost to a bad save but to loading a checkpoint at all; a clean checkpoint does it too, with the builder on or off. See #67. The rest of this comment stands.

A measurement on the "where can the shortcut be wrong" half, from Linux.

No program of the title's shader archive needs FIRSTLANE_OWN. An offline victory translate --list over the title's shader archive with VICTORY_FIRSTLANE_OWN=0 (b0cfe2b): 26,084 programs, and not one of them fails with a first-lane read where not every lane runs. So the only programs that take the shortcut are the builder's own (they come from the builder DLL, not from the archive), and =1 changes nothing anywhere else.

That makes it possible to take the shortcut by default where it was written for, without the global switch: the programs with spilled user data, the same test pipeline::of_builder already uses to recognise the builder (crate::spill::is_spilled). =1 keeps today's behaviour (every program), =0 turns it off:

-                        static OWN: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
-                        if *OWN.get_or_init(|| std::env::var_os("VICTORY_FIRSTLANE_OWN").is_some_and(|v| v == "1")) {
+                        static OWN: std::sync::OnceLock<Option<bool>> = std::sync::OnceLock::new();
+                        let own = *OWN.get_or_init(|| match std::env::var_os("VICTORY_FIRSTLANE_OWN") {
+                            Some(v) if v == "1" => Some(true),
+                            Some(v) if v == "0" => Some(false),
+                            _ => None,
+                        });
+                        if own.unwrap_or_else(|| crate::spill::is_spilled(self.x.native)) {
                             return int(self, mine);
                         }

With it, VICTORY_BVH_BUILDER=1 alone (what play.ps1 -RayTracing sets) gives the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53, with nothing else set.

Runs (RX 7900 XT 20 GB, 32 GB RAM, Arch, Wine (GE-Proton10-34) with the views-in-a-tree wineserver from #111, vkd3d-proton master, Mesa/RADV, Series X profile; play.ps1 settings plus VICTORY_RELAY=1 VICTORY_CARD_STEPS=0 VICTORY_LAND_ECHO=0 from #13 and #59, and the placeholder() fallback from #59). Same spot in the prison dormitory, about 6,800-7,000 draws a frame:

frame
builder off 100-110 ms
builder on (53/53), several minutes per run ~148-152 ms (preparing ~87, card ~59, copying back ~42)
builder on with VICTORY_BVH_QUARANTINE=1 the same, ~150 ms

No device removal and no GPU page fault in four builder runs. The interior gets its bounce light and the sun's shadows, as you describe.

This is still the same shortcut, not the wave-uniform proof the issue asks for: it only narrows where it applies to the programs it was written for, and makes -RayTracing work without a second switch.

One trap for anyone comparing runs: main characters' faces went missing with the builder on (eyes, teeth and hair floating, secondary characters fine). It survived the quarantine and was not the builder: the title's checkpoint save SARC0015 in the save folder was bad. Moved aside, the main character's face was back with the builder still on (the prison intro cutscene of a new game).

**@⁠bordersky** on GitHub · 2026-11-26 04:55 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/101#issuecomment-7183022660) · edited 2026-11-26 06:07 UTC > **Correction (later):** the faces were not lost to a bad save but to **loading a checkpoint at all**; a clean checkpoint does it too, with the builder on or off. See https://git.gtahub.st/github/avatarmanz--VIctory-7900XTX/issues/67. The rest of this comment stands. A measurement on the "where can the shortcut be wrong" half, from Linux. **No program of the title's shader archive needs `FIRSTLANE_OWN`.** An offline `victory translate --list` over the title's shader archive with `VICTORY_FIRSTLANE_OWN=0` (`b0cfe2b`): 26,084 programs, and not one of them fails with `a first-lane read where not every lane runs`. So the only programs that take the shortcut are the builder's own (they come from the builder DLL, not from the archive), and `=1` changes nothing anywhere else. That makes it possible to take the shortcut by default where it was written for, without the global switch: the programs with spilled user data, the same test `pipeline::of_builder` already uses to recognise the builder (`crate::spill::is_spilled`). `=1` keeps today's behaviour (every program), `=0` turns it off: ```diff - static OWN: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); - if *OWN.get_or_init(|| std::env::var_os("VICTORY_FIRSTLANE_OWN").is_some_and(|v| v == "1")) { + static OWN: std::sync::OnceLock<Option<bool>> = std::sync::OnceLock::new(); + let own = *OWN.get_or_init(|| match std::env::var_os("VICTORY_FIRSTLANE_OWN") { + Some(v) if v == "1" => Some(true), + Some(v) if v == "0" => Some(false), + _ => None, + }); + if own.unwrap_or_else(|| crate::spill::is_spilled(self.x.native)) { return int(self, mine); } ``` With it, `VICTORY_BVH_BUILDER=1` alone (what `play.ps1 -RayTracing` sets) gives `the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53`, with nothing else set. **Runs** (RX 7900 XT 20 GB, 32 GB RAM, Arch, Wine (GE-Proton10-34) with the views-in-a-tree wineserver from #111, vkd3d-proton master, Mesa/RADV, Series X profile; `play.ps1` settings plus `VICTORY_RELAY=1 VICTORY_CARD_STEPS=0 VICTORY_LAND_ECHO=0` from #13 and #59, and the `placeholder()` fallback from #59). Same spot in the prison dormitory, about 6,800-7,000 draws a frame: | | frame | |---|---| | builder off | 100-110 ms | | builder on (53/53), several minutes per run | ~148-152 ms (preparing ~87, card ~59, copying back ~42) | | builder on with `VICTORY_BVH_QUARANTINE=1` | the same, ~150 ms | No device removal and no GPU page fault in four builder runs. The interior gets its bounce light and the sun's shadows, as you describe. This is still the same shortcut, not the wave-uniform proof the issue asks for: it only narrows where it applies to the programs it was written for, and makes `-RayTracing` work without a second switch. One trap for anyone comparing runs: main characters' faces went missing with the builder on (eyes, teeth and hair floating, secondary characters fine). It survived the quarantine and was not the builder: the title's checkpoint save `SARC0015` in the save folder was bad. Moved aside, the main character's face was back with the builder still on (the prison intro cutscene of a new game).
This discussion has been locked. Commenting is limited to contributors.
No milestone
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
github/avatarmanz--VIctory-7900XTX#101
No description provided.