d3d12: the every-byte hash of a mapped title texture reads write-combined memory through a streaming copy (RT-TITLE-HASH-WC-STREAM) #1705
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1705"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-25T08:49:21Z.
Claimed in the coordination issue as: RT-TITLE-HASH-WC-STREAM (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157390683)
What and why
refresh_title_textureshashes 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_guardedin 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:
main3f81d46ac+ #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.title texture hash timeprinted by the runtime, intro and landing screenIn the "before" window all 1,151 hashes were of write-combined memory. The two mapped textures there are 2048x2048 and 1024x1024, format 65.
Tested
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.changed == 1.d3d12_existing_heap,d3d12_existing_heap_no_write_watch,d3d12_existing_heap_write_watchpass on the same GPU.Not done, not tested
copy_guarded's streaming path is the existing one.Counters, switch names and timings only; no game data. AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T09:45:36Z.
Review: COMMENTED
Review (read-only, not run). The measurements make the case well (0 of ~300 passes over 33 ms afterwards).
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 undertitle_texture_mutex.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).
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-25T10:34:05Z.
@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).Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T19:04:17Z.
Merge test for the #2464 campaign on an 8 GB laptop (profile M), done for the author. Main
ec91d695cwas 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).d3d12_existing_heap_testfrom this head: passed (exit 0). Built against mainec91d695c, 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.Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-27T20:20:07Z.
Thanks @OreoFR for the merge test. On the test passing on
maintoo: that is expected here. This pull request does not change what the every-byte hash computes, only how it reads write-combined pages: throughcopy_guarded's streaming copy instead of ordinary loads. The new cases ind3d12_existing_heap_testcheck that this new path still sees a changed byte, so they guard against a regression in the change. They cannot fail onmain, 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).
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T20:48:02Z.
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
texturessubmit 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 ind3d12_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.