A fresh title stock buffer sometimes holds old bytes (0xEE) in the parallel victory-gpu suite #387

Open
opened 2026-11-27 23:24:46 +00:00 by hamdanpor-ctrl · 4 comments
hamdanpor-ctrl commented 2026-11-27 23:24:46 +00:00 (Migrated from github.com)
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by hamdanpor-ctrl on 2026-11-27T23:24:46Z.


host::title_stock::tests::stopping_stock_keeps_issued_buffers_independent_and_mapped fails now and then in the parallel cargo test -p victory-gpu --locked because a fresh title buffer is not zero:

Tree Runs Failed Where
1d83085 + #382 40 1 title_stock.rs:209, a.1.read_volatile() not 0
fe7c6e5 + #288's diff 5 1 title_stock.rs:211, b.1.read_volatile() = 238 (0xEE), expected 0

b is read before anything in the test writes it, and 0xEE is not the test's own 0xa5, so b came back holding bytes from somewhere else. 0xEE is what some other tests write into GPU-visible memory, e.g. host/card_steps.rs:2046 and host/upcheck.rs:1362. So either a buffer from create_shared_buffer (custom heap, created not resident, then MakeResident + mapped) can come back without being zeroed after another test's buffer is released, or a write through an old mapping lands in memory that was freed and reused. The first would only matter to tests; the second would be a real bug.

#288 doesn't touch title_stock.rs, and the first failure was without it, so it is not from that PR. In 120 more runs on other trees it did not fail, so it is rare.

  • PC: RTX 3050 Laptop GPU 4 GB (driver 617.42), i7-12700H, 16 GB, Windows 11 Pro; Rust 1.98.1

AI-assisted (Claude Code).

