D3D12.X: texture pages in graphics reservations follow the title's memory #1514

Open
github-bot wants to merge 2 commits from github-bot/gh-1514 into main AGit
Owner

@⁠oishigeso on GitHub · 2026-11-24 17:10 UTC · original
oishigeso:vram-pages-follow → main · +254 −8 · 3 files · 2 commits · draft

For #646. A retail title places streamed textures over reserved-only graphics address space and maps physical pages only where tiles are resident. XCL gave every 64 KiB page of each such texture its own page of video memory anyway: on spawn, 22 808 textures held 6 GB, 4.3 GB of it over addresses with no title memory, and local video memory went 2 GB past the budget (title_memory_mb does not bound it).

An owned page of a placed texture in a graphics reservation is now mapped only while the title has memory there: committed, a physical page, or one mapped and not yet touched. Commits, decommits, releases and physical-page maps and unmaps there are noted (title_memory_changed), and the pages follow before the title's next submit: one UpdateTileMappings per texture and heap, then the pages' fence. Unmapped tiles read zero (resource heap tier 2).

The second commit covers the title's GPU views (kernelx::mirrors, placed in the no-access twin of a CPU reservation): they are never committed themselves, so their followed pages stayed unmapped and read zero (no intro video, missing textures). title_backed now looks through mirrors::source, and a change in a CPU view is noted for its GPU view too.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: followed pages per texture, update_ranges (only the changed tiles: the rest is skipped, consecutive heap tiles merge, unmapped ones become NULL ranges), test update_ranges_set_only_the_changed_tiles
  • crates/xcl/src/hle/kernelx.rs: the title's commit, decommit, release and physical-page changes in graphics reservations call title_memory_changed
  • crates/xcl/src/hle/kernelx/lazy.rs: is_lazy, a page mapped and not touched yet (counted as the title's memory)

Tested

  • AMD Radeon RX 6700 XT (driver 32.0.21030.2001), Ryzen 5 3600, Windows 10 Pro 19045, rustc 1.100.0, release
  • cargo test -p xcl --lib vram -- --test-threads=1: 8 passed, 2 failed. The 2 (placed_title_textures_share_vram_and_preserve_pixels, d32s8_targets_take_their_own_size_of_video_memory) fail the same way on main (1ec4c98, before the rebase: 7 passed, 2 failed); the new update_ranges_set_only_the_changed_tiles passes. Run before the rebase onto 930e8b4, which had no conflicts
  • On in about 10 test runs of a retail title on this PC (Series S profile, up to 20 min, into the world); local video memory stayed within the budget, intro video and textures as without it

Regression run

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: AMD Radeon RX 6700 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 373 (PresentX 374)
presents per 2 s (last 3): 0 28 60
device removals: 0
crashes: 0
peak commit: 19259 MB

PR (this PR's head commit; the title is run through a folder named RetailTitle):

xcl-smoke v1
commit: 73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8
gpu: AMD Radeon RX 6700 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 559 (PresentX 559)
presents per 2 s (last 3): 33 60 60
device removals: 0
crashes: 0
peak commit: 19025 MB

Not tested

  • NVIDIA, Intel; resource heap tier 1; Linux / Wine (vkd3d-proton's tiled resources)
  • The cost of the UpdateTileMappings calls while the title loads on NVIDIA: 7f94c6f measured ~0.13 ms a call there. This PR makes one call per texture and heap per submit, not one per tile, but how many textures change per submit during loading was not counted.

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, its test and this description, and ran the tests and runs above on my PC at my direction.

🤖 Generated with Claude Code

**@⁠oishigeso** on GitHub · 2026-11-24 17:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514) `oishigeso:vram-pages-follow` → `main` · +254 −8 · 3 files · 2 commits · draft For #646. A retail title places streamed textures over reserved-only graphics address space and maps physical pages only where tiles are resident. XCL gave every 64 KiB page of each such texture its own page of video memory anyway: on spawn, 22 808 textures held 6 GB, 4.3 GB of it over addresses with no title memory, and local video memory went 2 GB past the budget (`title_memory_mb` does not bound it). An owned page of a placed texture in a graphics reservation is now mapped only while the title has memory there: committed, a physical page, or one mapped and not yet touched. Commits, decommits, releases and physical-page maps and unmaps there are noted (`title_memory_changed`), and the pages follow before the title's next submit: one `UpdateTileMappings` per texture and heap, then the pages' fence. Unmapped tiles read zero (resource heap tier 2). The second commit covers the title's GPU views (`kernelx::mirrors`, placed in the no-access twin of a CPU reservation): they are never committed themselves, so their followed pages stayed unmapped and read zero (no intro video, missing textures). `title_backed` now looks through `mirrors::source`, and a change in a CPU view is noted for its GPU view too. **What is in it** - `crates/xcl/src/hle/d3d12x/vram.rs`: followed pages per texture, `update_ranges` (only the changed tiles: the rest is skipped, consecutive heap tiles merge, unmapped ones become NULL ranges), test `update_ranges_set_only_the_changed_tiles` - `crates/xcl/src/hle/kernelx.rs`: the title's commit, decommit, release and physical-page changes in graphics reservations call `title_memory_changed` - `crates/xcl/src/hle/kernelx/lazy.rs`: `is_lazy`, a page mapped and not touched yet (counted as the title's memory) **Tested** - AMD Radeon RX 6700 XT (driver 32.0.21030.2001), Ryzen 5 3600, Windows 10 Pro 19045, rustc 1.100.0, release - `cargo test -p xcl --lib vram -- --test-threads=1`: 8 passed, 2 failed. The 2 (`placed_title_textures_share_vram_and_preserve_pixels`, `d32s8_targets_take_their_own_size_of_video_memory`) fail the same way on `main` (1ec4c98, before the rebase: 7 passed, 2 failed); the new `update_ranges_set_only_the_changed_tiles` passes. Run before the rebase onto 930e8b4, which had no conflicts - On in about 10 test runs of a retail title on this PC (Series S profile, up to 20 min, into the world); local video memory stayed within the budget, intro video and textures as without it **Regression run** main: ``` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: AMD Radeon RX 6700 XT title: RetailTitle seconds: 60 exit: 0x0 frames shown: 373 (PresentX 374) presents per 2 s (last 3): 0 28 60 device removals: 0 crashes: 0 peak commit: 19259 MB ``` PR (this PR's head commit; the title is run through a folder named RetailTitle): ``` xcl-smoke v1 commit: 73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8 gpu: AMD Radeon RX 6700 XT title: RetailTitle seconds: 60 exit: 0x0 frames shown: 559 (PresentX 559) presents per 2 s (last 3): 33 60 60 device removals: 0 crashes: 0 peak commit: 19025 MB ``` **Not tested** - NVIDIA, Intel; resource heap tier 1; Linux / Wine (vkd3d-proton's tiled resources) - The cost of the `UpdateTileMappings` calls while the title loads on NVIDIA: 7f94c6f measured ~0.13 ms a call there. This PR makes one call per texture and heap per submit, not one per tile, but how many textures change per submit during loading was not counted. **AI use** - Claude Code (Claude Opus 5.5) wrote the change, its test and this description, and ran the tests and runs above on my PC at my direction. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A retail title places streamed textures over reserved-only graphics
address space and maps physical pages only where tiles are resident.
Every 64 KiB page of each such texture got its own page of video memory
anyway: on spawn 22,808 textures held 6 GB, 4.3 GB of it over addresses
with no title memory, and local video memory went 2 GB past the budget
(title_memory_mb does not bound it, #646).

An owned page of a placed texture in a graphics reservation is now
mapped only while the title has memory there (committed, a physical page,
or one mapped and not yet touched). Commits, decommits, releases and
physical-page maps/unmaps there are noted (title_memory_changed) and the
pages follow before the title's next submit: one UpdateTileMappings per
texture and heap, then the pages fence. Unmapped tiles read zero (tier 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The title's GPU views (kernelx::mirrors: its Bink video planes and more,
placed in the no-access twin of a CPU reservation) are never committed
themselves; title_textures fills them from the CPU view. The followed
pages there were left unmapped and read zero: no intro video, missing
textures. title_backed looks through mirrors::source, and changes in a
CPU view are noted for its GPU view too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:04 +00:00
Author
Owner

@⁠crosettiremi on GitHub · 2026-11-24 17:29 UTC · original · edited 2026-11-24 18:10 UTC

RX 7900 XT on Windows, retail Series X profile. I compared parent 930e8b4 and head 73b6001 with matching controller instrumentation, separate cold application caches, DRED enabled and a 28 GiB job limit. I verified distinct executable hashes at launch.

Both recorded two presents and stopped before the account picker. The last activity samples were 6.004 s and 8.006 s respectively. In both process snapshots, waiting-thread stack scans contained sparse statistics, resource release in sparse::forget_buffer, and a sparse upload around the native command allocator reset. I ended each process after more than 100 seconds without another log entry. Neither logged device removal. The isolated update_ranges_set_only_the_changed_tiles test passed on the head.

This pair cannot evaluate world-stage residency on this machine. The same startup signature on the parent previously cleared with the #789/#968 combination (earlier comparison). The controller script waits for two matching account-picker frames, so it sent no input in either run.

Integration follow-up: I added #1514 to the local #789/#968 stack on the same Series X profile. This time it passed the account picker, displayed loading artwork and streamed assets. Near 90 seconds, target pages were 2,467 MB (3,648 MB pooled), with process commit 18,623 MB. The older #789/#968 run without #1514 at 90.5 s recorded 7,949 MB target pages (8,448 MB pooled) and 26,638 MB process commit. Application cache state, preload settings and input timing differed between these two runs, so the difference is descriptive only.

The new run ended in device removal at 159.309 s (0x887a0006), DRED fault VA 0x1f0480000, no matching existing or recently freed allocation. Peak process commit 26,866 MB. No visible playable scene. The standalone parent/head comparison above remains the matched startup comparison.

Run 88 repeated the cold-cache residency integration on main 9e3831e with #789 and #1514 (#968 is in main). RX 7900 XT, 28 GiB whole-job commit limit, saved Series X profile. Scripted A selected Player1 at about 41 s. The last positive present interval ended at 188.538 s. The last capture (frame 1640) was flat green. Peak sampled process commit was 28,088 MB. No DRED removal was logged. Exit was 0xc0000409. The faulting XCL thread's stack scan contained the Rust allocation failure handler, miniz zlib inflate, and the DirectStorage queue worker. This identifies another failure during streaming under the test limit. Multiple changes separate this build from the previous comparison, so I cannot attribute this outcome to #1514.

**@⁠crosettiremi** on GitHub · 2026-11-24 17:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7139271349) · edited 2026-11-24 18:10 UTC RX 7900 XT on Windows, retail Series X profile. I compared parent 930e8b4 and head 73b6001 with matching controller instrumentation, separate cold application caches, DRED enabled and a 28 GiB job limit. I verified distinct executable hashes at launch. Both recorded two presents and stopped before the account picker. The last activity samples were 6.004 s and 8.006 s respectively. In both process snapshots, waiting-thread stack scans contained sparse statistics, resource release in `sparse::forget_buffer`, and a sparse upload around the native command allocator reset. I ended each process after more than 100 seconds without another log entry. Neither logged device removal. The isolated `update_ranges_set_only_the_changed_tiles` test passed on the head. This pair cannot evaluate world-stage residency on this machine. The same startup signature on the parent previously cleared with the #789/#968 combination ([earlier comparison](https://github.com/ivall/xcl/pull/968#issuecomment-7135973465)). The controller script waits for two matching account-picker frames, so it sent no input in either run. Integration follow-up: I added #1514 to the local #789/#968 stack on the same Series X profile. This time it passed the account picker, displayed loading artwork and streamed assets. Near 90 seconds, target pages were 2,467 MB (3,648 MB pooled), with process commit 18,623 MB. The older #789/#968 run without #1514 at 90.5 s recorded 7,949 MB target pages (8,448 MB pooled) and 26,638 MB process commit. Application cache state, preload settings and input timing differed between these two runs, so the difference is descriptive only. The new run ended in device removal at 159.309 s (0x887a0006), DRED fault VA 0x1f0480000, no matching existing or recently freed allocation. Peak process commit 26,866 MB. No visible playable scene. The standalone parent/head comparison above remains the matched startup comparison. Run 88 repeated the cold-cache residency integration on main 9e3831e with #789 and #1514 (#968 is in main). RX 7900 XT, 28 GiB whole-job commit limit, saved Series X profile. Scripted A selected Player1 at about 41 s. The last positive present interval ended at 188.538 s. The last capture (frame 1640) was flat green. Peak sampled process commit was 28,088 MB. No DRED removal was logged. Exit was 0xc0000409. The faulting XCL thread's stack scan contained the Rust allocation failure handler, miniz zlib inflate, and the DirectStorage queue worker. This identifies another failure during streaming under the test limit. Multiple changes separate this build from the previous comparison, so I cannot attribute this outcome to #1514.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7141305042) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠WebIdentity1 on GitHub · 2026-11-24 17:38 UTC · original · edited 2026-11-24 19:08 UTC

Native NVIDIA/AMD follow-up for exact head 73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8 (parent 930e8b49c1c2ec683d22c724a398b39111cd0e56): the new graphics-reservation residency path works in the six-phase RTX 3090 test, but a partial decommit leaves the first texture tile readable with stale data on this AMD integrated adapter. This is a GPU-byte finding, not just an allocation-counter mismatch. The direct NULL mapping control clears it.

Tested

  • Windows 10 Home 19045, Ryzen 7 7800X3D, NVIDIA RTX 3090 driver 591.74 / AMD Radeon integrated driver 32.0.21030.2001, Rust 1.98.1 MSVC, Agility 1.620.2, debug, SSH Session 0.
  • Fresh process per entry: cargo test --locked -p xcl --lib paired_graphics_texture_tiles_follow_cpu_backing -- --test-threads=1 --show-output --nocapture, with XCL_ADAPTER=3090 or AMD. Counts: exact head + identical final fixture: RTX 3090 1 passed / 0 failed / 0 ignored; AMD 0 / 1 / 0. Diagnostic with only the NULL mapping call changed: AMD 1 / 0 / 0. No SKIPPED lines, harness timeouts, or device-removal errors. Earlier exact parent with the same setup lacked dynamic residency: both adapters 0 / 1 / 0 with 98,304 wrong words, including tiles readable before CPU commit.
  • The public kernel memory entry points reserve paired 24 GiB virtual CPU/GPU views; only two 64 KiB CPU pages are committed. Two R32_UINT reserved textures alias those pages. Real CopyTiles uploads and standard CopyTextureRegion readbacks check all 32,768 words per phase; the test queries the driver tile shape (128×128) for the linear readback oracle. A sentinel fills the readback buffer before every copy. Native queue fences drain and the device-removal check succeeds. Phases: no backing; first page committed; both committed; first decommitted; first recommitted; CPU view released. A repeated read after draining the mapping queue checks persistence.
Phase RTX 3090 wrong words AMD wrong words on exact head
Reserved 0 0
First committed 0 0
Both committed 0 0
First decommitted 0 16,384 (old 0x55555555 rather than zero)
Decommitted, second read after mapping-queue drain 0 16,384
Recommitted 0 0
CPU view released 0 0

At the failing AMD phase, follow.mapped=false, one active page remains, and the mapping fence is already complete (5/5). The same stale first tile also appears with one texture instead of an alias pair and with CopyTiles readback. Issuing a direct one-tile UpdateTileMappings(NULL) after the failed read clears it. In a local diagnostic only, replacing this PR's full-resource NULL/SKIP call with one NULL call per changed tile made the identical two-texture fixture pass all phases on AMD, 1/0/0 with zero wrong words. The unmodified PR sends a NULL range followed by SKIP for the still-backed second tile. This comparison isolates the problematic call shape on this driver; I cannot yet say whether the driver mishandles a valid mixed range or XCL violates a more subtle mapping requirement. A per-tile workaround may cost too many calls during world loading, so I have not pushed it as a fix.

Not tested: retail/world loading, the count and cost of NULL mapping calls across thousands of textures, discrete AMD GPUs, release build, shader sampling, or any other driver. The test directly invokes the public kernel memory hooks and VRAM placement; it does not run a game or title executable. The local fixture and diagnostic are uncommitted. The first fixture used a 128 KiB reservation and accidentally exercised XCL's sparse window; that setup error was corrected to 24 GiB virtual reservations before these results.

AI use: Codex (GPT-6) wrote the synthetic fixture and diagnostic, ran the native tests, checked the outputs, and prepared this report.

Complete test fixture and diagnostic

crates/xcl/src/hle/d3d12x/texture_residency_probe.rs (test module appended to vram.rs; SHA256 f7d1800e0c70a01d66678f6e795c73789a796d73755ef13cacc057222b3b43ea):

//! Local PR1514 diagnostic. Run alone in a fresh process: owns graphics reservations/global VRAM state.
use super::*;
use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*, Dxgi::Common::*};
use crate::hle::kernelx;

unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) {
    let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
    queue.Signal(&fence, 1).unwrap();
    let start = std::time::Instant::now();
    while fence.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 {
        std::thread::sleep(std::time::Duration::from_millis(1));
    }
    assert_eq!(fence.GetCompletedValue(), 1, "queue drained");
    dev.GetDeviceRemovedReason().unwrap();
}

unsafe fn buffer(dev: &ID3D12Device, heap: D3D12_HEAP_TYPE, state: D3D12_RESOURCE_STATES) -> ID3D12Resource {
    let desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_BUFFER, Width: (2 * PAGE) as u64,
        Height: 1, DepthOrArraySize: 1, MipLevels: 1, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
        Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR, ..Default::default() };
    let mut out = None;
    dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: heap, ..Default::default() }, D3D12_HEAP_FLAG_NONE,
        &desc, state, None, &mut out).unwrap();
    out.unwrap()
}

fn transition(resource: &ID3D12Resource, from: D3D12_RESOURCE_STATES, to: D3D12_RESOURCE_STATES) -> D3D12_RESOURCE_BARRIER {
    D3D12_RESOURCE_BARRIER { Type: D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
        Anonymous: D3D12_RESOURCE_BARRIER_0 { Transition: std::mem::ManuallyDrop::new(D3D12_RESOURCE_TRANSITION_BARRIER {
            pResource: unsafe { std::mem::transmute_copy(resource) }, Subresource: D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
            StateBefore: from, StateAfter: to }) }, ..Default::default() }
}

unsafe fn roundtrip(dev: &ID3D12Device, queue: &ID3D12CommandQueue, a: &ID3D12Resource, b: &ID3D12Resource,
    upload: &ID3D12Resource, readback: &ID3D12Resource, write: Option<[u32; 2]>, expected: [u32; 2], phase: &str) -> usize {
    // Distinguish a NULL tile read from a copy that leaves the previous readback bytes untouched.
    let mut sentinel = std::ptr::null_mut();
    readback.Map(0, None, Some(&mut sentinel)).unwrap();
    std::ptr::write_bytes(sentinel as *mut u8, 0xA5, 2 * PAGE);
    readback.Unmap(0, None);
    before_execute(queue);
    if let Some(values) = write {
        let mut p = std::ptr::null_mut();
        upload.Map(0, None, Some(&mut p)).unwrap();
        let words = std::slice::from_raw_parts_mut(p as *mut u32, 2 * PAGE / 4);
        words[..PAGE / 4].fill(values[0]); words[PAGE / 4..].fill(values[1]);
        upload.Unmap(0, None);
    }
    let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
    let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, None).unwrap();
    let alias = D3D12_RESOURCE_BARRIER { Type: D3D12_RESOURCE_BARRIER_TYPE_ALIASING,
        Anonymous: D3D12_RESOURCE_BARRIER_0 { Aliasing: std::mem::ManuallyDrop::new(D3D12_RESOURCE_ALIASING_BARRIER::default()) }, ..Default::default() };
    list.ResourceBarrier(&[alias.clone()]);
    let coord = D3D12_TILED_RESOURCE_COORDINATE::default();
    let region = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() };
    if write.is_some() {
        list.ResourceBarrier(&[transition(a, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST)]);
        list.CopyTiles(a, &coord, &region, upload, 0, D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE);
        list.ResourceBarrier(&[transition(a, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON), alias]);
    }
    list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
    let src = D3D12_TEXTURE_COPY_LOCATION { pResource: std::mem::transmute_copy(b),
        Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
        Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: 0 } };
    let dst = D3D12_TEXTURE_COPY_LOCATION { pResource: std::mem::transmute_copy(readback),
        Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
        Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
            Offset: 0, Footprint: D3D12_SUBRESOURCE_FOOTPRINT { Format: DXGI_FORMAT_R32_UINT,
                Width: 256, Height: 128, Depth: 1, RowPitch: 1024 } } } };
    list.CopyTextureRegion(&dst, 0, 0, 0, &src, None);
    list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COMMON)]);
    list.Close().unwrap();
    super::super::title_textures::own_work(|| queue.ExecuteCommandLists(&[Some(list.cast().unwrap())]));
    drain(queue, dev);
    let mut p = std::ptr::null_mut();
    readback.Map(0, None, Some(&mut p)).unwrap();
    let words = std::slice::from_raw_parts(p as *const u32, 2 * PAGE / 4);
    let mut shape = D3D12_TILE_SHAPE::default();
    dev.GetResourceTiling(b, None, None, Some(&mut shape), None, 0, std::ptr::null_mut());
    let tw = shape.WidthInTexels as usize;
    let th = shape.HeightInTexels as usize;
    assert_eq!(tw * th * 4, PAGE);
    let tile_index = |i: usize| ((i / 256) / th) * (256 / tw) + ((i % 256) / tw);
    let wrong = words.iter().enumerate().filter(|&(i, &v)| v != expected[tile_index(i)]).count();
    let observed = [words[0], words[if tw < 256 { tw } else { th * 256 }]];
    println!("tile_shape={tw}x{th}");
    readback.Unmap(0, None);
    let g = PAGES.lock().unwrap();
    let pages = g.get(&(dev.as_raw() as usize)).unwrap().as_ref().unwrap();
    let active = pages.pages.values().filter(|p| p.users > 0).count();
    println!("phase={phase} expected={expected:x?} observed={observed:x?} words_checked={} wrong={wrong} active_pages={active} pool_bytes={}", 2 * PAGE / 4, pages.pools.len() * POOL_PAGES as usize * PAGE);
    wrong
}

#[test]
fn paired_graphics_texture_tiles_follow_cpu_backing() {
    unsafe {
        let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
        let selector = crate::gpu::adapter::Selector::from_env_or("auto");
        let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next() else {
            return crate::gpu::recomp::runner::skip_test("no GPU");
        };
        println!("adapter={}", crate::gpu::adapter::name(&desc));
        let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap();
        let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS::default();
        dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut options as *mut _ as *mut c_void, std::mem::size_of_val(&options) as u32).unwrap();
        assert!(options.TiledResourcesTier.0 >= 2 && options.ResourceHeapTier.0 >= 2, "native tier2 tiled resources and heaps");
        super::super::real::adopt(dev.as_raw(), super::super::real::Kind::Device);
        // Reserve 24 GiB of VA per view, beyond the UMA windows, to exercise the graphics fallback.
        // Only two 64 KiB pages are ever committed; the large ranges themselves consume no backing.
        let cpu = kernelx::VirtualAlloc(std::ptr::null(), 24usize << 30, 0x2040_2000, 0x4);
        let gpu = kernelx::VirtualAlloc(std::ptr::null(), 24usize << 30, 0x2040_2000, 0x801);
        assert!(!cpu.is_null() && !gpu.is_null());
        assert!(kernelx::in_graphics_reservation(cpu as usize) && kernelx::in_graphics_reservation(gpu as usize));
        assert_eq!(kernelx::mirrors::source(gpu as usize), Some(cpu as usize));
        let desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 256, Height: 128,
            DepthOrArraySize: 1, MipLevels: 1, Format: DXGI_FORMAT_R32_UINT,
            SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, ..Default::default() };
        let make = || {
            let mut p = std::ptr::null_mut();
            let hr = place_pages(dev.as_raw(), gpu as usize, &desc, D3D12_RESOURCE_STATE_COMMON.0 as u32, std::ptr::null(),
                Some((2 * PAGE) as u64), &ID3D12Resource::IID as *const _ as *const windows_sys::core::GUID, &mut p);
            assert!(hr.is_some_and(|hr| hr >= 0) && !p.is_null(), "reserved texture placed");
            let res = ID3D12Resource::from_raw(p);
            let mut count = 0;
            dev.GetResourceTiling(&res, Some(&mut count), None, None, None, 0, std::ptr::null_mut());
            assert_eq!(count, 2, "two 64 KiB texture tiles");
            res
        };
        let (a, b) = (make(), make());
        let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap();
        let upload = buffer(&dev, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ);
        let readback = buffer(&dev, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST);
        let mut wrong = roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x11111111, 0x22222222]), [0, 0], "reserved");
        assert_eq!(kernelx::VirtualAlloc(cpu, PAGE, 0x1000, 0x4), cpu);
        wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x33333333, 0x44444444]), [0x33333333, 0], "first-committed");
        let second = (cpu as usize + PAGE) as *mut c_void;
        assert_eq!(kernelx::VirtualAlloc(second, PAGE, 0x1000, 0x4), second);
        wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x55555555, 0x66666666]), [0x55555555, 0x66666666], "both-committed");
        assert_ne!(kernelx::VirtualFree(cpu, PAGE, 0x4000), 0);
        wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, None, [0, 0x66666666], "first-decommitted");
        { let g = PAGES.lock().unwrap(); let ps = g.get(&(dev.as_raw() as usize)).unwrap().as_ref().unwrap();
          let f = ps.follow.get(&(gpu as usize)).unwrap();
          println!("decommit_tracking mapped={} users={} page_present={} fence={}/{}", f.mapped, f.users.len(), ps.pages.contains_key(&(gpu as usize)), ps.fence.GetCompletedValue(), ps.value);
          assert!(!f.mapped);
          drain(&ps.queue, &dev);
        }
        wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, None, [0, 0x66666666], "first-decommitted-again");
        assert_eq!(kernelx::VirtualAlloc(cpu, PAGE, 0x1000, 0x4), cpu);
        wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x77777777, 0x88888888]), [0x77777777, 0x88888888], "recommitted");
        assert_ne!(kernelx::VirtualFree(cpu, 0, 0x8000), 0);
        wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, None, [0, 0], "cpu-released");
        drop((a, b));
        drain(&queue, &dev);
        assert_ne!(kernelx::VirtualFree(gpu, 0, 0x8000), 0);
        println!("phases=6 total_words_checked={} total_wrong={wrong}", 6 * 2 * PAGE / 4);
        assert_eq!(wrong, 0, "GPU alias bytes must follow the paired CPU reservation's backing");
    }
}

Local diagnostic change to vram.rs (not proposed for merge as-is):

diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
index 7e99996..6321f38 100644
--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -612,8 +612,17 @@ impl Pages {
                 .into_iter()
                 .map(|h| (Some(h), update_ranges(total, D3D12_TILE_RANGE_FLAG_NONE, |i| at.get(&i).copied().flatten().filter(|t| t.0 == h).map(|t| t.1))))
                 .collect();
+            // Local diagnostic: issue NULL updates per changed tile, without a SKIP range.
             if at.values().any(|t| t.is_none()) {
-                calls.push((None, update_ranges(total, D3D12_TILE_RANGE_FLAG_NULL, |i| at.get(&i).filter(|t| t.is_none()).map(|_| 0))));
+                for (&i, value) in &at {
+                    if value.is_some() { continue; }
+                    let coord = D3D12_TILED_RESOURCE_COORDINATE { X: i, ..Default::default() };
+                    let region = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() };
+                    let flag = D3D12_TILE_RANGE_FLAG_NULL;
+                    let offset = 0u32; let count = 1u32;
+                    self.queue.UpdateTileMappings(res, 1, Some(&coord), Some(&region), None, 1,
+                        Some(&flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
+                }
             }
             for (h, ranges) in calls {
                 let coord = D3D12_TILED_RESOURCE_COORDINATE::default();
@@ -1254,3 +1263,7 @@ mod tests {
         }
     }
 }
+
+#[cfg(test)]
+#[path = "texture_residency_probe.rs"]
+mod texture_residency_probe;
**@⁠WebIdentity1** on GitHub · 2026-11-24 17:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7139484656) · edited 2026-11-24 19:08 UTC Native NVIDIA/AMD follow-up for exact head `73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8` (parent `930e8b49c1c2ec683d22c724a398b39111cd0e56`): the new graphics-reservation residency path works in the six-phase RTX 3090 test, but **a partial decommit leaves the first texture tile readable with stale data on this AMD integrated adapter**. This is a GPU-byte finding, not just an allocation-counter mismatch. The direct NULL mapping control clears it. **Tested** - Windows 10 Home 19045, Ryzen 7 7800X3D, NVIDIA RTX 3090 driver 591.74 / AMD Radeon integrated driver 32.0.21030.2001, Rust 1.98.1 MSVC, Agility 1.620.2, debug, SSH Session 0. - Fresh process per entry: `cargo test --locked -p xcl --lib paired_graphics_texture_tiles_follow_cpu_backing -- --test-threads=1 --show-output --nocapture`, with `XCL_ADAPTER=3090` or `AMD`. Counts: exact head + identical final fixture: RTX 3090 **1 passed / 0 failed / 0 ignored**; AMD **0 / 1 / 0**. Diagnostic with only the NULL mapping call changed: AMD **1 / 0 / 0**. No SKIPPED lines, harness timeouts, or device-removal errors. Earlier exact parent with the same setup lacked dynamic residency: both adapters 0 / 1 / 0 with 98,304 wrong words, including tiles readable before CPU commit. - The public kernel memory entry points reserve paired 24 GiB virtual CPU/GPU views; only two 64 KiB CPU pages are committed. Two `R32_UINT` reserved textures alias those pages. Real `CopyTiles` uploads and standard `CopyTextureRegion` readbacks check all 32,768 words per phase; the test queries the driver tile shape (128×128) for the linear readback oracle. A sentinel fills the readback buffer before every copy. Native queue fences drain and the device-removal check succeeds. Phases: no backing; first page committed; both committed; first decommitted; first recommitted; CPU view released. A repeated read after draining the mapping queue checks persistence. | Phase | RTX 3090 wrong words | AMD wrong words on exact head | |---|---:|---:| | Reserved | 0 | 0 | | First committed | 0 | 0 | | Both committed | 0 | 0 | | First decommitted | 0 | **16,384** (old `0x55555555` rather than zero) | | Decommitted, second read after mapping-queue drain | 0 | **16,384** | | Recommitted | 0 | 0 | | CPU view released | 0 | 0 | At the failing AMD phase, `follow.mapped=false`, one active page remains, and the mapping fence is already complete (`5/5`). The same stale first tile also appears with one texture instead of an alias pair and with `CopyTiles` readback. Issuing a direct one-tile `UpdateTileMappings(NULL)` after the failed read clears it. In a **local diagnostic only**, replacing this PR's full-resource NULL/SKIP call with one NULL call per changed tile made the *identical* two-texture fixture pass all phases on AMD, 1/0/0 with zero wrong words. The unmodified PR sends a NULL range followed by SKIP for the still-backed second tile. This comparison isolates the problematic call shape on this driver; I cannot yet say whether the driver mishandles a valid mixed range or XCL violates a more subtle mapping requirement. A per-tile workaround may cost too many calls during world loading, so I have not pushed it as a fix. **Not tested:** retail/world loading, the count and cost of NULL mapping calls across thousands of textures, discrete AMD GPUs, release build, shader sampling, or any other driver. The test directly invokes the public kernel memory hooks and VRAM placement; it does not run a game or title executable. The local fixture and diagnostic are uncommitted. The first fixture used a 128 KiB reservation and accidentally exercised XCL's sparse window; that setup error was corrected to 24 GiB virtual reservations before these results. **AI use:** Codex (GPT-6) wrote the synthetic fixture and diagnostic, ran the native tests, checked the outputs, and prepared this report. <details><summary>Complete test fixture and diagnostic</summary> `crates/xcl/src/hle/d3d12x/texture_residency_probe.rs` (test module appended to `vram.rs`; SHA256 `f7d1800e0c70a01d66678f6e795c73789a796d73755ef13cacc057222b3b43ea`): ```rust //! Local PR1514 diagnostic. Run alone in a fresh process: owns graphics reservations/global VRAM state. use super::*; use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*, Dxgi::Common::*}; use crate::hle::kernelx; unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) { let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); queue.Signal(&fence, 1).unwrap(); let start = std::time::Instant::now(); while fence.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 { std::thread::sleep(std::time::Duration::from_millis(1)); } assert_eq!(fence.GetCompletedValue(), 1, "queue drained"); dev.GetDeviceRemovedReason().unwrap(); } unsafe fn buffer(dev: &ID3D12Device, heap: D3D12_HEAP_TYPE, state: D3D12_RESOURCE_STATES) -> ID3D12Resource { let desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_BUFFER, Width: (2 * PAGE) as u64, Height: 1, DepthOrArraySize: 1, MipLevels: 1, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR, ..Default::default() }; let mut out = None; dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: heap, ..Default::default() }, D3D12_HEAP_FLAG_NONE, &desc, state, None, &mut out).unwrap(); out.unwrap() } fn transition(resource: &ID3D12Resource, from: D3D12_RESOURCE_STATES, to: D3D12_RESOURCE_STATES) -> D3D12_RESOURCE_BARRIER { D3D12_RESOURCE_BARRIER { Type: D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, Anonymous: D3D12_RESOURCE_BARRIER_0 { Transition: std::mem::ManuallyDrop::new(D3D12_RESOURCE_TRANSITION_BARRIER { pResource: unsafe { std::mem::transmute_copy(resource) }, Subresource: D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, StateBefore: from, StateAfter: to }) }, ..Default::default() } } unsafe fn roundtrip(dev: &ID3D12Device, queue: &ID3D12CommandQueue, a: &ID3D12Resource, b: &ID3D12Resource, upload: &ID3D12Resource, readback: &ID3D12Resource, write: Option<[u32; 2]>, expected: [u32; 2], phase: &str) -> usize { // Distinguish a NULL tile read from a copy that leaves the previous readback bytes untouched. let mut sentinel = std::ptr::null_mut(); readback.Map(0, None, Some(&mut sentinel)).unwrap(); std::ptr::write_bytes(sentinel as *mut u8, 0xA5, 2 * PAGE); readback.Unmap(0, None); before_execute(queue); if let Some(values) = write { let mut p = std::ptr::null_mut(); upload.Map(0, None, Some(&mut p)).unwrap(); let words = std::slice::from_raw_parts_mut(p as *mut u32, 2 * PAGE / 4); words[..PAGE / 4].fill(values[0]); words[PAGE / 4..].fill(values[1]); upload.Unmap(0, None); } let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap(); let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, None).unwrap(); let alias = D3D12_RESOURCE_BARRIER { Type: D3D12_RESOURCE_BARRIER_TYPE_ALIASING, Anonymous: D3D12_RESOURCE_BARRIER_0 { Aliasing: std::mem::ManuallyDrop::new(D3D12_RESOURCE_ALIASING_BARRIER::default()) }, ..Default::default() }; list.ResourceBarrier(&[alias.clone()]); let coord = D3D12_TILED_RESOURCE_COORDINATE::default(); let region = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() }; if write.is_some() { list.ResourceBarrier(&[transition(a, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST)]); list.CopyTiles(a, &coord, &region, upload, 0, D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE); list.ResourceBarrier(&[transition(a, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON), alias]); } list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_SOURCE)]); let src = D3D12_TEXTURE_COPY_LOCATION { pResource: std::mem::transmute_copy(b), Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: 0 } }; let dst = D3D12_TEXTURE_COPY_LOCATION { pResource: std::mem::transmute_copy(readback), Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT { Offset: 0, Footprint: D3D12_SUBRESOURCE_FOOTPRINT { Format: DXGI_FORMAT_R32_UINT, Width: 256, Height: 128, Depth: 1, RowPitch: 1024 } } } }; list.CopyTextureRegion(&dst, 0, 0, 0, &src, None); list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COMMON)]); list.Close().unwrap(); super::super::title_textures::own_work(|| queue.ExecuteCommandLists(&[Some(list.cast().unwrap())])); drain(queue, dev); let mut p = std::ptr::null_mut(); readback.Map(0, None, Some(&mut p)).unwrap(); let words = std::slice::from_raw_parts(p as *const u32, 2 * PAGE / 4); let mut shape = D3D12_TILE_SHAPE::default(); dev.GetResourceTiling(b, None, None, Some(&mut shape), None, 0, std::ptr::null_mut()); let tw = shape.WidthInTexels as usize; let th = shape.HeightInTexels as usize; assert_eq!(tw * th * 4, PAGE); let tile_index = |i: usize| ((i / 256) / th) * (256 / tw) + ((i % 256) / tw); let wrong = words.iter().enumerate().filter(|&(i, &v)| v != expected[tile_index(i)]).count(); let observed = [words[0], words[if tw < 256 { tw } else { th * 256 }]]; println!("tile_shape={tw}x{th}"); readback.Unmap(0, None); let g = PAGES.lock().unwrap(); let pages = g.get(&(dev.as_raw() as usize)).unwrap().as_ref().unwrap(); let active = pages.pages.values().filter(|p| p.users > 0).count(); println!("phase={phase} expected={expected:x?} observed={observed:x?} words_checked={} wrong={wrong} active_pages={active} pool_bytes={}", 2 * PAGE / 4, pages.pools.len() * POOL_PAGES as usize * PAGE); wrong } #[test] fn paired_graphics_texture_tiles_follow_cpu_backing() { unsafe { let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap(); let selector = crate::gpu::adapter::Selector::from_env_or("auto"); let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next() else { return crate::gpu::recomp::runner::skip_test("no GPU"); }; println!("adapter={}", crate::gpu::adapter::name(&desc)); let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap(); let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS::default(); dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut options as *mut _ as *mut c_void, std::mem::size_of_val(&options) as u32).unwrap(); assert!(options.TiledResourcesTier.0 >= 2 && options.ResourceHeapTier.0 >= 2, "native tier2 tiled resources and heaps"); super::super::real::adopt(dev.as_raw(), super::super::real::Kind::Device); // Reserve 24 GiB of VA per view, beyond the UMA windows, to exercise the graphics fallback. // Only two 64 KiB pages are ever committed; the large ranges themselves consume no backing. let cpu = kernelx::VirtualAlloc(std::ptr::null(), 24usize << 30, 0x2040_2000, 0x4); let gpu = kernelx::VirtualAlloc(std::ptr::null(), 24usize << 30, 0x2040_2000, 0x801); assert!(!cpu.is_null() && !gpu.is_null()); assert!(kernelx::in_graphics_reservation(cpu as usize) && kernelx::in_graphics_reservation(gpu as usize)); assert_eq!(kernelx::mirrors::source(gpu as usize), Some(cpu as usize)); let desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 256, Height: 128, DepthOrArraySize: 1, MipLevels: 1, Format: DXGI_FORMAT_R32_UINT, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, ..Default::default() }; let make = || { let mut p = std::ptr::null_mut(); let hr = place_pages(dev.as_raw(), gpu as usize, &desc, D3D12_RESOURCE_STATE_COMMON.0 as u32, std::ptr::null(), Some((2 * PAGE) as u64), &ID3D12Resource::IID as *const _ as *const windows_sys::core::GUID, &mut p); assert!(hr.is_some_and(|hr| hr >= 0) && !p.is_null(), "reserved texture placed"); let res = ID3D12Resource::from_raw(p); let mut count = 0; dev.GetResourceTiling(&res, Some(&mut count), None, None, None, 0, std::ptr::null_mut()); assert_eq!(count, 2, "two 64 KiB texture tiles"); res }; let (a, b) = (make(), make()); let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap(); let upload = buffer(&dev, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); let readback = buffer(&dev, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); let mut wrong = roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x11111111, 0x22222222]), [0, 0], "reserved"); assert_eq!(kernelx::VirtualAlloc(cpu, PAGE, 0x1000, 0x4), cpu); wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x33333333, 0x44444444]), [0x33333333, 0], "first-committed"); let second = (cpu as usize + PAGE) as *mut c_void; assert_eq!(kernelx::VirtualAlloc(second, PAGE, 0x1000, 0x4), second); wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x55555555, 0x66666666]), [0x55555555, 0x66666666], "both-committed"); assert_ne!(kernelx::VirtualFree(cpu, PAGE, 0x4000), 0); wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, None, [0, 0x66666666], "first-decommitted"); { let g = PAGES.lock().unwrap(); let ps = g.get(&(dev.as_raw() as usize)).unwrap().as_ref().unwrap(); let f = ps.follow.get(&(gpu as usize)).unwrap(); println!("decommit_tracking mapped={} users={} page_present={} fence={}/{}", f.mapped, f.users.len(), ps.pages.contains_key(&(gpu as usize)), ps.fence.GetCompletedValue(), ps.value); assert!(!f.mapped); drain(&ps.queue, &dev); } wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, None, [0, 0x66666666], "first-decommitted-again"); assert_eq!(kernelx::VirtualAlloc(cpu, PAGE, 0x1000, 0x4), cpu); wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, Some([0x77777777, 0x88888888]), [0x77777777, 0x88888888], "recommitted"); assert_ne!(kernelx::VirtualFree(cpu, 0, 0x8000), 0); wrong += roundtrip(&dev, &queue, &a, &b, &upload, &readback, None, [0, 0], "cpu-released"); drop((a, b)); drain(&queue, &dev); assert_ne!(kernelx::VirtualFree(gpu, 0, 0x8000), 0); println!("phases=6 total_words_checked={} total_wrong={wrong}", 6 * 2 * PAGE / 4); assert_eq!(wrong, 0, "GPU alias bytes must follow the paired CPU reservation's backing"); } } ``` Local diagnostic change to `vram.rs` (not proposed for merge as-is): ```diff diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs index 7e99996..6321f38 100644 --- a/crates/xcl/src/hle/d3d12x/vram.rs +++ b/crates/xcl/src/hle/d3d12x/vram.rs @@ -612,8 +612,17 @@ impl Pages { .into_iter() .map(|h| (Some(h), update_ranges(total, D3D12_TILE_RANGE_FLAG_NONE, |i| at.get(&i).copied().flatten().filter(|t| t.0 == h).map(|t| t.1)))) .collect(); + // Local diagnostic: issue NULL updates per changed tile, without a SKIP range. if at.values().any(|t| t.is_none()) { - calls.push((None, update_ranges(total, D3D12_TILE_RANGE_FLAG_NULL, |i| at.get(&i).filter(|t| t.is_none()).map(|_| 0)))); + for (&i, value) in &at { + if value.is_some() { continue; } + let coord = D3D12_TILED_RESOURCE_COORDINATE { X: i, ..Default::default() }; + let region = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() }; + let flag = D3D12_TILE_RANGE_FLAG_NULL; + let offset = 0u32; let count = 1u32; + self.queue.UpdateTileMappings(res, 1, Some(&coord), Some(&region), None, 1, + Some(&flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); + } } for (h, ranges) in calls { let coord = D3D12_TILED_RESOURCE_COORDINATE::default(); @@ -1254,3 +1263,7 @@ mod tests { } } } + +#[cfg(test)] +#[path = "texture_residency_probe.rs"] +mod texture_residency_probe; ``` </details>
Author
Owner

@⁠WebIdentity1 on GitHub · 2026-11-24 19:21 UTC · original

Follow-up to my paired-residency result: the AMD stale tile reproduces with native D3D12 mapping and no XCL reservation, mirror, Pages, or before_execute hooks. This rules out a bookkeeping-only test failure and narrows the problem to this D3D12 call sequence on the tested AMD driver. It does not establish whether the driver violates the API contract or an additional resource/synchronization requirement is missing.

I added a local test-only native control using the same R32_UINT 256×128, two-tile reserved texture, a two-tile default heap, CopyTiles upload/readback, queue fences, and GPU device-removal check. It maps both tiles to the heap, uploads 0x55555555 and 0x66666666, drains, then changes only the first tile mapping. The readback buffer is filled with a sentinel before each read. The only run-time switch chooses the remapping call:

  • Mixed: one UpdateTileMappings over two tiles, pHeap=NULL, flags [NULL, SKIP], counts [1, 1], offsets [0, 0].
  • Single: one UpdateTileMappings over the first tile only, pHeap=NULL, flag [NULL], count [1].

Fresh process for each entry: cargo test --locked -p xcl --lib native_mixed_null_skip_mapping_returns_zero -- --test-threads=1 --show-output --nocapture, with XCL_ADAPTER=AMD or 3090; set XCL_PROBE_SINGLE_NULL=1 only for the single call. Windows 10 Home 19045, AMD Radeon integrated driver 32.0.21030.2001, RTX 3090 driver 591.74, Agility 1.620.2. All three used the same source (SHA256 97f9ec24ed9eb7756d2cdc73e6e0f4e41c545e02ffeeb78b068dda1b680c64de, matching the Windows copy), debug build, and explicit adapter selection. No harness timeouts or device removals.

Adapter Mapping Result First tile Second tile
AMD integrated mixed NULL/SKIP 0 passed / 1 failed / 0 ignored 16,384 stale 0x55555555 words 0 wrong words (0x66666666)
AMD integrated single NULL 1 / 0 / 0 0 wrong words (zero) 0 wrong words (0x66666666)
RTX 3090 mixed NULL/SKIP 1 / 0 / 0 0 wrong words (zero) 0 wrong words (0x66666666)

Microsoft's UpdateTileMappings contract describes mixed NULL/SKIP ranges and says their counts must sum to the region; this call uses one plus one for two tiles. Tier 2 specifies zero reads from NULL mapped texture tiles. The test checks Tier 2 before running. The independent native control reinforces a real GPU-visible compatibility bug on this AMD adapter. A narrow call shape workaround is supported by these tests, but its mapping-call overhead at world scale is unmeasured. The PR author still owns the implementation; I have not pushed a competing fix.

The local probe source is included below for reproduction. It reuses the small buffer and transition test helpers in the prior report's fixture (made pub(super) locally) and adds a #[cfg(test)] module declaration to vram.rs. This is a synthetic GPU test; no retail title, discrete AMD GPU, shader sampling, or driver version other than the one above was tested.

AI use: Codex (GPT-6) wrote and ran this test, checked the logs and source hashes, and prepared this report.

Native control test source
//! Local diagnostic: a native D3D12 NULL/SKIP tile mapping without XCL residency hooks.
use super::*;
use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*, Dxgi::Common::*};

unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) {
    let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
    queue.Signal(&fence, 1).unwrap();
    let start = std::time::Instant::now();
    while fence.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 {
        std::thread::sleep(std::time::Duration::from_millis(1));
    }
    assert_eq!(fence.GetCompletedValue(), 1);
    dev.GetDeviceRemovedReason().unwrap();
}

unsafe fn tile_copy(dev: &ID3D12Device, queue: &ID3D12CommandQueue, texture: &ID3D12Resource,
                    buffer: &ID3D12Resource, upload: bool) {
    let allocator: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
    let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &allocator, None).unwrap();
    let state = if upload { D3D12_RESOURCE_STATE_COPY_DEST } else { D3D12_RESOURCE_STATE_COPY_SOURCE };
    list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, D3D12_RESOURCE_STATE_COMMON, state)]);
    let coord = D3D12_TILED_RESOURCE_COORDINATE::default();
    let region = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() };
    let flags = if upload { D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE }
                else { D3D12_TILE_COPY_FLAG_SWIZZLED_TILED_RESOURCE_TO_LINEAR_BUFFER };
    list.CopyTiles(texture, &coord, &region, buffer, 0, flags);
    list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, state, D3D12_RESOURCE_STATE_COMMON)]);
    list.Close().unwrap();
    queue.ExecuteCommandLists(&[Some(list.cast().unwrap())]);
    drain(queue, dev);
}

#[test]
fn native_mixed_null_skip_mapping_returns_zero() {
    unsafe {
        let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
        let selector = crate::gpu::adapter::Selector::from_env_or("auto");
        let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next() else {
            return crate::gpu::recomp::runner::skip_test("no GPU");
        };
        println!("adapter={}", crate::gpu::adapter::name(&desc));
        let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap();
        let mut opts = D3D12_FEATURE_DATA_D3D12_OPTIONS::default();
        dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut opts as *mut _ as *mut c_void,
                                std::mem::size_of_val(&opts) as u32).unwrap();
        assert!(opts.TiledResourcesTier.0 >= 2 && opts.ResourceHeapTier.0 >= 2);
        let texture_desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
            Width: 256, Height: 128, DepthOrArraySize: 1, MipLevels: 1, Format: DXGI_FORMAT_R32_UINT,
            SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
            Layout: D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE, ..Default::default() };
        let mut texture = None;
        dev.CreateReservedResource(&texture_desc, D3D12_RESOURCE_STATE_COMMON, None, &mut texture).unwrap();
        let texture: ID3D12Resource = texture.unwrap();
        let mut count = 0;
        dev.GetResourceTiling(&texture, Some(&mut count), None, None, None, 0, std::ptr::null_mut());
        assert_eq!(count, 2);
        let heap_desc = D3D12_HEAP_DESC { SizeInBytes: 2 * PAGE as u64,
            Properties: D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() },
            Flags: D3D12_HEAP_FLAG_NONE, ..Default::default() };
        let mut heap = None;
        dev.CreateHeap(&heap_desc, &mut heap).unwrap();
        let heap: ID3D12Heap = heap.unwrap();
        let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap();
        let coord = D3D12_TILED_RESOURCE_COORDINATE::default();
        let region = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() };
        let map_flag = D3D12_TILE_RANGE_FLAG_NONE;
        let offset = 0u32;
        let count = 2u32;
        queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), &heap, 1,
            Some(&map_flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
        drain(&queue, &dev);
        let upload = super::texture_residency_probe::buffer(&dev, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ);
        let readback = super::texture_residency_probe::buffer(&dev, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST);
        let mut p = std::ptr::null_mut();
        upload.Map(0, None, Some(&mut p)).unwrap();
        let words = std::slice::from_raw_parts_mut(p as *mut u32, 2 * PAGE / 4);
        words[..PAGE / 4].fill(0x55555555);
        words[PAGE / 4..].fill(0x66666666);
        upload.Unmap(0, None);
        tile_copy(&dev, &queue, &texture, &upload, true);
        let single = std::env::var_os("XCL_PROBE_SINGLE_NULL").is_some();
        if single {
            let one = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() };
            let flag = D3D12_TILE_RANGE_FLAG_NULL;
            let offset = 0u32;
            let count = 1u32;
            queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&one), None, 1,
                Some(&flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
        } else {
            let range_flags = [D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP];
            let offsets = [0u32, 0u32];
            let counts = [1u32, 1u32];
            queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), None, 2,
                Some(range_flags.as_ptr()), Some(offsets.as_ptr()), Some(counts.as_ptr()), D3D12_TILE_MAPPING_FLAG_NONE);
        }
        println!("mapping={}", if single { "single-null" } else { "mixed-null-skip" });
        drain(&queue, &dev);
        readback.Map(0, None, Some(&mut p)).unwrap();
        std::ptr::write_bytes(p as *mut u8, 0xA5, 2 * PAGE);
        readback.Unmap(0, None);
        tile_copy(&dev, &queue, &texture, &readback, false);
        readback.Map(0, None, Some(&mut p)).unwrap();
        let words = std::slice::from_raw_parts(p as *const u32, 2 * PAGE / 4);
        let wrong0 = words[..PAGE / 4].iter().filter(|&&v| v != 0).count();
        let wrong1 = words[PAGE / 4..].iter().filter(|&&v| v != 0x66666666).count();
        println!("first={:x} second={:x} wrong0={wrong0} wrong1={wrong1}", words[0], words[PAGE / 4]);
        readback.Unmap(0, None);
        assert_eq!((wrong0, wrong1), (0, 0));
    }
}

**@⁠WebIdentity1** on GitHub · 2026-11-24 19:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7141984121) Follow-up to [my paired-residency result](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514): **the AMD stale tile reproduces with native D3D12 mapping and no XCL reservation, mirror, `Pages`, or `before_execute` hooks.** This rules out a bookkeeping-only test failure and narrows the problem to this D3D12 call sequence on the tested AMD driver. It does not establish whether the driver violates the API contract or an additional resource/synchronization requirement is missing. I added a local test-only native control using the same `R32_UINT` 256×128, two-tile reserved texture, a two-tile default heap, `CopyTiles` upload/readback, queue fences, and GPU device-removal check. It maps both tiles to the heap, uploads `0x55555555` and `0x66666666`, drains, then changes only the first tile mapping. The readback buffer is filled with a sentinel before each read. The only run-time switch chooses the remapping call: - **Mixed:** one `UpdateTileMappings` over two tiles, `pHeap=NULL`, flags `[NULL, SKIP]`, counts `[1, 1]`, offsets `[0, 0]`. - **Single:** one `UpdateTileMappings` over the first tile only, `pHeap=NULL`, flag `[NULL]`, count `[1]`. Fresh process for each entry: `cargo test --locked -p xcl --lib native_mixed_null_skip_mapping_returns_zero -- --test-threads=1 --show-output --nocapture`, with `XCL_ADAPTER=AMD` or `3090`; set `XCL_PROBE_SINGLE_NULL=1` only for the single call. Windows 10 Home 19045, AMD Radeon integrated driver 32.0.21030.2001, RTX 3090 driver 591.74, Agility 1.620.2. All three used the *same source* (SHA256 `97f9ec24ed9eb7756d2cdc73e6e0f4e41c545e02ffeeb78b068dda1b680c64de`, matching the Windows copy), debug build, and explicit adapter selection. No harness timeouts or device removals. | Adapter | Mapping | Result | First tile | Second tile | |---|---|---|---|---| | AMD integrated | mixed NULL/SKIP | **0 passed / 1 failed / 0 ignored** | **16,384 stale `0x55555555` words** | 0 wrong words (`0x66666666`) | | AMD integrated | single NULL | **1 / 0 / 0** | 0 wrong words (zero) | 0 wrong words (`0x66666666`) | | RTX 3090 | mixed NULL/SKIP | **1 / 0 / 0** | 0 wrong words (zero) | 0 wrong words (`0x66666666`) | [Microsoft's `UpdateTileMappings` contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12commandqueue-updatetilemappings) describes mixed NULL/SKIP ranges and says their counts must sum to the region; this call uses one plus one for two tiles. [Tier 2](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_tiled_resources_tier) specifies zero reads from NULL mapped texture tiles. The test checks Tier 2 before running. The independent native control reinforces a **real GPU-visible compatibility bug on this AMD adapter**. A narrow call shape workaround is supported by these tests, but its mapping-call overhead at world scale is unmeasured. The PR author still owns the implementation; I have not pushed a competing fix. The local probe source is included below for reproduction. It reuses the small `buffer` and `transition` test helpers in the prior report's fixture (made `pub(super)` locally) and adds a `#[cfg(test)]` module declaration to `vram.rs`. This is a synthetic GPU test; no retail title, discrete AMD GPU, shader sampling, or driver version other than the one above was tested. **AI use:** Codex (GPT-6) wrote and ran this test, checked the logs and source hashes, and prepared this report. <details><summary>Native control test source</summary> ```rust //! Local diagnostic: a native D3D12 NULL/SKIP tile mapping without XCL residency hooks. use super::*; use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*, Dxgi::Common::*}; unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) { let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); queue.Signal(&fence, 1).unwrap(); let start = std::time::Instant::now(); while fence.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 { std::thread::sleep(std::time::Duration::from_millis(1)); } assert_eq!(fence.GetCompletedValue(), 1); dev.GetDeviceRemovedReason().unwrap(); } unsafe fn tile_copy(dev: &ID3D12Device, queue: &ID3D12CommandQueue, texture: &ID3D12Resource, buffer: &ID3D12Resource, upload: bool) { let allocator: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap(); let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &allocator, None).unwrap(); let state = if upload { D3D12_RESOURCE_STATE_COPY_DEST } else { D3D12_RESOURCE_STATE_COPY_SOURCE }; list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, D3D12_RESOURCE_STATE_COMMON, state)]); let coord = D3D12_TILED_RESOURCE_COORDINATE::default(); let region = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() }; let flags = if upload { D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE } else { D3D12_TILE_COPY_FLAG_SWIZZLED_TILED_RESOURCE_TO_LINEAR_BUFFER }; list.CopyTiles(texture, &coord, &region, buffer, 0, flags); list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, state, D3D12_RESOURCE_STATE_COMMON)]); list.Close().unwrap(); queue.ExecuteCommandLists(&[Some(list.cast().unwrap())]); drain(queue, dev); } #[test] fn native_mixed_null_skip_mapping_returns_zero() { unsafe { let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap(); let selector = crate::gpu::adapter::Selector::from_env_or("auto"); let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next() else { return crate::gpu::recomp::runner::skip_test("no GPU"); }; println!("adapter={}", crate::gpu::adapter::name(&desc)); let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap(); let mut opts = D3D12_FEATURE_DATA_D3D12_OPTIONS::default(); dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut opts as *mut _ as *mut c_void, std::mem::size_of_val(&opts) as u32).unwrap(); assert!(opts.TiledResourcesTier.0 >= 2 && opts.ResourceHeapTier.0 >= 2); let texture_desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 256, Height: 128, DepthOrArraySize: 1, MipLevels: 1, Format: DXGI_FORMAT_R32_UINT, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, Layout: D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE, ..Default::default() }; let mut texture = None; dev.CreateReservedResource(&texture_desc, D3D12_RESOURCE_STATE_COMMON, None, &mut texture).unwrap(); let texture: ID3D12Resource = texture.unwrap(); let mut count = 0; dev.GetResourceTiling(&texture, Some(&mut count), None, None, None, 0, std::ptr::null_mut()); assert_eq!(count, 2); let heap_desc = D3D12_HEAP_DESC { SizeInBytes: 2 * PAGE as u64, Properties: D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() }, Flags: D3D12_HEAP_FLAG_NONE, ..Default::default() }; let mut heap = None; dev.CreateHeap(&heap_desc, &mut heap).unwrap(); let heap: ID3D12Heap = heap.unwrap(); let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap(); let coord = D3D12_TILED_RESOURCE_COORDINATE::default(); let region = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() }; let map_flag = D3D12_TILE_RANGE_FLAG_NONE; let offset = 0u32; let count = 2u32; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), &heap, 1, Some(&map_flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); drain(&queue, &dev); let upload = super::texture_residency_probe::buffer(&dev, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); let readback = super::texture_residency_probe::buffer(&dev, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); let mut p = std::ptr::null_mut(); upload.Map(0, None, Some(&mut p)).unwrap(); let words = std::slice::from_raw_parts_mut(p as *mut u32, 2 * PAGE / 4); words[..PAGE / 4].fill(0x55555555); words[PAGE / 4..].fill(0x66666666); upload.Unmap(0, None); tile_copy(&dev, &queue, &texture, &upload, true); let single = std::env::var_os("XCL_PROBE_SINGLE_NULL").is_some(); if single { let one = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() }; let flag = D3D12_TILE_RANGE_FLAG_NULL; let offset = 0u32; let count = 1u32; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&one), None, 1, Some(&flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); } else { let range_flags = [D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP]; let offsets = [0u32, 0u32]; let counts = [1u32, 1u32]; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), None, 2, Some(range_flags.as_ptr()), Some(offsets.as_ptr()), Some(counts.as_ptr()), D3D12_TILE_MAPPING_FLAG_NONE); } println!("mapping={}", if single { "single-null" } else { "mixed-null-skip" }); drain(&queue, &dev); readback.Map(0, None, Some(&mut p)).unwrap(); std::ptr::write_bytes(p as *mut u8, 0xA5, 2 * PAGE); readback.Unmap(0, None); tile_copy(&dev, &queue, &texture, &readback, false); readback.Map(0, None, Some(&mut p)).unwrap(); let words = std::slice::from_raw_parts(p as *const u32, 2 * PAGE / 4); let wrong0 = words[..PAGE / 4].iter().filter(|&&v| v != 0).count(); let wrong1 = words[PAGE / 4..].iter().filter(|&&v| v != 0x66666666).count(); println!("first={:x} second={:x} wrong0={wrong0} wrong1={wrong1}", words[0], words[PAGE / 4]); readback.Unmap(0, None); assert_eq!((wrong0, wrong1), (0, 0)); } } ``` </details>
Author
Owner

@⁠WebIdentity1 on GitHub · 2026-11-24 19:25 UTC · original · edited 2026-11-24 21:00 UTC

Packed-mip array follow-up — 24 November: I added a synthetic, test-only GPU-byte control at the unchanged #1514 head 73b6001 and the uncommitted local NULL-region candidate. This covers a complete one-tile packed-mip set per array slice, avoiding D3D12's undefined partial packed-set case. The 256×256 R32_UINT two-slice/9-mip reserved texture has 12 overall tiles on both drivers; packed tiles 5 and 11 correspond to subresources 2 and 11 at (X=0,Y=0,Z=0). I wrote distinct values into each slice's 64×64 mip 2 with CopyTextureRegion, decommitted slice 0's packed tile via XCL's mirrored graphics reservation, then checked all 4,096 pixels per slice with a sentinel-filled CopyTextureRegion readback. CopyTiles was not used for packed mips.

On Windows 10 19045, integrated AMD Radeon(TM) Graphics driver 32.0.21030.2001 and RTX 3090 driver 591.74, Rust 1.98.1 MSVC, Agility 1.620.2, each in a fresh SSH Session 0 process: cargo test --locked -p xcl --lib xcl_packed_mip_decommit_keeps_other_array_slice -- --test-threads=1 --show-output --nocapture, with XCL_ADAPTER=AMD or 3090.

Runtime tree AMD integrated RTX 3090 Wrong pixels after decommit (slice 0 / retained slice 1)
Untouched PR head + test-only fixture 0/1/0 1/0/0 AMD 4096/0; NVIDIA 0/0
Local explicit-NULL-region candidate + same test sequence 1/0/0, repeated after switching build trees 1/0/0 0/0 on both

The baseline fixture uses a local packed-coordinate helper because the unchanged PR has no production helper; otherwise its allocation, upload, decommit and readback sequence matches the candidate fixture. The candidate calls its production tile_coordinates. A separate native D3D12 packed-set control also passed 1/0/0 on each adapter with the candidate helper. All tests had no skip, timeout or device removal. Frozen baseline/candidate source snapshots matched 222/222 and 224/224 SHA256 files on Windows after testing; candidate vram.rs SHA256 4fc2d2329f962921d31ad0c69017a49cd410ba80ba0697965279a8553bd699d5, packed fixture 0cf99ccab80370d5b47028710c18db554426d3a4b22bf32ef7639f00677f7431; baseline fixture d5cc3f5a63d85514c02575bfb6a8f564e7dd1c5b4ea4c60e15ff4a29c6efc5b4. This extends the earlier failing-without-fix AMD control to one complete packed set per slice. Multi-tile packed sets, partial mappings, unusual-tiling fallback, discrete AMD, world-scale cost and retail smoke remain untested. The author still owns the fix; no code was committed, pushed or proposed as a competing PR. AI use: Codex (GPT-6) wrote and ran the synthetic fixtures, verified source hashes/logs, and prepared this follow-up.


Full-suite follow-up for the local NULL-region candidate — 24 November. The PR head is still 73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8; this is uncommitted local validation, not a competing implementation. I compared a clean exact-head archive (221 tracked files) with my candidate at that head (the same 221 files plus two local diagnostic modules). All Windows source hashes matched before and after. On Windows 10 19045, RTX 3090 driver 591.74, Ryzen 7 7800X3D, Rust 1.98.1 MSVC, Agility 1.620.2 x64, XCL_ADAPTER=3090, XCL_REQUIRE_GPU=mesh, XCL_HEAP_WINDOWS=1, direct DXIL unset, desktop Session 1: cargo build --locked --workspace exited 0 on both. cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output across 19 targets: untouched head 751 passed / 1 failed / 41 ignored; local candidate 754 / 1 / 41. The extra three passes are exactly the candidate's diagnostic tests, including integrated disjoint decommit. Both runs failed only the same known #202 v_pk_add_i16 clamp lane-0 check; two explicit debug-layer SKIPPED lines each; no timeout or device removal. Neither whole suite passed.

This complements the earlier AMD result below: the integrated four-tile test failed on the unchanged head and passed with explicit NULL regions on both AMD integrated and RTX 3090. Limits: the frozen local tree includes a native mixed-NULL/SKIP negative control that intentionally fails on the AMD driver, so it is not a mergeable cross-adapter suite. The coordinate helper has structural packed-mip/array checks but no packed-mip GPU-byte test; D3D12 leaves partially mapped packed-mip behavior vendor-specific. Its unusual-tiling fallback still uses the original mixed NULL/SKIP call shape. World-scale cost, discrete AMD, retail smoke, and interaction with #1747 remain untested. I would treat the explicit-region path as a validated direction for standard tiles, with those cases still to resolve before a runtime PR is merge-ready. AI use: Codex (GPT-6) ran the exact-head/candidate pair, checked hashes and logs, and prepared this update.


Integrated four-tile negative control — 24 November, 20:14 UTC: I exercised XCL's VirtualAlloc/VirtualFree mirror tracking, place_pages, before_execute and Pages::apply_backing with one reserved 256×256 R32_UINT texture. After committing and uploading four distinct 64 KiB tiles, I decommitted disjoint tiles 0 and 2 before the next GPU read. On the unchanged PR head 73b6001 plus test-only fixture, the AMD integrated adapter failed 0/1/0: both decommitted tiles retained all 16,384 old words; tiles 1 and 3 were correct. The RTX 3090 passed 1/0/0, with both decommitted tiles zero. On the uncommitted local candidate that sends explicitly addressed NULL regions in one call, AMD and RTX 3090 each passed 1/0/0, zero wrong words in all four tiles. I repeated the candidate runs after switching the shared Cargo build target back from the baseline: both still passed 1/0/0. Every run used a fresh process, sentinel-filled CopyTiles readback, queue fences and device-removal checks; no skips, harness timeouts or removal occurred. Command: cargo test --locked -p xcl --lib xcl_disjoint_decommits_unmap_both_texture_tiles -- --test-threads=1 --show-output --nocapture, with XCL_ADAPTER=AMD or 3090.

The baseline and candidate fixtures share the same allocation/upload/decommit/readback sequence; the baseline only substitutes known (0,0),(0,1) tile coordinates for the candidate helper and a local copy of the same barrier helper. Baseline vram.rs has only a test-module registration; its 221-file PR-head source archive had zero hash mismatches before the fixture overlay. Final fixture SHA256: baseline 521159dc01b0ec6195d971c2a82f8f5b3ac43d4af5d4044556569a5f5409a976; candidate aff04b6e37d3b6d52999a4a8625644cb1cfc29388fc1e2cc4a3fd9765dea3c80. This supplies an integrated GPU test that fails without the local mapping change and passes with it. The existing PR author still owns implementation. Full suite, retail smoke, packed-mip GPU behavior, and mapping cost remain untested; I have not committed, pushed, or opened a competing PR. AI use: Codex (GPT-6) wrote the synthetic test, ran the native comparisons, verified hashes/logs, and prepared this update.


Update — local XCL integration diagnostic, 24 November: I translated changed tile indices with GetResourceTiling and changed only Pages::apply_backing's NULL path on an uncommitted worktree at this PR's exact head 73b6001. One UpdateTileMappings call now receives one explicitly addressed resource region per changed tile and a single NULL range; the existing heap mapping path remains. This is a candidate, not a proposed or merge-ready fix.

On Windows 10, AMD Radeon integrated driver 32.0.21030.2001 and RTX 3090 driver 591.74, the paired 24 GiB CPU/GPU reservation and two aliased two-tile texture fixture passed 1/0/0 on each adapter, with 0 wrong out of 196,608 GPU-readback words across six phases, including partial decommit/recommit. In a separate native four-tile D3D12 control, the candidate helper generated coordinates (0,0) and (0,1) for disjoint tiles 0 and 2; a single two-region NULL call passed 1/0/0 on both adapters, all four tiles correct. In the same control source and AMD environment, switching back to one full-resource mixed NULL, SKIP, NULL, SKIP call failed 0/1/0, leaving 16,384 stale words in each unmapped tile. Fresh process per test; no skips, harness timeouts or device removals. Command filter: cargo test --locked -p xcl --lib <filter> -- --test-threads=1 --show-output --nocapture; XCL_ADAPTER=AMD or 3090, plus XCL_PROBE_DISJOINT=1 and (for the passing native batch) XCL_PROBE_BATCH_NULL=1. Final local source SHA256: vram.rs 3ce4018798085b117668effdb2883c54826c184ff1c683b7067afdab18331251, native probe a137baf420ce84f2891c9b5a707aa337c2f645fd2905f9b1bc0436cb42c31e62, paired probe 0dbe7807762a3948a040ed1288eee48a109940735d3dc604797241be78fe6b85; all matched the Windows copies before the native run.

This makes the stale tile a GPU-observable behavior of the mixed mapping call shape on this AMD driver, not a test bookkeeping failure. I still cannot assign driver versus subtler API/resource responsibility. The candidate's packed-mip coordinate check is structural only; no packed-mip GPU remap, world-scale overhead, discrete AMD, full suite or retail title was tested. Microsoft's packed-mip documentation says partial packed-mip mappings have vendor-specific undefined read/write behavior, which needs separate handling. I am keeping the code local so the PR author can decide whether this mapping strategy fits the branch. AI use: Codex (GPT-6) wrote the candidate and fixtures, ran the native tests, checked the logs and prepared this update.


Further native D3D12 control for the AMD stale-tile finding: one UpdateTileMappings call can NULL two disjoint texture tiles on the tested AMD adapter if they are supplied as two correctly addressed resource regions, with no SKIP ranges. This is a candidate for reducing mapping-call overhead versus one call per tile; I have not measured world-scale cost or integrated it into XCL.

The local test uses a 256×256 R32_UINT reserved texture with four 64 KiB tiles (driver-reported tile shape 128×128), one four-tile default heap, CopyTiles upload/readback, queue fences, a sentinel-filled readback buffer, and device-removal checks. All four tiles initially contain distinct values. It tries to unmap tiles 0 and 2 while retaining tiles 1 and 3. The correctly addressed tile-2 coordinate is (X=0, Y=1), since this is a two-dimensional, two-tiles-wide texture. D3D12's region description says UseBox=false traverses linearly from the starting x/y/z coordinate; a flat index is not generally a valid X coordinate for a nonpacked 2D texture. An early local exploratory run mistakenly used (X=2, Y=0) for tile 2; I discarded those results and did not publish them.

Fresh native test processes, same source SHA256 1a7b25f1be8f0ffc7755a18d4f279c558ba15475742110ae6cf84d7e0a1eca39 on Mac and Windows. Command: cargo test --locked -p xcl --lib native_mixed_null_skip_mapping_returns_zero -- --test-threads=1 --show-output --nocapture. XCL_PROBE_DISJOINT=1 in all runs; XCL_ADAPTER=AMD or 3090. XCL_PROBE_BATCH_NULL=1 selects the batch, XCL_PROBE_PER_TILE_NULL=1 selects separate calls; neither selects one full-resource mixed NULL/SKIP call. The source contains no XCL reservation/mirror/Pages/before_execute invocation. AMD Radeon integrated driver 32.0.21030.2001, RTX 3090 driver 591.74, Windows 10 Home 19045, Agility 1.620.2, debug build.

Adapter Native remap call shape Result Wrong words in tiles 0, 1, 2, 3
AMD integrated One four-tile region, flags NULL, SKIP, NULL, SKIP 0 passed / 1 failed / 0 ignored 16,384 / 0 / 16,384 / 0
AMD integrated One call, two one-tile regions at (0,0) and (0,1), one NULL range of count 2 1 / 0 / 0 0 / 0 / 0 / 0
AMD integrated Two separate one-tile NULL calls at those coordinates 1 / 0 / 0 0 / 0 / 0 / 0
RTX 3090 One-call two-region NULL batch 1 / 0 / 0 0 / 0 / 0 / 0

No skips, harness timeouts, or device removals. The documented UpdateTileMappings contract permits multiple resource regions and a range of NULL mappings whose count covers their total tiles. The result supports batching changed NULL tiles without SKIP ranges, provided production code translates its linear tile indices into correct resource/subresource coordinates, including packed-mip cases. These four-tile synthetic tests do not establish that such translation or the integration is correct, or that performance improves at world scale. The author owns the PR; this is validation input, not a competing fix.

AI use: Codex (GPT-6) built the synthetic control, caught and corrected the coordinate mistake, ran the native tests, checked source hashes and logs, and prepared this report.

Four-tile native control source
//! Local diagnostic: a native D3D12 NULL/SKIP tile mapping without XCL residency hooks.
use super::*;
use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*, Dxgi::Common::*};

unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) {
    let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
    queue.Signal(&fence, 1).unwrap();
    let start = std::time::Instant::now();
    while fence.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 {
        std::thread::sleep(std::time::Duration::from_millis(1));
    }
    assert_eq!(fence.GetCompletedValue(), 1);
    dev.GetDeviceRemovedReason().unwrap();
}

unsafe fn tile_copy(dev: &ID3D12Device, queue: &ID3D12CommandQueue, texture: &ID3D12Resource,
                    buffer: &ID3D12Resource, pages: u32, upload: bool) {
    let allocator: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
    let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &allocator, None).unwrap();
    let state = if upload { D3D12_RESOURCE_STATE_COPY_DEST } else { D3D12_RESOURCE_STATE_COPY_SOURCE };
    list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, D3D12_RESOURCE_STATE_COMMON, state)]);
    let coord = D3D12_TILED_RESOURCE_COORDINATE::default();
    let region = D3D12_TILE_REGION_SIZE { NumTiles: pages, UseBox: false.into(), ..Default::default() };
    let flags = if upload { D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE }
                else { D3D12_TILE_COPY_FLAG_SWIZZLED_TILED_RESOURCE_TO_LINEAR_BUFFER };
    list.CopyTiles(texture, &coord, &region, buffer, 0, flags);
    list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, state, D3D12_RESOURCE_STATE_COMMON)]);
    list.Close().unwrap();
    queue.ExecuteCommandLists(&[Some(list.cast().unwrap())]);
    drain(queue, dev);
}

