Skip to content

feat(bc7): always-on mode 6 / mode 4 selection — −33% MSE at speed parity - #16

Merged
verekia merged 1 commit into
mainfrom
feat/bc7-mode4
Sep 25, 2026
Merged

verekia merged 1 commit into
mainfrom
feat/bc7-mode4

Conversation

@verekia

@verekia verekia commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Summary

Every BC7 block now chooses between mode 6 (one RGBA line, 16 levels) and mode 4 (one channel split into its own scalar plane, 2-bit + 3-bit index sets, idxMode chosen per block). The opt-in adaptiveMode4 option is removed: this is the default and only path.

  • Decision: from the block covariance, with no extra pixel pass. The score is the variance each mode explains net of its quantisation, using a closed-form estimate of each candidate plane's principal eigenvalue.
  • Speed: both modes run the same per-pixel code (stored extents projections reused as indices, one 7-bit+p / 5-bit endpoint quantiser, anchor rule applied before indexing). Mixed warps no longer execute two paths, which is what made the old opt-in cost 1.4–1.5×.
  • Backends: f16 WGSL, f32 WGSL, and the WebGL GLSL port. GLSL is byte-identical to f32 WGSL (10 images × flipY plus a 133×61 crop).

Results

/eval, Apple M3, hardware decode, RGBA PSNR, vs the mode-6-only kernel:

MSE, 41-image corpus −33% geomean (+1.77 dB mean)
MSE, 32 real textures −25% geomean
Normal maps +2.4 … +4.5 dB
Rock colour +1.1 … +2.2 dB
Packed atlases +0.3 … +4.4 dB
Gray maps / smooth wood colour unchanged (±0.03 dB)
f16 GPU time ×0.99 geomean (1K mode-4-heavy +2–3%, 2K/4K par)
f32 GPU time ×0.75

A reference shader that exhaustively tries every single-subset candidate (modes 6, 4 and 5) sits only 0.1–0.9 dB above this encoder. The old gated mode 4 sat 2–8 dB below it.

Breaking changes

  • Removes the BC7Encoder adaptiveMode4 option and the exported BC7EncoderOptions type.
  • Removes the now-unused internal Encoder.pipelineConstants() hook.

Also in this PR

  • /test BC7 quality floors re-pinned to the new baselines (gray rows unchanged). 0 failures.
  • /eval reports a per-mode BC7 block histogram.
  • README BC7 description and f32 benchmark number updated.

Test plan

  • bun run all (format, lint, typecheck, warden, 225 tests)
  • /test GPU suite: 0 failures, both f16 and f32 variants
  • WebGL vs WebGPU-f32 byte identity
  • Full-corpus /eval A/B vs HEAD, f16 and f32

🤖 Generated with Claude Code

https://claude.ai/code/session_01CvMZvPkPRPM8oZMVs44qB7

…rity

Every block now chooses between mode 6 (one RGBA line, 16 levels) and
mode 4 (one channel split into its own scalar plane, 2-bit + 3-bit index
sets, idxMode per block). The choice comes from the block covariance:
the variance each mode explains net of its quantisation, with a
closed-form estimate of each candidate plane's principal eigenvalue.
Both modes run the same per-pixel code (stored extents projections
reused as indices, one endpoint quantiser, anchor rule applied before
indexing), so mixed warps no longer pay for two paths.

/eval (M3, hardware decode) vs the mode-6-only kernel:
- MSE −33% geomean over 41 images, −25% over the 32 real textures
- normal maps +2.4..4.5 dB, rock colour +1.1..2.2, packed +0.3..4.4;
  gray maps and smooth wood colour unchanged (±0.03 dB)
- f16 GPU time ×0.99 geomean (1K mode-4-heavy textures +2–3%, 2K/4K
  par); f32 fallback ×0.75
- WebGL GLSL byte-identical to the f32 WGSL module

BREAKING: removes the BC7Encoder `adaptiveMode4` option, the
BC7EncoderOptions type and the Encoder pipelineConstants() hook.
/test BC7 floors re-pinned; /eval reports a per-mode block histogram.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CvMZvPkPRPM8oZMVs44qB7
@verekia
verekia merged commit f841646 into main Sep 25, 2026
1 check passed
@verekia
verekia deleted the feat/bc7-mode4 branch September 25, 2026 08:25
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