Skip to content

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

Open
iggyvilla wants to merge 1 commit into
xcl-dev:mainfrom
iggyvilla:xcl-present-own-work
Open

iggyvilla wants to merge 1 commit into
xcl-dev:mainfrom
iggyvilla:xcl-present-own-work

Conversation

@iggyvilla

Copy link
Copy Markdown
Contributor

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: #674 (triple-buffer Presenter) and #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 #693, #455, #562 or #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

  • AMD Radeon RX 6650 XT (RDNA2), driver 32.0.21045.29003, Ryzen 7 5700X, Windows 10.0.26300, rustc 1.100.0. Debug for the tests; release for the smoke runs (with CARGO_PROFILE_RELEASE_DEBUG=1 for the profiles).

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 0f77bf1: 724 passed, 3 failed, 41 ignored, 0 SKIPPED. The 3 failures are the ones already on main:

  • Submit-thread profile of a retail title past the account prompt: a 20 s sample at 125 s, the same steps on both builds (taken on 1d22c03, before adding the vram::before_execute wait):

    f44cc79 f44cc79 + this commit
    submit thread 84 % of a core 86 % of a core
    refresh reached from present_now (hash + GetWriteWatch + VirtualQuery) 26.7 % none sampled
    fps, mean of the 5 s readings 63–125 s 9.8 10.6
    • The submit thread stays saturated: it does its other looks more often instead, and the time goes to frames. These are single runs. A second pair of runs came up in another state of the title (25.3 against 27.5 fps), where the submit thread was not among the busiest, so it says nothing about this change.
    • On the main base alone (dd2ae9a against 1d22c03), one run each gave 5.8 and 7.1 fps. That is within this title's run-to-run noise.

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.

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>
@fromthemoonx

Copy link
Copy Markdown

NVIDIA run, since Not tested lists NVIDIA.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug
  • Exact head 0f77bf18498dae6497b539db2b5ded8ed96a744d (on its base 6efdabc), clean worktree: cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 727 passed, 0 failed, 41 ignored (lib 685 / 0 / 21)
  • Merged onto current main 47efa2e (no conflict): the same command gives 741 passed, 0 failed, 41 ignored
  • The PR adds no test, so I repeated the path it changes: the test title presents through PresentX in e2e. cargo test -p xcl --test e2e -- --test-threads=1 on the merged tree, 10 runs: 10 of 10 passed (test_title_runs_and_game_folder_is_untouched, test_title_draws_with_a_root_signature_under_the_debug_layer, and the third e2e test).
  • D3D12 debug layer: the test title's XCL_D3D12_DEBUG=1 run logs the same set of debug-layer errors and warnings on the merged tree as on main. Nothing new from submitting the present copy as own_work.
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • XCL_SAMPLE_* not set

Not tested

  • The saving itself: XCL's log here has write-watch timing only for the sparse windows, not for title_textures::refresh, and there's no retail title. So the second look per present going away is not measured on this machine.
  • A presented resource that is kept in step with title memory (the case that still gets the look); release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests on the machine above and wrote this report from the logs.

@thehollowedone

Copy link
Copy Markdown

I measured the actual windowed PresentX copy at 0f77bf1 on Windows 11 with an RTX 3080 Ti (621.35) and Graphics Tools. I used the stock synthetic title with a scratch counter after the refresh guard and another after the write-watch scan.

For its direct PresentX copy from a DEFAULT render target, restoring the old submit path in the same binary gave one refresh and one write-watch scan. The PR path gave zero of each. Both runs passed the debug-layer e2e test and logged the same D3D12 message IDs and counts. Neither reported device removal.

This measures scan count for the synthetic render target. It leaves CPU time and the path for textures kept in step with title memory unmeasured. AI-assisted. Codex (GPT-6) added the scratch counters and ran the comparison.

@thaqiart139-alt

Copy link
Copy Markdown

Test report for this PR's head 0f77bf1, merged into main 689f2db (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card.

Tested

  • GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with XCL_ADAPTER.
  • System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
main 689f2db with this PR
RTX 5070 971 passed, 4 failed, 45 ignored 971 passed, 4 failed, 45 ignored
Radeon iGPU 974 passed, 1 failed, 45 ignored 974 passed, 1 failed, 45 ignored
  • This PR adds no failure. The failures are the same on main, from Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679's new fuzz tests, and both are already reported on Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679:
    • RTX 5070: fuzz_validate_and_gpu_0 to _3 (CreateComputePipelineState: 0x8007000E)
    • iGPU: fuzz_validate_and_gpu_1 (seed 540: res[833] = 0x7, CPU 0x6)
  • This is an NVIDIA run, which the description lists as not tested.
  • The three tests the description saw fail on its main pass here on both GPUs, on main and with this PR: placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory.
SKIPPED tests (the same on main and with this PR)
  • RTX 5070:
    • no wave64:
      • gpu::recomp::lower::tests: a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu
      • gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu, and the wave64 cases of its f16 / f32 / f64 / integer_programs_on_the_gpu
      • gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
    • the wave32 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused ("its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's")
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is off)
  • Radeon iGPU:
    • no mesh shaders: gpu::dxil::geometry_tests::gpu_geometry_direct_records, emitted_ms_primitive_attribute_reaches_the_pixel_shader, emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip, gpu_geometry_mode_es_gs_strip_with_branches, gpu_mesh_mode_two_passes
    • the wave32 and wave64 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused, as above
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off)

Not tested

  • a title run, Intel, RDNA3 / RDNA4; other GPUs; Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

5 participants