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

Merged
Olima34 merged 1 commit from upstream-pr/105 into main 2026-11-26 16:38:18 +00:00
Olima34 commented 2026-11-26 15:53:17 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T15:53:17Z.


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
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6630346775 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T15:53:17Z. --- ## 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
LakshanSivakumar commented 2026-11-26 15:55:39 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T15:55:39Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6077113876 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#pullrequestreview-6077113876). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T15:55:39Z. **Review:** COMMENTED --- 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.
Olima34 commented 2026-11-26 15:57:53 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T15:57:53Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7196992470 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#issuecomment-7196992470). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T15:57:53Z. --- 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.
LakshanSivakumar commented 2026-11-26 16:04:10 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:04:10Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6077227852 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#pullrequestreview-6077227852). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:04:10Z. **Review:** CHANGES_REQUESTED --- 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.
Olima34 commented 2026-11-26 16:27:27 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T16:27:27Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7197670308 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#issuecomment-7197670308). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T16:27:27Z. --- 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.
LakshanSivakumar commented 2026-11-26 16:37:27 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:37:27Z.

Review: APPROVED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6077662043 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/105#pullrequestreview-6077662043). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:37:27Z. **Review:** APPROVED --- 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.
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
LakshanSivakumar/Native-Victory-macOS!105
No description provided.