D3D12.X: video-memory arenas never overlap #121

Merged
gefydev merged 1 commit from upstream-pr/122 into main 2026-11-23 14:13:38 +00:00
gefydev commented 2026-11-23 13:25:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gefydev on 2026-11-23T13:25:18Z.


#104 item 1.

arena_for reused an arena only if it held the whole placement. A new arena took the 32 MiB blocks from below the address up to 128 MiB, with no check against the arenas already there. So a placement that straddled an arena, or a new arena that grew into one, gave two heaps over the same title addresses. Resources at one address could then land in different heaps and stop aliasing.

The layout is now a pure function, plan, over the arena ranges. arena_for applies it:

  • A placement inside an arena reuses that arena.
  • A new arena that overlaps no other still grows to 128 MiB, but it stops at the next arena.
  • A placement that overlaps arenas gets one new arena. It covers the union of the placement's range and all the arenas it overlaps; the union is taken again until no new arena joins. The old arenas leave the list. Placed resources hold a reference to their heap, so the old heaps live as long as their resources do. Later placements at those addresses use the new arena. Resources already in a replaced arena no longer alias later ones; that case is logged.

I picked merging over "allocate the remainder" because a D3D12 resource must sit in one heap. A straddling resource cannot be split between the old arena and a remainder heap.

Tests in vram::tests, CPU only:

  • the straddling sequence from #104: 16 MiB at 0x1_0400_0000, then 48 MiB at 0x1_0200_0000, then the first address again. After it there is one arena, and the third placement shares it with the second.
  • a new arena stops at the next one.
  • one placement merges two arenas across a gap.

Each step also checks that no two arenas overlap. With the old rule the first test's second step gives [0x1_0200_0000, +128 MiB) over the first arena. The other lib tests pass on a GTX 1650 under Wine. Not run with a retail title.

<!-- greyfinch-sync:ivall/xcl:issue:6560332165 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/122). Originally posted by [gefydev](https://github.com/gefydev) on 2026-11-23T13:25:18Z. --- #104 item 1. `arena_for` reused an arena only if it held the whole placement. A new arena took the 32 MiB blocks from below the address up to 128 MiB, with no check against the arenas already there. So a placement that straddled an arena, or a new arena that grew into one, gave two heaps over the same title addresses. Resources at one address could then land in different heaps and stop aliasing. The layout is now a pure function, `plan`, over the arena ranges. `arena_for` applies it: - A placement inside an arena reuses that arena. - A new arena that overlaps no other still grows to 128 MiB, but it stops at the next arena. - A placement that overlaps arenas gets one new arena. It covers the union of the placement's range and all the arenas it overlaps; the union is taken again until no new arena joins. The old arenas leave the list. Placed resources hold a reference to their heap, so the old heaps live as long as their resources do. Later placements at those addresses use the new arena. Resources already in a replaced arena no longer alias later ones; that case is logged. I picked merging over "allocate the remainder" because a D3D12 resource must sit in one heap. A straddling resource cannot be split between the old arena and a remainder heap. Tests in `vram::tests`, CPU only: - the straddling sequence from #104: 16 MiB at 0x1_0400_0000, then 48 MiB at 0x1_0200_0000, then the first address again. After it there is one arena, and the third placement shares it with the second. - a new arena stops at the next one. - one placement merges two arenas across a gap. Each step also checks that no two arenas overlap. With the old rule the first test's second step gives `[0x1_0200_0000, +128 MiB)` over the first arena. The other lib tests pass on a GTX 1650 under Wine. Not run with a retail title.
upstream-sync closed this pull request 2026-11-24 06:57:15 +00:00
ivall commented 2026-11-24 07:00:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T14:14:10Z.


Merged. XDefiant hits it in practice: ~78 s in it logs one straddling placement merged into a new arena, and runs on. Checked on Windows 11 with an RX 9070 (RDNA4), merged together with the rest of #110–#129: cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; the retail pack still translates 26 698 / 26 698; the FSR4 GPU probe passes; Unicorn Overlord and XDefiant run. Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7103687860 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/122#issuecomment-7103687860). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T14:14:10Z. --- Merged. XDefiant hits it in practice: ~78 s in it logs one straddling placement merged into a new arena, and runs on. Checked on Windows 11 with an RX 9070 (RDNA4), merged together with the rest of #110–#129: `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with `XCL_SPLIT_WAVE64=1`; the retail pack still translates 26 698 / 26 698; the FSR4 GPU probe passes; Unicorn Overlord and XDefiant run. Thanks!
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!121
No description provided.