Skip to content

D3D12.X: title textures share video-memory pages on a macOS host too - #2402

Draft
vakaobr wants to merge 2 commits into
xcl-dev:mainfrom
vakaobr:d3d12x/mac-shared-title-pages
Draft

vakaobr wants to merge 2 commits into
xcl-dev:mainfrom
vakaobr:d3d12x/mac-shared-title-pages

Conversation

@vakaobr

@vakaobr vakaobr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

On a Mac, title textures never use #288's shared video-memory pages: D3DMetal 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). D3DMetal does make these reserved textures, but a texture written by a copy and read through another reserved texture on the same tiles reads scrambled bytes unless it is block-compressed or made with ALLOW_UNORDERED_ACCESS. On a macOS host (util::mac_host) this takes block-compressed formats and formats with typed unordered access onto the pages, and gives the latter the unordered-access flag. Render and depth targets and GPU-owned textures stay in arenas. Windows is unchanged.

To run on a Mac this also needs #1904 (D3DMetal's vtable layout; without it, placing the texture faults in GetResourceTiling) and a deferred release for Releases that come from D3DMetal's own threads (#2445 + #2498; without it, a list that touches the texture never completes).

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: native_page_flags; reservable and place_on_pages use it on a macOS host; test sampled_textures_at_one_address_share_their_pages_in_every_slice.

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, at 861903f (on Memory: detect a macOS host under Wine (mac_host) #2361's 6d6a3e3, on main 65fc114).
  • cargo test -p xcl --lib --target x86_64-pc-windows-gnu --no-run, then every test in hle::d3d12x::title_textures and hle::d3d12x::vram one per process in a CrossOver bottle (<exe> --exact <test> --test-threads=1):
  • The new test 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).

Regression run

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

Memory on a Mac: use with #2306's level pages. These textures get pages under every level unless XCL_TEXTURE_LEVEL_PAGES=1 (#2306, off by default) maps a level when its texels come. shortside ran a retail title on a 24 GB M5 Pro with this change's earlier version on the Mac branch from #258 (which has neither #2306 nor its level-by-level mapping on this path): wired memory about 80 s into loading was 16.5 GB with shared pages, 12.6 GB without (XCL_VRAM_ARENAS=1), and 12.3 – 14.0 GB with their level tiles. So on a Mac this should go with level pages, and the Mac branch keeps it off by default for now. Whether this plus XCL_TEXTURE_LEVEL_PAGES=1 beats committed copies on a Mac is not measured: I have no title to run.

Formats this leaves with a copy of their own (measured on D3DMetal; nothing to change here): of 11 formats I checked (depth, typeless and SNORM ones that are neither block-compressed nor plain typed-UAV), the ones left out are the depth formats. D16_UNORM and D32_FLOAT can be made reserved, but a depth target cleared through one reserved texture reads back wrong through another on the same tiles (3968 of 4096 pixels); D24_UNORM_S8_UINT, D32_FLOAT_S8X24_UINT and R32G8X24_TYPELESS cannot be made reserved at all. A render target with unordered access (R8G8B8A8_UNORM) does share correctly (0 of 4096 wrong); letting render targets onto the pages is a follow-up.

Not tested

  • Windows (any GPU), so not whether Windows is unchanged in practice.
  • The whole suite.
  • Any title, and the memory saving itself in a title.
  • An array mapped as one region read through a shader (an earlier version mapped one region per subresource for that; I could not reproduce the problem with copy reads, so it is not here).

AI use

  • Claude Code with Claude Opus 5.5: checked whether the earlier Mac-branch commits apply to main, ported the change, wrote the test, ran the tests above under CrossOver, found the two runtime prerequisites, and drafted the commit message and this description.

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 xcl-dev#258.
xcl-dev#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 xcl-dev#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 xcl-dev#258.
@FIJI1299

Copy link
Copy Markdown

Summary of Test Results for Commit 861903f on Windows 11

Environment

  • OS: Windows 11
  • GPU: NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.35, wave32)
  • DXC: 1.8.2502.11 (Windows SDK 10.0.26100.0)

Test Execution Summary

  • hle::d3d12x::vram suite (cargo test -p xcl --lib hle::d3d12x::vram):
    • 17 passed, 0 failed, 1 ignored (key D3D12 vram allocation tests passing).
  • Full library test suite (.\scripts\test.ps1):
    • 1210 passed, 4 failed, 26 ignored
    • Known failures (4): Pre-existing gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState -> E_OUTOFMEMORY 0x8007000E on NVIDIA driver during full sequential run).
  • Skipped GPU tests (17 total):
    • 13 skipped due to no wave64 support.
    • 3 skipped due to wave32 form refusals (unsupported V_CVT_F16_F32 / V_MUL_F16 / V_PK_MUL_F16: VOP3 modifiers).
    • 1 skipped due to inability to disable driver cache (0x887A002D — requires Windows Developer Mode).

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

vakaobr added a commit to vakaobr/xcl that referenced this pull request Nov 25, 2026
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, xcl-dev#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.

On this branch mac7's on_pages() keeps every GPU-owned texture in arenas on a
Mac before place_on_pages is asked, so place also takes render targets to
the pages there when sampled_on_pages() does (XCL_VRAM_ARENAS=1 still
keeps them in arenas). Ported from 4c97142 (xcl-dev#2492), with its test.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No confirmed source-level defect found, but this draft/stacked PR is not merge-ready. The critical disclosed D3DMetal risk is a multi-slice array mapped as one region and sampled by a shader; the new test only covers copy write/read. Please add that shader-sampling regression, plus a non-typed-UAV rejection/committed-fallback test. It also needs its prerequisite stack, current Windows/required evidence, and measured title-memory benefit before merge.

vakaobr added a commit to vakaobr/xcl that referenced this pull request Nov 26, 2026
vakaobr added a commit to vakaobr/xcl that referenced this pull request Nov 26, 2026
…M_ARENAS=0

xcl-dev#2402 puts sampled title textures on the shared pages on a Mac, with pages
under every level, and xcl-dev#2492 render targets with them. The level tiles
(level_tiles) give a streamed texture video memory level by level only
once place_pages says no. shortside ran a retail title on mac/integration
(xcl-dev#258, 24 GB M5 Pro): about 80 s into loading, wired memory was 16.5 GB
with sampled textures on the pages and 12.6 GB without them (12.3 - 14.0
GB on their earlier builds with the level tiles).

So on a Mac place_pages and place keep title textures off the pages
unless XCL_VRAM_ARENAS=0, as on mac/integration (2b3f3d2); elsewhere
XCL_VRAM_ARENAS set still means arenas. With XCL_VRAM_ARENAS=0, main's
XCL_TEXTURE_LEVEL_PAGES=1 gives the pages a texture's levels lazily.

The two shared-page tests of xcl-dev#2402 and xcl-dev#2492 skip where title textures
are kept off the pages (arenas()).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants