Skip to content

[upstream #1075] D3D12.X: the present copy is XCL's own work and does not look again - #80

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1075
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1075

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

present_now (crates/xcl/src/hle/d3d12x/present.rs) submits its copy to the swap chain with q.ExecuteCommandLists, which is XCL's own hook. So it came back into q_execute_command_lists → title_textures::refresh outside own_work. As a result, every presented frame paid a second full look at the title's memory: GetWriteWatch over every watched range, then a hash of each dirty texture. That look is only for the title's own work. The copy is now submitted as own_work, the same way XCL's texture uploads are.

Why skipping that look can't miss a write the present needs: the copy reads only the presented resource.

  • Render targets live in video memory (vram::place) and are not kept in step with title memory, so no look could bring a CPU write to them.
  • Anything else the CPU wrote since the title's last submit stays dirty: GetWriteWatch resets its bits only during a look. It is uploaded before the title's next ExecuteCommandLists, which is the first work that can read it.
  • A presented resource that is kept in step with title memory (title_textures::address knows it) still gets the look, as before.
  • The look also made the queue wait for the pages mapped since its last work (vram::before_execute). The copy now calls that itself inside own_work, as XCL's other own-work submits do, so skipping the look never skips that wait.
  • The look also ran sparse::before_execute (CPU writes into mapped sparse tiles) and recheck_gpu_view_sources. The copy skips both; the title's next ExecuteCommandLists runs them. The copy reads only the presented resource, which is either GPU-owned (vram::place, no sparse window) or kept in step (it then gets the look). That no title presents a sparse-window resource that is not kept in step is a hypothesis, not measured.

Conflicts with open PRs: xcl-dev#674 (triple-buffer Presenter) and xcl-dev#711 (draft, its 2-buffer subset) change the same q.ExecuteCommandLists line in present.rs (they move it into present_frame_on). Whichever lands second re-applies this wrapper: keep their present_frame_on and p.queue, and wrap only the ExecuteCommandLists in the own_work conditional (after vram::before_execute); the meaning is the same. No code dependency on xcl-dev#693, xcl-dev#455, xcl-dev#562 or xcl-dev#786.

What is in it

  • crates/xcl/src/hle/d3d12x/present.rs: the copy's ExecuteCommandLists runs inside title_textures::own_work unless the presented resource is kept in step, after vram::before_execute (+13/−1).
  • crates/xcl/src/hle/d3d12x/title_textures.rs: gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes now also checks that a refresh inside own_work uploads nothing, and that the next refresh uploads the write. That is the rule the change relies on. The test checks existing behaviour, so it passes without the present.rs change too. Testing the present path itself would need a window and a swap chain.

Tested

Regression run

The title's first minute varies a lot between runs on this machine (earlier runs gave 300 to 1500 frames); these eight runs all landed in the same mode. After an unmeasured warm-up of each build, with no other build or title run on the machine, the runs alternated: head 446, main 449, main 446, head 447 frames; no device removals or crashes. The second pair is shown.

main:

xcl-smoke v1
commit: 6efdabcdaac93ce5cc123a85e85deba5d49cb294
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 446 (PresentX 452)
presents per 2 s (last 3): 52 48 0
device removals: 0
crashes: 0
peak commit: 15273 MB

This PR:

xcl-smoke v1
commit: 0f77bf18498dae6497b539db2b5ded8ed96a744d
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 447 (PresentX 452)
presents per 2 s (last 3): 52 48 0
device removals: 0
crashes: 0
peak commit: 15269 MB

Not tested

  • NVIDIA, Intel, RDNA3/4.
  • Other titles. Only one retail title, and only its first minutes (menus and account prompt).
  • A title that presents a texture its CPU writes after its last submit. The kept-in-step check covers it, but no title I have does this.
  • The submit-thread gain with this commit on main alone: there, the render thread hides it.

AI use

  • Claude Code, Claude Opus 5.5 (claude-opus-5-5): wrote the change, the test, the initial profiles, and the initial PR description.
  • Antigravity, Gemini 4 Neon: ran the full workspace test suite, isolated test reruns, and alternating 60 s regression smoke runs on the earlier head 4d0a00a, verified scripts/pr_check.py --local, and updated this description.
  • Claude Code, Claude Sonnet 5.5 (claude-sonnet-5-5): rebased the branch onto main 6efdabc, reran the suite and the smoke runs above on 0f77bf1, and updated this description.

Mirror of xcl-dev#1075 (auto-synced, do not edit).

present_now submits its copy with q.ExecuteCommandLists, which is XCL's
own hook: it re-entered q_execute_command_lists -> title_textures::refresh
outside own_work, so every presented frame paid a second full look at
the title's memory (GetWriteWatch over every watched range, then a copy
of each dirty texture to hash it). On a retail title at 125 s that second
look (refresh reached from present_now) was 26.7 % of the submit thread,
profiled on f44cc79 (xcl-dev#693's head), where the submit thread is the limit.

The copy reads only the presented resource. Render targets are the GPU's
(vram::place, not kept in step), so no look can bring a CPU write to
them; what the CPU wrote elsewhere since the title's last submit stays
dirty (GetWriteWatch resets only in a look) and is uploaded before the
title's next ExecuteCommandLists, the first work that can read it. A
presented resource that is kept in step with title memory still gets
the look, as before. The skipped look also made the queue wait for the
pages mapped since its last work (vram::before_execute); the copy now
calls it itself, as XCL's other own_work submits do.
The look also runs sparse::before_execute (CPU writes into mapped sparse
tiles); the copy skips it, and the title's next submit does it. (Hypothesis:
no title presents a sparse-window resource that is not kept in step.)

The title-texture GPU test now checks that a refresh under own_work
uploads nothing and the next refresh uploads the write.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1075 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1075 branch November 25, 2026 00:11
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.

2 participants