unsafe fn buffer_pages(dev: &ID3D12Device, pages: usize, heap: D3D12_HEAP_TYPE,
                       state: D3D12_RESOURCE_STATES) -> ID3D12Resource {
    let desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
        Width: (pages * PAGE) as u64, Height: 1, DepthOrArraySize: 1, MipLevels: 1,
        SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
        Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR, ..Default::default() };
    let mut out = None;
    dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: heap, ..Default::default() },
        D3D12_HEAP_FLAG_NONE, &desc, state, None, &mut out).unwrap();
    out.unwrap()
}

#[test]
fn native_mixed_null_skip_mapping_returns_zero() {
    unsafe {
        let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
        let selector = crate::gpu::adapter::Selector::from_env_or("auto");
        let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next() else {
            return crate::gpu::recomp::runner::skip_test("no GPU");
        };
        println!("adapter={}", crate::gpu::adapter::name(&desc));
        let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap();
        let mut opts = D3D12_FEATURE_DATA_D3D12_OPTIONS::default();
        dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut opts as *mut _ as *mut c_void,
                                std::mem::size_of_val(&opts) as u32).unwrap();
        assert!(opts.TiledResourcesTier.0 >= 2 && opts.ResourceHeapTier.0 >= 2);
        let disjoint = std::env::var_os("XCL_PROBE_DISJOINT").is_some();
        let pages = if disjoint { 4usize } else { 2usize };
        let texture_desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D,
            Width: 256, Height: if disjoint { 256 } else { 128 }, DepthOrArraySize: 1,
            MipLevels: 1, Format: DXGI_FORMAT_R32_UINT,
            SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
            Layout: D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE, ..Default::default() };
        let mut texture = None;
        dev.CreateReservedResource(&texture_desc, D3D12_RESOURCE_STATE_COMMON, None, &mut texture).unwrap();
        let texture: ID3D12Resource = texture.unwrap();
        let mut count = 0;
        let mut shape = D3D12_TILE_SHAPE::default();
        dev.GetResourceTiling(&texture, Some(&mut count), None, Some(&mut shape), None, 0, std::ptr::null_mut());
        assert_eq!(count, pages as u32);
        assert_eq!((shape.WidthInTexels, shape.HeightInTexels), (128, 128));
        let heap_desc = D3D12_HEAP_DESC { SizeInBytes: (pages * PAGE) as u64,
            Properties: D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() },
            Flags: D3D12_HEAP_FLAG_NONE, ..Default::default() };
        let mut heap = None;
        dev.CreateHeap(&heap_desc, &mut heap).unwrap();
        let heap: ID3D12Heap = heap.unwrap();
        let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap();
        let coord = D3D12_TILED_RESOURCE_COORDINATE::default();
        let region = D3D12_TILE_REGION_SIZE { NumTiles: pages as u32, UseBox: false.into(), ..Default::default() };
        let map_flag = D3D12_TILE_RANGE_FLAG_NONE;
        let offset = 0u32;
        let count = pages as u32;
        queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), &heap, 1,
            Some(&map_flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
        drain(&queue, &dev);
        let upload = buffer_pages(&dev, pages, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ);
        let readback = buffer_pages(&dev, pages, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST);
        let mut p = std::ptr::null_mut();
        upload.Map(0, None, Some(&mut p)).unwrap();
        let words = std::slice::from_raw_parts_mut(p as *mut u32, pages * PAGE / 4);
        let values = [0x55555555u32, 0x66666666, 0x77777777, 0x88888888];
        for (i, chunk) in words.chunks_mut(PAGE / 4).enumerate() { chunk.fill(values[i]); }
        upload.Unmap(0, None);
        tile_copy(&dev, &queue, &texture, &upload, pages as u32, true);
        let single = std::env::var_os("XCL_PROBE_SINGLE_NULL").is_some();
        let batch = std::env::var_os("XCL_PROBE_BATCH_NULL").is_some();
        let contiguous = std::env::var_os("XCL_PROBE_CONTIGUOUS_NULL").is_some();
        let per_tile = std::env::var_os("XCL_PROBE_PER_TILE_NULL").is_some();
        let drain_each = std::env::var_os("XCL_PROBE_DRAIN_EACH").is_some();
        if disjoint && contiguous {
            let two = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() };
            let flag = D3D12_TILE_RANGE_FLAG_NULL;
            let count = 2u32;
            queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&two), None, 1,
                Some(&flag), None, Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
        } else if disjoint && per_tile {
            let one = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() };
            let flag = D3D12_TILE_RANGE_FLAG_NULL;
            let count = 1u32;
            for (x, y) in [(0, 0), (0, 1)] {
                let coord = D3D12_TILED_RESOURCE_COORDINATE { X: x, Y: y, ..Default::default() };
                queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&one), None, 1,
                    Some(&flag), None, Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
                if drain_each { drain(&queue, &dev); }
            }
        } else if disjoint && batch {
            let coords = [D3D12_TILED_RESOURCE_COORDINATE { X: 0, ..Default::default() },
                          D3D12_TILED_RESOURCE_COORDINATE { X: 0, Y: 1, ..Default::default() }];
            let flag = D3D12_TILE_RANGE_FLAG_NULL;
            let count = 2u32;
            queue.UpdateTileMappings(&texture, 2, Some(coords.as_ptr()), None, None, 1,
                Some(&flag), None, Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
        } else if disjoint {
            let flags = [D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP,
                         D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP];
            let offsets = [0u32; 4];
            let counts = [1u32; 4];
            queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), None, 4,
                Some(flags.as_ptr()), Some(offsets.as_ptr()), Some(counts.as_ptr()), D3D12_TILE_MAPPING_FLAG_NONE);
        } else if single {
            let one = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() };
            let flag = D3D12_TILE_RANGE_FLAG_NULL;
            let offset = 0u32;
            let count = 1u32;
            queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&one), None, 1,
                Some(&flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE);
        } else {
            let range_flags = [D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP];
            let offsets = [0u32, 0u32];
            let counts = [1u32, 1u32];
            queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), None, 2,
                Some(range_flags.as_ptr()), Some(offsets.as_ptr()), Some(counts.as_ptr()), D3D12_TILE_MAPPING_FLAG_NONE);
        }
        println!("mapping={}", if disjoint && contiguous { "contiguous-two-null" }
                 else if disjoint && per_tile && drain_each { "disjoint-per-tile-drain" }
                 else if disjoint && per_tile { "disjoint-per-tile-null" }
                 else if disjoint && batch { "disjoint-batch-null" }
                 else if disjoint { "disjoint-mixed-null-skip" }
                 else if single { "single-null" } else { "mixed-null-skip" });
        drain(&queue, &dev);
        readback.Map(0, None, Some(&mut p)).unwrap();
        std::ptr::write_bytes(p as *mut u8, 0xA5, pages * PAGE);
        readback.Unmap(0, None);
        tile_copy(&dev, &queue, &texture, &readback, pages as u32, false);
        readback.Map(0, None, Some(&mut p)).unwrap();
        let words = std::slice::from_raw_parts(p as *const u32, pages * PAGE / 4);
        let wrong: Vec<usize> = words.chunks(PAGE / 4).enumerate()
            .map(|(i, chunk)| chunk.iter().filter(|&&v| v != if (contiguous && i < 2) || (!contiguous && i % 2 == 0) { 0 } else { values[i] }).count())
            .collect();
        let first: Vec<u32> = words.chunks(PAGE / 4).map(|chunk| chunk[0]).collect();
        println!("first={first:x?} wrong={wrong:?}");
        readback.Unmap(0, None);
        assert!(wrong.iter().all(|&n| n == 0), "NULL tiles should read zero");
    }
}

**@⁠WebIdentity1** on GitHub · 2026-11-24 19:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7142078539) · edited 2026-11-24 21:00 UTC **Packed-mip array follow-up — 24 November:** I added a synthetic, test-only GPU-byte control at the unchanged #1514 head `73b6001` and the uncommitted local NULL-region candidate. This covers a *complete* one-tile packed-mip set per array slice, avoiding [D3D12's undefined partial packed-set case](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_packed_mip_info). The 256×256 `R32_UINT` two-slice/9-mip reserved texture has 12 overall tiles on both drivers; packed tiles 5 and 11 correspond to subresources 2 and 11 at `(X=0,Y=0,Z=0)`. I wrote distinct values into each slice's 64×64 mip 2 with `CopyTextureRegion`, decommitted slice 0's packed tile via XCL's mirrored graphics reservation, then checked all 4,096 pixels per slice with a sentinel-filled `CopyTextureRegion` readback. `CopyTiles` was not used for packed mips. On Windows 10 19045, integrated AMD Radeon(TM) Graphics driver 32.0.21030.2001 and RTX 3090 driver 591.74, Rust 1.98.1 MSVC, Agility 1.620.2, each in a fresh SSH Session 0 process: `cargo test --locked -p xcl --lib xcl_packed_mip_decommit_keeps_other_array_slice -- --test-threads=1 --show-output --nocapture`, with `XCL_ADAPTER=AMD` or `3090`. | Runtime tree | AMD integrated | RTX 3090 | Wrong pixels after decommit (slice 0 / retained slice 1) | |---|---:|---:|---:| | Untouched PR head + test-only fixture | **0/1/0** | **1/0/0** | AMD **4096/0**; NVIDIA 0/0 | | Local explicit-NULL-region candidate + same test sequence | **1/0/0**, repeated after switching build trees | **1/0/0** | **0/0** on both | The baseline fixture uses a local packed-coordinate helper because the unchanged PR has no production helper; otherwise its allocation, upload, decommit and readback sequence matches the candidate fixture. The candidate calls its production `tile_coordinates`. A separate native D3D12 packed-set control also passed **1/0/0 on each adapter** with the candidate helper. All tests had no skip, timeout or device removal. Frozen baseline/candidate source snapshots matched **222/222** and **224/224** SHA256 files on Windows after testing; candidate `vram.rs` SHA256 `4fc2d2329f962921d31ad0c69017a49cd410ba80ba0697965279a8553bd699d5`, packed fixture `0cf99ccab80370d5b47028710c18db554426d3a4b22bf32ef7639f00677f7431`; baseline fixture `d5cc3f5a63d85514c02575bfb6a8f564e7dd1c5b4ea4c60e15ff4a29c6efc5b4`. This extends the earlier failing-without-fix AMD control to one complete packed set per slice. Multi-tile packed sets, partial mappings, unusual-tiling fallback, discrete AMD, world-scale cost and retail smoke remain untested. The author still owns the fix; no code was committed, pushed or proposed as a competing PR. **AI use:** Codex (GPT-6) wrote and ran the synthetic fixtures, verified source hashes/logs, and prepared this follow-up. --- **Full-suite follow-up for the local NULL-region candidate — 24 November.** The PR head is still `73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8`; this is **uncommitted local validation**, not a competing implementation. I compared a clean exact-head archive (221 tracked files) with my candidate at that head (the same 221 files plus two local diagnostic modules). All Windows source hashes matched before and after. On Windows 10 19045, RTX 3090 driver 591.74, Ryzen 7 7800X3D, Rust 1.98.1 MSVC, Agility 1.620.2 x64, `XCL_ADAPTER=3090`, `XCL_REQUIRE_GPU=mesh`, `XCL_HEAP_WINDOWS=1`, direct DXIL unset, desktop Session 1: `cargo build --locked --workspace` exited 0 on both. `cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output` across 19 targets: **untouched head 751 passed / 1 failed / 41 ignored; local candidate 754 / 1 / 41**. The extra three passes are exactly the candidate's diagnostic tests, including integrated disjoint decommit. Both runs failed only the same known #202 `v_pk_add_i16 clamp` lane-0 check; two explicit debug-layer `SKIPPED` lines each; no timeout or device removal. Neither whole suite passed. This complements the earlier AMD result below: the integrated four-tile test failed on the unchanged head and passed with explicit NULL regions on both AMD integrated and RTX 3090. **Limits:** the frozen local tree includes a native mixed-NULL/SKIP negative control that intentionally fails on the AMD driver, so it is not a mergeable cross-adapter suite. The coordinate helper has structural packed-mip/array checks but no packed-mip GPU-byte test; [D3D12 leaves partially mapped packed-mip behavior vendor-specific](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_packed_mip_info). Its unusual-tiling fallback still uses the original mixed NULL/SKIP call shape. World-scale cost, discrete AMD, retail smoke, and interaction with #1747 remain untested. I would treat the explicit-region path as a validated direction for standard tiles, with those cases still to resolve before a runtime PR is merge-ready. **AI use:** Codex (GPT-6) ran the exact-head/candidate pair, checked hashes and logs, and prepared this update. --- **Integrated four-tile negative control — 24 November, 20:14 UTC:** I exercised XCL's `VirtualAlloc`/`VirtualFree` mirror tracking, `place_pages`, `before_execute` and `Pages::apply_backing` with one reserved 256×256 `R32_UINT` texture. After committing and uploading four distinct 64 KiB tiles, I decommitted *disjoint* tiles 0 and 2 before the next GPU read. On the **unchanged PR head** `73b6001` plus test-only fixture, the AMD integrated adapter failed **0/1/0**: both decommitted tiles retained all 16,384 old words; tiles 1 and 3 were correct. The RTX 3090 passed **1/0/0**, with both decommitted tiles zero. On the **uncommitted local candidate** that sends explicitly addressed NULL regions in one call, AMD and RTX 3090 each passed **1/0/0**, zero wrong words in all four tiles. I repeated the candidate runs after switching the shared Cargo build target back from the baseline: both still passed **1/0/0**. Every run used a fresh process, sentinel-filled `CopyTiles` readback, queue fences and device-removal checks; no skips, harness timeouts or removal occurred. Command: `cargo test --locked -p xcl --lib xcl_disjoint_decommits_unmap_both_texture_tiles -- --test-threads=1 --show-output --nocapture`, with `XCL_ADAPTER=AMD` or `3090`. The baseline and candidate fixtures share the same allocation/upload/decommit/readback sequence; the baseline only substitutes known `(0,0),(0,1)` tile coordinates for the candidate helper and a local copy of the same barrier helper. Baseline `vram.rs` has only a test-module registration; its 221-file PR-head source archive had zero hash mismatches before the fixture overlay. Final fixture SHA256: baseline `521159dc01b0ec6195d971c2a82f8f5b3ac43d4af5d4044556569a5f5409a976`; candidate `aff04b6e37d3b6d52999a4a8625644cb1cfc29388fc1e2cc4a3fd9765dea3c80`. This supplies an integrated GPU test that **fails without** the local mapping change and passes with it. The existing PR author still owns implementation. Full suite, retail smoke, packed-mip GPU behavior, and mapping cost remain untested; I have not committed, pushed, or opened a competing PR. **AI use:** Codex (GPT-6) wrote the synthetic test, ran the native comparisons, verified hashes/logs, and prepared this update. --- **Update — local XCL integration diagnostic, 24 November:** I translated changed tile indices with `GetResourceTiling` and changed only `Pages::apply_backing`'s NULL path on an uncommitted worktree at this PR's exact head `73b6001`. One `UpdateTileMappings` call now receives one explicitly addressed resource region per changed tile and a single NULL range; the existing heap mapping path remains. This is a candidate, not a proposed or merge-ready fix. On Windows 10, AMD Radeon integrated driver 32.0.21030.2001 and RTX 3090 driver 591.74, the paired 24 GiB CPU/GPU reservation and two aliased two-tile texture fixture passed **1/0/0 on each adapter**, with **0 wrong out of 196,608 GPU-readback words** across six phases, including partial decommit/recommit. In a separate native four-tile D3D12 control, the candidate helper generated coordinates `(0,0)` and `(0,1)` for disjoint tiles 0 and 2; a *single* two-region NULL call passed **1/0/0 on both adapters**, all four tiles correct. In the same control source and AMD environment, switching back to one full-resource mixed `NULL, SKIP, NULL, SKIP` call failed **0/1/0**, leaving **16,384 stale words in each unmapped tile**. Fresh process per test; no skips, harness timeouts or device removals. Command filter: `cargo test --locked -p xcl --lib <filter> -- --test-threads=1 --show-output --nocapture`; `XCL_ADAPTER=AMD` or `3090`, plus `XCL_PROBE_DISJOINT=1` and (for the passing native batch) `XCL_PROBE_BATCH_NULL=1`. Final local source SHA256: `vram.rs` `3ce4018798085b117668effdb2883c54826c184ff1c683b7067afdab18331251`, native probe `a137baf420ce84f2891c9b5a707aa337c2f645fd2905f9b1bc0436cb42c31e62`, paired probe `0dbe7807762a3948a040ed1288eee48a109940735d3dc604797241be78fe6b85`; all matched the Windows copies before the native run. This makes the stale tile a **GPU-observable behavior of the mixed mapping call shape on this AMD driver**, not a test bookkeeping failure. I still cannot assign driver versus subtler API/resource responsibility. The candidate's packed-mip coordinate check is structural only; no packed-mip GPU remap, world-scale overhead, discrete AMD, full suite or retail title was tested. [Microsoft's packed-mip documentation](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_packed_mip_info) says partial packed-mip mappings have vendor-specific undefined read/write behavior, which needs separate handling. I am keeping the code local so the PR author can decide whether this mapping strategy fits the branch. **AI use:** Codex (GPT-6) wrote the candidate and fixtures, ran the native tests, checked the logs and prepared this update. --- Further native D3D12 control for [the AMD stale-tile finding](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514): **one `UpdateTileMappings` call can NULL two disjoint texture tiles on the tested AMD adapter if they are supplied as two correctly addressed resource regions, with no SKIP ranges.** This is a candidate for reducing mapping-call overhead versus one call per tile; I have not measured world-scale cost or integrated it into XCL. The local test uses a 256×256 `R32_UINT` reserved texture with four 64 KiB tiles (driver-reported tile shape 128×128), one four-tile default heap, `CopyTiles` upload/readback, queue fences, a sentinel-filled readback buffer, and device-removal checks. All four tiles initially contain distinct values. It tries to unmap tiles 0 and 2 while retaining tiles 1 and 3. The correctly addressed tile-2 coordinate is **`(X=0, Y=1)`**, since this is a two-dimensional, two-tiles-wide texture. [D3D12's region description](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_tile_region_size) says `UseBox=false` traverses linearly from the *starting x/y/z coordinate*; a flat index is not generally a valid `X` coordinate for a nonpacked 2D texture. An early local exploratory run mistakenly used `(X=2, Y=0)` for tile 2; I discarded those results and did not publish them. Fresh native test processes, same source SHA256 `1a7b25f1be8f0ffc7755a18d4f279c558ba15475742110ae6cf84d7e0a1eca39` on Mac and Windows. Command: `cargo test --locked -p xcl --lib native_mixed_null_skip_mapping_returns_zero -- --test-threads=1 --show-output --nocapture`. `XCL_PROBE_DISJOINT=1` in all runs; `XCL_ADAPTER=AMD` or `3090`. `XCL_PROBE_BATCH_NULL=1` selects the batch, `XCL_PROBE_PER_TILE_NULL=1` selects separate calls; neither selects one full-resource mixed NULL/SKIP call. The source contains no XCL reservation/mirror/Pages/before_execute invocation. AMD Radeon integrated driver 32.0.21030.2001, RTX 3090 driver 591.74, Windows 10 Home 19045, Agility 1.620.2, debug build. | Adapter | Native remap call shape | Result | Wrong words in tiles 0, 1, 2, 3 | |---|---|---|---| | AMD integrated | One four-tile region, flags `NULL, SKIP, NULL, SKIP` | **0 passed / 1 failed / 0 ignored** | **16,384 / 0 / 16,384 / 0** | | AMD integrated | **One call**, two one-tile regions at `(0,0)` and `(0,1)`, one NULL range of count 2 | **1 / 0 / 0** | **0 / 0 / 0 / 0** | | AMD integrated | Two separate one-tile NULL calls at those coordinates | **1 / 0 / 0** | **0 / 0 / 0 / 0** | | RTX 3090 | One-call two-region NULL batch | **1 / 0 / 0** | **0 / 0 / 0 / 0** | No skips, harness timeouts, or device removals. The [documented `UpdateTileMappings` contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12commandqueue-updatetilemappings) permits multiple resource regions and a range of NULL mappings whose count covers their total tiles. The result supports **batching changed NULL tiles without SKIP ranges**, provided production code translates its linear tile indices into correct resource/subresource coordinates, including packed-mip cases. These four-tile synthetic tests do not establish that such translation or the integration is correct, or that performance improves at world scale. The author owns the PR; this is validation input, not a competing fix. **AI use:** Codex (GPT-6) built the synthetic control, caught and corrected the coordinate mistake, ran the native tests, checked source hashes and logs, and prepared this report. <details><summary>Four-tile native control source</summary> ```rust //! Local diagnostic: a native D3D12 NULL/SKIP tile mapping without XCL residency hooks. use super::*; use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*, Dxgi::Common::*}; unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) { let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); queue.Signal(&fence, 1).unwrap(); let start = std::time::Instant::now(); while fence.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 { std::thread::sleep(std::time::Duration::from_millis(1)); } assert_eq!(fence.GetCompletedValue(), 1); dev.GetDeviceRemovedReason().unwrap(); } unsafe fn tile_copy(dev: &ID3D12Device, queue: &ID3D12CommandQueue, texture: &ID3D12Resource, buffer: &ID3D12Resource, pages: u32, upload: bool) { let allocator: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap(); let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &allocator, None).unwrap(); let state = if upload { D3D12_RESOURCE_STATE_COPY_DEST } else { D3D12_RESOURCE_STATE_COPY_SOURCE }; list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, D3D12_RESOURCE_STATE_COMMON, state)]); let coord = D3D12_TILED_RESOURCE_COORDINATE::default(); let region = D3D12_TILE_REGION_SIZE { NumTiles: pages, UseBox: false.into(), ..Default::default() }; let flags = if upload { D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE } else { D3D12_TILE_COPY_FLAG_SWIZZLED_TILED_RESOURCE_TO_LINEAR_BUFFER }; list.CopyTiles(texture, &coord, &region, buffer, 0, flags); list.ResourceBarrier(&[super::texture_residency_probe::transition(texture, state, D3D12_RESOURCE_STATE_COMMON)]); list.Close().unwrap(); queue.ExecuteCommandLists(&[Some(list.cast().unwrap())]); drain(queue, dev); } unsafe fn buffer_pages(dev: &ID3D12Device, pages: usize, heap: D3D12_HEAP_TYPE, state: D3D12_RESOURCE_STATES) -> ID3D12Resource { let desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_BUFFER, Width: (pages * PAGE) as u64, Height: 1, DepthOrArraySize: 1, MipLevels: 1, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR, ..Default::default() }; let mut out = None; dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: heap, ..Default::default() }, D3D12_HEAP_FLAG_NONE, &desc, state, None, &mut out).unwrap(); out.unwrap() } #[test] fn native_mixed_null_skip_mapping_returns_zero() { unsafe { let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap(); let selector = crate::gpu::adapter::Selector::from_env_or("auto"); let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &selector).into_iter().next() else { return crate::gpu::recomp::runner::skip_test("no GPU"); }; println!("adapter={}", crate::gpu::adapter::name(&desc)); let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap(); let mut opts = D3D12_FEATURE_DATA_D3D12_OPTIONS::default(); dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut opts as *mut _ as *mut c_void, std::mem::size_of_val(&opts) as u32).unwrap(); assert!(opts.TiledResourcesTier.0 >= 2 && opts.ResourceHeapTier.0 >= 2); let disjoint = std::env::var_os("XCL_PROBE_DISJOINT").is_some(); let pages = if disjoint { 4usize } else { 2usize }; let texture_desc = D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 256, Height: if disjoint { 256 } else { 128 }, DepthOrArraySize: 1, MipLevels: 1, Format: DXGI_FORMAT_R32_UINT, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, Layout: D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE, ..Default::default() }; let mut texture = None; dev.CreateReservedResource(&texture_desc, D3D12_RESOURCE_STATE_COMMON, None, &mut texture).unwrap(); let texture: ID3D12Resource = texture.unwrap(); let mut count = 0; let mut shape = D3D12_TILE_SHAPE::default(); dev.GetResourceTiling(&texture, Some(&mut count), None, Some(&mut shape), None, 0, std::ptr::null_mut()); assert_eq!(count, pages as u32); assert_eq!((shape.WidthInTexels, shape.HeightInTexels), (128, 128)); let heap_desc = D3D12_HEAP_DESC { SizeInBytes: (pages * PAGE) as u64, Properties: D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() }, Flags: D3D12_HEAP_FLAG_NONE, ..Default::default() }; let mut heap = None; dev.CreateHeap(&heap_desc, &mut heap).unwrap(); let heap: ID3D12Heap = heap.unwrap(); let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap(); let coord = D3D12_TILED_RESOURCE_COORDINATE::default(); let region = D3D12_TILE_REGION_SIZE { NumTiles: pages as u32, UseBox: false.into(), ..Default::default() }; let map_flag = D3D12_TILE_RANGE_FLAG_NONE; let offset = 0u32; let count = pages as u32; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), &heap, 1, Some(&map_flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); drain(&queue, &dev); let upload = buffer_pages(&dev, pages, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); let readback = buffer_pages(&dev, pages, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); let mut p = std::ptr::null_mut(); upload.Map(0, None, Some(&mut p)).unwrap(); let words = std::slice::from_raw_parts_mut(p as *mut u32, pages * PAGE / 4); let values = [0x55555555u32, 0x66666666, 0x77777777, 0x88888888]; for (i, chunk) in words.chunks_mut(PAGE / 4).enumerate() { chunk.fill(values[i]); } upload.Unmap(0, None); tile_copy(&dev, &queue, &texture, &upload, pages as u32, true); let single = std::env::var_os("XCL_PROBE_SINGLE_NULL").is_some(); let batch = std::env::var_os("XCL_PROBE_BATCH_NULL").is_some(); let contiguous = std::env::var_os("XCL_PROBE_CONTIGUOUS_NULL").is_some(); let per_tile = std::env::var_os("XCL_PROBE_PER_TILE_NULL").is_some(); let drain_each = std::env::var_os("XCL_PROBE_DRAIN_EACH").is_some(); if disjoint && contiguous { let two = D3D12_TILE_REGION_SIZE { NumTiles: 2, UseBox: false.into(), ..Default::default() }; let flag = D3D12_TILE_RANGE_FLAG_NULL; let count = 2u32; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&two), None, 1, Some(&flag), None, Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); } else if disjoint && per_tile { let one = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() }; let flag = D3D12_TILE_RANGE_FLAG_NULL; let count = 1u32; for (x, y) in [(0, 0), (0, 1)] { let coord = D3D12_TILED_RESOURCE_COORDINATE { X: x, Y: y, ..Default::default() }; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&one), None, 1, Some(&flag), None, Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); if drain_each { drain(&queue, &dev); } } } else if disjoint && batch { let coords = [D3D12_TILED_RESOURCE_COORDINATE { X: 0, ..Default::default() }, D3D12_TILED_RESOURCE_COORDINATE { X: 0, Y: 1, ..Default::default() }]; let flag = D3D12_TILE_RANGE_FLAG_NULL; let count = 2u32; queue.UpdateTileMappings(&texture, 2, Some(coords.as_ptr()), None, None, 1, Some(&flag), None, Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); } else if disjoint { let flags = [D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP, D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP]; let offsets = [0u32; 4]; let counts = [1u32; 4]; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), None, 4, Some(flags.as_ptr()), Some(offsets.as_ptr()), Some(counts.as_ptr()), D3D12_TILE_MAPPING_FLAG_NONE); } else if single { let one = D3D12_TILE_REGION_SIZE { NumTiles: 1, UseBox: false.into(), ..Default::default() }; let flag = D3D12_TILE_RANGE_FLAG_NULL; let offset = 0u32; let count = 1u32; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&one), None, 1, Some(&flag), Some(&offset), Some(&count), D3D12_TILE_MAPPING_FLAG_NONE); } else { let range_flags = [D3D12_TILE_RANGE_FLAG_NULL, D3D12_TILE_RANGE_FLAG_SKIP]; let offsets = [0u32, 0u32]; let counts = [1u32, 1u32]; queue.UpdateTileMappings(&texture, 1, Some(&coord), Some(&region), None, 2, Some(range_flags.as_ptr()), Some(offsets.as_ptr()), Some(counts.as_ptr()), D3D12_TILE_MAPPING_FLAG_NONE); } println!("mapping={}", if disjoint && contiguous { "contiguous-two-null" } else if disjoint && per_tile && drain_each { "disjoint-per-tile-drain" } else if disjoint && per_tile { "disjoint-per-tile-null" } else if disjoint && batch { "disjoint-batch-null" } else if disjoint { "disjoint-mixed-null-skip" } else if single { "single-null" } else { "mixed-null-skip" }); drain(&queue, &dev); readback.Map(0, None, Some(&mut p)).unwrap(); std::ptr::write_bytes(p as *mut u8, 0xA5, pages * PAGE); readback.Unmap(0, None); tile_copy(&dev, &queue, &texture, &readback, pages as u32, false); readback.Map(0, None, Some(&mut p)).unwrap(); let words = std::slice::from_raw_parts(p as *const u32, pages * PAGE / 4); let wrong: Vec<usize> = words.chunks(PAGE / 4).enumerate() .map(|(i, chunk)| chunk.iter().filter(|&&v| v != if (contiguous && i < 2) || (!contiguous && i % 2 == 0) { 0 } else { values[i] }).count()) .collect(); let first: Vec<u32> = words.chunks(PAGE / 4).map(|chunk| chunk[0]).collect(); println!("first={first:x?} wrong={wrong:?}"); readback.Unmap(0, None); assert!(wrong.iter().all(|&n| n == 0), "NULL tiles should read zero"); } } ``` </details>
Author
Owner

