Metal 遊戲效能:把長時間遊玩中的掉幀變成可回溯、可定位、可修復的資料
這場 session 聚焦遊戲效能 debug:從 Metal Performance HUD 的即時指標,到 Instruments / look-back traces / metalperftrace,再用 StateReporting 把 FPS 掉點對回遊戲狀態。
Apple 要解的不是「怎麼看 FPS」而是「怎麼在玩家玩了幾小時後,仍能知道掉幀發生在什麼裝置狀態、遊戲狀態與渲染情境」。
這支影片其實在重組遊戲效能診斷迴圈
先用共同指標建立 baseline
FPS、GPU time、frame interval、memory、layer size、composition mode 與 MetalFX 指標,是比較不同 session、裝置與畫面狀態的基礎。
長時間問題不能只靠當下錄影
Game Performance Overview 適合桌上測試;macOS / iOS 27 的 look-back collection 則讓系統保存數天聚合指標,事後再取 trace。
metalperftrace 把 trace 變成可查詢資料
CLI 可以列 overall overview、session breakdown、匯出 JSON,適合腳本化、CI 分析或交給 agent 找可疑區段。
StateReporting 讓掉幀對回遊戲事件
只知道 7:23 掉到 42 FPS 不夠。domain、state 與 metadata 會出現在 HUD、CLI 與 Instruments tracks,讓問題變得可行動。
從「感覺卡」到「可修」的效能流程
定義效能目標與觀測指標
用 HUD 快速看 FPS、GPU time、frame interval、記憶體與顯示相關 metrics,先確認目標與現況差距。
收集桌上與真機長時間 trace
桌上用 Instruments 的 Game Performance Overview;macOS 用 metalperftrace collect --last;iOS 需先在 Developer Settings 開啟 Performance Trace look-back collection。
用 CLI 與 Instruments 找異常區段
先用 overview / JSON 找 session 與時間範圍,再用 Instruments 視覺化 FPS、GPU、CPU、memory 與相關 tracks。
把遊戲狀態寫進 StateReporting
把 loading、level、graphics preset、combat、menu、boss fight 等狀態變成 domain/state,讓 trace 不再只是系統指標。
發布後用 MetricKit 看 field data
iOS / macOS 27 的 MetricKit 可收 Metal frame rate 與 performance metrics,並按 StateReporting domain 看 breakdown。
重點 1:HUD 是即時儀表板,不是長時間證據庫
Metal Performance HUD 適合開發者在遊玩時快速看 FPS、memory usage、frame interval 等指標,也能透過設定面板調整顯示 metrics。它的限制是沒有保存長時間脈絡:當問題發生在第 90 分鐘、溫度升高、玩家切換地圖或圖形設定後,只靠 HUD 很難還原。
因此影片把 HUD 放在 baseline 位置:用它確認哪些指標重要,再把真正的長時間證據交給 trace collection。
重點 2:Look-back collection 是這次最實用的新能力
桌上測試可以用 Instruments 的 Game Performance Overview template,收集 Metal aggregated metrics 與 Time Profiler CPU samples。更重要的是系統層級 look-back:遊戲執行時,系統持續以低成本保存 Metal performance 與 resource usage metrics,包含聚合資料與可選 per-frame 指標,並保留數天。
metalperftrace collect,可指定 --last 或明確 start/end time,事後收集過去幾小時到幾天的資料。重點 3:StateReporting 讓 trace 有產品語意
StateReporting API 讓遊戲描述自己的 runtime state:用 domain 表示一類狀態,用 state 表示目前值,再加 metadata。這些 state transitions 會出現在 Metal Performance HUD、metalperftrace output 與 Instruments tracks。
對遊戲團隊來說,這代表 performance report 不再只是「GPU time 變高」,而是「BossArena / Ultra preset / streaming assets / combat phase 2 時 GPU time 變高」。這種語境才足以導向修復。
風險與導入注意事項
來源
主要來源為 Apple Developer 官方影片頁、transcript 與章節摘要;YouTube 影片頁用於 iframe 與發布 metadata。官方頁:Find and fix performance issues in your Metal games - WWDC26。YouTube:WWDC26: Find and fix performance issues in your Metal games | Apple。
- →Metal Performance HUD 適合即時 baseline;長時間問題要靠 trace collection。
- →macOS / iOS 27 的 look-back traces 讓數小時遊玩後仍能事後回收效能資料。
- →
metalperftrace可輸出 overview 與 JSON,適合自動化與 agent-assisted analysis。 - →StateReporting 是關鍵:把 FPS 掉點連回遊戲狀態,才知道該修哪裡。