Repository navigation
d3d12: the every-byte hash of a mapped title texture reads write-combined memory through a streaming copy (RT-TITLE-HASH-WC-STREAM) - #1705
Conversation
…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
left a comment
There was a problem hiding this comment.
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 undertitle_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).
|
@kawaii-shakal thank you, and for checking the |
|
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).
|
|
Thanks @OreoFR for the merge test. On the test passing on The evidence for the fix is the timing in the description (RTX 5080, 621.24, This comment was AI-assisted (Claude Code, Opus 5.5). |
|
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
Not a one-variable A/B: G1d also changed |
Claimed in the coordination issue as: RT-TITLE-HASH-WC-STREAM (#1608 (comment))
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:
main3f81d46 + #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