Skip to content

perf: pool exact-size filter render targets across slots - #9

Merged
bbbreaddd merged 6 commits into
bbbreaddd:mainfrom
AbdullahTrees:pr/filter-target-hysteresis
Nov 16, 2026
Merged

bbbreaddd merged 6 commits into
bbbreaddd:mainfrom
AbdullahTrees:pr/filter-target-hysteresis

Conversation

@AbdullahTrees

@AbdullahTrees AbdullahTrees commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Filter slots currently retain only one displaced target each, so cycling through three or more sizes repeatedly allocates and evicts GPU targets.

Replace this PR's oversized-target hysteresis and shader rewriting with a shared pool matched by exact physical dimensions. The existing entry limit and 32 MiB cache budget remain, with LRU eviction. Shaders, sampling coordinates and clears keep their existing behavior. On allocation failure, reclaim idle cached targets, finish queued GPU work and retry once while preserving active targets.

Validation:

  • Warmed four-size cycle: 12 target allocations before, zero after; exact pixels preserved.
  • 13 focused native tests pass, including full 1024×512 pixels, auxiliary samplers, padding, source replacement, eviction, allocation failure and teardown.
  • Stock MV and OMORI filter-reference comparisons pass; ISAT blur and bloom match with zero differing pixels.
  • Local OMORI battle comparisons complete two encounters per run with matching action/damage events and unchanged renderer-target memory. This route already has no steady allocation churn, so no OMORI FPS improvement is claimed.
  • Full local CTest sweep: 342/344 pass. The build-provenance and node-image-bytes failures reproduce on the pre-PR baseline. Maintained JavaScript suite: 2,306 pass, 50 skipped.

Merged the current main branch into this branch to resolve the previous source-layout conflicts. The pre-push hook also clears repository-local Git environment variables so provenance checks inspect their temporary fixture repositories correctly.

Battle turns reallocated ~1,000 filter targets per session because
ensureFilterTarget accepted a target only at the exact requested POT
size; two group slots flipped between 1024x512, 512x128, 512x8 and
64x32 almost every frame, at ~1 ms per create.

Targets now carry a logical size (the POT of the frame, exactly today's
value) and a physical allocation that may be larger. A target is kept
while it fits dimension-wise; the game and its shaders keep seeing the
logical size in filterArea, filterClamp and the vertex coordinates,
and only texture2D(uSampler, ...) reads are scaled by
logical/physical in the renderer's fragment transform. Group targets
drawn for custom filter plans reuse the same rule; other filter paths
keep their exact-size allocation.

A reused target is cleared over the whole physical allocation before
the group content is drawn, so samples outside the frame read
transparent instead of stale pixels. Oversized targets shrink back
after 120 frames without a request at their size. The exact-size path
remains available through PMJS_DISABLE_OPT=render.filter-target-reuse.
A reused target can be several POT buckets larger than the frame it
holds. Clearing the whole physical allocation on every pass made the
reuse path slower than the allocations it removed in a real battle:
every pass paid the largest bucket instead of the current frame.

New allocations still clear the whole physical texture once, so the
tail beyond the logical extent stays transparent and out-of-frame
samples cannot read stale pixels. Later clears scissor to the logical
extent, which is exactly the area the exact-size path would have
cleared.

PMJS_DISABLE_OPT is validated against the registered optimization IDs
at boot, so register render.filter-target-reuse in pmjs-pixi4;
otherwise the fallback variant refused to boot instead of running the
exact-size path.
@AbdullahTrees
AbdullahTrees force-pushed the pr/filter-target-hysteresis branch from 979da36 to df19236 Compare November 5, 2026 20:53
@bbbreaddd bbbreaddd changed the title perf: keep filter render targets while the request still fits perf: pool exact-size filter render targets across slots Nov 15, 2026
@bbbreaddd
bbbreaddd marked this pull request as ready for review November 15, 2026 23:59
@bbbreaddd
bbbreaddd merged commit aef8282 into bbbreaddd:main Nov 16, 2026
2 checks passed
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.

2 participants