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

Open
opened 2026-11-26 21:18:43 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1705
Author: @DadaCap
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: title-hash-streaming


📝 Commits (1)

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

📊 Changes

2 files changed (+61 additions, -1 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+11 -1)
📝 runtime/test/d3d12_existing_heap_test.cpp (+50 -0)

📄 Description

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_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 3f81d46ac + #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 #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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1705 **Author:** [@DadaCap](https://github.com/DadaCap) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `title-hash-streaming` --- ### 📝 Commits (1) - [`abe3f20`](https://github.com/ubiquitarianism/leonida/commit/abe3f204294248840466afae979b534cad7b6369) d3d12: the every-byte hash of a mapped title texture reads write-combined memory through a streaming copy (RT-TITLE-HASH-WC-STREAM) ### 📊 Changes **2 files changed** (+61 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+11 -1) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+50 -0) </details> ### 📄 Description 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_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` 3f81d46ac + #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 #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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1719
No description provided.