Harden Metal presentation lifetimes
X9
3mo ago+375+375+012345678901234567890123456789-85-85-01234567890123456789
Fixes verified replay completion safety. Adds renderer lifetime invalidation, generation-based stale-frame rejection, and moves synchronous callback delivery outside the draw mutex while preserving current swap-chain drain and iOS queued behavior.\n\nVerified: zig build test -Drenderer=metal passes.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Hardens Metal presentation lifetimes to prevent stale or late GPU completions from mutating UI or renderer state after resize or teardown. Adds generation-based validation and moves sync presentation callback delivery outside the draw mutex while preserving swap-chain drain and iOS’s queued behavior.
- Bug Fixes
- Generation-tracked
IOSurfaceLayerlifetime rejects stale frames and cancels after teardown. - Surface size is clamped and observed;
presentation_generationis passed through frame/present paths. setSurfaceSyncvalidates generation and size; returns false instead of touching invalid state.- Sync presentation returns the callback to the caller; delivery occurs after
draw_mutexunlocks (async and iOS unchanged). - Added tests for lifetime invalidation and stale-generation rejection.
- Generation-tracked
Summary by CodeRabbit
- Bug Fixes
- Improved Metal presentation reliability by preventing stale or invalid frame updates from reaching the display.
- Prevented queued presentation callbacks from affecting detached or inactive surfaces.
- Added safeguards to reject surfaces whose dimensions do not match the current drawable area.
- Clamped runtime surface sizes to supported device texture limits.
- Improved synchronization for frame completion and presentation updates to reduce visual glitches during resizing or rapid frame changes.