D3D12.X: render targets share video-memory pages on a macOS host too #2492

Open
github-bot wants to merge 3 commits from github-bot/gh-2492 into main AGit
Owner

@⁠vakaobr on GitHub · 2026-11-25 20:13 UTC · original
vakaobr:d3d12x/mac-render-targets-on-pages → main · +286 −1 · 2 files · 3 commits · draft

Stacked on #2402; only the top commit belongs here. Part of #258.

On a macOS host, #2402 keeps every GPU-owned texture (vram::place: render targets, depth targets, UAVs) in an arena, since place_on_pages returns at require_aligned there; its RT/DS flag check is never reached by a title's texture. Render targets can share the title's video-memory pages on D3DMetal: with two reserved textures on the same tiles, an R8G8B8A8_UNORM render target (RT + UAV) cleared through one reads back through the other with 0 of 4096 pixels wrong. A D32_FLOAT depth target reads back with 3968 of 4096 wrong, so depth targets, and the GPU-owned textures that were not probed, keep their arenas. Windows is unchanged.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: on a Mac, place_on_pages lets render targets through the require_aligned return; they get ALLOW_UNORDERED_ACCESS from native_page_flags, and a format without typed UAV still stays in its arena. New test render_targets_at_one_address_share_their_pages: two render targets placed through vram::place at one address must be on the shared pages, and a clear through one reads back through the other.

Tested

  • MacBook Pro M5 Pro, macOS 27.2.1, CrossOver 26.3.0, D3DMetal 3.0, Rust 1.100.0 x86_64-pc-windows-gnu, debug.
  • On a Mac the vram tests need #1904 and a deferred release for D3DMetal's threads (then #2474, now #2445 + #2498), so they ran on a stack: #2361 + #1904 + #1789 + #2474 + #2402, one test per process in the CrossOver bottle.
  • render_targets_at_one_address_share_their_pages: fails without this change (not placed on the pages), passes with it (0 of 65536 pixels wrong).
  • hle::d3d12x::vram::tests + hle::d3d12x::title_textures::tests, 38 tests: without this change 36 passed, 1 failed (the new test), 1 ignored (churn_update_tile_mappings_timing); with it 37 passed, 0 failed, 1 ignored. No SKIPPED.
  • The 0 of 4096 and 3968 of 4096 numbers come from raw CreateReservedResource / UpdateTileMappings probes on the same Mac; those probes are not in this PR.

Regression run

  • None: I have no title of my own to run scripts/smoke.ps1 on.

Not tested

  • Windows: the change is behind mac_host(), but I did not build or run it there.
  • The whole suite; any title, and the memory saving in one.
  • Render targets in a format without typed UAV, or multisampled, on a Mac: they stay in arenas by the code (native_page_flags / reservable), not by a test.

AI use

  • Claude Code with Claude Opus 5.5: found that #2402's RT check is never reached by a title's render target, wrote the change and the test, ran the tests on the Mac and wrote this description. Claude Opus 4.6 ran the earlier probes.
**@⁠vakaobr** on GitHub · 2026-11-25 20:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/2492) `vakaobr:d3d12x/mac-render-targets-on-pages` → `main` · +286 −1 · 2 files · 3 commits · draft Stacked on #2402; only the top commit belongs here. Part of #258. On a macOS host, #2402 keeps every GPU-owned texture (`vram::place`: render targets, depth targets, UAVs) in an arena, since `place_on_pages` returns at `require_aligned` there; its RT/DS flag check is never reached by a title's texture. Render targets can share the title's video-memory pages on D3DMetal: with two reserved textures on the same tiles, an `R8G8B8A8_UNORM` render target (RT + UAV) cleared through one reads back through the other with 0 of 4096 pixels wrong. A `D32_FLOAT` depth target reads back with 3968 of 4096 wrong, so depth targets, and the GPU-owned textures that were not probed, keep their arenas. Windows is unchanged. **What is in it** - `crates/xcl/src/hle/d3d12x/vram.rs`: on a Mac, `place_on_pages` lets render targets through the `require_aligned` return; they get `ALLOW_UNORDERED_ACCESS` from `native_page_flags`, and a format without typed UAV still stays in its arena. New test `render_targets_at_one_address_share_their_pages`: two render targets placed through `vram::place` at one address must be on the shared pages, and a clear through one reads back through the other. **Tested** - MacBook Pro M5 Pro, macOS 27.2.1, CrossOver 26.3.0, D3DMetal 3.0, Rust 1.100.0 `x86_64-pc-windows-gnu`, debug. - On a Mac the `vram` tests need #1904 and a deferred release for D3DMetal's threads (then #2474, now #2445 + #2498), so they ran on a stack: #2361 + #1904 + #1789 + #2474 + #2402, one test per process in the CrossOver bottle. - `render_targets_at_one_address_share_their_pages`: fails without this change (not placed on the pages), passes with it (0 of 65536 pixels wrong). - `hle::d3d12x::vram::tests` + `hle::d3d12x::title_textures::tests`, 38 tests: without this change 36 passed, 1 failed (the new test), 1 ignored (`churn_update_tile_mappings_timing`); with it 37 passed, 0 failed, 1 ignored. No SKIPPED. - The 0 of 4096 and 3968 of 4096 numbers come from raw `CreateReservedResource` / `UpdateTileMappings` probes on the same Mac; those probes are not in this PR. **Regression run** - None: I have no title of my own to run `scripts/smoke.ps1` on. **Not tested** - Windows: the change is behind `mac_host()`, but I did not build or run it there. - The whole suite; any title, and the memory saving in one. - Render targets in a format without typed UAV, or multisampled, on a Mac: they stay in arenas by the code (`native_page_flags` / `reservable`), not by a test. **AI use** - Claude Code with Claude Opus 5.5: found that #2402's RT check is never reached by a title's render target, wrote the change and the test, ran the tests on the Mac and wrote this description. Claude Opus 4.6 ran the earlier probes.
util::mac_host(): the process runs under Wine on a Mac (CrossOver or the
Game Porting Toolkit), where D3D12 is Apple's D3DMetal and the title's
code runs through Rosetta 2. ntdll's wine_get_host_version names the
host's system; "Darwin" is a Mac. XCL_MAC_HOST=1 / 0 overrides it.

