Skip to content

Read both mip levels through one filter call (codepawl/crucible#1171) - #56

Merged
anxuanng merged 1 commit into
mainfrom
1171-mips-fog-cost
Nov 16, 2026
Merged

anxuanng merged 1 commit into
mainfrom
1171-mips-fog-cost

Conversation

@anxuanng

Copy link
Copy Markdown
Contributor

What changed

  • The trilinear read filters its two levels through one call inside a loop (the level filter is compiled once per texture read, not twice), and finds the upper level by one step from the lower instead of walking the halving chain again.
  • Adds tools/measure-fog-mips.mjs: the issue's room (checker textured floor and boxes, fog, glass box, coated box, 8 bounces) timed with fog and mips on and off. The Rust test that pins the level walk now follows the new shape and checks the single call site.
  • Part of Cook: texture mips cost a fogged scene about five times the sampling time crucible#1171; not claimed to close it (see below).

Evidence

RTX 3060, Vulkan, 960x540, 128 spp, warm pipeline, median of 3 tracedSeconds. Same card, same scene, one session each.

scene main this branch
fog, mips off 4.43 s 3.52 s
fog, mips on 5.33 s 4.37 s
no fog, mips off 3.53 s 3.53 s
no fog, mips on 4.39 s 4.27 s
fog, mips on / off 1.20x 1.24x

Same scene with an extra metallic-roughness, normal and emission map on every material (EXTRA_TEXTURES=1 FOG_DENSITY=0.3): fog on/off 6.71/5.13 s (1.31x) on main, 6.32/4.11 s (1.54x) here; no fog 6.67/4.11 s on main, 6.33/4.11 s here. Mips-off times move by up to 1 s between runs of identical code, so the mips-on column is the steadier one: it fell by 0.1 to 1 s.

What I found:

  • The 5.6x of the issue does not reproduce on current main on a 3060: the fog ratio is 1.2x with the issue's scene. Cook at the commit of the issue (5107699) on the same card gives 1.47 s off and 5.40 s on with fog, 1.60 s and 5.41 s without: 3.7x, with and without fog. So the cost was never fog specific here, and it was the mips path itself. Mips-on time has stayed near 5.4 s while the mips-off kernel got slower, which is why the ratio dropped (inferred, from those two measurements).
  • The cost is the texture reads of the mip path (up to 8 pool fetches and 8 decodes per read), not the ray cone or the volume loop. Moving the two levels into one loop alone changed nothing measurable; stepping the descriptor once gave the gain above. The ratio with many textured slots (1.54x) is still over 1.3x, so this stays a draft. Not tried: a cheaper filter for levels past 0, which would change the picture.

How I checked it

  • Pictures: all four cases (fog and no fog, mips on and off) are byte-identical to main (0 differing floats of 2,073,600 per picture), mips on included. Mips-off kernels are specialised without the mip code, so they are unchanged by construction.
  • node tools/run-cargo-tests.mjs: 139 + 23 passed. node --test: 195 passed.
  • release-guard: clean.

…iptor once (codepawl/crucible#1171)

The trilinear read now filters its two levels through a single call inside a loop and finds the upper level by one step from the
lower, instead of walking the halving chain twice. Adds tools/measure-fog-mips.mjs, the fogged textured room of the issue.
Mips-off kernels are unchanged and every picture is byte-identical.
@anxuanng
anxuanng marked this pull request as ready for review November 16, 2026 18:54
@anxuanng
anxuanng merged commit cb1f08d into main Nov 16, 2026
5 checks passed
@anxuanng
anxuanng deleted the 1171-mips-fog-cost branch November 16, 2026 18:56
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