Skip to content

kernelx: textures in a GPU view read what is mapped in its CPU view (retail movie no longer green) - #323

Closed
Sr-0w wants to merge 2 commits into
ivall:mainfrom
Sr-0w:gpu-views
Closed

Sr-0w wants to merge 2 commits into
ivall:mainfrom
Sr-0w:gpu-views

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 23, 2026 •

Copy link
Copy Markdown

Stacked on #252; only the top commit (b8537b2) belongs here.

A retail game reserves 24 GB of GPU-visible memory read-write, then right after it 24 GB more with a graphics protection (0x801). The second is the same memory as the GPU sees it. The game maps its physical pages into the first reservation only, and places the textures the CPU fills at the same offset in the second. Its movies are decoded on the CPU into the first; the R8 Y/Cb/Cr plane textures the movie shader samples are at +0x600000000, in the second.

Under XCL the second reservation is memory of its own and nothing is ever mapped into it. title_textures kept those textures in step with reserved memory, i.e. zeros, and a YUV frame of zeros is a green screen. The game's first movie was green from start to end.

A reservation with a graphics protection made right after one of the same size without one is now recorded as that one's GPU view (XCL_GPU_VIEWS=0 turns this off). For textures in a GPU view, title_textures:

  • reads pages that hold nothing from the CPU view;
  • watches the CPU view's pages;
  • uploads the texture again when those pages are written.

Before / after: the first movie, window title cropped.

before after
before after

What is in it

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.32029.2010), Ryzen 7 3700X, Windows 10.0.26300, rustc 1.100.0, release.
  • cargo test --release --workspace -- --test-threads=4: 656 passed, 0 failed, 40 ignored; no SKIPPED tests.
  • a_gpu_view_reads_its_cpu_view fails without the read_committed change (checked by disabling it) and passes with it.
  • In the retail game:
    • the log names its GPU view (0x1581e230000 (0x600000000 bytes, protection 0x801) is the GPU view of 0x1521e230000);
    • its first movie plays instead of a green screen (screenshots above);
    • a probe of the Bink frame buffers (not in this PR) showed the planes at the CPU view holding decoded data and the textures at CPU view + 0x600000000.

Regression run

main:

xcl-smoke v1
commit: 4017f8ff8faaae6007fd83910d230a027dd85a33
gpu: AMD  Radeon RX 7800 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 930 (PresentX 931)
presents per 2 s (last 3): 42 42 42
device removals: 0
crashes: 0
peak commit: 15028 MB

this PR:

xcl-smoke v1
commit: b8537b20f6a3c3cb042538d4df015a54abaed958
gpu: AMD  Radeon RX 7800 XT
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 919 (PresentX 919)
presents per 2 s (last 3): 42 42 43
device removals: 0
crashes: 0
peak commit: 15003 MB

Not tested

  • NVIDIA / Intel GPUs.
  • Other titles: none I have makes a graphics-protected reservation after a plain one of the same size. The smoke run above (60 s, no input) stops on the title screen, before the movie; the movie was checked by hand.
  • CPU access through a GPU view: this only covers what is read of it for the GPU.

AI use

  • Claude Code, Claude Opus 5.5: found the cause (probes in the Bink imports and in the page mapping), wrote the change and its tests, ran the tests and the regression runs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA

jessenic and others added 2 commits November 24, 2026 00:23
…d (retail menu text complete)

A retail game reserves 24 GB of 64 KiB pages (VirtualAlloc flags 0x20402000) and commits
2.2 GB of large pages with a graphics protection (flags 0x20003000, protection 0x2404).
Neither fits a sparse or the coherent window, so both fell through to plain memory without
MEM_WRITE_WATCH. Textures the title places there are kept in step with the memory
(d3d12x::title_textures), which relies on GetWriteWatch to see CPU writes: they were
uploaded once, empty, and never again (128+ textures in the first 45 s).

One of them is the game's 2048x2048 A8_UNORM glyph atlas, which the CPU fills as text is
laid out. Its GPU copy stayed zero, so every glyph drawn from it (the x-height letters:
a c e m n o r s u v w x z) was missing from the menus; letters drawn by the vector path
(ascenders, descenders, capitals) were fine. Found by a GPU readback of the atlas (zero)
against its CPU view (glyphs) while the menu was on screen.

The fallback VirtualAlloc now adds MEM_WRITE_WATCH for GPU-visible reservations
(MEM_GRAPHICS, MEM_LARGE_PAGES / MEM_64K_PAGES, or a PAGE_GRAPHICS_* protection) and
records them with the graphics reservations, whose ranges title_textures watches.

Test: gpu_visible_fallback_memory_is_write_watched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail game reserves 24 GB of GPU-visible memory read-write and, right
after it, 24 GB more with a graphics protection (0x801): the same memory as
the GPU sees it. It maps its physical pages into the first reservation only
and places the textures the CPU fills at the same offset in the second. Its
movie frames are decoded on the CPU into the first; the R8 plane textures
the movie shader samples are at +0x600000000 in the second.

Here the second reservation is memory of its own that nothing is ever mapped
into, so those textures were kept in step with reserved memory: zeros, and
a YUV frame of zeros is a green screen. The game's first movie was green.

A graphics-protected reservation made right after one of the same size
without a graphics protection is now recorded as that one's GPU view
(XCL_GPU_VIEWS=0 turns it off). title_textures reads the pages of a GPU view
that hold nothing from its CPU view, watches the CPU view's pages of such
textures, and uploads them again when those pages are written.

Stacked on ivall#252, which makes those reservations write-watched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA
@ethandepstein-del

Copy link
Copy Markdown

Heads-up (static check on b8537b2 vs current main db1ddb2 — not tested on Windows; no game files):

AI use: static code check of b8537b2 vs main (db1ddb2) with Antigravity (Gemini 4 Neon).

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by #283 (merged in 21b8723), which solves the same CPU-view / GPU-view mapping for the green movie with kernelx::mirrors; this branch now conflicts with it. If something here is still missing on main, a small PR on top of #283 is welcome - thanks for the analysis.

@ivall ivall closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants