[pr-fix][memory] Release eligible resources behind out-of-order retirement entries #81

Manually merged
TrustNo1 merged 1 commit from ALeCs1080/Darner:fix/general-retirement-order into main 2026-12-03 20:19:27 +00:00
Contributor

Contributor role (optional)

  • Fluxer ID: 1576348275320041472

What it changes

The general resource retirement queue previously relied on retirement entries arriving in ascending submission order. Producers sample submission numbers before acquiring their shard lock, so concurrent producers can insert entries out of order.

The existing prefix drain stops at the first entry whose retirement number exceeds the completion threshold. This can leave otherwise eligible resources waiting behind a future entry.

A regression test reproduced this through the original production bury() path:

  • Completion threshold after safety lag: 110
  • Queue before selection: [90, 120, 100, 105, 110]
  • Original remaining queue: [120, 100, 105, 110]
  • Expected remaining queue: [120]

This change introduces a per-shard ordering flag, retaining the existing prefix-drain fast path for ordered queues and selecting all eligible entries when an inversion has been detected.

The queue automatically returns to its ordered fast path once the remaining entries are ordered again.

The existing submission threshold, retirement safety lag, asynchronous destruction and destruction outside shard locks are preserved. Relative arrival order is retained within the selected and remaining groups.

How it was tested

  • Tested revision: changes committed as 412a0ecc09163ff5bbd873f178663059ca5524b1, based on Main 1a5286a78daa512f1f715d682a3192b94232e16a. Validation was performed on the changes before committing.

  • Commands and results:

    • cargo test --locked -p darner-gpu --lib host::bury_tests:: -- --nocapture --test-threads=1 — 10 passed.
    • cargo test --locked -p darner-gpu --features diagnostics --lib host::bury_tests:: -- --nocapture --test-threads=1 — 10 passed.
    • cargo clippy --workspace --all-targets --locked -- -D warnings — passed.
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — passed.
    • cargo test --workspace --locked — compiled successfully, but GPU test execution terminated with exit code 3.
    • Clean Main comparison using cargo test --workspace --locked -- --nocapture --test-threads=1 reproduced the identical failure at ambient::tests::the_passes_build.
    • git diff --cached --check — passed.
    • cargo xtask policy --staged — passed, one file checked.
  • Gameplay, when relevant: Not tested. Development system uses Windows 10 22H2 and an NVIDIA RTX 4080.

  • Before and after, when relevant:

    A standalone optimised synthetic queue benchmark was run using seven alternating samples.

    Scenario Entries Original drain Corrected drain
    Ordered, half ready 1,024 1.120 µs 1.201 µs
    Ordered, all ready 1,024 1.998 µs 1.989 µs
    Ordered, half ready 8,192 16.923 µs 17.867 µs
    Ordered, all ready 8,192 33.057 µs 33.103 µs
    Unordered, none ready 8,192 0.006 µs 20.165 µs
    Unordered, half ready 8,192 0.006 µs 25.315 µs

    In the unordered half-ready scenario, the original implementation selected zero entries, while the corrected implementation selected all 4,096 eligible entries.

    The unordered path requires a full traversal. The ordered path retains the original prefix-drain approach.

  • Shader wave sizes tested, when relevant: Not applicable.

  • Coverage gaps:

    • Full workspace tests could not complete because the active Direct3D runtime reports Shader Model 6.5 rather than the required 6.6. The same failure was reproduced on unmodified Main.
    • The synthetic benchmark does not measure mutex contention, COM destruction, GPU execution or gameplay.
    • No runtime memory savings or FPS improvements are claimed.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #36, #50, #52, #56, #57, #58, #59, #62. Related issue: #19.

Open and closed issues, PR descriptions, available discussion comments and exported source diffs were reviewed on 3 December 2026. No directly competing general retirement queue correction was identified.

Historical records and inline review coverage remain limited following the repository migrations.

## Contributor role (optional) - Fluxer ID: 1576348275320041472 ## What it changes The general resource retirement queue previously relied on retirement entries arriving in ascending submission order. Producers sample submission numbers before acquiring their shard lock, so concurrent producers can insert entries out of order. The existing prefix drain stops at the first entry whose retirement number exceeds the completion threshold. This can leave otherwise eligible resources waiting behind a future entry. A regression test reproduced this through the original production `bury()` path: - Completion threshold after safety lag: `110` - Queue before selection: `[90, 120, 100, 105, 110]` - Original remaining queue: `[120, 100, 105, 110]` - Expected remaining queue: `[120]` This change introduces a per-shard ordering flag, retaining the existing prefix-drain fast path for ordered queues and selecting all eligible entries when an inversion has been detected. The queue automatically returns to its ordered fast path once the remaining entries are ordered again. The existing submission threshold, retirement safety lag, asynchronous destruction and destruction outside shard locks are preserved. Relative arrival order is retained within the selected and remaining groups. ## How it was tested - Tested revision: changes committed as `412a0ecc09163ff5bbd873f178663059ca5524b1`, based on Main `1a5286a78daa512f1f715d682a3192b94232e16a`. Validation was performed on the changes before committing. - Commands and results: - `cargo test --locked -p darner-gpu --lib host::bury_tests:: -- --nocapture --test-threads=1` — 10 passed. - `cargo test --locked -p darner-gpu --features diagnostics --lib host::bury_tests:: -- --nocapture --test-threads=1` — 10 passed. - `cargo clippy --workspace --all-targets --locked -- -D warnings` — passed. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — passed. - `cargo test --workspace --locked` — compiled successfully, but GPU test execution terminated with exit code 3. - Clean Main comparison using `cargo test --workspace --locked -- --nocapture --test-threads=1` reproduced the identical failure at `ambient::tests::the_passes_build`. - `git diff --cached --check` — passed. - `cargo xtask policy --staged` — passed, one file checked. - Gameplay, when relevant: Not tested. Development system uses Windows 10 22H2 and an NVIDIA RTX 4080. - Before and after, when relevant: A standalone optimised synthetic queue benchmark was run using seven alternating samples. | Scenario | Entries | Original drain | Corrected drain | |---|---:|---:|---:| | Ordered, half ready | 1,024 | 1.120 µs | 1.201 µs | | Ordered, all ready | 1,024 | 1.998 µs | 1.989 µs | | Ordered, half ready | 8,192 | 16.923 µs | 17.867 µs | | Ordered, all ready | 8,192 | 33.057 µs | 33.103 µs | | Unordered, none ready | 8,192 | 0.006 µs | 20.165 µs | | Unordered, half ready | 8,192 | 0.006 µs | 25.315 µs | In the unordered half-ready scenario, the original implementation selected zero entries, while the corrected implementation selected all 4,096 eligible entries. The unordered path requires a full traversal. The ordered path retains the original prefix-drain approach. - Shader wave sizes tested, when relevant: Not applicable. - Coverage gaps: - Full workspace tests could not complete because the active Direct3D runtime reports Shader Model 6.5 rather than the required 6.6. The same failure was reproduced on unmodified Main. - The synthetic benchmark does not measure mutex contention, COM destruction, GPU execution or gameplay. - No runtime memory savings or FPS improvements are claimed. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #36, #50, #52, #56, #57, #58, #59, #62. Related issue: #19. Open and closed issues, PR descriptions, available discussion comments and exported source diffs were reviewed on 3 December 2026. No directly competing general retirement queue correction was identified. Historical records and inline review coverage remain limited following the repository migrations.
TrustNo1 manually merged commit 86c76f1bc0 into main 2026-12-03 20:19:27 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!81
No description provided.