D3D12.X: preserve live texture aliases during L0 promotion #3745

Open
jeroenhaentjens wants to merge 2 commits from upstream-pr/3745 into main
jeroenhaentjens commented 2026-12-02 23:57:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-02T23:57:15Z.


What & Why

Stacked on #3740 at 2ff33838. Only the top commit belongs to #3745. Preserve the contents and overlap of eligible live aliases when creating a render target that requires local backing. #3620 offers related promotion under XCL_L0_VRAM_MARGIN_MB. This PR builds on #3740's sampled TextureBudget policy and protects the tile move at native submission boundaries.

What is in it

  • Gate title submissions, both KickoffX paths and sparse texture uploads. A later receipt from the same queue covers its earlier work. A busy placement can fall back to the arena.
  • Lease aliases during backup, remapping and restore. Replay supersession unmaps after reopening admission. Reusing an alias cancels its pending request through the point where replay claims it under the page lock.
  • Exercise the deadline with a held CPU admission slot. Verify that a reactivated alias retains its tiles, deferred unmaps complete after reopening, and native readbacks preserve contents.

Tested

  • Commit eced294121. Intel Core i7-9750H, NVIDIA Quadro RTX 3000 (driver 597.06 / 32.0.15.9706), Windows 11 25H2 build 26200.9974, Rust MSVC 1.100.0 and DXC 1.9.2609.5.
  • git diff --check passed. cargo test --locked --workspace -- --test-threads=4 reported 3017 passed, 0 failed, 52 ignored and 26 SKIPPED diagnostics. The log recorded 0 D3D12 Debug Layer validation warnings or errors during execution. The integration fixture emitted 8 live-object warnings at process shutdown.
  • The native timeout and alias-reuse fixture also passed on the Microsoft Basic Render Driver with zero D3D12 validation messages. The repository-owned smoke fixture presents one frame and stays alive until the 60-second run timer.

Regression run

Baseline (main)

xcl-smoke v1
commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a
gpu: NVIDIA Quadro RTX 3000
title: xcl-owned-test-fixture
seconds: 60
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 1379 MB

PR head

xcl-smoke v1
commit: eced294121156fa9a83b0c1ca7e48155ba3a35ce
gpu: NVIDIA Quadro RTX 3000
title: xcl-owned-test-fixture
seconds: 60
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 1439 MB

Not tested

AMD, Intel discrete GPUs, Linux and retail titles.

AI use

OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR update. The author reviewed the diff and the recorded test results.

<!-- greyfinch-sync:ivall/xcl:issue:5616928924 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-12-02T23:57:15Z. --- **What & Why** Stacked on #3740 at 2ff33838. Only the top commit belongs to #3745. Preserve the contents and overlap of eligible live aliases when creating a render target that requires local backing. #3620 offers related promotion under XCL_L0_VRAM_MARGIN_MB. This PR builds on #3740's sampled TextureBudget policy and protects the tile move at native submission boundaries. **What is in it** - Gate title submissions, both KickoffX paths and sparse texture uploads. A later receipt from the same queue covers its earlier work. A busy placement can fall back to the arena. - Lease aliases during backup, remapping and restore. Replay supersession unmaps after reopening admission. Reusing an alias cancels its pending request through the point where replay claims it under the page lock. - Exercise the deadline with a held CPU admission slot. Verify that a reactivated alias retains its tiles, deferred unmaps complete after reopening, and native readbacks preserve contents. **Tested** - Commit eced294121156fa9a83b0c1ca7e48155ba3a35ce. Intel Core i7-9750H, NVIDIA Quadro RTX 3000 (driver 597.06 / 32.0.15.9706), Windows 11 25H2 build 26200.9974, Rust MSVC 1.100.0 and DXC 1.9.2609.5. - git diff --check passed. cargo test --locked --workspace -- --test-threads=4 reported 3017 passed, 0 failed, 52 ignored and 26 SKIPPED diagnostics. The log recorded 0 D3D12 Debug Layer validation warnings or errors during execution. The integration fixture emitted 8 live-object warnings at process shutdown. - The native timeout and alias-reuse fixture also passed on the Microsoft Basic Render Driver with zero D3D12 validation messages. The repository-owned smoke fixture presents one frame and stays alive until the 60-second run timer. **Regression run** Baseline (main) ``` xcl-smoke v1 commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a gpu: NVIDIA Quadro RTX 3000 title: xcl-owned-test-fixture seconds: 60 exit: 0x0 frames shown: 1 (PresentX 1) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 1379 MB ``` PR head ``` xcl-smoke v1 commit: eced294121156fa9a83b0c1ca7e48155ba3a35ce gpu: NVIDIA Quadro RTX 3000 title: xcl-owned-test-fixture seconds: 60 exit: 0x0 frames shown: 1 (PresentX 1) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 1439 MB ``` **Not tested** AMD, Intel discrete GPUs, Linux and retail titles. **AI use** OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR update. The author reviewed the diff and the recorded test results.
Foniass commented 2026-12-03 00:05:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T00:05:10Z.


Review of 9bc13632 (code reading only, not a merge-check; draft) · 2 high, 4 medium

