texture: 8-lane hardware AES-NI texture digest #442

Open
Paliton wants to merge 2 commits from Paliton/Darner-fork:pr/aes-texture-digest into Main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: texture::digest (crates/darner-gpu/src/texture.rs) hashes texture payloads in software using 4 lanes of 64-bit folded multiplications over 64-byte chunks on every texture change check.

Ports the 8-lane hardware AES-NI 128-bit digest (digest_aes, 128 bytes/iteration via _mm_aesenc_si128) from ProjectLeonida/mandy 640b0d0df (PR #2802, bobcatchris, GPL-3.0), runtime-dispatched via is_x86_feature_detected!("aes") with the existing digest_folded kept as fallback.

How it was tested

  • Tested revision: 5d5f4f4 (based on f3840d7)

  • Commands and results:

    • cargo xtask policy -> asset policy: 555 files ok
    • cargo clippy --workspace --all-targets --locked -- -D warnings -> ok (0 warnings)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings -> ok (0 warnings)
    • cargo test -p darner-gpu --lib --locked a_digest_tells_bytes_apart -- --test-threads=1 -> 1 passed; 0 failed (verifies length sensitivity, single-byte flips, and adjacent byte swaps across 0..400 bytes)
    • cargo test --workspace --locked -> all non-flaky tests pass (1772/1773 in darner-gpu; the single failure is the pre-existing gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback flake fixed by #261)
  • Changes a default: yes (automatic AES-NI dispatch on x86_64 CPUs with AES-NI; Digest is in-memory only and not persisted across runs).

  • A/B result:

    1. Isolated CPU microbenchmark (rustc -O, Intel Core i7-14700KF, 2 runs):

      Payload size A (digest_folded) B (digest_aes)
      1 MiB (512 iters) 21.1–21.3 us/MiB (49.3–49.8 GB/s) 8.4–9.0 us/MiB (116.9–124.2 GB/s, 2.35×–2.52×)
      4 MiB (128 iters) 21.3–23.0 us/MiB (45.6–49.3 GB/s) 12.8–13.0 us/MiB (80.9–82.0 GB/s, 1.64×–1.80×)
      16 MiB (32 iters) 28.7–29.2 us/MiB (36.0–36.5 GB/s) 16.5–18.1 us/MiB (57.9–63.5 GB/s, 1.61×–1.74×)
    2. In-game A/B (2 runs each, 240 s automated opening sequence, --profile diag --features diagnostics, pure play-defaults, RTX 5070 12 GB + i7-14700KF, Series X, 1440p -> 4K, DLSS off, FG off, RT off). Because this rig is GPU-bound and steady-state tex_refresh_ms is already <0.05 ms/frame on an i7-14700KF, full-run FPS is at parity within run-to-run variance, with slightly lower prep_ms and zero stale/corrupted textures:

      Metric (2 runs each) A (off, f3840d7) B (on, 5d5f4f4)
      Total frames (240 s) 5,367 / 5,537 (mean 5,452) 5,466 / 5,416 (mean 5,441, parity)
      Window 3 (180-235 s) fps (mean) 21.52 / 22.16 (21.84 fps) 22.61 / 21.82 (22.22 fps, +0.38)
      Window 3 median frame time 45.26 / 43.89 (44.58 ms) 43.06 / 44.49 (43.77 ms, -0.80 ms)
      Window 3 prep_ms (mean) 13.09 / 12.38 (12.74 ms) 12.83 / 12.05 (12.44 ms, -0.30 ms)
      Window 3 p95 / p99 frame time 47.1 / 94.3 ms (mean) 46.3 / 91.5 ms (mean)
  • Gates run on that revision: all three AGENTS.md gates + cargo xtask policy on 5d5f4f4.

  • Gameplay, when relevant: RTX 5070 12 GB + i7-14700KF, Series X, 1440p -> 4K, DLSS off, FG off, RT off. Texture uploads/refreshes clean, zero stale textures.

  • Hardware dependence: x86_64 CPUs with AES-NI (safe digest_folded fallback elsewhere).

  • Coverage gaps: in-game A/B was run on a GPU-bound system; larger in-game CPU savings would show on slower CPUs or heavier texture-streaming scenes.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #282, #50 (also touch crates/darner-gpu/src/texture.rs, non-overlapping lines)
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `texture::digest` (`crates/darner-gpu/src/texture.rs`) hashes texture payloads in software using 4 lanes of 64-bit folded multiplications over 64-byte chunks on every texture change check. Ports the 8-lane hardware AES-NI 128-bit digest (`digest_aes`, 128 bytes/iteration via `_mm_aesenc_si128`) from `ProjectLeonida/mandy` `640b0d0df` (PR #2802, `bobcatchris`, GPL-3.0), runtime-dispatched via `is_x86_feature_detected!("aes")` with the existing `digest_folded` kept as fallback. ## How it was tested - Tested revision: `5d5f4f4` (based on `f3840d7`) - Commands and results: - `cargo xtask policy` -> `asset policy: 555 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings` -> ok (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` -> ok (0 warnings) - `cargo test -p darner-gpu --lib --locked a_digest_tells_bytes_apart -- --test-threads=1` -> `1 passed; 0 failed` (verifies length sensitivity, single-byte flips, and adjacent byte swaps across 0..400 bytes) - `cargo test --workspace --locked` -> all non-flaky tests pass (`1772/1773` in `darner-gpu`; the single failure is the pre-existing `gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` flake fixed by #261) - Changes a default: yes (automatic AES-NI dispatch on x86_64 CPUs with AES-NI; `Digest` is in-memory only and not persisted across runs). - A/B result: 1. **Isolated CPU microbenchmark** (`rustc -O`, Intel Core i7-14700KF, 2 runs): | Payload size | A (`digest_folded`) | B (`digest_aes`) | |---|---|---| | 1 MiB (512 iters) | 21.1–21.3 us/MiB (49.3–49.8 GB/s) | **8.4–9.0 us/MiB (116.9–124.2 GB/s, 2.35×–2.52×)** | | 4 MiB (128 iters) | 21.3–23.0 us/MiB (45.6–49.3 GB/s) | **12.8–13.0 us/MiB (80.9–82.0 GB/s, 1.64×–1.80×)** | | 16 MiB (32 iters) | 28.7–29.2 us/MiB (36.0–36.5 GB/s) | **16.5–18.1 us/MiB (57.9–63.5 GB/s, 1.61×–1.74×)** | 2. **In-game A/B** (2 runs each, 240 s automated opening sequence, `--profile diag --features diagnostics`, pure `play-defaults`, RTX 5070 12 GB + i7-14700KF, Series X, 1440p -> 4K, DLSS off, FG off, RT off). Because this rig is GPU-bound and steady-state `tex_refresh_ms` is already `<0.05 ms/frame` on an i7-14700KF, full-run FPS is at parity within run-to-run variance, with slightly lower `prep_ms` and zero stale/corrupted textures: | Metric (2 runs each) | A (off, `f3840d7`) | B (on, `5d5f4f4`) | |---|---|---| | Total frames (240 s) | 5,367 / 5,537 (mean 5,452) | 5,466 / 5,416 (mean 5,441, parity) | | Window 3 (180-235 s) fps (mean) | 21.52 / 22.16 (21.84 fps) | 22.61 / 21.82 (22.22 fps, +0.38) | | Window 3 median frame time | 45.26 / 43.89 (44.58 ms) | 43.06 / 44.49 (43.77 ms, -0.80 ms) | | Window 3 `prep_ms` (mean) | 13.09 / 12.38 (12.74 ms) | 12.83 / 12.05 (12.44 ms, -0.30 ms) | | Window 3 p95 / p99 frame time | 47.1 / 94.3 ms (mean) | 46.3 / 91.5 ms (mean) | - Gates run on that revision: all three `AGENTS.md` gates + `cargo xtask policy` on `5d5f4f4`. - Gameplay, when relevant: RTX 5070 12 GB + i7-14700KF, Series X, 1440p -> 4K, DLSS off, FG off, RT off. Texture uploads/refreshes clean, zero stale textures. - Hardware dependence: x86_64 CPUs with AES-NI (safe `digest_folded` fallback elsewhere). - Coverage gaps: in-game A/B was run on a GPU-bound system; larger in-game CPU savings would show on slower CPUs or heavier texture-streaming scenes. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #282, #50 (also touch `crates/darner-gpu/src/texture.rs`, non-overlapping lines) - Replaces or overlaps: none found
Contributor

Test report, together with #440 (both merged on A): no measurable change in this scene, and nothing wrong on screen.

PC: RTX 4080 16 GB (driver 621.40), i7-13700K (24 logical processors), 64 GB, Windows 11 26300. Series X profile, 1440p with DLSS Quality, frame generation off, hardware ray tracing on, Reflex off, DARNER_ALIAS_SHARE=1, DARNER_D3D12_BACKGROUND=0.
Method: the opening scene of one save, entered the same way every run (no input after the start screen); medians of per-second values from the host log in three 45-second windows from the moment the world appears; warm pipelines; one run each. A = main 47d21cd + #334, #337, #457, #274, #397, #312, #304, #303, #438, #439.

A A + #440 (f24eeae) + #442 (c971d13)
frame time, ms 25.3 / 25.2 / 24.8 25.3 / 25.1 / 24.9
landing: merging what was fetched, ms a frame (all threads) 1.37 / 1.39 / 1.40 (3.34 / 3.39 / 3.37) 1.34 / 1.35 / 1.34 (3.28 / 3.32 / 3.25)
texture refreshes, ms a frame (all threads) 1.0 / 1.3 / 1.3 1.5 / 1.2 / 1.3

The merge got about 0.05 ms a frame (3%) faster, within the spread; the scene is static, so little is merged or re-hashed.

Not tested: more than one run each, scenes with streaming (driving), other CPUs.

Test report, together with #440 (both merged on A): no measurable change in this scene, and nothing wrong on screen. **PC:** RTX 4080 16 GB (driver 621.40), i7-13700K (24 logical processors), 64 GB, Windows 11 26300. Series X profile, 1440p with DLSS Quality, frame generation off, hardware ray tracing on, Reflex off, `DARNER_ALIAS_SHARE=1`, `DARNER_D3D12_BACKGROUND=0`. **Method:** the opening scene of one save, entered the same way every run (no input after the start screen); medians of per-second values from the host log in three 45-second windows from the moment the world appears; warm pipelines; one run each. A = main 47d21cd + #334, #337, #457, #274, #397, #312, #304, #303, #438, #439. | | A | A + #440 (f24eeae) + #442 (c971d13) | |---|---|---| | frame time, ms | 25.3 / 25.2 / 24.8 | 25.3 / 25.1 / 24.9 | | landing: merging what was fetched, ms a frame (all threads) | 1.37 / 1.39 / 1.40 (3.34 / 3.39 / 3.37) | 1.34 / 1.35 / 1.34 (3.28 / 3.32 / 3.25) | | texture refreshes, ms a frame (all threads) | 1.0 / 1.3 / 1.3 | 1.5 / 1.2 / 1.3 | The merge got about 0.05 ms a frame (3%) faster, within the spread; the scene is static, so little is merged or re-hashed. Not tested: more than one run each, scenes with streaming (driving), other CPUs.
First-time contributor

Tested merged on c8258f9 on Intel Core Ultra 7 265KF (AES-NI) + RTX 5070 Ti across 3 full Series X sessions (up to 537,076 texture uploads / 26,087 MB in 30k+ frames): zero digest mismatches or corruption, clippy --all-features -D warnings and all unit tests passed cleanly.

Tested merged on `c8258f9` on Intel Core Ultra 7 265KF (AES-NI) + RTX 5070 Ti across 3 full Series X sessions (up to `537,076` texture uploads / `26,087 MB` in 30k+ frames): zero digest mismatches or corruption, `clippy --all-features -D warnings` and all unit tests passed cleanly.
TrustNo1 changed title from [pr-performance][memory] texture: 8-lane hardware AES-NI texture digest to texture: 8-lane hardware AES-NI texture digest 2026-12-06 03:29:00 +00:00
Owner

Test needed — commit c971d13f; what to check:

  • The problem on main: texture::digest (crates/darner-gpu/src/texture.rs) hashes texture payloads in software using 4 lanes of 64-bit folded multiplications over 64-byte chunks on every texture change check.

Ports the 8-lane hardware AES-NI 128-bit digest (digest_aes, 128 bytes/iteration via _mm_aesenc_si128) from ProjectLeonida/mandy 640b0d0df (PR #2802, bobcatchris, GPL-3.0), runtime-dispatched via is_x86_feature_detected!("aes") with the existing digest_folded kept as fallback.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `c971d13f`; what to check: - The problem on main: `texture::digest` (`crates/darner-gpu/src/texture.rs`) hashes texture payloads in software using 4 lanes of 64-bit folded multiplications over 64-byte chunks on every texture change check. Ports the 8-lane hardware AES-NI 128-bit digest (`digest_aes`, 128 bytes/iteration via `_mm_aesenc_si128`) from `ProjectLeonida/mandy` `640b0d0df` (PR #2802, `bobcatchris`, GPL-3.0), runtime-dispatched via `is_x86_feature_detected!("aes")` with the existing `digest_folded` kept as fallback. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/aes-texture-digest:Paliton-pr/aes-texture-digest'
git switch 'Paliton-pr/aes-texture-digest'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'Paliton-pr/aes-texture-digest'
git switch 'Paliton-pr/aes-texture-digest'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'Paliton-pr/aes-texture-digest'
git switch 'Paliton-pr/aes-texture-digest'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'Paliton-pr/aes-texture-digest'
git switch 'Main'
git merge --squash 'Paliton-pr/aes-texture-digest'
git switch 'Main'
git merge --ff-only 'Paliton-pr/aes-texture-digest'
git switch 'Main'
git merge 'Paliton-pr/aes-texture-digest'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
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
TrustNo1/Darner!442
No description provided.