feat(render): surface-cache primitives (baked fill + BakeSurface) - #20
Merged
Conversation
Adds the building blocks of Quake's surface cache, so the world-surface span loop can collapse to a single fetch + store per pixel instead of a per-pixel lightmap bilinear + colormap lookup: - CachedSurface / CachedVertex: a per-face baked surface (texture already modulated by the lightmap through the colormap, as final palette indices). - FillPerspectiveCachedPolygon: perspective-correct textured copy from a baked surface (same 1/z subdivision as the other fills; clamped, no per-pixel lightmap/colormap). Benchmarks 2.45x faster than the lightmapped fill on the same ~250k-px quad (412us vs 1011us, 0 allocs). - BakeSurface: builds a CachedSurface for a face -- per baked texel it samples the texture (tile-wrapped) + the lightmap plane (bilinear) and combines them through the colormap, mirroring FillPerspectiveLightmappedPolygon exactly. A parity test confirms the cached path reproduces the per-pixel path bit-for-bit on a uniform-Z face. Pure additions -- nothing wires them yet, so no behaviour change. The runner integration (a persistent per-face cache for static faces) lands next. 100% line coverage on both new files; benchmarks + parity test included. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Jul 6, 2026
Wires the surface-cache primitives (#20) into the world-face draw. A face is CACHEABLE when its lightmap is constant over time -- fullbright (LightOfs<0) or every active lightstyle is style 0 ('m', the only time-independent style) -- AND its texture is not animated (no '+' chain). Such a face is baked ONCE via render.BakeSurface into a per-face render.CachedSurface (keyed by face index, persisted for the map's lifetime -- static faces never change, so no invalidation) and painted with render.FillPerspectiveCachedPolygon: a single fetch+store per pixel instead of a per-pixel lightmap bilinear + colormap lookup. Animated faces (flickering lights, '+' textures) keep the per-pixel lightmapped path; sky/turbulent are unchanged. texMinS/texMinT for the bake come straight from lmInfo.MinS/MinT, since TransformFaceLightmapped defines LmS=(U-MinS)/16 (so U=MinS+LmS*16, and the cache is indexed by LmS*16 / LmT*16). Verified in-browser (Firefox/Playwright, lq_e0m1): the world renders pixel-identical to the per-pixel path (walls fully textured + lit, no artifacts) and the same scene measured 1.32 -> 1.56 fps (+18%) under the identical throttled harness. The win is scene-dependent -- larger in wall-heavy views, bounded here by the ~half-screen of (uncached) water + sky; the isolated cached fill benchmarks 2.45x faster than the lightmapped fill. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First step of the renderer perf work: Quake's surface cache. Collapses the world-surface span loop from a per-pixel lightmap bilinear + colormap lookup to a single fetch + store.
FillPerspectiveLightmappedPolygonexactly. A parity test confirms the cached path reproduces the per-pixel path bit-for-bit on a uniform-Z face.Pure additions — nothing wires them yet, so no behaviour change. The runner integration (a persistent per-face cache for static faces) lands next. 100% line coverage on both new files; benchmarks + parity test included.
🤖 Generated with Claude Code