In short: Stacked on #3740; only the top commit 9bc13632 belongs here, and it is reviewed alone. It adds a per-device admission gate on native queue submits. When a render target lands on sampled L0 tiles, it copies every live alias out, remaps the shared tiles to local memory and copies the data back. Everything is behind XCL_TEXTURE_BUDGET=1, so the default path is unchanged. Two things block it: KickoffX submits bypass the gate, and a busy gate now fails the title's resource creation where the base fell back.

High

  1. KickoffX submits bypass the promotion gate.

    • kickoff_x submits the title's lists through the original ExecuteCommandLists inside queue_submit::with (list_x.rs ~5515 for the earlier lists, ~5560 for the current one). Only q_execute_command_lists, native_queue_execute and the mapping copy go through vram_promotion::submit (real.rs ~1177, ~12052, ~12103).
    • So Gate::close cannot see KickoffX work in flight, because no mark fence is signalled for it, and it does not hold back a KickoffX submit while the backup, remap and restore run.
    • A title that uses KickoffX can read or write the L0 tiles while they are copied and remapped.

    Fix: route both KickoffX submits through vram_promotion::submit(q_raw, ...), and check that no other title submit path calls the native slot directly.

  2. A busy gate now fails the title's resource creation.

    • BindFailure::Busy comes from:
      • Gate::close missing its 50 ms deadline (vram_promotion.rs ~121 calls that the expected result on a busy device);
      • a re-entrant call;
      • an overlapping promoting range (vram.rs ~3025);
      • missing_receipt, which is set at ~114 and never cleared, so one failed CreateFence or Signal makes every later promotion fail.
    • place_on_pages turns Busy into Some(E_OUTOFMEMORY) (vram.rs ~3324). place (~4183) returns it instead of trying the arena fallback, and CreatePlacedResourceX hands it to the title (device_x.rs ~1284).
    • On the base, the same overlap returned None and fell back. Each failed attempt also stalls the creating thread for up to 50 ms.

    Fix: treat Busy like Unavailable, or retry, and reset missing_receipt once a submit records its mark.

Medium

  1. Superseded textures are never unmapped when the budget is on. unmap_placed returns at once whenever texture_budget::enabled() (vram.rs ~3357). That covers every unmap_superseded / unmap_superseded_target caller in vram.rs and title_textures.rs, not only aliases a promotion leased. A title that reuses an address without releasing the old texture keeps all its tiles until the release. Limit the change to the aliases that need it, or describe it and measure its memory cost.
  2. local_pinned only grows. Addresses are only ever added (vram.rs ~2978), and nothing removes them when the pages are freed or recycled. After one promotion, every later sampled texture at that address is forced to local memory for the rest of the run, slowly undoing the L0 budget for addresses titles reuse. Drop the entries when the page goes away.
  3. The second GPU test does not run the new code, and the failure paths have no test.
    • texture_budget_native_alias_promotion_after_producer_completion (vram.rs ~4504) calls bind_range and Pages::map and records its own copy lists. It never calls bind_eager, promote_tiles or the gate, so it tests the driver, not this PR, though the description presents it as confirming preserved data.
    • Nothing covers a gate timeout, a refused lease, a failed promotion, or what the title gets back in those cases (finding 2).
  4. Size, and overlap with #3620.
    • The commit is +1108/-25 (about 470 lines of tests), with no reason given for going past ~800. It splits naturally: the admission gate (vram_promotion.rs and the submit hooks, inert until used), then the promotion.
    • #3620 handles the same case under XCL_L0_VRAM_MARGIN_MB: it promotes an L0 page to local in place when a target binds it, drains the queues first, and remaps every live alias. Both rewrite the same bind path in vram.rs, so only one mechanism should land.
