gpu(native): show nothing for a buffer view of memory in no pool #105

Manually merged
github merged 1 commit from github-bot/gh-105 into main 2026-11-26 16:40:53 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 15:53 UTC · original
Olima34:fix/native-null-unresolved-view → main · +107 −8 · 3 files · 1 commits · merged 2026-11-26 16:38 UTC

What this changes

Refs #15, point 2 of my last comment there. NativeHost::mirror returned before write_buffer when a buffer view's address resolved to no pool ("Stale or unsupported views leave the entry as it was"). If the title reuses a descriptor slot for such a buffer, the Metal entry kept the buffer an earlier view named there. The title may have given that memory to something else since, and shaders went on reading and writing it, silently: the kind of corruption whose crash site moves between runs.

  • A buffer view of memory in no pool now gets the null view (size 0, the one write_pairs already uses for pair 0): reads give 0 and writes are dropped. The error is still returned, so the log line stays. The entry is not marked mirrored, so a later mirror of that slot writes the real view.
  • Only buffer views change. Undecodable records and image or sampler views the host cannot make still leave the entry as it was, since a buffer in a texture or sampler entry is not something to hand the GPU. The doc comment says so.
  • null_view() makes the null page at first use and borrows the contract only for the call. write_pairs now takes it first and borrows the contract read-only. I checked that remirror_tables and the glue callers hold no borrow of the contract when they call mirror.

Known limit: remirror_tables tries each record once, whatever the result. A slot left null at submission is written again only when its record changes, or by a title call that mirrors it. Before, that same slot stayed stale.

How it was tested

  • a_view_of_unmapped_memory_no_longer_shows_the_previous_buffer (native, Metal). A shader writes buffer A through a descriptor table. The slot is then rewritten to 0x10_0000_0000 (no pool), and mirror errs. The same dispatch runs again, and A must be unchanged. Finally the slot is pointed back at A, and the dispatch writes A again. With main's mirror, step 3 fails: A still gets [1, 4, 7, …] through the stale entry.
  • victory-gpu on arm64 with the Metal Shader Converter, 167 tests, 3 passes; arm64 cargo test --workspace (691)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features
  • cargo xtask policy; it merges cleanly with #100 and #102
  • Ran the game: not done, no copy of it here

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • No guesses about console behaviour (D3D12 null descriptors read 0 and drop writes)
  • No new diagnostics
