Skip to content

Textures: copy readable UMA bytes into owned memory - #1400

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/texture-uma-owned-copy
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/texture-uma-owned-copy

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

  • crates/xcl/src/gpu/texture.rs: checked owned UMA copy and synthetic committed, sparse and cross-window checks.

Tested

  • Windows 11 Pro x64 build 26300, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT 16 GB, driver 32.0.32029.2010; Rust 1.98.1 MSVC, debug.
  • cargo test -p xcl --lib uma_copy_is_owned_and_rejects_uncommitted_memory: 1 passed, 0 failed.
  • cargo test --workspace -- --test-threads=4 --nocapture: 752 passed, 0 failed, 41 ignored. The reported passes include tests that return early.
  • SKIPPED: test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (D3D12 debug layer unavailable).

Regression run

main:

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14837 MB

PR:

xcl-smoke v1
commit: 23da9be703ba710c5a6be61e3d40f9c62e43df83
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1680 (PresentX 1681)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14706 MB

Not tested

  • Retail title and debug-layer validation. The existing readability helper limits copies to 256 MiB. The public return type changes from a borrowed slice to Vec<u8>; there are no in-tree callers. The copy is not an atomic snapshot of concurrent guest writes.

AI use

  • Codex (GPT-6): wrote implementation and unit tests, ran validation, and drafted this description.

Avoid creating a static shared slice over guest-controlled or uncommitted memory. Validate the window and copy through the operating system.

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…#1395 in-place vtables

Integrates 16 upstream PRs (xcl-dev#1380, xcl-dev#1383, xcl-dev#1384, xcl-dev#1395, xcl-dev#1398, xcl-dev#1400,
xcl-dev#1404, xcl-dev#1405, xcl-dev#1419, xcl-dev#1420, xcl-dev#1421, xcl-dev#1423, xcl-dev#1424, xcl-dev#1427, xcl-dev#1428, xcl-dev#1429)
on top of the Linux/Proton fork, plus three Proton/vkd3d-proton fixes
caught during verification:
- Recompiler (xcl-dev#1428): flatten IO_GROUP_LIMIT early-return in compute
  shaders so vkd3d-proton v3.1 dxil-spirv accepts the emitted CFG.
- D3D12.X (xcl-dev#1395 + xcl-dev#867): skip UnadoptGuard on in-place-patched vtables
  and restore native vtables in runner::submit_list when a prior test
  adopted the singleton ID3D12Device.
- Tests: match Wine centered default in window_position_modes.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int
  + window_position_modes: 3 passed, 0 failed
- Broad sweep (present, real, sparse, clamp, dstorage, gpu_valu,
  gpu_typed_buffer): 82 passed, 0 failed, 1 ignored, 0 skipped
- 2.5 min retail title run (XCL_MEM_LIMIT=12G): 3,000+ frames at 30.0
  fps, 6.0-6.1 GB flat committed RAM, 6.4 GB local VRAM, 0 DS failures.
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 23da9be

#1530 makes the same change to gpu/texture.rs::uma_bytes (owned Vec copy instead of &'static [u8], rejecting sparse/uncommitted and cross-window spans); this PR was opened first, merges cleanly and has a test.
Note: uma_bytes has no caller in crates/ on main, so the change has no runtime effect today.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: b2b1f10
head: 23da9be
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored (second run; base alone: 2902 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), same set as base; failing: none from this PR. In the first run, the lib binary aborted (0xc0000409) on an xcl-pso-ahead-3 thread with "misaligned pointer dereference … 0x4332": the fake pipeline of graphics_first_use_carries_the_exact_serialized_recipe_identity, which #3493 fixes.
review: no correctness problem found after reading the whole diff (1 file, +39 -6). uma_bytes now returns an owned copy made with ReadProcessMemory after checking that the span is non-empty, in one UMA window and readable, instead of a &'static slice of guest-writable memory.

  • uma_bytes has no caller in crates/ on main (as the triage says), so today this changes no runtime path; only the new test reaches copy_uma_bytes.
  • uma_copy_is_owned_and_rejects_uncommitted_memory passes 10 of 10 alone (CPU only).
  • Mutations: removing the same-window check, the readable check, or both still passes the test, because ReadProcessMemory fails on the reserved pages by itself. With both removed, the cross-window case took 19.6 s instead of 0.00 s: it reserved and zeroed the whole ~4 GiB span before the read failed. So the checks stop that allocation, but nothing tests them; asserting on the error text would.
  • Cosmetic: the blank line before fn err is removed.
  • Memory: reject sparse and cross-window spans in texture::uma_bytes #1530 makes the same change (per the triage); this PR was opened first.
    performance: no runtime effect today (no caller). For a future caller, a copy per call instead of a borrow.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown

merge-check claim
head: 23da9be

@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: 23da9be
merge: clean (merged tree 71ba8083, git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> two runs on the merge. Run 1: 2909 passed, 1 failed, 51 ignored; failing: gpu::texture::tests::uma_copy_is_owned_and_rejects_uncommitted_memory, the test this PR adds (texture.rs:797, assertion failed: u.contains(sparse)); it does not exist on the base. Run 2: 2906 passed, 4 failed, 51 ignored; the PR's test passed, and the four failures are in a file this PR does not touch (hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels and the three stream_recheck_* tests that then fail on the lock it poisoned): a timing race between GPU tests that I have seen on main before, not this PR's. SKIPPED: 25 in both runs (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. The PR's test alone (cargo test -p xcl --lib uma_copy_is_owned_and_rejects_uncommitted_memory): 3 of 3 passed; the gpu::texture module with 4 threads: 6 of 6 passed.
review: whole diff read (one file, texture.rs, +39/-6). One finding that should be fixed first: the new test assumes that u.base() + 4 GiB lies in a window of the Uma it has just made (assert!(u.contains(sparse))). That holds only when Uma::new could reserve its sparse windows there; in the whole suite, where other tests make their own UMA at the same time, it did not hold in 1 of 2 runs here, so the test fails by chance and would cost other PRs their test reports. Taking the address from the Uma itself (a sparse window it reports, and skipping that part when it has none) would make it independent of what else runs. The change itself reads right to me: uma_bytes has no caller on main, so the new return type breaks nothing; the copy goes through ReadProcessMemory after the readability check, so a page that goes away in between gives an error instead of a fault; a span that crosses windows or is empty is refused. The first check on this head, on another machine, had no failure.
performance: none by default: the function has no caller. A caller would now pay a copy of the texture (up to 256 MiB by the readability helper's limit) instead of borrowing it.
verdict: not yet: the test this PR adds fails by chance in the whole suite (u.contains(sparse), 1 of 2 runs with --test-threads=4 on this machine)
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.

@github-actions github-actions Bot added checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look goal:world-load Bears on the retail title getting past world loading gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants