bvh: fix canonical 64-bit VA and non-hidden lazy mapping for hardware BVH64 (#33) #38

Closed
github-bot wants to merge 1 commit from github-bot/gh-38 into main AGit
Owner

@⁠HeroOfOlympus on GitHub · 2026-11-30 19:29 UTC · original
HeroOfOlympus:main → main · +30 −16 · 3 files · 1 commits · closed without merging

Fixes #33

Root cause

Two issues prevented VICTORY_BVH_HARDWARE=1 (image_bvh64_intersect_ray) from returning hits on RADV:

  1. Non-canonical 40-bit base VA & wrong descriptor bounds (crates/victory-shader/src/emit/intersect.rs)

    • um.rs mirror allocations land in high canonical AMDGPU VA space (e.g. 0xffff80025e600000), which gets truncated when packed into word0/word1 of the BVH descriptor.
    • word2 was set to card[3] - 1 (64-byte node count instead of 8-byte units / full range).
    • Fix: reconstruct the canonical 64-bit GPU VA for each node (sign-extending bit 47, shifting by 3, masking with RADV's 42-bit mask ((1 << 42) - 1) << 3) and pass a zero-based full-range descriptor (word0 = 0, word1 = flags, word2 = 0xffff_ffff, word3 = 0x3ff | (DESCRIPTOR_TYPE << 28) | RETURN_BARYCENTRICS), matching RADV (radv_nir_rt_common.c).
  2. HIDDEN lazy mappings backed by zero_bo (crates/victory-gpu/src/um/lazy.rs)

    • bind() and make() mapped unseen pages with HIDDEN (VK_MEMORY_ALIAS_HIDDEN_BIT_RADV). Because Test::Card bypasses SLOT_MEMORY/SLOT_FAULTS, hardware BVH64 reads hit zero_bo instead of actual title BVH memory.
    • Fix: drop HIDDEN in bind() and make() (keeping probe_card() intact).
  3. Bumped TRANSLATOR_VERSION to 11 in crates/victory-shader/src/lib.rs to invalidate cached shaders.

Result

Tested on RX 9070 XT (RADV 26.3.1, Linux): VICTORY_BVH_HARDWARE=1 renders full geometry and daytime RT GI cleanly (~35–48 FPS, 0 dropped draws, 0 GPU hangs).

**@⁠HeroOfOlympus** on GitHub · 2026-11-30 19:29 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/38) `HeroOfOlympus:main` → `main` · +30 −16 · 3 files · 1 commits · closed without merging Fixes #33 ### Root cause Two issues prevented `VICTORY_BVH_HARDWARE=1` (`image_bvh64_intersect_ray`) from returning hits on RADV: 1. **Non-canonical 40-bit base VA & wrong descriptor bounds (`crates/victory-shader/src/emit/intersect.rs`)** - `um.rs` mirror allocations land in high canonical AMDGPU VA space (e.g. `0xffff80025e600000`), which gets truncated when packed into `word0`/`word1` of the BVH descriptor. - `word2` was set to `card[3] - 1` (64-byte node count instead of 8-byte units / full range). - Fix: reconstruct the canonical 64-bit GPU VA for each node (sign-extending bit 47, shifting by 3, masking with RADV's 42-bit mask `((1 << 42) - 1) << 3`) and pass a zero-based full-range descriptor (`word0 = 0`, `word1 = flags`, `word2 = 0xffff_ffff`, `word3 = 0x3ff | (DESCRIPTOR_TYPE << 28) | RETURN_BARYCENTRICS`), matching RADV (`radv_nir_rt_common.c`). 2. **`HIDDEN` lazy mappings backed by `zero_bo` (`crates/victory-gpu/src/um/lazy.rs`)** - `bind()` and `make()` mapped unseen pages with `HIDDEN` (`VK_MEMORY_ALIAS_HIDDEN_BIT_RADV`). Because `Test::Card` bypasses `SLOT_MEMORY`/`SLOT_FAULTS`, hardware BVH64 reads hit `zero_bo` instead of actual title BVH memory. - Fix: drop `HIDDEN` in `bind()` and `make()` (keeping `probe_card()` intact). 3. Bumped `TRANSLATOR_VERSION` to `11` in `crates/victory-shader/src/lib.rs` to invalidate cached shaders. ### Result Tested on RX 9070 XT (RADV 26.3.1, Linux): `VICTORY_BVH_HARDWARE=1` renders full geometry and daytime RT GI cleanly (~35–48 FPS, 0 dropped draws, 0 GPU hangs).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 07:41:53 +00:00
Author
Owner

@⁠enjoyerofslop on GitHub · 2026-11-30 23:25 UTC · original

Tested on a Radeon 8060S (Strix Halo, RDNA 3.5 iGPU): Bazzite 45, Mesa 26.3.1 with this repo's RADV patch, Proton-CachyOS 11.0, at 4cce312 plus this PR (plus a local change so um.rs accepts an integrated GPU).

Before the PR, VICTORY_BVH_HARDWARE=1 drew most geometry black, as in #33. With the PR, most geometry renders, but some thin geometry (the railing balusters on the prologue deck) is still solid black in some camera shots.

With VICTORY_BVH_HARDWARE=0 the PR renders correctly and has no measurable effect on frame time.

Timing (diag, 2560x1440, Series X profile, 330 s window, matched draw count): hardware test 41.4 ms vs inline 46.7 ms.

**@⁠enjoyerofslop** on GitHub · 2026-11-30 23:25 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/38#issuecomment-7295100581) Tested on a Radeon 8060S (Strix Halo, RDNA 3.5 iGPU): Bazzite 45, Mesa 26.3.1 with this repo's RADV patch, Proton-CachyOS 11.0, at 4cce312 plus this PR (plus a local change so `um.rs` accepts an integrated GPU). Before the PR, `VICTORY_BVH_HARDWARE=1` drew most geometry black, as in #33. With the PR, most geometry renders, but some thin geometry (the railing balusters on the prologue deck) is still solid black in some camera shots. With `VICTORY_BVH_HARDWARE=0` the PR renders correctly and has no measurable effect on frame time. Timing (diag, 2560x1440, Series X profile, 330 s window, matched draw count): hardware test 41.4 ms vs inline 46.7 ms.
Author
Owner

@⁠enjoyerofslop on GitHub · 2026-12-01 02:31 UTC · original

Correction to my comment above: I can no longer reproduce the black thin geometry with this PR on the 8060S.

  • Seven runs with VICTORY_BVH_HARDWARE=1 since then render it correctly. One was a full run: 42.0 ms at 8,582 draws, against 46.8 ms at 8,875 draws with VICTORY_BVH_HARDWARE=0 (diag, 2560x1440, Series X profile, 150–480 s window).
  • Rebuilding the exact source of the runs that showed the black also renders correctly now. So what I reported came from some state on my machine at the time, not from this PR. I haven't pinned it down. Those runs came shortly after a run that ended in a GPU watchdog crash.

The builds carried two local changes besides this PR:

  1. um.rs accepts an integrated GPU (device type 1) when there's no discrete one.
  2. In bvh_hardware, a triangle test on a node the card doesn't hold goes in as kind 7 and returns 0xffffffff in all four dwords. That's four NaNs, which the walk programs' distance tests accept as a hit. It now returns [inf, 0, 0, 0], as a node of zeros does inline. This didn't affect the black, but it looks like a real hole. I can open a PR for it if useful.

For what it's worth, on RDNA 3.5 the instruction returns all four triangle dwords scaled by |largest direction component|³. The ratios are the same, so num/den and the barycentrics come out unchanged. An in-game comparison against the inline test over the seven walk programs shows hit decisions agreeing apart from ties at the ray's extent.

**@⁠enjoyerofslop** on GitHub · 2026-12-01 02:31 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/38#issuecomment-7298700987) Correction to my comment above: I can no longer reproduce the black thin geometry with this PR on the 8060S. - Seven runs with `VICTORY_BVH_HARDWARE=1` since then render it correctly. One was a full run: 42.0 ms at 8,582 draws, against 46.8 ms at 8,875 draws with `VICTORY_BVH_HARDWARE=0` (diag, 2560x1440, Series X profile, 150–480 s window). - Rebuilding the exact source of the runs that showed the black also renders correctly now. So what I reported came from some state on my machine at the time, not from this PR. I haven't pinned it down. Those runs came shortly after a run that ended in a GPU watchdog crash. The builds carried two local changes besides this PR: 1. `um.rs` accepts an integrated GPU (device type 1) when there's no discrete one. 2. In `bvh_hardware`, a triangle test on a node the card doesn't hold goes in as kind 7 and returns `0xffffffff` in all four dwords. That's four NaNs, which the walk programs' distance tests accept as a hit. It now returns `[inf, 0, 0, 0]`, as a node of zeros does inline. This didn't affect the black, but it looks like a real hole. I can open a PR for it if useful. For what it's worth, on RDNA 3.5 the instruction returns all four triangle dwords scaled by |largest direction component|³. The ratios are the same, so num/den and the barycentrics come out unchanged. An in-game comparison against the inline test over the seven walk programs shows hit decisions agreeing apart from ties at the ray's extent.
Author
Owner

@⁠YaBulochka on GitHub · 2026-12-01 08:30 UTC · original

Hardware BVH64 on RDNA3 renders, but the whole scene comes out dark: underexposed, as if every surface sits in shadow. Not dark textures — the light itself is missing.

Environment. RX 7600 XT (8 GB, RDNA3), Ryzen 5 9600X, 30 GB RAM, RADV 26.3.1 from ./setup.sh. Build ede9bc9 (pr38 + #51 + #52 merged on 37bb30f). series-x, VICTORY_OUTPUT=1920x1080, RT on.

What happens.

  • With VICTORY_BVH_HARDWARE=1: the ray-tracing node test by the card's own instruction on=true, no errors in the log, geometry is there and correct (no black meshes, faces fine), ~12.2 fps / 81.8 ms in the harbour scene, 1280x720 -> 1920x1080. The picture, though, is far too dark: pavement, cars and foliage read as if in shade, while the sky and the water reflections are normal.
  • With VICTORY_BVH_HARDWARE=0 on the same build and settings, the same place is lit normally.

So the node test itself passes now (it did not before the PR), but the traced results look like a hit that should miss, for shadow/GI rays rather than primary ones: reflections and direct light survive, shadowed regions swallow everything.

Two things I could not tell apart from the outside, in case one of them is a known limitation: ray origin epsilon / self-intersection, or the instance transform (BLAS -> TLAS) being applied with the wrong basis, both of which would darken shadow rays first.

Happy to run any diagnostic switch you point me at. No game files, screenshots or captures included.

**@⁠YaBulochka** on GitHub · 2026-12-01 08:30 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/38#issuecomment-7305419196) Hardware BVH64 on **RDNA3** renders, but the whole scene comes out dark: underexposed, as if every surface sits in shadow. Not dark textures — the light itself is missing. **Environment.** RX 7600 XT (8 GB, RDNA3), Ryzen 5 9600X, 30 GB RAM, RADV 26.3.1 from `./setup.sh`. Build `ede9bc9` (`pr38` + #51 + #52 merged on `37bb30f`). `series-x`, `VICTORY_OUTPUT=1920x1080`, RT on. **What happens.** - With `VICTORY_BVH_HARDWARE=1`: `the ray-tracing node test by the card's own instruction on=true`, no errors in the log, geometry is there and correct (no black meshes, faces fine), `~12.2 fps / 81.8 ms` in the harbour scene, 1280x720 -> 1920x1080. The picture, though, is far too dark: pavement, cars and foliage read as if in shade, while the sky and the water reflections are normal. - With `VICTORY_BVH_HARDWARE=0` on the same build and settings, the same place is lit normally. So the node test itself passes now (it did not before the PR), but the traced results look like a hit that should miss, for shadow/GI rays rather than primary ones: reflections and direct light survive, shadowed regions swallow everything. Two things I could not tell apart from the outside, in case one of them is a known limitation: ray origin epsilon / self-intersection, or the instance transform (BLAS -> TLAS) being applied with the wrong basis, both of which would darken shadow rays first. Happy to run any diagnostic switch you point me at. No game files, screenshots or captures included.
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:00 UTC · original · edited 2026-12-05 11:24 UTC

As I read it, this is already in main: this exact change was cherry-picked to main as 8aec563, with the same title, the same --stat, and a body naming this PR's head (79e9a57).

The lines are live today: crates/victory-gpu/src/um/lazy.rs:496 let protection = if touched { READ_WRITE } else { 0 }; (and :640-641), and intersect.rs builds the descriptor from bvh_address with word3 0x3ff | (DESCRIPTOR_TYPE << 28) | RETURN_BARYCENTRICS. The merged copy was then refined by e7e7bb4 ("gpu: pre-encode the native BVH64 mirror base"), and TRANSLATOR_VERSION is now 20, so the version bump has been superseded three times over.

Nothing here is unreviewed work — the PR is older than what runs. If you want to continue on BVH64, start from main.

Whether it still has work of its own is the maintainer's call, not mine.

**@⁠Luxuride** on GitHub · 2026-12-04 12:00 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/38#issuecomment-7410836486) · edited 2026-12-05 11:24 UTC As I read it, this is already in `main`: this exact change was cherry-picked to `main` as `8aec563`, with the same title, the same `--stat`, and a body naming this PR's head (`79e9a57`). The lines are live today: `crates/victory-gpu/src/um/lazy.rs:496` `let protection = if touched { READ_WRITE } else { 0 };` (and `:640-641`), and `intersect.rs` builds the descriptor from `bvh_address` with word3 `0x3ff | (DESCRIPTOR_TYPE << 28) | RETURN_BARYCENTRICS`. The merged copy was then refined by `e7e7bb4` ("gpu: pre-encode the native BVH64 mirror base"), and `TRANSLATOR_VERSION` is now 20, so the version bump has been superseded three times over. Nothing here is unreviewed work — the PR is older than what runs. If you want to continue on BVH64, start from `main`. Whether it still has work of its own is the maintainer's call, not mine.
github-bot closed this pull request 2026-12-05 17:31:40 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.