@⁠rrrarrra9 on GitHub · 2026-11-24 22:06 UTC · original

I independently reproduced the two-standard-tile result from the native control above on another Windows machine with an integrated Radeon. The GTX 1650 (4 GB) also provides a low-VRAM NVIDIA control.

This was a standalone D3D12 test with a synthetic 256×128 R32_UINT reserved texture and two populated tiles. It verified both patterns before unmapping, then fenced and read back both tiles. Each adapter ran both variants twice in fresh processes, in mixed/single/single/mixed order.

Adapter First tile after mixed NULL, SKIP First tile after single-region NULL
Integrated Radeon (tiled tier 3) 16,384 old words in both runs 16,384 zero words in both runs
GTX 1650 (tiled tier 4) 16,384 zero words in both runs 16,384 zero words in both runs

The second tile retained all 16,384 original words in all eight runs. This confirms that single-region NULL clears the requested standard tile on both tested adapters. XCL integration, packed mips, and retail behavior need separate validation.

AI use: OpenAI Codex (gpt-6.2-sol) wrote and ran this independent control and drafted the report.

**@⁠rrrarrra9** on GitHub · 2026-11-24 22:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7145813465) I independently reproduced the two-standard-tile result from [the native control above](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514) on another Windows machine with an integrated Radeon. The GTX 1650 (4 GB) also provides a low-VRAM NVIDIA control. This was a standalone D3D12 test with a synthetic 256×128 `R32_UINT` reserved texture and two populated tiles. It verified both patterns before unmapping, then fenced and read back both tiles. Each adapter ran both variants twice in fresh processes, in mixed/single/single/mixed order. | Adapter | First tile after mixed `NULL, SKIP` | First tile after single-region `NULL` | | --- | ---: | ---: | | Integrated Radeon (tiled tier 3) | 16,384 old words in both runs | 16,384 zero words in both runs | | GTX 1650 (tiled tier 4) | 16,384 zero words in both runs | 16,384 zero words in both runs | The second tile retained all 16,384 original words in all eight runs. This confirms that single-region `NULL` clears the requested standard tile on both tested adapters. XCL integration, packed mips, and retail behavior need separate validation. AI use: OpenAI Codex (gpt-6.2-sol) wrote and ran this independent control and drafted the report.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-24 22:44 UTC · original

RTX 5060 Laptop GPU (8 GB), Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112, vkd3d-proton 4522cc1a8b1347f+ with local allocation changes.

I tested a synthetic 64 KiB RGBA tile placed in a watched graphics reservation. The test uploads a pattern and reads back every byte through reserve, commit, decommit and re-commit. The baseline failed the first zero-read check. The test passed on PR head 73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8 and on a local port to 9e3831e with the same residency and storage changes as the baseline. Each focused test invocation ran one test with zero skips.

In two Series X runs starting with matching cache and title state, the nearest samples to 75,000 storage requests showed 8,512 MiB of texture pools before the port and 3,584 MiB after (74,963 and 74,876 requests respectively). Reported non-local memory was 6,518 and 1,526 MiB. The port reached 78,537 requests with zero reported storage failures. The previous system journal ends during that run, so its exit status and the cause are unknown. Loading artwork was the furthest verified scene. The local port also retained explicit GPU views and eviction tracking, which limits attribution of the title measurements.

OpenAI Codex (GPT-6.2-Sol high) assisted with the test, port and runs. OpenAI Codex (GPT-6.2-astra) checked the retained results and posted this report.

**@⁠Filip722** on GitHub · 2026-11-24 22:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7146592021) RTX 5060 Laptop GPU (8 GB), Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112, vkd3d-proton `4522cc1a8b1347f+` with local allocation changes. I tested a synthetic 64 KiB RGBA tile placed in a watched graphics reservation. The test uploads a pattern and reads back every byte through reserve, commit, decommit and re-commit. The baseline failed the first zero-read check. The test passed on PR head `73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8` and on a local port to `9e3831e` with the same residency and storage changes as the baseline. Each focused test invocation ran one test with zero skips. In two Series X runs starting with matching cache and title state, the nearest samples to 75,000 storage requests showed 8,512 MiB of texture pools before the port and 3,584 MiB after (74,963 and 74,876 requests respectively). Reported non-local memory was 6,518 and 1,526 MiB. The port reached 78,537 requests with zero reported storage failures. The previous system journal ends during that run, so its exit status and the cause are unknown. Loading artwork was the furthest verified scene. The local port also retained explicit GPU views and eviction tracking, which limits attribution of the title measurements. OpenAI Codex (GPT-6.2-Sol high) assisted with the test, port and runs. OpenAI Codex (GPT-6.2-astra) checked the retained results and posted this report.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-24 23:22 UTC · original

I reproduced a second-placement case on the exact 73b60019 head. When a second texture is placed after committing a title page but before the next submit, placement can mark the shared page as mapped while the original texture still has a NULL tile. The fix lets the new alias inherit the existing mapping so the queued backing update reaches both textures. Fix and synthetic regression

I ran the same filter serially on the RTX 5060 Laptop GPU with Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112 and vkd3d-proton 4522cc1a8b1347f+, using the Windows MSVC release test binary.

--test-threads=1 --exact hle::d3d12x::vram::tests::reserved_texture_follows_pending_commit_when_an_alias_is_placed

  • 73b60019 with the fixture failed at the post-commit readback (0.70 s). The first byte was 0x00, expected 0xa5.
  • 9c553339 with the same fixture passed (0.67 s, zero skips).

The earlier one-texture commit/decommit test still passed on 73b60019 (1.45 s). The alias and commit/decommit fixture also passed on a local port based on 689f2db with #1747 (0.68 s).

OpenAI Codex (GPT-6) assisted with the fix, synthetic fixture, builds and report.