Checked and fine
  • With XCL_TEXTURE_BUDGET unset, vram_promotion::submit falls through to queue_submit::with, and native_queue_execute calls the same native slot. lock_tracked_srv_lifetime, unmap_placed and forget_promotion_resource are gated on the flag. bind_eager without the budget does what the old Pages::bind did.
  • Gate ordering: admission is taken before the ordered queue turn. Own-work submits nested in an admitted submit pass through the thread-local ACTIVE list. The epoch re-check stops a submit from slipping in between the fence snapshot and closing the gate.
  • Backup and restore run on the mapping queue (native_mapping_copy_execute), with CPU fence waits and no GPU wait on a title queue.
  • The lease holds a strong reference to every overlapping alias under the lifetime lock. It checks each page's user count against the registered owners, and refuses partly mapped aliases and aliases with lazy levels.
  • Copies use each sampled alias's own tile coordinates and leave packed mips out. Render-target aliases are only remapped.
  • A failure before the remap returns Unavailable and falls back. A failed backup or restore ends the title, after leaking the native objects the driver may still use.
  • promotion_state uses try_lock on TEXTURES, so it does not wait on a submitter blocked at admission.
  • texture_budget_promotes_four_live_rt_aliases_with_readback runs bind_eager through the gate, with four aliases and a submit blocked during the promotion. README updated.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7362777504 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7362777504). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T00:05:10Z. --- **Review** of `9bc13632` (code reading only, not a merge-check; draft) · 2 high, 4 medium **In short:** Stacked on #3740; only the top commit `9bc13632` belongs here, and it is reviewed alone. It adds a per-device admission gate on native queue submits. When a render target lands on sampled L0 tiles, it copies every live alias out, remaps the shared tiles to local memory and copies the data back. Everything is behind `XCL_TEXTURE_BUDGET=1`, so the default path is unchanged. Two things block it: `KickoffX` submits bypass the gate, and a busy gate now fails the title's resource creation where the base fell back. #### High 1. **`KickoffX` submits bypass the promotion gate.** - `kickoff_x` submits the title's lists through the original `ExecuteCommandLists` inside `queue_submit::with` (`list_x.rs` ~5515 for the earlier lists, ~5560 for the current one). Only `q_execute_command_lists`, `native_queue_execute` and the mapping copy go through `vram_promotion::submit` (`real.rs` ~1177, ~12052, ~12103). - So `Gate::close` cannot see `KickoffX` work in flight, because no mark fence is signalled for it, and it does not hold back a `KickoffX` submit while the backup, remap and restore run. - A title that uses `KickoffX` can read or write the L0 tiles while they are copied and remapped. Fix: route both `KickoffX` submits through `vram_promotion::submit(q_raw, ...)`, and check that no other title submit path calls the native slot directly. 2. **A busy gate now fails the title's resource creation.** - `BindFailure::Busy` comes from: - `Gate::close` missing its 50 ms deadline (`vram_promotion.rs` ~121 calls that the expected result on a busy device); - a re-entrant call; - an overlapping `promoting` range (`vram.rs` ~3025); - `missing_receipt`, which is set at ~114 and never cleared, so one failed `CreateFence` or `Signal` makes every later promotion fail. - `place_on_pages` turns `Busy` into `Some(E_OUTOFMEMORY)` (`vram.rs` ~3324). `place` (~4183) returns it instead of trying the arena fallback, and `CreatePlacedResourceX` hands it to the title (`device_x.rs` ~1284). - On the base, the same overlap returned `None` and fell back. Each failed attempt also stalls the creating thread for up to 50 ms. Fix: treat `Busy` like `Unavailable`, or retry, and reset `missing_receipt` once a submit records its mark. #### Medium 3. **Superseded textures are never unmapped when the budget is on.** `unmap_placed` returns at once whenever `texture_budget::enabled()` (`vram.rs` ~3357). That covers every `unmap_superseded` / `unmap_superseded_target` caller in `vram.rs` and `title_textures.rs`, not only aliases a promotion leased. A title that reuses an address without releasing the old texture keeps all its tiles until the release. Limit the change to the aliases that need it, or describe it and measure its memory cost. 4. **`local_pinned` only grows.** Addresses are only ever added (`vram.rs` ~2978), and nothing removes them when the pages are freed or recycled. After one promotion, every later sampled texture at that address is forced to local memory for the rest of the run, slowly undoing the L0 budget for addresses titles reuse. Drop the entries when the page goes away. 5. **The second GPU test does not run the new code, and the failure paths have no test.** - `texture_budget_native_alias_promotion_after_producer_completion` (`vram.rs` ~4504) calls `bind_range` and `Pages::map` and records its own copy lists. It never calls `bind_eager`, `promote_tiles` or the gate, so it tests the driver, not this PR, though the description presents it as confirming preserved data. - Nothing covers a gate timeout, a refused lease, a failed promotion, or what the title gets back in those cases (finding 2). 6. **Size, and overlap with #3620.** - The commit is +1108/-25 (about 470 lines of tests), with no reason given for going past ~800. It splits naturally: the admission gate (`vram_promotion.rs` and the submit hooks, inert until used), then the promotion. - #3620 handles the same case under `XCL_L0_VRAM_MARGIN_MB`: it promotes an L0 page to local in place when a target binds it, drains the queues first, and remaps every live alias. Both rewrite the same bind path in `vram.rs`, so only one mechanism should land. <details><summary>Checked and fine</summary> - With `XCL_TEXTURE_BUDGET` unset, `vram_promotion::submit` falls through to `queue_submit::with`, and `native_queue_execute` calls the same native slot. `lock_tracked_srv_lifetime`, `unmap_placed` and `forget_promotion_resource` are gated on the flag. `bind_eager` without the budget does what the old `Pages::bind` did. - Gate ordering: admission is taken before the ordered queue turn. Own-work submits nested in an admitted submit pass through the thread-local `ACTIVE` list. The `epoch` re-check stops a submit from slipping in between the fence snapshot and closing the gate. - Backup and restore run on the mapping queue (`native_mapping_copy_execute`), with CPU fence waits and no GPU wait on a title queue. - The lease holds a strong reference to every overlapping alias under the lifetime lock. It checks each page's user count against the registered owners, and refuses partly mapped aliases and aliases with lazy levels. - Copies use each sampled alias's own tile coordinates and leave packed mips out. Render-target aliases are only remapped. - A failure before the remap returns `Unavailable` and falls back. A failed backup or restore ends the title, after leaking the native objects the driver may still use. - `promotion_state` uses `try_lock` on `TEXTURES`, so it does not wait on a submitter blocked at admission. - `texture_budget_promotes_four_live_rt_aliases_with_readback` runs `bind_eager` through the gate, with four aliases and a submit blocked during the promotion. README updated. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
jeroenhaentjens commented 2026-12-03 08:05:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T08:05:35Z.


@Foniass rebased on #3740 at 1a2bef6. Both KickoffX submits are gated, a new receipt from the same queue clears its block, and a busy promotion can fall back to an arena. Supersession waits only for leased aliases, and local pins disappear when the last page user releases them. The second native fixture now checks the actual timeout, arena and promotion paths. The description identifies the top commit and the overlap with #3620.

