Queue work may still be running when its submit returns: intermittent queue:: and query:: test failures #116

Open
opened 2026-11-26 03:36:03 +00:00 by github-bot · 0 comments
Owner

@⁠ySKELLETONX on GitHub · 2026-11-25 14:33 UTC · original

Summary

Several victory-gpu tests in queue::tests and query::tests fail intermittently. They all assume that a queue's work has run by the time the call that submitted it returns, which is what timeline.rs describes ("Work runs on the thread that submits it, as long as nothing holds the queue back") and what signal2_x relies on ("our submissions are complete when they return").

That doesn't hold when another thread is running the same queue at that moment. timeline::pump() steps every queue, not only the caller's, and it runs both on the victory-queues watcher thread and on every submitting thread. If another thread is in Timeline::step for a queue (busy), the submitter's step returns at once, and the submit returns before its work has run.

Data

RX 7600 XT, Windows 11 build 26300, Rust 1.98.1, main at 01aadd1, the victory_gpu test binary run directly:

Run Failures
cargo test -p victory-gpu --lib, 80 runs 4 runs failed: present_runs_after_a_queues_wait x2 (queue.rs:833, completed(done) is 0, FRAMES already moved), queries_not_run_keep_their_stand_in_values x1 (query.rs:597), occlusion_queries_around_draws_not_run_stay_visible x1 (query.rs:533)
victory_gpu-*.exe query:: queue::, 150 runs page_mappings_run_after_a_queues_wait 38, present_runs_after_a_queues_wait 34, queue_signals_complete_at_once 9, work_after_a_wait_runs_once_the_other_queue_signals 4, occlusion_queries_around_draws_not_run_stay_visible 2, host_timestamps_are_on_the_title_clock 1
same, with the watcher's pump() disabled (temporary local change) the query failures go away; the queue ones stay: 27 / 34 / 2 / 12
query:: alone, 150 runs 1

In the query failures the result buffer still holds the 0xeeee_eeee_eeee_eeee fill. So run(queue, list) returned before the list ran: the resolve hadn't been written yet. It hadn't been skipped.

With the watcher off, the queue tests still fail because the tests' own threads pump each other's queues. Test A's pump() takes test B's queue (busy). B's signal/present returns, and B checks completed/FRAMES before A has finished running B's work.

Does it matter outside the tests?

Possibly. In a title run, the watcher pumps while any queue is held, and the title's submitting thread pumps too. A Signal or ExecuteCommandLists can then return before it has run, even though the queue was not held. Real D3D12 allows that, and titles wait on fences or events. But the code here documents and relies on the opposite. A frame-pacing or present path that reads a fence right after signalling it would see the old value now and then. I couldn't check this in the title.

Possible fixes

  1. Make submit keep its promise. After pump(), a submitter that is not itself running queue work (thread-local flag, so work that submits doesn't wait on itself) waits until no queue is busy on another thread, stepping queues itself in the meantime. The watcher already does this work, so the submitter only waits for what it would otherwise have run itself.
  2. Tests only. The tests wait (with a timeout) for the queues they use to be idle before asserting, and the "complete when they return" comments are relaxed to match.

Option 1 keeps the documented behaviour and fixes the race at its source, but it touches the core scheduling path. Option 2 is safe, but it accepts that a submit may return early. I can send a PR for either.

**@⁠ySKELLETONX** on GitHub · 2026-11-25 14:33 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/116) ## Summary Several `victory-gpu` tests in `queue::tests` and `query::tests` fail intermittently. They all assume that a queue's work has run by the time the call that submitted it returns, which is what `timeline.rs` describes ("Work runs on the thread that submits it, as long as nothing holds the queue back") and what `signal2_x` relies on ("our submissions are complete when they return"). That doesn't hold when another thread is running the same queue at that moment. `timeline::pump()` steps every queue, not only the caller's, and it runs both on the `victory-queues` watcher thread and on every submitting thread. If another thread is in `Timeline::step` for a queue (`busy`), the submitter's `step` returns at once, and the submit returns before its work has run. ## Data RX 7600 XT, Windows 11 build 26300, Rust 1.98.1, `main` at `01aadd1`, the `victory_gpu` test binary run directly: | Run | Failures | |---|---| | `cargo test -p victory-gpu --lib`, 80 runs | 4 runs failed: `present_runs_after_a_queues_wait` x2 (queue.rs:833, `completed(done)` is 0, `FRAMES` already moved), `queries_not_run_keep_their_stand_in_values` x1 (query.rs:597), `occlusion_queries_around_draws_not_run_stay_visible` x1 (query.rs:533) | | `victory_gpu-*.exe query:: queue::`, 150 runs | `page_mappings_run_after_a_queues_wait` 38, `present_runs_after_a_queues_wait` 34, `queue_signals_complete_at_once` 9, `work_after_a_wait_runs_once_the_other_queue_signals` 4, `occlusion_queries_around_draws_not_run_stay_visible` 2, `host_timestamps_are_on_the_title_clock` 1 | | same, with the watcher's `pump()` disabled (temporary local change) | the query failures go away; the queue ones stay: 27 / 34 / 2 / 12 | | `query::` alone, 150 runs | 1 | In the query failures the result buffer still holds the `0xeeee_eeee_eeee_eeee` fill. So `run(queue, list)` returned before the list ran: the resolve hadn't been written yet. It hadn't been skipped. With the watcher off, the queue tests still fail because the tests' own threads pump each other's queues. Test A's `pump()` takes test B's queue (`busy`). B's `signal`/`present` returns, and B checks `completed`/`FRAMES` before A has finished running B's work. ## Does it matter outside the tests? Possibly. In a title run, the watcher pumps while any queue is held, and the title's submitting thread pumps too. A `Signal` or `ExecuteCommandLists` can then return before it has run, even though the queue was not held. Real D3D12 allows that, and titles wait on fences or events. But the code here documents and relies on the opposite. A frame-pacing or present path that reads a fence right after signalling it would see the old value now and then. I couldn't check this in the title. ## Possible fixes 1. **Make submit keep its promise.** After `pump()`, a submitter that is not itself running queue work (thread-local flag, so work that submits doesn't wait on itself) waits until no queue is `busy` on another thread, stepping queues itself in the meantime. The watcher already does this work, so the submitter only waits for what it would otherwise have run itself. 2. **Tests only.** The tests wait (with a timeout) for the queues they use to be idle before asserting, and the "complete when they return" comments are relaxed to match. Option 1 keeps the documented behaviour and fixes the race at its source, but it touches the core scheduling path. Option 2 is safe, but it accepts that a submit may return early. I can send a PR for either.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.