**@⁠Filip722** on GitHub · 2026-11-24 23:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7147320604) I reproduced a second-placement case on the exact `73b60019` head. When a second texture is placed after committing a title page but before the next submit, placement can mark the shared page as mapped while the original texture still has a NULL tile. The fix lets the new alias inherit the existing mapping so the queued backing update reaches both textures. [Fix and synthetic regression](https://github.com/Filip722/xcl/commit/9c553339aa09ed48eb9d0e6024a6ef56ec54cccd) I ran the same filter serially on the RTX 5060 Laptop GPU with Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112 and vkd3d-proton `4522cc1a8b1347f+`, using the Windows MSVC release test binary. `--test-threads=1 --exact hle::d3d12x::vram::tests::reserved_texture_follows_pending_commit_when_an_alias_is_placed` - `73b60019` with the fixture failed at the post-commit readback (0.70 s). The first byte was `0x00`, expected `0xa5`. - `9c553339` with the same fixture passed (0.67 s, zero skips). The earlier one-texture commit/decommit test still passed on `73b60019` (1.45 s). The alias and commit/decommit fixture also passed on a local port based on `689f2db` with #1747 (0.68 s). OpenAI Codex (GPT-6) assisted with the fix, synthetic fixture, builds and report.
Author
Owner

@⁠Raul-Paiva on GitHub · 2026-11-25 00:34 UTC · original

A result from an 8 GB card in Series X mode (device_type = "anaconda"). This PR cuts video memory a lot here. Counts only.

Setup: RTX 3070 Laptop 8 GB, driver 32.0.16.2124, i7-11800H, 32 GB RAM, Windows 10 19045, rustc 1.100.0, release. The base is main 80f4819 + #684, #501, #1592, #1803, #1914, #1697, plus local logging. I applied this PR's two commits (4a9e8e5, 73b6001) on top. The first one conflicts with #1747 in vram.rs, so I merged it by hand:

  • map takes &[Option<Tile>] in #1747's scratch-buffer form;
  • bind gives the pool tiles taken for pages it leaves unmapped back with return_tiles;
  • take_tile is rebuilt on take_batch(1, …).

Tests on that tree: cargo test --workspace --no-fail-fast -- --test-threads=4: 1010 passed, 1 failed, 45 ignored. The failure is vram::tests::d32s8_targets_take_their_own_size_of_video_memory, which fails under load and passes alone (3 of 3). The wave64 GPU tests are SKIPPED (no wave64).

Run: a retail title with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_DRED=1 and warm caches, one 420 s run. I read the peak from the memory: log lines.

without this PR with this PR
peak local video memory 11 – 12 GB 8.1 GB
last present 92 – 106 s 96 s
device removed yes yes, 0x887a0006 at 99.5 s
  • The "without" column comes from my earlier runs on #1269, on this base and on an older one, and not from a run made side by side with this one. On this base without the PR, one of those runs reached 12.5 GB at 77 s, when my VRAM guard stopped it.
  • The removal is the one reported on #1269:
    • DRED reports a page fault at GPU VA 0x0;
    • the partly executed list names a wind-simulation compute pipeline;
    • Nsight Aftermath reports the device as "Hung" in that compute work.
  • So on this card the hang is not caused by oversubscribing video memory. It stays with about 4 GB less in use.

Not tested: the HLSL path; Series S mode; more than one run; AMD; this PR without the other PRs listed above.

AI use: Claude Code (Claude Opus 5.5) merged the PR locally, ran the builds, tests and the run, read the logs and wrote this comment.

**@⁠Raul-Paiva** on GitHub · 2026-11-25 00:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7148647567) A result from an 8 GB card in Series X mode (`device_type = "anaconda"`). This PR cuts video memory a lot here. Counts only. **Setup:** RTX 3070 Laptop 8 GB, driver 32.0.16.2124, i7-11800H, 32 GB RAM, Windows 10 19045, rustc 1.100.0, release. The base is `main` `80f4819` + #684, #501, #1592, #1803, #1914, #1697, plus local logging. I applied this PR's two commits (`4a9e8e5`, `73b6001`) on top. The first one conflicts with #1747 in `vram.rs`, so I merged it by hand: - `map` takes `&[Option<Tile>]` in #1747's scratch-buffer form; - `bind` gives the pool tiles taken for pages it leaves unmapped back with `return_tiles`; - `take_tile` is rebuilt on `take_batch(1, …)`. **Tests** on that tree: `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1010 passed, 1 failed, 45 ignored. The failure is `vram::tests::d32s8_targets_take_their_own_size_of_video_memory`, which fails under load and passes alone (3 of 3). The wave64 GPU tests are SKIPPED (no wave64). **Run:** a retail title with `XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_DRED=1` and warm caches, one 420 s run. I read the peak from the `memory:` log lines. | | without this PR | with this PR | |---|---|---| | peak local video memory | 11 – 12 GB | **8.1 GB** | | last present | 92 – 106 s | 96 s | | device removed | yes | yes, `0x887a0006` at 99.5 s | - The "without" column comes from my earlier runs on #1269, on this base and on an older one, and not from a run made side by side with this one. On this base without the PR, one of those runs reached 12.5 GB at 77 s, when my VRAM guard stopped it. - The removal is the one reported on #1269: - DRED reports a page fault at GPU VA 0x0; - the partly executed list names a wind-simulation compute pipeline; - Nsight Aftermath reports the device as "Hung" in that compute work. - So on this card the hang is not caused by oversubscribing video memory. It stays with about 4 GB less in use. **Not tested:** the HLSL path; Series S mode; more than one run; AMD; this PR without the other PRs listed above. **AI use:** Claude Code (Claude Opus 5.5) merged the PR locally, ran the builds, tests and the run, read the logs and wrote this comment.
Author
Owner

@⁠veyn-sudo on GitHub · 2026-11-25 00:53 UTC · original

Result on 73b6001: with memory under only part of a mip chain, the wrong tiles stay mapped. bind pairs the PC's tile i with console page i, but the two orders differ: the console keeps the mip tail in a slice's first block and the largest level at its end, while the PC's tiles start with the largest level and end with the packed mips.

Test: 1024×1024 RGBA8, 11 levels, 64KB_S layout (0x109), placed with place_pages in a 24 GB GPU view; every level written with a pattern, then read back with CopyTextureRegion. The console's tail block (levels of 64×64 and smaller) is page 0. The driver reports 86 tiles, with the packed mips in tile 85.

memory committed in the CPU view 1024 512–128 64–1
all of it (control) all texels all all
first 64 KiB (the tail) 16,384 of 1,048,576 0 0

So with only the tail there, one tile of the empty largest level is kept and the tail's own levels read zero.

How common it is: on a retail title during world loading (local tree: main + #1055 + #1102), 1,336 streamed textures had memory under only part of their chain; 1,305 of them had none under their largest level. Going by level instead (a level's tiles are mapped once any of its console bytes have memory), 605 MB of the 3,491 MB of pages were needed. The console offsets come from xg::Texture and the PC tiles from GetResourceTiling.

A second point: title_backed asks the CPU view. With #1055 / #1102 a GPU-view page can have memory without any there (pages mapped by queue #31), so it would have to ask mirrors::mapped_source first.

I have a by-level version in my local tree. @⁠3L1A5-1, does your change on top of #1102 go by level too? I don't want to duplicate it; otherwise I can send the test or the code.

Tested: RTX 2070 SUPER (driver 617.14), Windows 11 26300, debug; the test ran twice with the same result (control passed, tail case failed). Not tested: other GPUs, the full suite, the title with this PR.

AI use: Claude Code (Claude Opus 5.5) wrote and ran the test and wrote this.

**@⁠veyn-sudo** on GitHub · 2026-11-25 00:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7149000997) Result on `73b6001`: with memory under only part of a mip chain, the wrong tiles stay mapped. `bind` pairs the PC's tile `i` with console page `i`, but the two orders differ: the console keeps the mip tail in a slice's first block and the largest level at its end, while the PC's tiles start with the largest level and end with the packed mips. **Test:** 1024×1024 RGBA8, 11 levels, 64KB_S layout (`0x109`), placed with `place_pages` in a 24 GB GPU view; every level written with a pattern, then read back with `CopyTextureRegion`. The console's tail block (levels of 64×64 and smaller) is page 0. The driver reports 86 tiles, with the packed mips in tile 85. | memory committed in the CPU view | 1024 | 512–128 | 64–1 | |---|---|---|---| | all of it (control) | all texels | all | all | | first 64 KiB (the tail) | 16,384 of 1,048,576 | 0 | **0** | So with only the tail there, one tile of the empty largest level is kept and the tail's own levels read zero. **How common it is:** on a retail title during world loading (local tree: `main` + #1055 + #1102), 1,336 streamed textures had memory under only part of their chain; 1,305 of them had none under their largest level. Going by level instead (a level's tiles are mapped once any of its console bytes have memory), 605 MB of the 3,491 MB of pages were needed. The console offsets come from `xg::Texture` and the PC tiles from `GetResourceTiling`. **A second point:** `title_backed` asks the CPU view. With #1055 / #1102 a GPU-view page can have memory without any there (pages mapped by queue #31), so it would have to ask `mirrors::mapped_source` first. I have a by-level version in my local tree. @⁠3L1A5-1, does your change on top of #1102 go by level too? I don't want to duplicate it; otherwise I can send the test or the code. **Tested:** RTX 2070 SUPER (driver 617.14), Windows 11 26300, debug; the test ran twice with the same result (control passed, tail case failed). **Not tested:** other GPUs, the full suite, the title with this PR. AI use: Claude Code (Claude Opus 5.5) wrote and ran the test and wrote this.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 05:15 UTC · original

Independent native D3D12 check of Filip722’s alias regression on Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug.

I ran reserved_texture_follows_pending_commit_when_an_alias_is_placed twice per build in fresh processes. 73b60019 with only the test fixture failed both times at step 2. The first byte read back as 0x00 after the alias was placed, with 0xa5 expected. 9c553339 passed both runs and verified all 65,536 tile bytes. Zero skips or ignores across the four runs.

Coverage was limited to the single-tile alias case. Packed mips, retail, and the workspace suite remain untested here. AI use: OpenAI Codex (GPT-6) ran the comparison and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-25 05:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7153592363) Independent native D3D12 check of [Filip722’s alias regression](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514) on Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. I ran `reserved_texture_follows_pending_commit_when_an_alias_is_placed` twice per build in fresh processes. [73b60019](https://github.com/xcl-dev/xcl/commit/73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8) with only the test fixture failed both times at step 2. The first byte read back as `0x00` after the alias was placed, with `0xa5` expected. [9c553339](https://github.com/Filip722/xcl/commit/9c553339aa09ed48eb9d0e6024a6ef56ec54cccd) passed both runs and verified all 65,536 tile bytes. Zero skips or ignores across the four runs. Coverage was limited to the single-tile alias case. Packed mips, retail, and the workspace suite remain untested here. AI use: OpenAI Codex (GPT-6) ran the comparison and drafted this report.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 05:34 UTC · original

Independent packed-mip check following veyn-sudo’s report. On 73b60019, I used a synthetic 256×256 RGBA8 64KB_S texture with nine mips. Native D3D12 reports six tiles, with the seven packed mips sharing tile 5. I compared XCL placement with a direct D3D12 control that maps the expected native tile groups and uses the same upload and readback.

Guest backing XCL placement Direct D3D12 control
Full All pixels matched All pixels matched
Tail only 16,384 pixels matched in mip 0; all tail pixels read zero All 5,461 tail pixels matched; mips 0 and 1 read zero
Largest mip only 32,768 of 65,536 pixels matched in mip 0; the other eight mips also had matching data All 65,536 pixels matched in mip 0; all other mips read zero

Two fresh processes per path gave identical results on Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. Both native controls passed. Both draft runs failed the partial-backing assertion. Graphics Tools reported zero D3D12 errors or corruption messages. No skips. Coverage is one texture format and one packed tile; arrays, retail and the workspace suite remain untested here.

If the by-level patch is ready to share, I can run this fixture against it. AI use: OpenAI Codex (GPT-6) wrote the synthetic fixture, ran it, and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-25 05:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7153909588) Independent packed-mip check following [veyn-sudo’s report](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514). On [73b60019](https://github.com/xcl-dev/xcl/commit/73b60019ad4a414ef4a2e51e87e3524cb1d2e4c8), I used a synthetic 256×256 RGBA8 `64KB_S` texture with nine mips. Native D3D12 reports six tiles, with the seven packed mips sharing tile 5. I compared XCL placement with a direct D3D12 control that maps the expected native tile groups and uses the same upload and readback. | Guest backing | XCL placement | Direct D3D12 control | | --- | --- | --- | | Full | All pixels matched | All pixels matched | | Tail only | 16,384 pixels matched in mip 0; all tail pixels read zero | All 5,461 tail pixels matched; mips 0 and 1 read zero | | Largest mip only | 32,768 of 65,536 pixels matched in mip 0; the other eight mips also had matching data | All 65,536 pixels matched in mip 0; all other mips read zero | Two fresh processes per path gave identical results on Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. Both native controls passed. Both draft runs failed the partial-backing assertion. Graphics Tools reported zero D3D12 errors or corruption messages. No skips. Coverage is one texture format and one packed tile; arrays, retail and the workspace suite remain untested here. If the by-level patch is ready to share, I can run this fixture against it. AI use: OpenAI Codex (GPT-6) wrote the synthetic fixture, ran it, and drafted this report.
Author
Owner

@⁠3L1A5-1 on GitHub · 2026-11-25 07:50 UTC · original

A data point for this approach from an 8 GB NVIDIA card, from a local change of mine that does the same for textures in GPU views (no video memory where nothing is mapped), so not this PR's code. Details in my comment on #1102:

  • RTX 2060 SUPER 8 GB, retail 1.0.2.1, Series X, world load, one run each. At 100 s: target pages 3 382 vs 6 448 MB, local video memory 7 372 vs 10 351 MB. Without the change the run ended at 104.9 s on CreateHeap → 0x8007000e and the title's +0x193e00f; with it the run went on to 202 s.

So I'm not opening that change: this PR covers it and was here first. What it adds on top, keying a GPU-view page's video memory by the physical page it shows (so a GPU view and its CPU view, or two aliases, share one tile), needs #1102. I'll offer that as a small follow-up once this PR and #1102 are in.

My version pairs the PC's tile i with console page i the same way, so @⁠veyn-sudo's mip-order finding above applies to it too.

AI use: Claude Code (Claude Opus 5.5) wrote this.

**@⁠3L1A5-1** on GitHub · 2026-11-25 07:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7156316163) A data point for this approach from an 8 GB NVIDIA card, from a local change of mine that does the same for textures in GPU views (no video memory where nothing is mapped), so not this PR's code. Details in [my comment on #1102](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1102): - RTX 2060 SUPER 8 GB, retail 1.0.2.1, Series X, world load, one run each. At 100 s: target pages 3 382 vs 6 448 MB, local video memory 7 372 vs 10 351 MB. Without the change the run ended at 104.9 s on `CreateHeap` → `0x8007000e` and the title's `+0x193e00f`; with it the run went on to 202 s. So I'm not opening that change: this PR covers it and was here first. What it adds on top, keying a GPU-view page's video memory by the physical page it shows (so a GPU view and its CPU view, or two aliases, share one tile), needs #1102. I'll offer that as a small follow-up once this PR and #1102 are in. My version pairs the PC's tile `i` with console page `i` the same way, so @⁠veyn-sudo's mip-order finding above applies to it too. AI use: Claude Code (Claude Opus 5.5) wrote this.
Author
Owner

@⁠veyn-sudo on GitHub · 2026-11-25 10:14 UTC · original

@⁠3L1A5-1 thanks, then I won't be duplicating it. @⁠thehollowedone thanks for the independent check; your direct D3D12 control shows the same thing.

My by-level version works on GPU-view textures and needs #1102. It is one commit of about 420 lines on a local tree with other changes (main, #1055, #1102), so not a patch for this head. A level's tiles are mapped once any of its console bytes have memory; the packed mips are one group. One retail title reaches its world with it, then loses the device for a reason I haven't found, so I can't call it ready. I can push it to a branch if it helps you or @⁠oishigeso.

AI use: Claude Code (Claude Opus 5.5) wrote this.

**@⁠veyn-sudo** on GitHub · 2026-11-25 10:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7159421960) @⁠3L1A5-1 thanks, then I won't be duplicating it. @⁠thehollowedone thanks for the independent check; your direct D3D12 control shows the same thing. My by-level version works on GPU-view textures and needs #1102. It is one commit of about 420 lines on a local tree with other changes (`main`, #1055, #1102), so not a patch for this head. A level's tiles are mapped once any of its console bytes have memory; the packed mips are one group. One retail title reaches its world with it, then loses the device for a reason I haven't found, so I can't call it ready. I can push it to a branch if it helps you or @⁠oishigeso. AI use: Claude Code (Claude Opus 5.5) wrote this.
Author
Owner

@⁠3L1A5-1 on GitHub · 2026-11-25 21:21 UTC · original

Follow-up to my 8 GB A/B above: #1055 + #1102 + this PR ported onto current main 68a284a, with a game run.

Branch: https://github.com/3L1A5-1/xcl/tree/port/vram-stack-1182 (each PR cherry-picked with -x, authorship kept).

  • vram.rs had moved a lot (TilePool/take_batch, #2306 level pages, #1985 canonical_va), so this PR is re-applied by hand on main's file. No redesign was needed.
  • c7c7b2c (ours): #1102 makes a texture's src a Source, but main's #2029 stream recheck still passes an address. Adds Source::fully_watched / Source::fingerprint.
  • d656862 (ours, with a test): title_backed only checked the CPU view behind a GPU-view address. Since canonical_va places an unmapped GPU-view texture at the CPU-view address, a page the title maps directly in the GPU view (physical page or the page-mapping method) read as "no memory" and the texture stayed NULL. It now asks the method mapping, then the physical page, then the CPU view. Test: a_page_the_page_mapping_method_mapped_in_a_gpu_view_is_backed.
  • On top: #640 and #1182. So the run below is the whole stack, not this PR alone.

Run (RTX 2060 SUPER 8 GB, driver 617.14, 16 GB RAM, Windows 11 26300, retail 1.0.2.1, XCL_PAGE_BUDGET_MB=3072, one 600 s run each):

main 68a284a main + #2357 #2224 #2138 this stack
ended at 91 s, CreateHeap 0x8007000e 172 s, Close 0x8007000e 457 s, device removed 0x887a0005
peak local video memory 10 537 MB 9 658 MB 8 946 MB (at the end, slow growth)
target pages 5.8 GB 5.4 GB ~3.0 GB from 98 s on

Tests on the stack: cargo test -p xcl 1229 passed, 1 failed (lower_dxil::…a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, fails the same way on main), 26 ignored.

The game reaches the intro cutscene with this stack. It then sits there at 0.2-0.5 fps on cold driver compiles of large compute programs, which is a separate problem. The removal at 457 s came with ~14.7 GB of total (local + non-local) video memory; the growth after world load is in the sparse pools.

AI-assisted: yes (Claude Code, Claude Opus 5.5) — the port, the two adaptation commits and the runs.

**@⁠3L1A5-1** on GitHub · 2026-11-25 21:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7174976890) Follow-up to my 8 GB A/B above: #1055 + #1102 + this PR ported onto current `main` `68a284a`, with a game run. **Branch:** https://github.com/3L1A5-1/xcl/tree/port/vram-stack-1182 (each PR cherry-picked with `-x`, authorship kept). - `vram.rs` had moved a lot (`TilePool`/`take_batch`, #2306 level pages, #1985 `canonical_va`), so this PR is re-applied by hand on main's file. No redesign was needed. - `c7c7b2c` (ours): #1102 makes a texture's `src` a `Source`, but main's #2029 stream recheck still passes an address. Adds `Source::fully_watched` / `Source::fingerprint`. - `d656862` (ours, with a test): `title_backed` only checked the CPU view behind a GPU-view address. Since `canonical_va` places an unmapped GPU-view texture at the CPU-view address, a page the title maps directly in the GPU view (physical page or the page-mapping method) read as "no memory" and the texture stayed NULL. It now asks the method mapping, then the physical page, then the CPU view. Test: `a_page_the_page_mapping_method_mapped_in_a_gpu_view_is_backed`. - On top: #640 and #1182. So the run below is the whole stack, not this PR alone. **Run** (RTX 2060 SUPER 8 GB, driver 617.14, 16 GB RAM, Windows 11 26300, retail 1.0.2.1, `XCL_PAGE_BUDGET_MB=3072`, one 600 s run each): | | `main` 68a284a | main + #2357 #2224 #2138 | this stack | |---|---|---|---| | ended at | 91 s, `CreateHeap` `0x8007000e` | 172 s, `Close` `0x8007000e` | 457 s, device removed `0x887a0005` | | peak local video memory | 10 537 MB | 9 658 MB | 8 946 MB (at the end, slow growth) | | target pages | 5.8 GB | 5.4 GB | ~3.0 GB from 98 s on | Tests on the stack: `cargo test -p xcl` 1229 passed, 1 failed (`lower_dxil::…a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`, fails the same way on `main`), 26 ignored. The game reaches the intro cutscene with this stack. It then sits there at 0.2-0.5 fps on cold driver compiles of large compute programs, which is a separate problem. The removal at 457 s came with ~14.7 GB of total (local + non-local) video memory; the growth after world load is in the sparse pools. AI-assisted: yes (Claude Code, Claude Opus 5.5) — the port, the two adaptation commits and the runs.
Author
Owner