<!-- greyfinch-sync:ivall/xcl:comment:7371812102 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7371812102). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-12-03T08:05:35Z. --- @Foniass rebased on #3740 at 1a2bef6. Both KickoffX submits are gated, a new receipt from the same queue clears its block, and a busy promotion can fall back to an arena. Supersession waits only for leased aliases, and local pins disappear when the last page user releases them. The second native fixture now checks the actual timeout, arena and promotion paths. The description identifies the top commit and the overlap with #3620.
Foniass commented 2026-12-03 08:12:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T08:12:12Z.


Follow-up review of 55057068, since 9bc13632 (code reading only, not a merge-check) · 2 high, 3 medium

In short: Stacked on #3740 (now at 1a2bef64); only the top commit 55057068 belongs here. Since 9bc13632:

  • both KickoffX paths go through the promotion gate;
  • a busy gate falls back to the arena;
  • only leased aliases defer their unmap, and local_pinned entries go with the last page user;
  • receipts are tracked per queue;
  • the second GPU test drives bind_eager, the gate timeout and the fallback.

Two gate problems remain: XCL's own texture uploads still reach the title queue without passing it, and a deferred unmap can deadlock with a title Signal waiting for admission.

High

  1. Texture uploads still bypass the gate.

    • prepare_title_submission runs before admission (real.rs ~12091, list_x.rs ~5497). Its uploads go through texture_upload::submit → sparse::pc_execute (texture_upload.rs ~877, sparse.rs ~5218-5225), which calls the native ExecuteCommandLists inside queue_submit::with, not vram_promotion::submit.
    • These copies write into exactly the sampled L0 textures a promotion leases. They get no gate mark, so Gate::close does not wait for an upload in flight, and an upload prepared while the gate is closed is not held back.
    • The backup can read the tiles before the upload lands, and the restore writes the old bytes over it. known still records the upload as sent, so the texture stays wrong until the next CPU write.

    Fix: route pc_execute through vram_promotion::submit (it re-enters correctly when nested in an admitted submit), or take admission before prepare_title_submission.

  2. A deferred unmap can deadlock with a title Signal.

    • The title's Signal path takes the queue turn first (real.rs ~11741). Inside it, submit_prepared_downloads reaches TextureDownloadPlan::submit → native_queue_execute (title_textures.rs ~3819). With the budget on, that waits at Gate::enter with no limit (vram_promotion.rs ~96).
    • Meanwhile the promotion still holds the gate closed when PromotionRange::drop (vram.rs ~2864) runs the deferred unmap_placed. That signals each active title queue through native_queue_signal, which needs the same queue turn.
    • So each waits on the other, against the gate's own rule that admission comes before the queue turn.

    Fix: run the deferred unmaps after closed is dropped in bind_eager, or take admission before the queue turn in the Signal path. Nothing tests the deferred-unmap path yet.

Medium

  1. The remap path does not promote. remap_if_unmapped (vram.rs ~3471) calls Pages::bind directly. With #3740's live-L0 refusal, bind_range returns None for a render target over a live L0 page, and both callers ignore that (placements.rs ~480, title_textures.rs ~1043), so a superseded target taken back into use stays unmapped. Promotion runs only in bind_eager, from place_on_pages. The README line ("For supported live aliases, XCL waits ... remaps the aliases to local tiles") claims more than the code does. Cover this path, or say that only creation is covered.
  2. Size, and overlap with #3620 (still open). +1174/-26, about 550 lines of tests, with no reason for going past ~800. It still splits naturally: the admission gate (vram_promotion.rs and the submit hooks), then the promotion. The description now names #3620, but both rewrite the same bind path in vram.rs for the same case, and only one should land.
  3. The whole suite is not reported. Tested lists only hle::d3d12x::vram::tests and hle::d3d12x::vram_promotion::tests (91 passed, 1 ignored). This change hooks every native submit path under XCL_TEXTURE_BUDGET=1. Report cargo test --workspace -- --test-threads=4.
