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

Manually merged
github merged 1 commit from gh-pr/122/head into gh-pr/122/base 2026-11-26 04:11:13 +00:00
Owner

@⁠gefydev on GitHub · 2026-11-23 13:25 UTC · original
gefydev:d3d12x-vram-arenas → main · +123 −8 · 1 files · 1 commits · merged 2026-11-23 14:13 UTC

#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.

**@⁠gefydev** on GitHub · 2026-11-23 13:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/122) `gefydev:d3d12x-vram-arenas` → `main` · +123 −8 · 1 files · 1 commits · merged 2026-11-23 14:13 UTC #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.
arena_for reused an arena only if it held the whole placement, and a new
one took the 32 MiB blocks below the address up to 128 MiB with no regard
for the arenas already there. A placement straddling an arena (or a new
arena growing into one) gave two heaps over the same title addresses, so
resources at one address could land in different heaps and stop aliasing.

The layout is now a pure function (plan) over the arena ranges:
- a placement inside an arena reuses it;
- a new arena that overlaps none grows to 128 MiB but stops at the next
  arena;
- a placement that overlaps arenas gets one arena over the union of its
  range and all of them (to closure), and those leave the list. Their
  resources keep their heaps; later placements at those addresses use the
  new arena.

Tests (vram::tests): the straddling sequence from #104, a new arena
stopping at the next one, a placement merging two arenas over a gap.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:12 +00:00
github manually merged commit 70d7e0a9d1 into gh-pr/122/base 2026-11-26 04:11:13 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 14:14 UTC · original

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!

**@⁠ivall** on GitHub · 2026-11-23 14:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/122#issuecomment-7103687860) 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!
This discussion has been locked. Commenting is limited to contributors.
No description provided.