<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:6656036577 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/387). Originally posted by [hamdanpor-ctrl](https://github.com/hamdanpor-ctrl) on 2026-11-27T23:24:46Z. --- `host::title_stock::tests::stopping_stock_keeps_issued_buffers_independent_and_mapped` fails now and then in the parallel `cargo test -p victory-gpu --locked` because a fresh title buffer is not zero: | Tree | Runs | Failed | Where | |---|---:|---:|---| | `1d83085` + #382 | 40 | 1 | `title_stock.rs:209`, `a.1.read_volatile()` not 0 | | `fe7c6e5` + #288's diff | 5 | 1 | `title_stock.rs:211`, `b.1.read_volatile()` = **238** (0xEE), expected 0 | `b` is read before anything in the test writes it, and 0xEE is not the test's own 0xa5, so `b` came back holding bytes from somewhere else. 0xEE is what some other tests write into GPU-visible memory, e.g. `host/card_steps.rs:2046` and `host/upcheck.rs:1362`. So either a buffer from `create_shared_buffer` (custom heap, created not resident, then `MakeResident` + `mapped`) can come back without being zeroed after another test's buffer is released, or a write through an old mapping lands in memory that was freed and reused. The first would only matter to tests; the second would be a real bug. #288 doesn't touch `title_stock.rs`, and the first failure was without it, so it is not from that PR. In 120 more runs on other trees it did not fail, so it is rare. - PC: RTX 3050 Laptop GPU 4 GB (driver 617.42), i7-12700H, 16 GB, Windows 11 Pro; Rust 1.98.1 AI-assisted (Claude Code).
zmelumian972 commented 2026-11-28 08:14:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by zmelumian972 on 2026-11-28T08:14:14Z.


I couldn't reproduce this on Linux, so it may be specific to the Windows driver.

Setup: main at fe7c6e5, CachyOS, RTX 5090, NVIDIA 620.73.04, cargo xwin test binary run under GE-Proton11-14 Wine (vkd3d-proton).

  • Full parallel victory-gpu lib suite, about 60 runs. I left out three indirect::tests that hang under Wine. stopping_stock_keeps_issued_buffers_independent_and_mapped passed in every run.
  • A probe for the first explanation in the report, run 200 times per path: make a 64 KiB shared_buffer, fill it with 0xEE, release it, then make a fresh one the way the stock does (fresh_title_batch(1), or shared_buffer(BYTES) with VICTORY_WAIT_RESIDENT=0). The fresh buffer's first 64 KiB were all zero in 400 of 400 tries.

vkd3d-proton zeroes new allocations itself, so that zeroing hides the first explanation here. If the probe below finds dirty bytes on Windows, released shared memory comes back non-zeroed there, and only the test's assumption needs changing. If it stays clean on Windows too, a late write is the more likely cause. Put it in host/title_stock.rs's mod tests, then run cargo test -p victory-gpu --lib probe_released -- --nocapture:

#[test]
fn probe_released_shared_memory_comes_back_zeroed() {
    let Some(host) = super::super::host() else { return };
    let resident = super::super::wait_resident();
    let mut dirty = 0;
    for round in 0..200 {
        let (old, data) = host.shared_buffer(1 << 16).unwrap();
        // SAFETY: a live 64 KiB mapping.
        unsafe { std::ptr::write_bytes(data, 0xEE, 1 << 16) };
        drop(old);
        let (b, p) = if resident {
            host.fresh_title_batch(1).unwrap().pop().map(|f| (f.0, f.1))
        } else {
            host.shared_buffer(BYTES)
        }
        .unwrap();
        // SAFETY: a live mapping of at least 64 KiB.
        let bytes = unsafe { std::slice::from_raw_parts(p, 1 << 16) };
        if let Some(at) = bytes.iter().position(|&x| x != 0) {
            dirty += 1;
            eprintln!("round {round}: byte {at} = {:#x}", bytes[at]);
        }
        drop(b);
    }
    eprintln!("resident_path={resident} dirty {dirty} of 200");
    assert_eq!(dirty, 0);
}
<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7236452461 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/387#issuecomment-7236452461). Originally posted by [zmelumian972](https://github.com/zmelumian972) on 2026-11-28T08:14:14Z. --- I couldn't reproduce this on Linux, so it may be specific to the Windows driver. Setup: `main` at `fe7c6e5`, CachyOS, RTX 5090, NVIDIA 620.73.04, `cargo xwin` test binary run under GE-Proton11-14 Wine (vkd3d-proton). - Full parallel `victory-gpu` lib suite, about 60 runs. I left out three `indirect::tests` that hang under Wine. `stopping_stock_keeps_issued_buffers_independent_and_mapped` passed in every run. - A probe for the first explanation in the report, run 200 times per path: make a 64 KiB `shared_buffer`, fill it with 0xEE, release it, then make a fresh one the way the stock does (`fresh_title_batch(1)`, or `shared_buffer(BYTES)` with `VICTORY_WAIT_RESIDENT=0`). The fresh buffer's first 64 KiB were all zero in 400 of 400 tries. vkd3d-proton zeroes new allocations itself, so that zeroing hides the first explanation here. If the probe below finds dirty bytes on Windows, released shared memory comes back non-zeroed there, and only the test's assumption needs changing. If it stays clean on Windows too, a late write is the more likely cause. Put it in `host/title_stock.rs`'s `mod tests`, then run `cargo test -p victory-gpu --lib probe_released -- --nocapture`: ```rust #[test] fn probe_released_shared_memory_comes_back_zeroed() { let Some(host) = super::super::host() else { return }; let resident = super::super::wait_resident(); let mut dirty = 0; for round in 0..200 { let (old, data) = host.shared_buffer(1 << 16).unwrap(); // SAFETY: a live 64 KiB mapping. unsafe { std::ptr::write_bytes(data, 0xEE, 1 << 16) }; drop(old); let (b, p) = if resident { host.fresh_title_batch(1).unwrap().pop().map(|f| (f.0, f.1)) } else { host.shared_buffer(BYTES) } .unwrap(); // SAFETY: a live mapping of at least 64 KiB. let bytes = unsafe { std::slice::from_raw_parts(p, 1 << 16) }; if let Some(at) = bytes.iter().position(|&x| x != 0) { dirty += 1; eprintln!("round {round}: byte {at} = {:#x}", bytes[at]); } drop(b); } eprintln!("resident_path={resident} dirty {dirty} of 200"); assert_eq!(dirty, 0); } ```
TaynanGT commented 2026-11-29 11:37:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:37:34Z.


Thanks for the repeated Linux runs and the fresh-buffer probe. The 400 zeroed allocations under vkd3d-proton are useful negative evidence, not proof of Windows behavior. The native Windows probe and a check for late writes should distinguish the two explanations.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7255239291 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/387#issuecomment-7255239291). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:37:34Z. --- Thanks for the repeated Linux runs and the fresh-buffer probe. The 400 zeroed allocations under vkd3d-proton are useful negative evidence, not proof of Windows behavior. The native Windows probe and a check for late writes should distinguish the two explanations.
TaynanGT commented 2026-11-30 17:00:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:00:43Z.


main has moved to a new line of the code and everything is now named Vice-Tay: vice-tay.exe play, and VICE_TAY_* switches instead of VICTORY_* (details in #468). Could you check whether this still happens on the current main and say so here, with a log if you can?

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285579080 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/387#issuecomment-7285579080). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:00:43Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay: `vice-tay.exe play`, and `VICE_TAY_*` switches instead of `VICTORY_*` (details in #468). Could you check whether this still happens on the current `main` and say so here, with a log if you can?
TaynanGT commented 2026-11-30 20:16:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T20:16:22Z.


host::title_stock::tests::stopping_stock_keeps_issued_buffers_independent_and_mapped isn't in this tree - main moved to a different line of the code on 30 November (#468) and the title-stock work was on the old one.

Leaving this open rather than closing it, because a fresh buffer holding 0xEE is the kind of thing that's about buffer reuse rather than about one test, and that could still be here under another name.

If you can run your 40-pass harness against the current cargo test -p vice-tay-gpu --locked, that would say whether it followed the code over. Reporting a 1-in-40 failure with the run counts, rather than as "flaky", is what made this readable at all.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7290660758 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/387#issuecomment-7290660758). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T20:16:22Z. --- `host::title_stock::tests::stopping_stock_keeps_issued_buffers_independent_and_mapped` isn't in this tree - `main` moved to a different line of the code on 30 November (#468) and the title-stock work was on the old one. Leaving this open rather than closing it, because a fresh buffer holding `0xEE` is the kind of thing that's about buffer reuse rather than about one test, and that could still be here under another name. If you can run your 40-pass harness against the current `cargo test -p vice-tay-gpu --locked`, that would say whether it followed the code over. Reporting a 1-in-40 failure with the run counts, rather than as "flaky", is what made this readable at all.
Sign in to join this conversation.
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
TaynanGT/Vice-Tay#387
No description provided.