Checked and fine
  • Earlier finding fixed: KickoffX submits bypassed the gate. Both use vram_promotion::submit now (list_x.rs ~5515, ~5560).
  • Earlier finding fixed: a busy gate reached the title as E_OUTOFMEMORY. place_on_pages returns None on any failure (~3347), and the fixture checks the arena takes over after a gate timeout.
  • Earlier finding fixed: missing_receipt was never cleared. It is now kept per queue and generation, and a later receipt on the same queue clears it, with a test.
  • Earlier finding fixed: unmap_placed skipped every unmap under the budget. Only aliases in leased_aliases are deferred now, and they are replayed when the range is dropped (~3395).
  • Earlier finding fixed: local_pinned only grew. An entry goes when a page's user count reaches zero in release_tiles (~2595), as the fixture checks.
  • Earlier finding fixed: the second GPU test did not reach the new code. It now calls bind_eager, holds a producer through Gate::submit, checks the timeout counter and the arena fallback, then promotes and reads back.
  • With XCL_TEXTURE_BUDGET unset, the submit hooks fall through to the previous calls.
  • The lease and the promotion condition ignore idle L0 pages, consistent with #3740 replacing them in bind_range.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7371957494 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7371957494). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T08:12:12Z. --- **Follow-up review** of `55057068`, since `9bc13632` (code reading only, not a merge-check) · 2 high, 3 medium **In short:** Stacked on #3740 (now at `1a2bef64`); only the top commit `55057068` belongs here. Since `9bc13632`: - both `KickoffX` paths go through the promotion gate; - a busy gate falls back to the arena; - only leased aliases defer their unmap, and `local_pinned` entries go with the last page user; - receipts are tracked per queue; - the second GPU test drives `bind_eager`, the gate timeout and the fallback. Two gate problems remain: XCL's own texture uploads still reach the title queue without passing it, and a deferred unmap can deadlock with a title `Signal` waiting for admission. #### High 1. **Texture uploads still bypass the gate.** - `prepare_title_submission` runs before admission (`real.rs` ~12091, `list_x.rs` ~5497). Its uploads go through `texture_upload::submit` → `sparse::pc_execute` (`texture_upload.rs` ~877, `sparse.rs` ~5218-5225), which calls the native `ExecuteCommandLists` inside `queue_submit::with`, not `vram_promotion::submit`. - These copies write into exactly the sampled L0 textures a promotion leases. They get no gate mark, so `Gate::close` does not wait for an upload in flight, and an upload prepared while the gate is closed is not held back. - The backup can read the tiles before the upload lands, and the restore writes the old bytes over it. `known` still records the upload as sent, so the texture stays wrong until the next CPU write. Fix: route `pc_execute` through `vram_promotion::submit` (it re-enters correctly when nested in an admitted submit), or take admission before `prepare_title_submission`. 2. **A deferred unmap can deadlock with a title `Signal`.** - The title's `Signal` path takes the queue turn first (`real.rs` ~11741). Inside it, `submit_prepared_downloads` reaches `TextureDownloadPlan::submit` → `native_queue_execute` (`title_textures.rs` ~3819). With the budget on, that waits at `Gate::enter` with no limit (`vram_promotion.rs` ~96). - Meanwhile the promotion still holds the gate closed when `PromotionRange::drop` (`vram.rs` ~2864) runs the deferred `unmap_placed`. That signals each active title queue through `native_queue_signal`, which needs the same queue turn. - So each waits on the other, against the gate's own rule that admission comes before the queue turn. Fix: run the deferred unmaps after `closed` is dropped in `bind_eager`, or take admission before the queue turn in the `Signal` path. Nothing tests the deferred-unmap path yet. #### Medium 3. **The remap path does not promote.** `remap_if_unmapped` (`vram.rs` ~3471) calls `Pages::bind` directly. With #3740's live-L0 refusal, `bind_range` returns `None` for a render target over a live L0 page, and both callers ignore that (`placements.rs` ~480, `title_textures.rs` ~1043), so a superseded target taken back into use stays unmapped. Promotion runs only in `bind_eager`, from `place_on_pages`. The README line ("For supported live aliases, XCL waits ... remaps the aliases to local tiles") claims more than the code does. Cover this path, or say that only creation is covered. 4. **Size, and overlap with #3620 (still open).** +1174/-26, about 550 lines of tests, with no reason for going past ~800. It still splits naturally: the admission gate (`vram_promotion.rs` and the submit hooks), then the promotion. The description now names #3620, but both rewrite the same bind path in `vram.rs` for the same case, and only one should land. 5. **The whole suite is not reported.** **Tested** lists only `hle::d3d12x::vram::tests` and `hle::d3d12x::vram_promotion::tests` (91 passed, 1 ignored). This change hooks every native submit path under `XCL_TEXTURE_BUDGET=1`. Report `cargo test --workspace -- --test-threads=4`. <details><summary>Checked and fine</summary> - Earlier finding fixed: `KickoffX` submits bypassed the gate. Both use `vram_promotion::submit` now (`list_x.rs` ~5515, ~5560). - Earlier finding fixed: a busy gate reached the title as `E_OUTOFMEMORY`. `place_on_pages` returns `None` on any failure (~3347), and the fixture checks the arena takes over after a gate timeout. - Earlier finding fixed: `missing_receipt` was never cleared. It is now kept per queue and generation, and a later receipt on the same queue clears it, with a test. - Earlier finding fixed: `unmap_placed` skipped every unmap under the budget. Only aliases in `leased_aliases` are deferred now, and they are replayed when the range is dropped (~3395). - Earlier finding fixed: `local_pinned` only grew. An entry goes when a page's user count reaches zero in `release_tiles` (~2595), as the fixture checks. - Earlier finding fixed: the second GPU test did not reach the new code. It now calls `bind_eager`, holds a producer through `Gate::submit`, checks the timeout counter and the arena fallback, then promotes and reads back. - With `XCL_TEXTURE_BUDGET` unset, the submit hooks fall through to the previous calls. - The lease and the promotion condition ignore idle L0 pages, consistent with #3740 replacing them in `bind_range`. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
jeroenhaentjens commented 2026-12-03 13:14:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T13:14:06Z.


@Foniass Texture upload submits through sparse::pc_execute now acquire promotion admission before the queue turn. Deferred unmaps are replayed after the gate opens. The native regression holds a queue turn during promotion and checks that the deferred unmap completes, the upload survives and the render target shares the promoted tiles. The README scopes promotion to creation, and the complete workspace result is in the PR.

