Skip to content

Include hasWarn and textures in the shader rebuild key#67

Merged
kmatzen merged 1 commit into
mainfrom
fix-shader-rebuild-key
Jul 25, 2026
Merged

Include hasWarn and textures in the shader rebuild key#67
kmatzen merged 1 commit into
mainfrom
fix-shader-rebuild-key

Conversation

@kmatzen

@kmatzen kmatzen commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Fixes #55. Supersedes #59 (that PR was auto-closed when its base branch fix-gpu-resource-leak was deleted on merging #57; reopen wasn't possible, so re-filing against main). Same commit, rebased onto current main (which now includes #57).

The rebuild decision compared only glsl and paramCount:

if (sdf.glsl !== this.lastGlsl || sdf.paramCount !== this.lastParamCount) {

but rebuild() bakes two more inputs into the material — hasWarn selects the fragment source via buildFrag(sdf.glsl, sdf.paramCount, sdf.hasWarn), and each texture becomes a uniform. An evaluation producing identical GLSL and param count but a different hasWarn therefore never reached the GPU, leaving the thin-wall highlight showing the previous evaluation's state.

Scope note (carried from #59)

The textures half is latent, not live. codegen.ts declares/resets/returns a textures array but nothing ever pushes to it, so sdf.textures is always [] at runtime and a texture-only change cannot currently produce a stale render. Only hasWarn is a live bug. The texture key (FNV-1a over content) is included anyway — it costs nothing while the array is empty and is already correct for when textures get wired up.

Verification

  • tsc --noEmit — exit 0
  • SdfMesh tests, this branch — 7/7 pass (2 fail on pre-fix base)

🤖 Generated with Claude Code

Fixes #55.

The rebuild decision compared only glsl and paramCount, but rebuild() bakes
two more inputs into the material: hasWarn selects the fragment source via
buildFrag, and each texture becomes a uniform. An evaluation producing
identical GLSL and param count but a different hasWarn therefore never
reached the GPU, leaving the thin-wall highlight showing the previous
evaluation's state.

Correction to the issue as I filed it: the textures half is latent, not
live. codegen declares `textures`, resets it, and returns it, but nothing
ever pushes to it, and nothing else in src/worker/sdf references textures --
so sdf.textures is always [] at runtime and cannot currently go stale. Only
hasWarn is a live bug. The texture key is included anyway: it costs nothing
while the array is empty, and it means the key is already correct when
textures get wired up rather than being a trap waiting for that change.

The texture key hashes content (FNV-1a) rather than just dimensions, so a
content edit at unchanged width/height still invalidates.

Tests fail 2/3 against the base branch. The third asserts that an identical
display does NOT rebuild, which both satisfy -- it guards against
over-invalidating, since each rebuild recompiles a shader and disposes the
previous one.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🚀 Preview deployed: https://fix-shader-rebuild-key.sinter.pages.dev

(updates on every push to this PR)

@kmatzen
kmatzen merged commit 9e46155 into main Jul 25, 2026
5 checks passed
@kmatzen
kmatzen deleted the fix-shader-rebuild-key branch July 25, 2026 16:59
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.

Shader rebuild key ignores hasWarn and textures

1 participant