@⁠jessenic on GitHub · 2026-11-25 23:24 UTC · original

A port onto a #1055 / #1102 / #640 / #1182 tree, on an RTX 5070 Ti (newer retail title of #505, Series S profile): target pages 6.5 → 2.3 GB, local video memory 17.4 → 13.6 GB against a 15.2 GB DXGI budget, and world frame rate up about a quarter. Two runs each way, same binary for the last pair.

What was ported. The port is behind a switch, XCL_TEXTURE_FOLLOW=1, and is off without it. It is built from:

  • this PR's two commits, adapted to the #1747 pool (take_batch, heap_ranges_trimmed);
  • @⁠3L1A5-1's d656862a: title_backed asks the page-mapping method (mirrors::mapped_source), then the physical page, then the CPU view, and notes changes in both views. This is needed on a tree with #1055 / #1102: without it, method-mapped GPU-view textures stay NULL;
  • @⁠Filip722's 9c553339 alias rule: a new follow starts at mapped = shared || title_backed(a).

Things done differently on this tree:

  • Only sampled textures follow. GPU-owned targets (#1182's physical-page keying) never do.
  • evict_lru (#640) unfollows what it evicts.
  • apply_backing calls budget_room once before taking tiles.
  • recheck_gpu_view_sources feeds take_changed to title_memory_changed.

The mip-order gap @⁠veyn-sudo found (tile i paired with page i) is not addressed.

Tested. RTX 5070 Ti 16 GB (driver 610.88), 32 GB RAM, Windows 11 26300, release. The tree is main 0829441 plus about 40 open PRs. Settings: XCL_HEAP_WINDOWS=1 XCL_UMA_SHADOW=1 XCL_COHERENT_MB=1024 XCL_COHERENT_HEAPS=sparse:256 XCL_PAGE_BUDGET_MB=5120, with the 1000 CS_RaytracingResolve programs refused (#2403). Scripted timed input, 480 s runs. Frame rate is counted from the world's first #101 + 60 s.

  • cargo test --release -p xcl --lib hle::d3d12x::vram -- --test-threads=1: 30 passed, 0 failed, 1 ignored. That includes update_ranges_set_only_the_changed_tiles, a new no_tile_is_skipped_by_every_heap, and d656862a's a_page_the_page_mapping_method_mapped_in_a_gpu_view_is_backed.
run XCL_TEXTURE_FOLLOW presents/s, #101 +60 to +160 s over the whole world draws/s target pages at the end local video memory at the end peak commit
B2 off 1.05 1.25 3,776 6,476 MB 16,433 MB 35,077 MB
R2 off 1.12 1.12 3,942 6,462 MB 17,437 MB 34,923 MB
F1 1 1.38 1.43 4,841 2,285 MB 13,645 MB 31,758 MB
F2 1 1.39 1.41 4,861 1,965 MB 13,856 MB 31,977 MB

R2, F1 and F2 are the same binary. B2 is an earlier build of the same tree, without two local buffer-pool changes and with fewer diagnostics.

  • At the end of the runs, about 16,000 textures followed about 90,000 pages, and about 72,000 of those pages (4.5 GB) had no video memory under them. apply_backing had mapped and unmapped about 500,000 tiles each as the title's memory changed.
  • No device removal, no crash, and no stall over 6 s with the switch on.
  • The loading-screen art (large streamed textures) looks the same with and without it. The world behind the opening credits is flat (RT resolve refused), so missing tail mips in the world would not show in these runs.

Not tested: AMD (WebIdentity1's mixed NULL/SKIP finding applies there); a run with world geometry visible, so mip-tail correctness is unchecked; the whole workspace suite.

AI use: Claude Code (Claude Opus 5.5) ported the change (a subagent wrote it from the commits named above; I have read its summary, not every line of the diff), ran the tests and runs, and wrote this comment.

**@⁠jessenic** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7177509836) **A port onto a #1055 / #1102 / #640 / #1182 tree, on an RTX 5070 Ti (newer retail title of #505, Series S profile): target pages 6.5 → 2.3 GB, local video memory 17.4 → 13.6 GB against a 15.2 GB DXGI budget, and world frame rate up about a quarter.** Two runs each way, same binary for the last pair. **What was ported.** The port is behind a switch, `XCL_TEXTURE_FOLLOW=1`, and is off without it. It is built from: - this PR's two commits, adapted to the #1747 pool (`take_batch`, `heap_ranges_trimmed`); - @⁠3L1A5-1's d656862a: `title_backed` asks the page-mapping method (`mirrors::mapped_source`), then the physical page, then the CPU view, and notes changes in both views. This is needed on a tree with #1055 / #1102: without it, method-mapped GPU-view textures stay NULL; - @⁠Filip722's 9c553339 alias rule: a new follow starts at `mapped = shared || title_backed(a)`. Things done differently on this tree: - Only sampled textures follow. GPU-owned targets (#1182's physical-page keying) never do. - `evict_lru` (#640) unfollows what it evicts. - `apply_backing` calls `budget_room` once before taking tiles. - `recheck_gpu_view_sources` feeds `take_changed` to `title_memory_changed`. The mip-order gap @⁠veyn-sudo found (tile i paired with page i) is not addressed. **Tested.** RTX 5070 Ti 16 GB (driver 610.88), 32 GB RAM, Windows 11 26300, release. The tree is `main` `0829441` plus about 40 open PRs. Settings: `XCL_HEAP_WINDOWS=1 XCL_UMA_SHADOW=1 XCL_COHERENT_MB=1024 XCL_COHERENT_HEAPS=sparse:256 XCL_PAGE_BUDGET_MB=5120`, with the 1000 `CS_RaytracingResolve` programs refused (#2403). Scripted timed input, 480 s runs. Frame rate is counted from the world's first `#101` + 60 s. - `cargo test --release -p xcl --lib hle::d3d12x::vram -- --test-threads=1`: 30 passed, 0 failed, 1 ignored. That includes `update_ranges_set_only_the_changed_tiles`, a new `no_tile_is_skipped_by_every_heap`, and d656862a's `a_page_the_page_mapping_method_mapped_in_a_gpu_view_is_backed`. | run | `XCL_TEXTURE_FOLLOW` | presents/s, `#101` +60 to +160 s | over the whole world | draws/s | target pages at the end | local video memory at the end | peak commit | |---|---|---|---|---|---|---|---| | B2 | off | 1.05 | 1.25 | 3,776 | 6,476 MB | 16,433 MB | 35,077 MB | | R2 | off | 1.12 | 1.12 | 3,942 | 6,462 MB | 17,437 MB | 34,923 MB | | F1 | **1** | **1.38** | **1.43** | 4,841 | **2,285 MB** | **13,645 MB** | 31,758 MB | | F2 | **1** | **1.39** | **1.41** | 4,861 | **1,965 MB** | **13,856 MB** | 31,977 MB | R2, F1 and F2 are the same binary. B2 is an earlier build of the same tree, without two local buffer-pool changes and with fewer diagnostics. - At the end of the runs, about 16,000 textures followed about 90,000 pages, and about 72,000 of those pages (4.5 GB) had no video memory under them. `apply_backing` had mapped and unmapped about 500,000 tiles each as the title's memory changed. - No device removal, no crash, and no stall over 6 s with the switch on. - The loading-screen art (large streamed textures) looks the same with and without it. The world behind the opening credits is flat (RT resolve refused), so missing tail mips in the world would not show in these runs. **Not tested:** AMD (WebIdentity1's mixed NULL/SKIP finding applies there); a run with world geometry visible, so mip-tail correctness is unchecked; the whole workspace suite. **AI use:** Claude Code (Claude Opus 5.5) ported the change (a subagent wrote it from the commits named above; I have read its summary, not every line of the diff), ran the tests and runs, and wrote this comment.
Author
Owner

@⁠jessenic on GitHub · 2026-11-25 23:44 UTC · original

Follow-up to my comment above: the gain there comes from mipmapped textures, where @⁠veyn-sudo's mip-order problem applies, so don't read those numbers as a safe win.

An independent review of my port confirmed two defects that matter for anyone carrying it:

  • A page that gets memory back is mapped to a recycled pool tile, and nothing uploads the texture again. On top of that, LAST_CONTENT's unchanged-hash check skips a later rewrite of the same bytes. So the texture samples another texture's old texels. In my tree I now record the textures apply_backing maps tiles for, call forget_content on them and mark them pending, so the submit uploads them whole.
  • Tile i is paired with console page i, but the console keeps the mip tail first and the PC keeps it last. So with a partly backed mip chain, tiles that hold data can be NULLed.

To avoid the second, I let only textures with one level and one slice follow. On this title that leaves almost nothing (one 480 s run, same setup as above):

  • 814 textures follow, on 3,128 pages;
  • 59 MB of pages without video memory, against about 4.5 GB in F1 / F2;
  • target pages 6.2 GB, local video memory 17.3 GB;
  • 1.11 presents/s, the same as without the switch.

The run also ended in the code-heap removal (#2403) at 437 MB of bound code.

So on this title the saving is in mipmapped textures. It needs the console page → PC subresource / tile translation, or following at whole-texture granularity: map every tile once any of the texture's pages has memory, and none when none does. I'm trying the second next; it only saves on textures with no memory at all, and I'll report how much that is.

AI use: Claude Code (Claude Opus 5.5): review workflow, run and this comment.

**@⁠jessenic** on GitHub · 2026-11-25 23:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7177986034) **Follow-up to [my comment above](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514): the gain there comes from mipmapped textures, where @⁠veyn-sudo's mip-order problem applies, so don't read those numbers as a safe win.** An independent review of my port confirmed two defects that matter for anyone carrying it: - **A page that gets memory back is mapped to a recycled pool tile, and nothing uploads the texture again.** On top of that, `LAST_CONTENT`'s unchanged-hash check skips a later rewrite of the same bytes. So the texture samples another texture's old texels. In my tree I now record the textures `apply_backing` maps tiles for, call `forget_content` on them and mark them pending, so the submit uploads them whole. - **Tile i is paired with console page i, but the console keeps the mip tail first and the PC keeps it last.** So with a partly backed mip chain, tiles that hold data can be NULLed. To avoid the second, I let only textures with one level and one slice follow. On this title that leaves almost nothing (one 480 s run, same setup as above): - 814 textures follow, on 3,128 pages; - 59 MB of pages without video memory, against about 4.5 GB in F1 / F2; - target pages 6.2 GB, local video memory 17.3 GB; - 1.11 presents/s, the same as without the switch. The run also ended in the code-heap removal (#2403) at 437 MB of bound code. So on this title the saving is in mipmapped textures. It needs the console page → PC subresource / tile translation, or following at whole-texture granularity: map every tile once any of the texture's pages has memory, and none when none does. I'm trying the second next; it only saves on textures with no memory at all, and I'll report how much that is. **AI use:** Claude Code (Claude Opus 5.5): review workflow, run and this comment.
Author
Owner

@⁠jessenic on GitHub · 2026-11-26 00:56 UTC · original · edited 2026-11-26 01:13 UTC

Follow-up 2, on the mip-order problem: following per subresource keeps nearly all of the saving. Same RTX 5070 Ti, same tree and setup as my first comment. Two runs each way.

What mode 3 does. It is a third value of my local switch, XCL_TEXTURE_FOLLOW=3, used instead of pairing tile i with page i:

  • PC side. GetResourceTiling (subresource tilings plus D3D12_PACKED_MIP_INFO) groups a texture's PC tiles per standard subresource. All packed mips form one group.
  • Console side. Each group gets the console bytes of the same subresources, from XCL's own layout (xg::Texture → gpu::tiling::Chain): tail levels [0, block_bytes), level i [levels[i].offset, levels[i-1].offset), mip 0 to slice_bytes, per slice.
  • Mapping. A group's tiles are mapped if and only if any 64 KiB page under its console bytes has title memory.
  • Fallback. A texture whose layout can't be matched falls back to following the whole texture: all its tiles are mapped if any of its pages is backed. That was 275 of about 18,500 textures here.
  • Re-upload. Each group that is turned on uploads the texture whole again, with forget_content so the unchanged-hash check can't skip it.
run mode presents/s, #101 +60 to +160 s whole world target pages at the end local video memory at the end peak commit
R2 off 1.12 1.12 6,462 MB 17,437 MB 34,923 MB
F2 1 (tile i ↔ page i, mip-unsafe) 1.39 1.41 1,965 MB 13,856 MB 31,977 MB
F4 whole texture only 1.11 1.02 4,991 MB 16,224 MB 34,798 MB
F5 3 (per subresource) 1.34 1.38 2,633 MB 14,041 MB 31,924 MB
F6 3 1.33 1.38 2,317 MB 13,617 MB 32,082 MB
F7 3, with the review fixes below 1.40 1.45 2,482 MB 13,560 MB 31,931 MB
  • At the end of F5, 27,586 of 50,656 subresource groups had no title memory under them.
  • Whole-texture following saves little because most streamed textures are partly backed: their small mips have memory, their top levels not yet. Per page, mip-unsafe, saved a little more than per subresource, but per subresource is the safe form.
  • No removal, crash or stall over 6 s in F5–F7. The loading-screen and credits art (large streamed textures) is complete and sharp.

Two defects that a review of mode 3 found, fixed for F7:

  1. Backing was applied in every vram::before_execute, including the texture-upload queue's own calls. A group turned on there was sampled from a recycled tile until the next look. It is now applied only before the title's own submit, which uploads the turned-on textures in the same pass.
  2. The page budget's room was counted over every tile of a group turning on, including tiles still held, so evict_lru was called far too often. It now counts only the missing tiles.

Not tested: AMD; the world with geometry visible (the scene behind the credits is flat with RT resolve refused); console modes beyond the three exercised by the unit test of the range formula (0x105, 0x119, 0x11B).

This is all on a local tree with #1055 / #1102 / #640 / #1182, so it is not a patch for this PR's head. Reference branch (not for merge, with local diagnostics mixed in): https://github.com/jessenic/xcl/tree/local/story5-fps (92cb999); the follow code is in vram.rs (follow_mode and below), the hooks in kernelx.rs, and the re-upload in title_textures.rs.

AI use: Claude Code (Claude Opus 5.5). Subagents wrote modes 2 and 3; a multi-agent review checked mode 3 and its findings were verified before fixing; I ran the unit tests (hle::d3d12x::vram: 36 passed, 0 failed, 1 ignored) and the runs, and wrote this comment.

**@⁠jessenic** on GitHub · 2026-11-26 00:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/1514#issuecomment-7179272755) · edited 2026-11-26 01:13 UTC **Follow-up 2, on the mip-order problem: following per subresource keeps nearly all of the saving.** Same RTX 5070 Ti, same tree and setup as [my first comment](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1514). Two runs each way. **What mode 3 does.** It is a third value of my local switch, `XCL_TEXTURE_FOLLOW=3`, used instead of pairing tile i with page i: - **PC side.** `GetResourceTiling` (subresource tilings plus `D3D12_PACKED_MIP_INFO`) groups a texture's PC tiles per standard subresource. All packed mips form one group. - **Console side.** Each group gets the console bytes of the same subresources, from XCL's own layout (`xg::Texture` → `gpu::tiling::Chain`): tail levels `[0, block_bytes)`, level i `[levels[i].offset, levels[i-1].offset)`, mip 0 to `slice_bytes`, per slice. - **Mapping.** A group's tiles are mapped if and only if any 64 KiB page under its console bytes has title memory. - **Fallback.** A texture whose layout can't be matched falls back to following the whole texture: all its tiles are mapped if any of its pages is backed. That was 275 of about 18,500 textures here. - **Re-upload.** Each group that is turned on uploads the texture whole again, with `forget_content` so the unchanged-hash check can't skip it. | run | mode | presents/s, `#101` +60 to +160 s | whole world | target pages at the end | local video memory at the end | peak commit | |---|---|---|---|---|---|---| | R2 | off | 1.12 | 1.12 | 6,462 MB | 17,437 MB | 34,923 MB | | F2 | 1 (tile i ↔ page i, mip-unsafe) | 1.39 | 1.41 | 1,965 MB | 13,856 MB | 31,977 MB | | F4 | whole texture only | 1.11 | 1.02 | 4,991 MB | 16,224 MB | 34,798 MB | | F5 | **3 (per subresource)** | **1.34** | **1.38** | 2,633 MB | **14,041 MB** | 31,924 MB | | F6 | **3** | **1.33** | **1.38** | 2,317 MB | **13,617 MB** | 32,082 MB | | F7 | **3**, with the review fixes below | **1.40** | **1.45** | 2,482 MB | **13,560 MB** | 31,931 MB | - At the end of F5, 27,586 of 50,656 subresource groups had no title memory under them. - Whole-texture following saves little because most streamed textures are partly backed: their small mips have memory, their top levels not yet. Per page, mip-unsafe, saved a little more than per subresource, but per subresource is the safe form. - No removal, crash or stall over 6 s in F5–F7. The loading-screen and credits art (large streamed textures) is complete and sharp. **Two defects that a review of mode 3 found, fixed for F7:** 1. Backing was applied in every `vram::before_execute`, including the texture-upload queue's own calls. A group turned on there was sampled from a recycled tile until the next look. It is now applied only before the title's own submit, which uploads the turned-on textures in the same pass. 2. The page budget's room was counted over every tile of a group turning on, including tiles still held, so `evict_lru` was called far too often. It now counts only the missing tiles. **Not tested:** AMD; the world with geometry visible (the scene behind the credits is flat with RT resolve refused); console modes beyond the three exercised by the unit test of the range formula (`0x105`, `0x119`, `0x11B`). This is all on a local tree with #1055 / #1102 / #640 / #1182, so it is not a patch for this PR's head. Reference branch (not for merge, with local diagnostics mixed in): https://github.com/jessenic/xcl/tree/local/story5-fps (`92cb999`); the follow code is in `vram.rs` (`follow_mode` and below), the hooks in `kernelx.rs`, and the re-upload in `title_textures.rs`. **AI use:** Claude Code (Claude Opus 5.5). Subagents wrote modes 2 and 3; a multi-agent review checked mode 3 and its findings were verified before fixing; I ran the unit tests (`hle::d3d12x::vram`: 36 passed, 0 failed, 1 ignored) and the runs, and wrote this comment.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/vram.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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