<!-- greyfinch-sync:ivall/xcl:comment:7379510641 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7379510641). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-12-03T13:14:06Z. --- @Foniass Texture upload submits through sparse::pc_execute now acquire promotion admission before the queue turn. Deferred unmaps are replayed after the gate opens. The native regression holds a queue turn during promotion and checks that the deferred unmap completes, the upload survives and the render target shares the promoted tiles. The README scopes promotion to creation, and the complete workspace result is in the PR.
Foniass commented 2026-12-03 13:20:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T13:20:13Z.


Follow-up review of 100cac75, since 55057068 (code reading only, not a merge-check) · 1 high, 1 medium

In short: Stacked on #3740 (now at 2ff33838); only the top commit 100cac75 belongs here. Since 55057068:

  • texture uploads go through the promotion gate;
  • deferred unmaps run after the gate reopens;
  • the README limits promotion to creation;
  • the whole suite is reported.

One new problem: a deferred unmap is replayed without checking whether the title used the texture again meanwhile, so a texture in use can lose its tiles. The size and the overlap with #3620 are still open.

High

  1. A deferred unmap can unmap a texture the title is using again.

    • Normally placements::unmap_if_superseded (placements.rs ~541) checks under the registry lock that the target is still superseded before unmapping it, so the unmap and a later use_again stay in order.
    • During a promotion, unmap_placed only queues a leased alias in unmaps_after_promotion (vram.rs ~3407-3410), and the target stays mapped.
    • If the title uses that texture before the replay, note_use (placements.rs ~566-570) calls remap_if_unmapped. That returns true at once because the target is still mapped (vram.rs ~3456-3458), and use_again marks it live. The same happens through settle → map_again when the newer placement is released.
    • bind_eager then replays the queued unmap anyway (~3101). The texture loses its tiles while the registry counts it as mapped and no longer superseded, so nothing maps it again.

    Fix: let remap_if_unmapped cancel a queued promotion unmap, as it already cancels held_unmaps (~3460), or replay through a check that the target is still superseded. Add a test where the alias is used again between the deferral and the replay.

Medium

  1. Size, and overlap with #3620 (still open). +1239/-28, about 600 lines of tests, with no reason for going past ~800. It still splits naturally: the admission gate (vram_promotion.rs and the submit hooks), then the promotion in vram.rs. The description names #3620, which is still open; both rewrite the same bind path for the same case, so only one should land.
Checked and fine
  • Earlier finding fixed: texture uploads bypassed the gate. pc_execute now uses vram_promotion::submit (sparse.rs ~5226), so each upload gets a mark and waits while the gate is closed. The fixture sends an upload through pc_execute and checks the timeout and the arena fallback.
  • Earlier finding fixed: a deferred unmap could deadlock with a title Signal. PromotionRange::drop only moves the queued unmaps out, and bind_eager drops closed before replaying them (~3100). The fixture holds the producer's queue turn while it waits for the gate to reopen.
  • Earlier finding fixed: the README claimed more than the remap path does. It now limits promotion to creation, and says superseded targets mapped again get #3740's private local tiles.
  • Earlier finding fixed: Tested gives the whole suite (3017 passed, 0 failed, 52 ignored, 26 skipped) and both smoke blocks.
  • Promotion and #3740's private tiles do not interfere: a render target never keeps an L0 page in used, so it is never leased.
  • Early returns inside the new closure still reopen the gate and replay the queued unmaps before the error is returned.
  • With XCL_TEXTURE_BUDGET unset, pc_execute falls through to queue_submit::with as before.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7379661876 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7379661876). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T13:20:13Z. --- **Follow-up review** of `100cac75`, since `55057068` (code reading only, not a merge-check) · 1 high, 1 medium **In short:** Stacked on #3740 (now at `2ff33838`); only the top commit `100cac75` belongs here. Since `55057068`: - texture uploads go through the promotion gate; - deferred unmaps run after the gate reopens; - the README limits promotion to creation; - the whole suite is reported. One new problem: a deferred unmap is replayed without checking whether the title used the texture again meanwhile, so a texture in use can lose its tiles. The size and the overlap with #3620 are still open. #### High 1. **A deferred unmap can unmap a texture the title is using again.** - Normally `placements::unmap_if_superseded` (`placements.rs` ~541) checks under the registry lock that the target is still superseded before unmapping it, so the unmap and a later `use_again` stay in order. - During a promotion, `unmap_placed` only queues a leased alias in `unmaps_after_promotion` (`vram.rs` ~3407-3410), and the target stays `mapped`. - If the title uses that texture before the replay, `note_use` (`placements.rs` ~566-570) calls `remap_if_unmapped`. That returns `true` at once because the target is still mapped (`vram.rs` ~3456-3458), and `use_again` marks it live. The same happens through `settle` → `map_again` when the newer placement is released. - `bind_eager` then replays the queued unmap anyway (~3101). The texture loses its tiles while the registry counts it as mapped and no longer superseded, so nothing maps it again. Fix: let `remap_if_unmapped` cancel a queued promotion unmap, as it already cancels `held_unmaps` (~3460), or replay through a check that the target is still superseded. Add a test where the alias is used again between the deferral and the replay. #### Medium 2. **Size, and overlap with #3620 (still open).** +1239/-28, about 600 lines of tests, with no reason for going past ~800. It still splits naturally: the admission gate (`vram_promotion.rs` and the submit hooks), then the promotion in `vram.rs`. The description names #3620, which is still open; both rewrite the same bind path for the same case, so only one should land. <details><summary>Checked and fine</summary> - Earlier finding fixed: texture uploads bypassed the gate. `pc_execute` now uses `vram_promotion::submit` (`sparse.rs` ~5226), so each upload gets a mark and waits while the gate is closed. The fixture sends an upload through `pc_execute` and checks the timeout and the arena fallback. - Earlier finding fixed: a deferred unmap could deadlock with a title `Signal`. `PromotionRange::drop` only moves the queued unmaps out, and `bind_eager` drops `closed` before replaying them (~3100). The fixture holds the producer's queue turn while it waits for the gate to reopen. - Earlier finding fixed: the README claimed more than the remap path does. It now limits promotion to creation, and says superseded targets mapped again get #3740's private local tiles. - Earlier finding fixed: **Tested** gives the whole suite (3017 passed, 0 failed, 52 ignored, 26 skipped) and both smoke blocks. - Promotion and #3740's private tiles do not interfere: a render target never keeps an L0 page in `used`, so it is never leased. - Early returns inside the new closure still reopen the gate and replay the queued unmaps before the error is returned. - With `XCL_TEXTURE_BUDGET` unset, `pc_execute` falls through to `queue_submit::with` as before. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
