Formats: bounds-check a detiled row once, not each run in it #2026
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2026
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2026"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 03:28 UTC · original
0xkn0wh3r3:formats/detile-rows-checked-once→main· +196 −34 · 1 files · 2 commits · openThe problem
Detiling and tiling a texture spent much of its time on bounds checks.
Layout::detileandLayout::tilecopy a subresource as the contiguous runs its columns make, the same runs on every row. Each run was a slice copy through a closure, bounds-checked on both sides. A 4K RGBA8 texture in a 64 KiB standard swizzle is about two million 16-byte runs, so about two million pairs of checks.The fix
Runs): the furthest tiled byte from the row's start, and the linear row's bytes, which they cover.Runs::newasserts that every run lies in the linear row. Every run lies in the tiled span by construction.Measured on a Ryzen 9 7900X (release; old and new alternating 40 times in one binary, best of each; same bytes out):
Copying rows in bands (each run for several rows at once, to stay in a micro-tile) was slower at every band size tried (4, 8, 16) and is not done.
Testing
addresses_are_a_bijection_and_copies_round_trip(detile and tile round trips over every addressable mode),layouts_match_addrlib, the mip-tail and deep-volume tests, and the depth-pitch tests.cargo test --release -p victory-formats: 38 passed. The 3 ignored tests that need reference data files (bcpack::tests::reference_chunks,xma::tests::matches_a_reference_decoder,xma::tests::walks_saved_streams) were not run.cargo test --release -p victory-gpu(its texture uploads detile through this): all pass exceptdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views, which fail the same way onmainon this RTX 5070 Ti (#1835).cargo clippy -p victory-formats --all-targets, with and without--all-features: clean.Related
Complementary to #1135 (detile only the subresources written), #1873 (one scratch buffer) and #388 (detile into cached memory): those make fewer or cheaper detiles, this makes each one faster. Builds on #603's fixed-width runs.
@jeremygold02 on GitHub · 2026-11-25 03:31 UTC · original
Triage verdict — Promising follow-up to #603; verify the linear path and row boundaries (
376946a)Evidence
Vecwith a direct row copy to a one-entry run list. The posted speedups cover swizzled layouts, so they leave that separate cost unmeasured.Checks and limits
Next step
This verification was AI-assisted.
@Calvix2k on GitHub · 2026-11-25 03:57 UTC · original
Verified on Windows 10 19045, head
376946a:cargo test -p victory-formats --lib— 38 passed, 0 failed, 5 ignored.The two tests that matter for this change both pass:
addresses_are_a_bijection_and_copies_round_trip(the property that would catch a wrongspan/bytesin the new row contract — theunsafecopy trusts exactly those) andlayouts_match_addrlib. The ignored five are the pre-existing#[ignore]d ones, not skipped by this change.On the diff: making the bound the row's
span/bytesand keeping the per-run offsets relative to it is the only way to hoist the check, and theSAFETYcomment names the invariant. If you want belt and braces for the unsafe block, a debug-onlyassert!(runs.span <= … && runs.bytes <= …)insideRuns::copywould document it at the point of use; the round-trip test is what covers it today.@0xkn0wh3r3 on GitHub · 2026-11-25 06:31 UTC · original
Thanks @jeremygold02, the linear timing found a real regression. Fixed in
8bd4270.Timing (release build, synthetic RGBA8 textures, detiling every mip, best of five, two alternating runs each):
The one-entry run list for linear layouts was allocated on every call. A single run is now kept inline, and a row with one run is copied as a single slice.
Bounds: following @Calvix2k's suggestion,
Runs::copynow takes the row's two slices and checks once per row that they are exactly itsspantiled andbyteslinear bytes. The runs are then copied without checks as before, and the call sites no longer needunsafe.New test
rows_are_copied_exactly_at_their_bounds:tileleaves every tiled byte outside its subresource untouched.It runs on both tiled and linear layouts, across all mips. All 39 formats tests pass.
@Calvix2k on GitHub · 2026-11-25 08:14 UTC · original
Re-verified on the new head
8bd4270, Windows 10 19045 (RX 7800 XT):cargo test -p victory-formats --lib— 39 passed, 0 failed, 5 ignored (one more test than before, the new linear-row case).The linear-timing regression jeremygold02 found and the fix make sense together: the run list is only needed for tiled layouts, and linear rows copy as one span. Good fix, nothing else to add.
@Marvisak on GitHub · 2026-11-25 09:18 UTC · original · edited 2026-11-26 01:24 UTC
Automated triage for the maintainers.
Merge candidate. The new head
1ec3877is the same change rebased onto currentmain, plus the nit from the last triage: the trailing blank line at the end ofcrates/victory-formats/src/texture.rsis gone. It merges cleanly.I re-read
Runsand itscopyagainst the rebased file.copystill asserts that each row's slices are exactlyspantiled andbyteslinear bytes before the uncheckedcopy_nonoverlappingruns, andRuns::newasserts every run lies inbytes. Linear rows still take the inlineRuns::onepath with a single slice copy.rows_are_copied_exactly_at_their_boundsstill covers exact-sized buffers, a partial last run and untouched padding.CI: passing (
check). Recommending a look, not approving.Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-26 00:17 UTC · original
Thanks for the review. The nit is fixed in
1ec3877: the branch no longer adds a blank line at the end oftexture.rs. It's also rebased onto currentmain.victory-formatstests (47 passed), clippy and policy pass. @Calvix2k thanks for re-verifying on the RX 7800 XT.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.