js-multisample-resolve-sample-pattern-coverage-exactness
Done. The solution is written to /workspace/SOLUTION.md (and /workspace/solution/SOLUTION.md), with a working implementation in /workspace/solution/msaa_resolve.js and a verification harness in /workspace/solution/verify.js.
Root cause: A byte-exact MSAA resolve fails on any of four independent decisions that must all match the lab reference:
1. Divisor must be the actual kept-sample count (covered and inside the resolve rect), never the nominal 4/8.
2. Accumulation must be exact integer, with round-half-away-from-zero (floor((2·sum+count)/(2·count))), not float means or ties-to-even.
3. sRGB OETF must be applied once, after rounding, at the end — not per sample or twice.
4. Empty lanes (mask == 0, or bits set but all samples clipped) must keep the previous destination.
Plus half-open scissor bounds ([x0,x1)) and the correct rotated-grid sample positions.
Fix: resolveMsaaTile() uses the standard rotated grids (1/16-pixel units):
- 4x: (6,6) (14,2) (2,14) (10,10)
- 8x: (9,5) (7,11) (13,9) (3,7) (11,3) (5,13) (15,1) (1,15)
It filters by mask and rect (half-open), sums exact integers, divides by the kept count, rounds half-away, and applies a deterministic sRGB LUT once when srgb: true. A linearizeSamples option covers the case where the source itself is sRGB-encoded.
Verification: 11 checks pass under Node, including the discriminating 8x/3-sample case (rect x∈[0,0.95), y∈[0,0.3333) keeps s0,s4,s6 → asserts 90/3 = 30, and explicitly that it is neither 90/8 nor 680/8), plus a 3000-iteration differential fuzz against an independent slow reference.
All 11 checks passed.
# Evidence - Problem class: js-multisample-resolve-sample-pattern-coverage-exactness - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-25T16:03:50.880Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a bit-exact multisample anti-aliasing resolve for the rotated-grid 4x and 8x MSAA sample patterns in Node 20: given a per-sample RGBA8 color buffer plus a per-sample coverage bitmask for a tile, average only the covered samples and quantize with the lab reference rule (exact integer accumulation, round-half-away-from-zero, then the piecewise sRGB transfer function applied once at the end). Fully uncovered pixels must retain their previous destination color instead of resolving to black, and lanes whose sample mask is nonzero but whose samples lie outside a partial scissor rect must divide by the count of covered samples that are inside the rect, not by the pattern's nominal sample count. The implementation is graded on byte-exact output for a battery of tiles covering partial coverage, single-sample lanes, sRGB-stored surfaces, and resolve-rect clipping where an 8x pattern keeps only 3 of its 8 samples.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "js-multisample-resolve-sample-pattern-coverage-exactness", "provider": "openrouter", "solved_at": "2026-09-25T16:03:50.881Z", "version": "20"}