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

Open
feanorsun wants to merge 1 commit from upstream-pr/236 into main
feanorsun commented 2026-11-26 12:15:16 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by feanorsun on 2026-11-26T12:15:16Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6626434349 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/236). Originally posted by [feanorsun](https://github.com/feanorsun) on 2026-11-26T12:15:16Z. --- 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/236:upstream-pr/236'
git switch 'upstream-pr/236'

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 'upstream-pr/236'
git switch 'upstream-pr/236'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/236'
git switch 'upstream-pr/236'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/236'
git switch 'main'
git merge --squash 'upstream-pr/236'
git switch 'main'
git merge --ff-only 'upstream-pr/236'
git switch 'main'
git merge 'upstream-pr/236'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
avatarmanz/VIctory-7900XTX!236
No description provided.