Repository navigation
fix(texture): keep coordinate UVs out of atlas regions - #1734
Conversation
|
Hi @snowyukitty, thanks for this one as well ! This is bit more tricky, so I'll keep it for the next 20.10 release as it needs proper testing and non regression test. |
… them drawImage and drawPattern now work a source rectangle's UVs out with four divisions by the image size, into a per-atlas scratch array: no string key, no allocation, and nothing stored per rectangle. - a page whose JSON size differs from its image (or whose frames were normalised by several sizes) keeps its frames' own UVs, found through an x -> y -> size index built by addUVs - the size is read when the pixels go to the GPU: on the first draw, and again after CanvasRenderTarget#invalidate (through the new TextureCache#sizeChanged); videos and 0x0 images are read every draw - getUVs(x, y, w, h) returns a frame's own UVs for a frame of the active page and a new array otherwise; a "x,y,w,h" string is no longer read as a rectangle, and frames no longer get "x,y,w,h" alias keys - both drawPattern implementations compute the UVs last, right before addQuad, since the scratch array is only valid until the next call Bit-identical to 20.10.1's UVs on every shipped atlas (fuzzed against the old implementation); the example sweep adds no new warning, error or "x,y,w,h" region. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx
|
Thanks @snowyukitty, both for this and for chasing #1281. While reviewing it we went one step further and pushed a rework onto your branch (56535d3), on top of your own merge of 20.10.1. What changed
How it was checked
The changelog entries credit you. Merging once CI is green. |
Description
Numeric source-rectangle lookups currently create named regions, while
addUVs()adds coordinate aliases for every frame. Cropped images and repeating patterns therefore change the same dictionary that animation consumers enumerate. Identical rectangles on different atlas pages can also reuse the previous page's UVs.This separates numeric UV caching from named regions. Parsed frames seed the private numeric cache with their existing UV arrays; arbitrary rectangles are cached without registering frames. The last-lookup cache checks the active atlas dictionary and is invalidated when
addUVs()replaces a rectangle. Both GPU pattern consumers now use numeric lookups. The batchers already receive UV values, so their interfaces stay the same.Compatibility:
getUVs(name)now throws a descriptive error for an unknown name. UsegetUVs(x, y, width, height)instead of a coordinate string, or explicitly define a named region withaddRegion(). Explicitly authored names containing commas still work.13 new browser regressions cover dictionary purity, frame UV reuse, alternating crops, missing names, named-coordinate collisions, atlas page changes, replacement, intrinsic video dimensions, packed rotated/trimmed frames, and both GPU pattern consumers. Real WebGL pixel checks cover cropped images and repeating patterns; WebGPU's changed consumer is exercised with the real atlas and a recording batcher, rather than a WebGPU pixel test.
Current upstream integration
Merged
masterthroughd63bcfd(20.10.1) to resolve conflicts in the changelog and WebGL pattern path. The upstream pattern-effect handling is preserved; the existing UV lookup edits and regression tests are unchanged relative to the new base. All released changelog text is preserved, with the pending atlas entry under a version-neutral unreleased heading.Fresh contained validation on Linux:
pnpm lint,pnpm build, andpnpm test --runpass. The main browser suite reports 8176 passed and 11 skipped across 335 test files, including all 81 texture/atlas cases and the 23 ImageLayer cases. The same focused suite with this PR's tests on unmodified upstreamd63bcfdgives 10 failures and 71 passes.Original validation at
cdcbecb2d1f6925b189ff9c70d81acb46dce8941pnpm lintpnpm buildpnpm test— 7933 passed, 11 skippedpnpm -F @melonjs/matter-adapter test— 226 passedpnpm -F @melonjs/planck-adapter test— 221 passedpnpm -F @melonjs/debug-plugin test— 23 passedA Chromium CPU microbenchmark interleaved the original and changed
TextureAtlas.getUVs()implementations for 20 rounds of 1,000,000 lookups per workload after warm-up, alternating run order and checking equal UV checksums. Median milliseconds per round:The same-frame path pays a few extra nanoseconds per lookup for the atlas check; alternating rectangles avoid string keys and region searches. These are lookup timings on one Chromium/Linux container, not an FPS measurement. Cache retention remains unchanged in principle: previously encountered rectangles stay cached for the atlas lifetime.
Type of change
Checklist
pnpm lintpassespnpm test --runpasses on the integrated source; original adapter results and CPU benchmark remain separately anchored abovepnpm buildsucceedsRelated issues
Refs #1281. This addresses the remaining atlas lookup work on the current renderer, whose batchers already consume UVs directly.
The adapter-suite results and CPU microbenchmark above remain anchored to the original head named above; they were not rerun for this merge with current master (changelog and WebGL pattern conflicts). The current main-suite results are reported separately. Windows/macOS runtime and WebGPU pixel tests were not run locally.