gpu(native): snapshot descriptor table records when recording commands #546

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

@⁠Sheffy007 on GitHub · 2026-11-28 02:28 UTC · original
Sheffy007:fix/snapshot-recorded-table-entries → main · +759 −115 · 10 files · 1 commits · open

Summary

  • Snapshot the 12-byte [tag, index, generation] descriptor slot records of each bound Root::Table span when recording Cmd::Dispatch and Cmd::Draw (snapshot_roots), rather than reading live title descriptor heap memory at submission time after the title may have unbound or overwritten entries used by an earlier command.
  • Route mirror through mirror_record(&heap, index, record) (and descriptor::view_record) so submission-time mirroring, evicted-texture recreation (resources_named), typed buffer materialization (materialize_typed_buffers), UAV dirty-page tracking (note_written), and first-use view_strides / view_addresses tables all read the command's recorded slot records, including null buffer SRVs/UAVs ({ addr: 0, size: 0 }) and null image views (clear_entry).
  • Prevent later commands in the same submission whose statically-bounded DXIL heap accesses do not read index (cmd_may_read_entry) from clobbering heap entries claimed by earlier commands in that submission, and catch up rolled_back entries (sync_rolled_back) at the start of the next submission before bindless work runs.
  • Document the behavior in docs/native-host.md and add unit and Metal GPU end-to-end tests covering intra-submission CBV/SRV unbinds, null-buffer-to-placed-buffer overwrites with next-submission bindless catch-up, and evicted texture recreation after unbind.

Verification

  • cargo xtask policy
  • cargo test -p victory-gpu --lib --locked -- --test-threads=1
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings

Closes #542
Refs #258
cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-28 02:28 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/542) `Sheffy007:fix/snapshot-recorded-table-entries` → `main` · +759 −115 · 10 files · 1 commits · open ## Summary - Snapshot the 12-byte `[tag, index, generation]` descriptor slot records of each bound `Root::Table` span when recording `Cmd::Dispatch` and `Cmd::Draw` (`snapshot_roots`), rather than reading live title descriptor heap memory at submission time after the title may have unbound or overwritten entries used by an earlier command. - Route `mirror` through `mirror_record(&heap, index, record)` (and `descriptor::view_record`) so submission-time mirroring, evicted-texture recreation (`resources_named`), typed buffer materialization (`materialize_typed_buffers`), UAV dirty-page tracking (`note_written`), and first-use `view_strides` / `view_addresses` tables all read the command's recorded slot records, including null buffer SRVs/UAVs (`{ addr: 0, size: 0 }`) and null image views (`clear_entry`). - Prevent later commands in the same submission whose statically-bounded DXIL heap accesses do not read `index` (`cmd_may_read_entry`) from clobbering heap entries claimed by earlier commands in that submission, and catch up `rolled_back` entries (`sync_rolled_back`) at the start of the next submission before bindless work runs. - Document the behavior in `docs/native-host.md` and add unit and Metal GPU end-to-end tests covering intra-submission CBV/SRV unbinds, null-buffer-to-placed-buffer overwrites with next-submission bindless catch-up, and evicted texture recreation after unbind. ## Verification - `cargo xtask policy` - `cargo test -p victory-gpu --lib --locked -- --test-threads=1` - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings` Closes #542 Refs #258 cc @⁠Olima34
Root::Table bindings previously captured only the heap and base index,
so submission-time mirroring read live title heap memory after the title
could have unbound or overwritten entries used by an earlier recorded
draw or dispatch.

Snapshot the 12-byte view slot records for each bound descriptor table
span when recording draws and dispatches, mirror and materialize views
from those recorded records, keep intra-submission unbinds from clobbering
entries claimed by earlier commands in the same submission, and catch up
rolled-back entries before the next submission's bindless work runs.

Closes #538
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 02:32:39 +00:00
github-bot force-pushed github-bot/gh-542 from 93ee6a8389 to 69a64d3bd6 2026-11-28 03:00:29 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 03:54 UTC · original · requested changes

Thanks @⁠Sheffy007. Reading the records a command was recorded with, rather than whatever the heap holds at submission, is the D3D12 rule, and the tests (intra-submission unbinds, null-to-placed overwrite with the next-submission catch-up, evicted texture recreation) cover the cases well. We read the whole diff of 69a64d3b while helping the maintainer clear the queue. One thing is missing before it can merge:

A cost measurement on the recording path. snapshot_roots now runs at every draw_call and dispatch. For each bound table it does one safe_read (a mach_vm_read_overwrite system call on macOS) of up to the table's checked span, plus a Vec and an Rc<[_]> allocation. All of that runs on the title's command-list recording thread, before submission, and comes on top of the reads remirror_tables already does at submission. A world frame records thousands of draws and dispatches with two or more tables each, so this could be several thousand extra system calls a frame. World frame rate is one of the project's three goals right now, and the PR only lists unit and clippy checks.

Could you post a before/after from a world run? tools/macos/run-summary.sh --compare of two headless runs of the same length would do, fps per 64 frames plus VICTORY_SUBMIT_TIMING=1 if you can. If the cost shows, two cheaper options: reuse the previous command's snapshot when the table base and the span's bytes are unchanged, or snapshot only spans the title wrote since the last record. Either would keep the semantics.

Smaller: the Windows safe_read (ReadProcessMemory) is fine, but say in the description why it's needed here (the snapshot reaches it on the Windows build too, we assume), so it doesn't read as unrelated.

CI is green on this head. No game run on our side.

**@⁠Olima34** on GitHub · 2026-11-28 03:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/542#pullrequestreview-6095589654) · **requested changes** Thanks @⁠Sheffy007. Reading the records a command was recorded with, rather than whatever the heap holds at submission, is the D3D12 rule, and the tests (intra-submission unbinds, null-to-placed overwrite with the next-submission catch-up, evicted texture recreation) cover the cases well. We read the whole diff of 69a64d3b while helping the maintainer clear the queue. One thing is missing before it can merge: **A cost measurement on the recording path.** `snapshot_roots` now runs at every `draw_call` and `dispatch`. For each bound table it does one `safe_read` (a `mach_vm_read_overwrite` system call on macOS) of up to the table's checked span, plus a `Vec` and an `Rc<[_]>` allocation. All of that runs on the title's command-list recording thread, before submission, and comes on top of the reads `remirror_tables` already does at submission. A world frame records thousands of draws and dispatches with two or more tables each, so this could be several thousand extra system calls a frame. World frame rate is one of the project's three goals right now, and the PR only lists unit and clippy checks. Could you post a before/after from a world run? `tools/macos/run-summary.sh --compare` of two headless runs of the same length would do, fps per 64 frames plus `VICTORY_SUBMIT_TIMING=1` if you can. If the cost shows, two cheaper options: reuse the previous command's snapshot when the table base and the span's bytes are unchanged, or snapshot only spans the title wrote since the last record. Either would keep the semantics. Smaller: the Windows `safe_read` (`ReadProcessMemory`) is fine, but say in the description why it's needed here (the snapshot reaches it on the Windows build too, we assume), so it doesn't read as unrelated. CI is green on this head. No game run on our side.
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/546/head:github-bot/gh-542'
git switch 'github-bot/gh-542'

Merge

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