jeroenhaentjens commented 2026-12-03 14:22:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T14:22:55Z.


@Foniass Reactivating a leased alias now cancels its pending unmap through the replay handoff. The regression checks the retained tile ownership and reads back the preserved contents. The timeout fixture holds a CPU admission slot while the explicit test budget exercises the deadline, so adapter-specific budget admission cannot bypass the assertion. The workspace results and smoke evidence are in the PR.

<!-- greyfinch-sync:ivall/xcl:comment:7381349404 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7381349404). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-12-03T14:22:55Z. --- @Foniass Reactivating a leased alias now cancels its pending unmap through the replay handoff. The regression checks the retained tile ownership and reads back the preserved contents. The timeout fixture holds a CPU admission slot while the explicit test budget exercises the deadline, so adapter-specific budget admission cannot bypass the assertion. The workspace results and smoke evidence are in the PR.
Foniass commented 2026-12-03 14:25:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:25:20Z.


Follow-up review of eced2941, since 100cac75 (code reading only, not a merge-check) · 2 medium

In short: This push fixes the high finding from the last review. A deferred unmap that the title cancels by using the texture again is now dropped before it can run. The new fixture step covers that case, and the fallback-timeout part of the fixture now holds the admission slot itself. Still stacked on #3740 at 2ff33838. The size and the overlap with #3620 remain open, and the regression run uses the repository's test fixture, which does not reach this code.

Medium

  1. The regression run does not reach this code. Both smoke blocks are of xcl-owned-test-fixture, which shows 1 frame (presents per 2 s: 0 0 0), with no setting given. The promotion and the gate only run with XCL_TEXTURE_BUDGET set, so they never run in this check. CONTRIBUTING.md asks for the regression run on a real title. Add a pair of runs on a title, made on main and on eced2941, ideally with the opt-in on.
  2. Size, and overlap with #3620 (still open). The top commit is now about +1300 lines, about half of them tests, with no reason given for going past ~800. It still splits naturally: the admission gate (vram_promotion.rs and the submit hooks), then the promotion in vram.rs. #3620 is still open and rewrites the same bind path for the same case, so only one of the two should land.
