D3D12.X: port XCL_TEXTURE_SYSMEM (#3039) to amd-dev with L0 heap reclamation #3335

Closed
iggyvilla wants to merge 1 commit from upstream-pr/3335 into amd-dev
iggyvilla commented 2026-11-29 09:05:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-11-29T09:05:18Z.


Ports @treybertram06's opt-in XCL_TEXTURE_SYSMEM=1 (#3039, which targets main and does not apply to amd-dev) to amd-dev f33df5a7. Off by default; needs XCL_TEXTURE_LEVEL_PAGES=1.

New pages that map_levels takes for lazily mapped texture levels come from 64 MiB L0 system-memory pool heaps (custom, write-back, sampled by the GPU over PCIe) instead of local video memory; a page there has SYS_TILE (bit 31) in its heap index. If an L0 heap cannot be made, local video memory is used. Pages already mapped at a title address keep their backing, so aliasing (an RT placed over a streamed page) is unchanged.

  • vram.rs: SYS_TILE, texture_sysmem(), alloc_sys_pool_heap(), heap_in(), cool_in(), sys_pools/sys_pool on Pages, bind_range_in(.., sys), SYS_TILE handling in drain_fenced_tiles, flush_zero_tiles, map, release_tiles, the byte counts, and empty L0 heap reclamation next to the local one in sweep_and_reclaim (per @thehollowedone's review on #3039; creation-order aliasing wording per @thehollowedone and @andrewDoing).
  • Two tests: a_system_memory_page_is_told_apart_and_cools_in_its_own_pool, cooled_system_memory_pool_heaps_are_reclaimed_independently.
  • Earlier drafts of this port also fixed apply_backing; that function no longer exists on f33df5a7.

Tested

  • Hardware / OS / Rust: AMD Radeon RX 6650 XT (8 GB RDNA2, driver 32.0.21045.29003), Ryzen 7 5700X, Windows 11, rustc 1.100.0, debug test build on origin/amd-dev f33df5a7 + this commit.
  • cargo test --lib system_memory: 2 passed (the GPU one ran, it did not skip). hle::d3d12x::vram::: 30 passed, 0 failed, 1 ignored.
  • cargo test --lib hle::d3d12x:: -- --test-threads=1: the same 8 tests fail with and without this commit; no new failures.
  • Retail: on the earlier base (a local branch on 7c795f5e) the port ran 600 s world-load runs on this card up to 3,027 presents with no crash. On f33df5a7 only the 60 s smoke below was run (with the option off); the option's path is not soaked on this base.

Regression run
Both 60 s runs with scripts/smoke.ps1 -Seconds 60, XCL_PREPARE=0, on the same retail title and RX 6650 XT, after xcl pso-precompile --used had warmed the compute pipeline cache (with a build that has all three ports of this series). First main d8bd9a38, then this PR's head. XCL_TEXTURE_SYSMEM was not set, so this run covers the off (no-change) path.

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15479 MB
xcl-smoke v1
commit: 13500f30ef6fb1d7062b320bb042908200bf9f15
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1441 (PresentX 1441)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 25048 MB

Peak commit is 1.56x main's, past the 1.25x rule, but that is amd-dev's, not this change's: the same 60 s run on amd-dev f33df5a7 without this commit peaks at 25,028 MB (1,429 frames). So every amd-dev PR will fail that one line of the check until amd-dev itself comes down.

Not tested

  • cargo test --workspace, NVIDIA, RDNA3/RDNA4.

AI use

  • The first version of this change (against amd-dev 7c795f5e) was written and tested by Antigravity with Gemini 4 Neon (High). Its port to f33df5a7 (the old patch no longer applied: the code moved) was done by Claude Code (Claude Sonnet 5.5, effort high), which also ran the tests below and wrote this text. The account owner did not write the code or this text.
  • Original #3039 by @treybertram06.
<!-- greyfinch-sync:ivall/xcl:issue:5549256907 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3335). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-11-29T09:05:18Z. --- Ports @treybertram06's opt-in `XCL_TEXTURE_SYSMEM=1` (#3039, which targets `main` and does not apply to `amd-dev`) to `amd-dev` `f33df5a7`. Off by default; needs `XCL_TEXTURE_LEVEL_PAGES=1`. New pages that `map_levels` takes for lazily mapped texture levels come from 64 MiB L0 system-memory pool heaps (custom, write-back, sampled by the GPU over PCIe) instead of local video memory; a page there has `SYS_TILE` (bit 31) in its heap index. If an L0 heap cannot be made, local video memory is used. Pages already mapped at a title address keep their backing, so aliasing (an RT placed over a streamed page) is unchanged. - `vram.rs`: `SYS_TILE`, `texture_sysmem()`, `alloc_sys_pool_heap()`, `heap_in()`, `cool_in()`, `sys_pools`/`sys_pool` on `Pages`, `bind_range_in(.., sys)`, `SYS_TILE` handling in `drain_fenced_tiles`, `flush_zero_tiles`, `map`, `release_tiles`, the byte counts, and empty L0 heap reclamation next to the local one in `sweep_and_reclaim` (per @thehollowedone's review on #3039; creation-order aliasing wording per @thehollowedone and @andrewDoing). - Two tests: `a_system_memory_page_is_told_apart_and_cools_in_its_own_pool`, `cooled_system_memory_pool_heaps_are_reclaimed_independently`. - Earlier drafts of this port also fixed `apply_backing`; that function no longer exists on `f33df5a7`. **Tested** - Hardware / OS / Rust: AMD Radeon RX 6650 XT (8 GB RDNA2, driver `32.0.21045.29003`), Ryzen 7 5700X, Windows 11, `rustc 1.100.0`, debug test build on `origin/amd-dev` `f33df5a7` + this commit. - `cargo test --lib system_memory`: 2 passed (the GPU one ran, it did not skip). `hle::d3d12x::vram::`: 30 passed, 0 failed, 1 ignored. - `cargo test --lib hle::d3d12x:: -- --test-threads=1`: the same 8 tests fail with and without this commit; no new failures. - Retail: on the earlier base (a local branch on `7c795f5e`) the port ran 600 s world-load runs on this card up to 3,027 presents with no crash. On `f33df5a7` only the 60 s smoke below was run (with the option off); the option's path is not soaked on this base. **Regression run** Both 60 s runs with `scripts/smoke.ps1 -Seconds 60`, `XCL_PREPARE=0`, on the same retail title and RX 6650 XT, after `xcl pso-precompile --used` had warmed the compute pipeline cache (with a build that has all three ports of this series). First `main` `d8bd9a38`, then this PR's head. `XCL_TEXTURE_SYSMEM` was not set, so this run covers the off (no-change) path. ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15479 MB ``` ``` xcl-smoke v1 commit: 13500f30ef6fb1d7062b320bb042908200bf9f15 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1441 (PresentX 1441) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 25048 MB ``` Peak commit is 1.56x main's, past the 1.25x rule, but that is `amd-dev`'s, not this change's: the same 60 s run on `amd-dev` `f33df5a7` without this commit peaks at 25,028 MB (1,429 frames). So every `amd-dev` PR will fail that one line of the check until `amd-dev` itself comes down. **Not tested** - `cargo test --workspace`, NVIDIA, RDNA3/RDNA4. **AI use** - The first version of this change (against `amd-dev` `7c795f5e`) was written and tested by Antigravity with Gemini 4 Neon (High). Its port to `f33df5a7` (the old patch no longer applied: the code moved) was done by Claude Code (Claude Sonnet 5.5, effort high), which also ran the tests below and wrote this text. The account owner did not write the code or this text. - Original #3039 by @treybertram06.
Foniass commented 2026-12-01 09:12:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:12:31Z.


Review (head 13500f30, diff read, not a merge-check; draft, base amd-dev, conflicts with it):

  • A second change is bundled in. The L0 heap reclamation (sweep_and_reclaim, vram.rs ~1180-1218, and its test ~3598) isn't in #3039, the original on main (still open). Unless it goes into #3039 too, or into its own PR, main and amd-dev diverge on it.
  • System-memory tiles can stay cooling forever (reasoned, not run). The cool-probe arming (~1994, ~2017) and need_unmap_work (~2102) only look at pool.cooling, never sys_pool.cooling. Tiles freed into the L0 pool while no video-memory page is cooling get no probe, so their heaps are never reclaimed. Constant video-memory churn probably hides it.
  • L0 memory isn't reported anywhere. page_bytes_for (~2181) and page_bytes (~2261) now leave L0 pages out, but no L0 total is added, so the memory report undercounts.
  • No test binds or samples a texture through an L0 page (bind_range_in with sys=true). The debug layer wasn't run, and a render target placed over an L0 page inherits that backing.
  • The description is stale. amd-dev 8ea8524f made level pages the default, so "needs XCL_TEXTURE_LEVEL_PAGES=1" no longer holds.
  • The red CI tests (release_tests::the_last_release_drops_entries..., sparse::tests::a_gpu_write_into_a_gpu_view...) are in files this PR doesn't touch; amd-dev's own CI is red too.

Fine: off by default, and with it off the behaviour is unchanged (no tagged tiles, so the preferred filter is a no-op). The bit-31 tag is handled consistently in drain_fenced_tiles, flush_zero_tiles, map and release_tiles, and when no L0 heap can be made it falls back to video memory.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7306367744 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3335#issuecomment-7306367744). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:12:31Z. --- Review (head 13500f30, diff read, not a merge-check; draft, base `amd-dev`, conflicts with it): - **A second change is bundled in.** The L0 heap reclamation (`sweep_and_reclaim`, `vram.rs` ~1180-1218, and its test ~3598) isn't in #3039, the original on main (still open). Unless it goes into #3039 too, or into its own PR, main and amd-dev diverge on it. - **System-memory tiles can stay cooling forever** (reasoned, not run). The cool-probe arming (~1994, ~2017) and `need_unmap_work` (~2102) only look at `pool.cooling`, never `sys_pool.cooling`. Tiles freed into the L0 pool while no video-memory page is cooling get no probe, so their heaps are never reclaimed. Constant video-memory churn probably hides it. - **L0 memory isn't reported anywhere.** `page_bytes_for` (~2181) and `page_bytes` (~2261) now leave L0 pages out, but no L0 total is added, so the memory report undercounts. - No test binds or samples a texture through an L0 page (`bind_range_in` with `sys=true`). The debug layer wasn't run, and a render target placed over an L0 page inherits that backing. - **The description is stale.** amd-dev 8ea8524f made level pages the default, so "needs `XCL_TEXTURE_LEVEL_PAGES=1`" no longer holds. - The red CI tests (`release_tests::the_last_release_drops_entries...`, `sparse::tests::a_gpu_write_into_a_gpu_view...`) are in files this PR doesn't touch; amd-dev's own CI is red too. Fine: off by default, and with it off the behaviour is unchanged (no tagged tiles, so the `preferred` filter is a no-op). The bit-31 tag is handled consistently in `drain_fenced_tiles`, `flush_zero_tiles`, `map` and `release_tiles`, and when no L0 heap can be made it falls back to video memory. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 09:49:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:49:42Z.


Triage (#1607) – head 13500f3

This is a port of the vram.rs half of open #3039 (XCL_TEXTURE_SYSMEM) to amd-dev, where #3039 does not apply. It also adds reclamation of empty L0 heaps. TEXTURE_SYSMEM is not on origin/amd-dev or main yet. It does not overlap #3112 (same author, sparse.rs pools under XCL_SPARSE_VRAM_CAP_MB). The large line overlap with #3111/#3361/#3099 comes from the amd-dev base, not from this commit. No problems found in the diff: SYS_TILE-tagged tiles are routed through cooling, fenced returns, zeroing, scratch heaps and reclaim, and the byte counts leave system-memory pages out. The PR conflicts with amd-dev.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7307264904 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3335#issuecomment-7307264904). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:49:42Z. --- **Triage (#1607)** – head 13500f3 This is a port of the vram.rs half of open #3039 (`XCL_TEXTURE_SYSMEM`) to `amd-dev`, where #3039 does not apply. It also adds reclamation of empty L0 heaps. `TEXTURE_SYSMEM` is not on `origin/amd-dev` or `main` yet. It does not overlap #3112 (same author, sparse.rs pools under `XCL_SPARSE_VRAM_CAP_MB`). The large line overlap with #3111/#3361/#3099 comes from the amd-dev base, not from this commit. No problems found in the diff: `SYS_TILE`-tagged tiles are routed through cooling, fenced returns, zeroing, scratch heaps and reclaim, and the byte counts leave system-memory pages out. The PR conflicts with `amd-dev`. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
iggyvilla commented 2026-12-02 03:54:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-12-02T03:54:13Z.


Closing as superseded by #3587 (XCL_VRAM_BUDGET=1), which spills sampled texture pools to L0 dynamically under VRAM pressure rather than unconditionally.

<!-- greyfinch-sync:ivall/xcl:comment:7334354561 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3335#issuecomment-7334354561). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-12-02T03:54:13Z. --- Closing as superseded by #3587 (`XCL_VRAM_BUDGET=1`), which spills sampled texture pools to L0 dynamically under VRAM pressure rather than unconditionally.

Pull request closed

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!3335
No description provided.