Nothing calls it yet. The Mac changes that need to know they run there
(the barrier default, title textures on shared pages) build on it; until
now only Ahmet-Dedeler's mac7 branch had it. Part of #258.
#288's shared pages never run on D3DMetal: it reports
D3D12_FORMAT_SUPPORT2_TILED for no format, so `reservable` refuses every
texture and each title texture keeps a copy of its own in video memory
(about 16 GB more wired memory while a title loads on a Mac).  D3DMetal
does make the reserved textures.  Measured with copies and shader reads
on CrossOver 26.3: a texture written by a copy and read through another
reserved texture on the same tiles reads scrambled bytes, whatever the
barrier, format or layout.  Block-compressed textures, and textures made
with ALLOW_UNORDERED_ACCESS, share correctly.  The likely reason is
compression state that D3DMetal keeps per texture, not per tile.

On a macOS host (util::mac_host):
- `reservable` skips the TILED bit and accepts block-compressed formats
  and formats with typed unordered access (single-sample only);
- `place_on_pages` gives the reserved texture ALLOW_UNORDERED_ACCESS
  unless it is block-compressed.  Render and depth targets, and the
  GPU-owned `place`, stay in arenas: their sharing was not probed.
Windows is unchanged.

sampled_textures_at_one_address_share_their_pages_in_every_slice places
two 256x256, 4-slice, 9-level textures (RGBA8 and BC7) at one address,
writes all 36 subresources through one and reads them through the
other.  On the Mac it needs the native-host vtable fix of #1904 and a
deferred release for D3DMetal's own threads: without the first, placing
the texture faults in GetResourceTiling; without the second, a list that
touches it never completes.  With both, it fails without this change
(not placed on the pages), passes with it, and fails again if RGBA8
gets no unordered-access flag (every subresource reads back wrong).

Part of #258.
A title's GPU-owned textures (render targets, depth targets, UAVs) are
placed through vram::place, which asks place_on_pages with
require_aligned. On a Mac, #2402 returned there for all of them, so a
render target never reached the shared pages; its own RT/DS flag check
was never reached by a title's texture.

Render targets share correctly on D3DMetal: with two reserved textures on
the same tiles, an R8G8B8A8_UNORM render target (RT + UAV) cleared
through one reads back through the other with 0 of 4096 texels wrong. A
D32_FLOAT depth target reads back with 3968 of 4096 wrong (D3DMetal's
compression state, kept per texture). Both measured with raw
CreateReservedResource / UpdateTileMappings probes on an M5 Pro under
CrossOver 26.3.

On a macOS host, place_on_pages now lets render targets through the
require_aligned return; they get ALLOW_UNORDERED_ACCESS from
native_page_flags, and one whose format has no typed UAV still stays in
its arena (native_page_flags is None). Depth targets and the other
GPU-owned textures keep their arenas. Windows is unchanged.

render_targets_at_one_address_share_their_pages places two render
targets at one address through vram::place: it fails without this (not
on the shared pages) and passes with it, 0 of 65536 pixels wrong.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:32:04 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 20:53 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 20:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2492#issuecomment-7174320408) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2492/head:github-bot/gh-2492'
git switch 'github-bot/gh-2492'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2492'
git switch 'github-bot/gh-2492'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2492'
git switch 'github-bot/gh-2492'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2492'
git switch 'main'
git merge --squash 'github-bot/gh-2492'
git switch 'main'
git merge --ff-only 'github-bot/gh-2492'
git switch 'main'
git merge 'github-bot/gh-2492'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.