**@⁠Olima34** on GitHub · 2026-11-26 15:53 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105) `Olima34:fix/native-null-unresolved-view` → `main` · +107 −8 · 3 files · 1 commits · merged 2026-11-26 16:38 UTC ## What this changes Refs #15, point 2 of my last comment there. `NativeHost::mirror` returned before `write_buffer` when a buffer view's address resolved to no pool ("Stale or unsupported views leave the entry as it was"). If the title reuses a descriptor slot for such a buffer, the Metal entry kept the buffer an earlier view named there. The title may have given that memory to something else since, and shaders went on reading and writing it, silently: the kind of corruption whose crash site moves between runs. - A buffer view of memory in no pool now gets the null view (size 0, the one `write_pairs` already uses for pair 0): reads give 0 and writes are dropped. The error is still returned, so the log line stays. The entry is not marked mirrored, so a later `mirror` of that slot writes the real view. - Only buffer views change. Undecodable records and image or sampler views the host cannot make still leave the entry as it was, since a buffer in a texture or sampler entry is not something to hand the GPU. The doc comment says so. - `null_view()` makes the null page at first use and borrows the contract only for the call. `write_pairs` now takes it first and borrows the contract read-only. I checked that `remirror_tables` and the `glue` callers hold no borrow of the contract when they call `mirror`. Known limit: `remirror_tables` tries each record once, whatever the result. A slot left null at submission is written again only when its record changes, or by a title call that mirrors it. Before, that same slot stayed stale. ## How it was tested - [x] `a_view_of_unmapped_memory_no_longer_shows_the_previous_buffer` (native, Metal). A shader writes buffer A through a descriptor table. The slot is then rewritten to `0x10_0000_0000` (no pool), and `mirror` errs. The same dispatch runs again, and A must be unchanged. Finally the slot is pointed back at A, and the dispatch writes A again. With `main`'s `mirror`, step 3 fails: A still gets `[1, 4, 7, …]` through the stale entry. - [x] `victory-gpu` on arm64 with the Metal Shader Converter, 167 tests, 3 passes; arm64 `cargo test --workspace` (691) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features` - [x] `cargo xtask policy`; it merges cleanly with #100 and #102 - [ ] Ran the game: not done, no copy of it here ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] No guesses about console behaviour (D3D12 null descriptors read 0 and drop writes) - [x] No new diagnostics
NativeHost::mirror returned before writing the entry when a buffer
view's address resolved to no pool, so a descriptor the title reused
for such a buffer kept the host entry of the buffer it named before:
shaders went on reading and writing that memory, which the title may
have given to something else (issue #15: writes landing elsewhere).
The entry now gets the null view (size 0, the one pair 0 uses, now
from a small null_view helper) and mirror still returns the error,
without marking the entry mirrored. Image and sampler views the host
cannot make still leave the entry as it was.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:57:19 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 15:55 UTC · original · reviewed

Giving a buffer view of memory in no pool the null view (size 0) instead of leaving the previous buffer in the Metal entry is the right call for stale-descriptor corruption, and the test covers it. macos-scripts passes, main check still pending. I will approve once it is green. Relevant to the prologue crash: this closes one way a shader can touch memory the title has since reused, but it will not explain pages owned twice in xmem_posix, so keep #15 open after it lands.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 15:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#pullrequestreview-6077113876) · **reviewed** Giving a buffer view of memory in no pool the null view (size 0) instead of leaving the previous buffer in the Metal entry is the right call for stale-descriptor corruption, and the test covers it. macos-scripts passes, main check still pending. I will approve once it is green. Relevant to the prologue crash: this closes one way a shader can touch memory the title has since reused, but it will not explain pages owned twice in xmem_posix, so keep #15 open after it lands.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-26 15:57 UTC · original

The failing check isn't this change: it's victory-platform's a_page_pool_maps_at_several_addresses (tests/conformance.rs:102, Windows error 487, "Attempt to access invalid address"). That test releases a reservation and then maps at its address, and its own comment says this races the other tests for the address. This PR only touches victory-gpu/src/native, which isn't built on Windows. Could you rerun the failed job? I can't rerun it from a fork. If that test keeps flaking on other PRs, I can send a separate fix that retries the mapping at a fresh reservation when it hits 487.

**@⁠Olima34** on GitHub · 2026-11-26 15:57 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#issuecomment-7196992470) The failing `check` isn't this change: it's `victory-platform`'s `a_page_pool_maps_at_several_addresses` (`tests/conformance.rs:102`, Windows error 487, "Attempt to access invalid address"). That test releases a reservation and then maps at its address, and its own comment says this races the other tests for the address. This PR only touches `victory-gpu/src/native`, which isn't built on Windows. Could you rerun the failed job? I can't rerun it from a fork. If that test keeps flaking on other PRs, I can send a separate fix that retries the mapping at a fresh reservation when it hits 487.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 16:04 UTC · original · requested changes

The main CI check has now failed on this PR (macos-scripts passes). Please look at the failure and fix or explain it; I could not tell from the diff alone whether it comes from this change. The change itself still looks right.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 16:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#pullrequestreview-6077227852) · **requested changes** The main CI check has now failed on this PR (macos-scripts passes). Please look at the failure and fix or explain it; I could not tell from the diff alone whether it comes from this change. The change itself still looks right.
github-bot force-pushed github-bot/gh-105 from da1009bb53 to 01cbebdc5c 2026-11-26 16:30:23 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-26 16:27 UTC · original

Rebased on main to rerun CI; the change is the same (167 victory-gpu tests pass on Metal). The failure was in victory-platform's a_page_pool_maps_at_several_addresses (Windows 487, "Attempt to access invalid address"). That test releases a reservation, then maps at its address, and its own comment notes it races the other tests for that address. This PR doesn't touch victory-platform or any Windows code.

**@⁠Olima34** on GitHub · 2026-11-26 16:27 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#issuecomment-7197670308) Rebased on `main` to rerun CI; the change is the same (167 victory-gpu tests pass on Metal). The failure was in `victory-platform`'s `a_page_pool_maps_at_several_addresses` (Windows 487, "Attempt to access invalid address"). That test releases a reservation, then maps at its address, and its own comment notes it races the other tests for that address. This PR doesn't touch `victory-platform` or any Windows code.
github manually merged commit 445d8a4619 into main 2026-11-26 16:40:53 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 16:37 UTC · original · approved these changes

Checked the diff: a buffer view of memory in no pool now writes the null view, the new test covers the stale entry and the recovery. Merged onto main, native tests, windows clippy and xtask policy are clean, CI is green.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 16:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#pullrequestreview-6077662043) · **approved these changes** Checked the diff: a buffer view of memory in no pool now writes the null view, the new test covers the stale entry and the recovery. Merged onto main, native tests, windows clippy and xtask policy are clean, CI is green.
This discussion has been locked. Commenting is limited to contributors.
No description provided.