Skip to content

Textures: detile linear levels a row at a time, tiled ones with per-row and per-column parts - #474

Closed
NiiRoZz wants to merge 1 commit into
ivall:mainfrom
NiiRoZz:nii/movie-speed
Closed

NiiRoZz wants to merge 1 commit into
ivall:mainfrom
NiiRoZz:nii/movie-speed

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 24, 2026 •

Copy link
Copy Markdown

Kept-in-step title textures are detiled on the CPU at every upload, one element at a time (Chain::detile_level → element_at: three divisions, six table lookups and a bounds-checked copy per element). A retail title's intro movie is three linear R8 planes, 12.4 MB a frame, uploaded whenever the decoder writes them: on main the movie shows its picture (#283) but plays at 7 to 8 presented frames per 2 s, with ~1.75 s of every 2 s spent in the detile. Linear levels are now copied a row at a time, and tiled levels work out their address parts once per row and per column. The bytes are the same.

Overlap: three open PRs opened shortly before this one make the same linear-level change: #440 (linear levels a row at a time), #458 (levels a row at a time) and #451 (reused upload memory and faster detiling, which also covers the upload cost listed under Not tested). I had not seen them when this was written. This one differs in also covering tiled levels with per-row and per-column parts and in its equivalence test over every mode; close it if one of those is taken.

What is in it

  • gpu/tiling.rs: two fast paths in detile_level (linear: whole rows; other modes: the x parts once per level, the y and slice parts once per row), and the test detile_level_matches_element_at: against element_at byte for byte, for every mode (linear too), element sizes 1 to 16 B, three pipe configurations, mips in and out of the tail, two slices, a base swizzle and a source cut short. With either new path broken on purpose the test fails.

Tested

  • NVIDIA GeForce RTX 5090 (driver 621.35), AMD Ryzen 7 9800X3D, Windows 11 Pro 26300, Rust 1.100.0, release.
  • cargo test --release -p xcl --lib tiling: 12 passed.
  • cargo test --workspace -- --test-threads=4: 671 passed, 0 failed, 41 ignored (SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, no wave64). That run was on main 3516080 plus this change; since then the commit was only rebased onto 2997c9a without conflicts.
  • Synthetic release timing of the three planes: linear 107–113 ms → 1.4–2.0 ms; 64KB_R_X 112–116 ms → 22–33 ms.
  • A retail title, main 3516080 with and without this change, one run each with the machine to itself: presented frames per 2 s during the intro movie 7–8 → 34–46; read + detile ~1.75 s → ~0.33 s per 2 s; the movie (15.0 s long) took ~19 s, one 4 s stall included.

Regression run

Pending: the two 60 s scripts/smoke.ps1 runs (main, this PR's head), with scripted A presses so that the intro movie plays during the run, are queued on the test machine and will be added here.

Not tested

  • AMD GPUs, other titles.
  • The movie is still below its 30 fps after this: what remains is the upload itself (each plane goes up about three times per presented frame, through a new staging buffer and a blocking wait each time). Not in this PR.
  • The whole suite on this exact head (see above).

AI use

  • Claude Code with Claude Opus 5.5 measured, wrote the code and the test; Claude Fable 5.2 checked the diff, made the regression runs and wrote this description. The runs were made on the author's machine.

…ow and per-column parts

`Chain::detile_level` computed every element's address from scratch (`element_at`: block
index, six table lookups, divisions) and copied it with a bounds check. Kept-in-step title
textures are detiled on the CPU at every upload. A retail title's intro movie is decoded on
the CPU into three linear R8 planes (3840x2160 + 2 x 1920x1080, 12.4 MB a frame) that are
uploaded again whenever the decoder writes them: on main 85bdf21..3516080 detiling took
~1.75 s of every 2 s of the movie, and it played at 7-8 presented frames per 2 s.

- Linear levels (mode 0, no base swizzle, not in a mip tail): each row is copied whole, `pitch`
  elements apart (the case gw1337x profiled in ivall#283; also closed PR ivall#334).
- Other levels: the address is a block row part plus a block column part, and the XOR of an x
  part and a y (and slice) part; the x parts are worked out once per level, the y parts once
  per row.

Same bytes as before: a new test compares with `element_at` for every mode (linear too), each
element size, three pipe configurations, mips in and out of the tail, two slices, a base
swizzle and a source cut short. Synthetic release timing, the three planes: linear 107-113 ms
→ 1.4-2.0 ms; 64KB_R_X 112-116 ms → 22-33 ms.

Retail movie on main 3516080 (RTX 5090, exclusive runs): 7-8 → 34-46 presented frames per 2 s;
read + detile 1.75 s → ~0.33 s per 2 s. What remains is the staging upload (~1.3 s per 2 s,
~1.1 GB: each plane is uploaded about three times per presented frame).

AI-assisted.
@NiiRoZz

NiiRoZz commented Nov 24, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate: #440, #458 and #451 were opened before this and make the same linear-level change. The equivalence test here (new paths against element_at for every mode) is free to take.

AI-assisted.

@NiiRoZz NiiRoZz closed this Nov 24, 2026
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.

1 participant