Checked and fine
  • Earlier finding fixed: a deferred unmap could take the tiles from a texture the title used again.
    • Each request is now an Arc that stays in unmaps_after_promotion. PromotionRange::drop only hands clones to the caller.
    • remap_if_unmapped (vram.rs ~3463) removes every queued request for the resource. It is the path both note_use and map_again take.
    • The replay in bind_eager passes the request to unmap_placed, which returns unless it can still find that Arc (Arc::ptr_eq, ~3410).
    • The search, the removal and the mapped = false update all happen under one PAGES lock. So a use is ordered either before the replay (the replay is cancelled) or after it (the use remaps the texture).
  • If another promotion starts after the gate reopens and before the replay, the same request can be handed out twice. The first replay removes it, and the second finds nothing and returns.
  • No request can be queued after drop, because leased_aliases is cleared there.
  • The new fixture step leases the sampled alias, queues its unmap, hands it off, calls remap_if_unmapped and then replays. It checks that the alias stays mapped with the same used tiles, and that the queue is empty.
  • The timeout part now holds an active submit through Gate::with_active_submit (test only) while bind_eager runs. It checks for BindFailure::Busy and one more timeout before the arena fallback, then sends the upload.
  • The test now falls back to WARP when no hardware adapter matches auto. The existing skips (no Debug Layer, no sampled L0 tile heap) still apply there. Tested says the fixture passes on the Microsoft Basic Render Driver.
  • Tested gives the whole suite on eced2941 (3017 passed, 0 failed, 52 ignored, 26 SKIPPED).

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7381418176 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7381418176). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T14:25:20Z. --- **Follow-up review** of `eced2941`, since `100cac75` (code reading only, not a merge-check) · 2 medium **In short:** This push fixes the high finding from the last review. A deferred unmap that the title cancels by using the texture again is now dropped before it can run. The new fixture step covers that case, and the fallback-timeout part of the fixture now holds the admission slot itself. Still stacked on #3740 at `2ff33838`. The size and the overlap with #3620 remain open, and the regression run uses the repository's test fixture, which does not reach this code. #### Medium 1. **The regression run does not reach this code.** Both smoke blocks are of `xcl-owned-test-fixture`, which shows 1 frame (`presents per 2 s: 0 0 0`), with no setting given. The promotion and the gate only run with `XCL_TEXTURE_BUDGET` set, so they never run in this check. CONTRIBUTING.md asks for the regression run on a real title. Add a pair of runs on a title, made on `main` and on `eced2941`, ideally with the opt-in on. 2. **Size, and overlap with #3620 (still open).** The top commit is now about +1300 lines, about half of them tests, with no reason given for going past ~800. It still splits naturally: the admission gate (`vram_promotion.rs` and the submit hooks), then the promotion in `vram.rs`. #3620 is still open and rewrites the same bind path for the same case, so only one of the two should land. <details><summary>Checked and fine</summary> - Earlier finding fixed: a deferred unmap could take the tiles from a texture the title used again. - Each request is now an `Arc` that stays in `unmaps_after_promotion`. `PromotionRange::drop` only hands clones to the caller. - `remap_if_unmapped` (`vram.rs` ~3463) removes every queued request for the resource. It is the path both `note_use` and `map_again` take. - The replay in `bind_eager` passes the request to `unmap_placed`, which returns unless it can still find that `Arc` (`Arc::ptr_eq`, ~3410). - The search, the removal and the `mapped = false` update all happen under one `PAGES` lock. So a use is ordered either before the replay (the replay is cancelled) or after it (the use remaps the texture). - If another promotion starts after the gate reopens and before the replay, the same request can be handed out twice. The first replay removes it, and the second finds nothing and returns. - No request can be queued after `drop`, because `leased_aliases` is cleared there. - The new fixture step leases the sampled alias, queues its unmap, hands it off, calls `remap_if_unmapped` and then replays. It checks that the alias stays mapped with the same `used` tiles, and that the queue is empty. - The timeout part now holds an active submit through `Gate::with_active_submit` (test only) while `bind_eager` runs. It checks for `BindFailure::Busy` and one more timeout before the arena fallback, then sends the upload. - The test now falls back to WARP when no hardware adapter matches `auto`. The existing skips (no Debug Layer, no sampled L0 tile heap) still apply there. **Tested** says the fixture passes on the Microsoft Basic Render Driver. - **Tested** gives the whole suite on `eced2941` (3017 passed, 0 failed, 52 ignored, 26 SKIPPED). </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Gevroska commented 2026-12-03 17:45:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-12-03T17:45:36Z.


@jeroenhaentjens I tested queue replacement on eced2941. The registered-queue control waited for the old fence as expected. I found two cases worth checking separately.

  1. When a replacement queue had the same synthetic address and lacked title-list registration, it advanced the retired queue’s fence from 0 to 2 through the shared fallback key. That let the promotion gate close before I supplied a separate completion for the old queue.
  2. After 16 registered queues completed and retired, 16 marks and their fence references remained. This case required no address reuse.

I tried using the queue lease generation for the receipt and removing completed retired marks after validating the full prefix. The replacement then received its own mark at 1, the old fence stayed at 0 until its own completion, and the 16 retired marks dropped to zero. Same-queue signal recovery still passed.

These were controlled Windows tests with stand-in fences. The fixture explicitly drove queue creation and final release through the lease registry. I haven’t observed native D3D12 address reuse or measured GPU memory impact.

AI disclosure: OpenAI Codex GPT-6.2 Sol tested the PR and wrote the local correction. An independent Codex reviewer repeated the comparison. GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7387016865 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3745#issuecomment-7387016865). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-12-03T17:45:36Z. --- @jeroenhaentjens I tested queue replacement on `eced2941`. The registered-queue control waited for the old fence as expected. I found two cases worth checking separately. 1. When a replacement queue had the same synthetic address and lacked title-list registration, it advanced the retired queue’s fence from 0 to 2 through the shared fallback key. That let the promotion gate close before I supplied a separate completion for the old queue. 2. After 16 **registered** queues completed and retired, 16 marks and their fence references remained. This case required no address reuse. I tried using the queue lease generation for the receipt and removing completed retired marks after validating the full prefix. The replacement then received its own mark at 1, the old fence stayed at 0 until its own completion, and the 16 retired marks dropped to zero. Same-queue signal recovery still passed. These were controlled Windows tests with stand-in fences. The fixture explicitly drove queue creation and final release through the lease registry. I haven’t observed native D3D12 address reuse or measured GPU memory impact. AI disclosure: OpenAI Codex GPT-6.2 Sol tested the PR and wrote the local correction. An independent Codex reviewer repeated the comparison. GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3745:upstream-pr/3745'
git switch 'upstream-pr/3745'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3745'
git switch 'upstream-pr/3745'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3745'
git switch 'upstream-pr/3745'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3745'
git switch 'main'
git merge --squash 'upstream-pr/3745'
git switch 'main'
git merge --ff-only 'upstream-pr/3745'
git switch 'main'
git merge 'upstream-pr/3745'
git push origin 'main'
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
xcl-dev/xcl!3745
No description provided.