Preserve full guest addresses when deduplicating BVH builder memory operations #236

Open
github-bot wants to merge 1 commit from github-bot/gh-236 into main AGit
Owner

@⁠feanorsun on GitHub · 2026-11-26 12:15 UTC · original
feanorsun:fix/bvh-builder-memory-keys → main · +89 −2 · 2 files · 1 commits · open

Fixes #202

The BVH builder used bits 2 through 32 of the guest address to deduplicate work within a command-list recording. After 0x1_0001_0000, a request at 0x3_0001_0000 produced the same key and could skip a second write preparation or small-buffer copy-back registration.

Record Write(at) for the incoming root address and Back(start) for the buffer start returned by shadow::in_buffer. The low two bits matter because Root::View passes the byte address through, buffers are registered at their exact starts, and Memory::small processes the byte range [start, start + len).

Each command list owns its set in Deferred. An exact repeat of the same operation is skipped until reset replaces that recording's state. HostList::untouched counts a recorded builder operation as work, as it did when the old keys lived in the texture set.

Thanks to FunWithFlagsDev for identifying both collisions, providing the 8 GiB counterexample and proposing the typed per-recording keys. This change integrates that approach with the current command-list state and adds separate native regressions for the write and copy-back paths.

Windows verification

cargo test --offline --locked -j 1 -p victory-gpu --lib host::tests::builder_memory:: -- --list
cargo test --offline --locked -j 1 -p victory-gpu --lib host::tests::builder_memory:: -- --test-threads=1 --nocapture

Both listings found five tests. For the baseline, the same recording method inserted the two original expressions into the original set. Two tests passed and three failed. Write and copy-back independently rejected 0x3_0001_0000 after 0x1_0001_0000. Both also rejected the next byte, 0x1_0001_0001, in the same dword.

With typed keys, all five passed, including exact repeats, distinct operations, independent recordings and reset. These tests use integer addresses and CPU recording state. An earlier PowerShell invocation accidentally split --list into single-character filters and ran other library tests, including WARP tests. The counts above are from the subsequent module-filtered runs.

**@⁠feanorsun** on GitHub · 2026-11-26 12:15 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/236) `feanorsun:fix/bvh-builder-memory-keys` → `main` · +89 −2 · 2 files · 1 commits · open Fixes #202 The BVH builder used bits 2 through 32 of the guest address to deduplicate work within a command-list recording. After `0x1_0001_0000`, a request at `0x3_0001_0000` produced the same key and could skip a second write preparation or small-buffer copy-back registration. Record `Write(at)` for the incoming root address and `Back(start)` for the buffer start returned by `shadow::in_buffer`. The low two bits matter because `Root::View` passes the byte address through, buffers are registered at their exact starts, and `Memory::small` processes the byte range `[start, start + len)`. Each command list owns its set in `Deferred`. An exact repeat of the same operation is skipped until reset replaces that recording's state. `HostList::untouched` counts a recorded builder operation as work, as it did when the old keys lived in the texture set. Thanks to FunWithFlagsDev for identifying both collisions, providing the 8 GiB counterexample and proposing the typed per-recording keys. This change integrates that approach with the current command-list state and adds separate native regressions for the write and copy-back paths. ## Windows verification ```powershell cargo test --offline --locked -j 1 -p victory-gpu --lib host::tests::builder_memory:: -- --list cargo test --offline --locked -j 1 -p victory-gpu --lib host::tests::builder_memory:: -- --test-threads=1 --nocapture ``` Both listings found five tests. For the baseline, the same recording method inserted the two original expressions into the original set. Two tests passed and three failed. Write and copy-back independently rejected `0x3_0001_0000` after `0x1_0001_0000`. Both also rejected the next byte, `0x1_0001_0001`, in the same dword. With typed keys, all five passed, including exact repeats, distinct operations, independent recordings and reset. These tests use integer addresses and CPU recording state. An earlier PowerShell invocation accidentally split `--list` into single-character filters and ran other library tests, including WARP tests. The counts above are from the subsequent module-filtered runs.
Track write preparation by the root byte address and small-buffer copy-back by the registered buffer start. Keep both kinds of work in the recording until reset and count them when checking whether the list is untouched.

Thanks to FunWithFlagsDev for reporting both collisions in #202, supplying the 8 GiB counterexample and proposing typed per-recording keys. Cover the two admission paths, byte offsets, exact repeats and recording lifetime with native CPU tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:16:02 +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 origin '+refs/pull/236/head:github-bot/gh-236'
git switch 'github-bot/gh-236'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-236'
git switch 'github-bot/gh-236'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-236'
git switch 'github-bot/gh-236'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-236'
git switch 'main'
git merge --squash 'github-bot/gh-236'
git switch 'main'
git merge --ff-only 'github-bot/gh-236'
git switch 'main'
git merge 'github-bot/gh-236'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.