Skip to content

d3d12: the every-byte hash of a mapped title texture reads write-combined memory through a streaming copy (RT-TITLE-HASH-WC-STREAM) - #1705

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
DadaCap:title-hash-streaming
Nov 27, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
DadaCap:title-hash-streaming

Conversation

@DadaCap

@DadaCap DadaCap commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-TITLE-HASH-WC-STREAM (#1608 (comment))

What and why

refresh_title_textures hashes every byte of a mapped title texture of up to 4 MiB each sixth pass (every_byte()), with ordinary loads straight from the title's pages. In a real boot those pages are write-combined, and ordinary loads from write-combined memory are not cached; copy_guarded in the same file says so and reads them with MOVNTDQA for that reason. The hash did not.

Measured on the intro (a temporary timer around hash_guarded, not in this PR): one every-byte hash takes 36 ms on average and up to 78 ms over 4,096 KiB, so about every sixth pass spends one to two frames of a title that paces itself for 30 Hz. The title then presents 24 frames a second, the launch movie's sound stutters and its picture jumps ahead and back.

The change: when the texture's memory is write-combined, the every-byte hash reads it through copy_guarded's streaming copy into the scratch buffer the fill of the same texture already uses, and hashes the copy. Ordinary pages and the sampled hash are untouched. 12 lines.

Measured

Native Windows 11, RTX 5080 16 GB, NVIDIA 621.24, 64 GB, own 1.0.2.1, MSVC RelWithDebInfo with SDL3. Tree for both columns: main 3f81d46 + #1558 + #1631 + #1694 (without #1694 this machine does not get past the landing screen). LEONIDA_ARENA_MB=2048 LEONIDA_FRAME_PACING=1 LEONIDA_PRESENT_NO_TEAR=1, keyboard pad with A every 5 s from 30 s, an existing save.

before with this change
title texture hash time printed by the runtime, intro and landing screen 15.3, 13.2, 15.2 ms/pass 3.5, 3.4, 3.3 ms/pass
every-byte hashes in the first 10 s window (timer) 60, 36.3 ms each, longest 65.3 ms 70, 1.1 ms each, longest 3.0 ms
passes that spend over 33 ms hashing, per 10 s window (timer) 30 of 182, 34 of 210, 40 of 244, 41 of 248 0 of 211, 0 of 257, 0 of 306, 0 of 309
presents from 8 s to 30 s (a capture every 30 presents) 510, 23.2 a second 630 and 600 in two runs, 28.6 and 27.3 a second
presents from 8 s to 60 s 1,260, 24.2 a second 1,530 and 1,470, 29.4 and 28.3 a second
the launch movie, watched by a person sound stutters, the picture jumps ahead and back plays cleanly

In the "before" window all 1,151 hashes were of write-combined memory. The two mapped textures there are 2048x2048 and 1024x1024, format 65.

Tested

  • New case in d3d12_existing_heap_test: a mapped 1024x512 R8 plane (above 256 KiB, so hashed by samples, and under 4 MiB, so hashed in full each sixth pass) in ordinary pages and in write-combined ones. One byte is changed 1,000 bytes into a page, where the sampled hash does not look, and must reach the GPU within 14 submissions. Both pass.
  • Negative check: with the every-byte hash switched off, both new cases fail at changed == 1.
  • d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch pass on the same GPU.
  • The real boot, two runs with the change, as in the table; the second ran through the story load to the world phase and ended there on the title's hang watchdog at 146.8 s, the stop described in finding: on main the world-start device loss is the 64 MiB title-window cap (LEONIDA_TITLE_WINDOWS_MB); raising it gets past it #1537.

Not done, not tested

  • The sampled hash still reads write-combined memory in place: about 0.5 ms a texture here, 3.3 to 3.5 ms a pass in total. I left it; it is no longer a frame.
  • AMD, Intel, Linux: not run. copy_guarded's streaming path is the existing one.
  • I did not look at whether the title's pages could be read from a cached view instead; that would be a different change.

Counters, switch names and timings only; no game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

…ined memory through a streaming copy (RT-TITLE-HASH-WC-STREAM)

refresh_title_textures hashes every byte of a mapped texture of up to 4 MiB each sixth pass, straight from the
title's pages. In a real boot those pages are write-combined, where ordinary loads are not cached: on the intro one
such hash took 36 ms on average and up to 78 ms, so every sixth pass cost one to two frames and the title presented
24 frames a second where it paces itself for 30. The bytes now come through copy_guarded's streaming copy, as the
fill of the same texture already does, and the copy is hashed: 0.4 to 1.1 ms.

The test places a mapped plane in ordinary and in write-combined pages and changes one byte the sampled hash does not
cover.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@kawaii-shakal kawaii-shakal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (read-only, not run). The measurements make the case well (0 of ~300 passes over 33 ms afterwards).

  • Reusing title_tiled_ is safe: the fill path (d3d12_vulkan_device.cpp ~11047) always copies the texture into it again before it uses it, and both run under title_texture_mutex.
  • The new test's negative check, failing with the every-byte hash off, shows the case is real.

One possible follow-up, not for this PR: when the every-byte hash finds a change, the fill streams the same 4 MiB into the same buffer again. Passing a flag that the scratch already holds this pass's bytes would save the second copy on the passes that upload.

AI-assisted review (Claude Code, Claude Opus 5.5).

@DadaCap

DadaCap commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@kawaii-shakal thank you, and for checking the title_tiled_ reuse against the fill path. The second copy on the passes that upload is a fair point: at 4 to 5 GiB/s it is about 1 ms for a 4 MiB texture, on at most one pass in six, so I left it out to keep this change to the hash alone. I am not claiming that follow-up; it is free for whoever wants it. AI-assisted (Claude Code).

@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Merge test for the #2464 campaign on an 8 GB laptop (profile M), done for the author. Main ec91d69 was merged without conflict, in one tree together with #1705, #1694 and #1284, which touch different code. The numbers were recomputed from the raw logs. AI-assisted (Claude Code, Claude Opus 5.5).

RUN dada3 | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        main ec91d695c + #1705 (abe3f2042) + #1694 (3768be502) + #1284 (7358f3261), merged cleanly | shaders: main translation + #2447 (one-lane) pack
MACHINE:     RTX 4070 Laptop 8 GB, laptop (profile M) | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented + DEVIATIONS: ASYNC_PIPELINES=1 ASYNC_MIN_BYTES=1048576 VALUE_WAIT_TIMEOUT_MS=30000 MAP_READBACK=1 DEVICE_TYPE=6 ARENA_MB=4095 DEVICE_FAULT=1
OS/DRIVER:   TdrDelay 60
TARGET:      regression check against regA (main ec91d695c, same recipe and caches) | PREDICTED: world reached, no loss
MEASURED:    world entry ~237 s (regA 223 s) | 0 device lost, 0 exceptions (regA 0 / 0) | gpu-stall lines 2 (regA 10)
END:         stopped by our script 56 s after world entry (t=293 s): the known display stop after world entry is the same on main
CACHES:      warm | RUN 1 of 1
VERDICT:     no regression seen (n=1)
  • d3d12_existing_heap_test from this head: passed (exit 0). Built against main ec91d69, it also passes (exit 0), so here it does not show the case this PR fixes. A case that fails on main would make the fix provable.

@DadaCap

DadaCap commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @OreoFR for the merge test. On the test passing on main too: that is expected here. This pull request does not change what the every-byte hash computes, only how it reads write-combined pages: through copy_guarded's streaming copy instead of ordinary loads. The new cases in d3d12_existing_heap_test check that this new path still sees a changed byte, so they guard against a regression in the change. They cannot fail on main, which hashes the same bytes, only more slowly.

The evidence for the fix is the timing in the description (RTX 5080, 621.24, MEASURED): title texture hash time 13-15 ms → 3.3-3.5 ms a pass, every-byte hashes 36 ms → 1.1 ms each, and 24 → 28-29 presents a second on the intro. The negative check in the description is the closest thing to a failing case: with the every-byte hash off, both new cases fail.

This comment was AI-assisted (Claude Code, Opus 5.5).

@Tyrannys

Copy link
Copy Markdown
Contributor

Profile M data point with #1705 and #2012 applied together (RTX 4070 SUPER 12 GB, NVIDIA 621.01, Windows 11). Counts only. AI-assisted (Claude Code).

The textures submit phase (Device::refresh_title_textures) after 900 s, means per submission:

Not a one-variable A/B: G1d also changed LEONIDA_KEYBOARD_PAD (always -> 1), LEONIDA_CAPTURE_LIMIT (40 -> 80) and ran on caches one run warmer, and the two pull requests are not separated. One run each, PROVISIONAL; refuted if the same tree without the two pull requests also shows tens of ms. Not run: #1705's new case in d3d12_existing_heap_test, because that test file does not compile in this local stack for an unrelated earlier merge; title_texture_refresh_test (#2012) passes.

RUN c3-G1d | 2026-11-27 | Tyrannys | AI-assisted: Claude Code
BASE:        2859d0c9b + #2233 #2275 #2418 #2440 #2020 #2166 #2432 #2224 #2179 #2228 #1851 #1882 #2260 #2267 #1592 (+ local test fix) + #443 + #1705 + #2012 | shaders: library re-translated with w64-one-lane-fold; DirectStorage predictor profile regenerated after 2a491668a
MACHINE:     RTX 4070 SUPER 12 GB, desktop | NVIDIA 621.01 | Windows 11 | 64 GB
RECIPE:      OreoFR's world recipe (#1608, 2026-11-27 08:23) + DEVIATIONS: COMPILE_GATE=0 PIPELINE_PREWARM_ORDER=1 SHADOW_ALIAS_MS=1000 SKIP_COMPUTE=<1,009 ray-hit programs> RT_AS=off DEVICE_FAULT=1 TITLE_HUD=1 MEM_PROBE=60 FRAME_PACING=1 PRESENT_NO_TEAR=1 KEYBOARD_PAD=1 CAPTURE_LIMIT=80 | precompile: yes, library programs except the skip list
OS/DRIVER:   TdrDelay=60
TARGET:      textures phase ms per submission after 900 s; how far | PREDICTED: textures at least halved vs c3-G1c (474.6); < 1 frame/s; autosave prompt or gameplay
MEASURED:    full 1,804 s, PresentX 3,191 ok / 0 failed, 11.0 M D3D12 calls, 0 decompression errors, 0 device stalls, 0 presses besides the script (235)
             world-start pipeline burst ~270 s; letterboxed near-white cutscene from ~600 s; by ~1,200 s the game's own control hint
             ("move around / move the camera") over a screen that is almost all white (mean RGB 252-254) to the end
             after 900 s (means): textures 24.0 ms per submission (c3-G1c 474.6), heaps 12.8, shadows 19.7; 7.7 submissions/s; 0.30 frames/s
             process dedicated / shared (MiB, means): burst+0..180 s 10,777 / 1,446; +180..240 s 10,695 / 1,696; +240 s..end 10,759 / 2,345
             (shared max 7,107 after a +5,120 MiB rise at ~1,664 s); HUD VRAM 10.0-13.6 GB used vs a 10.7 GB budget
             3D engine mean: 8.4% (0..300 s), 9.8%, 59.9%, 29.8%; compute 0.0%, copy 0.0-1.0%
             skip list: 250 of the 1,009 skipped programs were requested, each first by ~600 s, none first requested during gameplay;
             their dispatches are dropped. Loop-guard hits: not observable (the translator's guard exits silently, no counter)
END:         time limit
CACHES:      warm (journal + session/heavy caches after G1b, G1b-ctl, G1c) | RUN 1 of 1
INSTRUMENTS: TITLE_HUD, MEM_PROBE=60, DEVICE_FAULT=1, Windows GPU performance counters every 10 s, gputaskman --json every 30 s
VERDICT:     prediction held (textures down ~95%; 0.30 frames/s; gameplay control reached, picture white)

@aslan2142
aslan2142 merged commit 75151be into ProjectLeonida:main Nov 27, 2026
5 of 12 checks passed
aslan2142 added a commit that referenced this pull request Nov 27, 2026
d3d12: merge bundle of eight open runtime PRs, conflicts fixed (#2020 #2166 #1851 #2465 #1705 #2117 #2012 #407)
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