Commit 14a7978
metal: collapse consecutive same-target passes into one encoder
Higher-level engines (e.g. macroquad's draw-call loop) issue one
`begin_pass` / `end_render_pass` pair per draw call so they can stream
batched draws to whatever the active camera's render target is. Each
pair was becoming its own `MTLRenderCommandEncoder`, which on tile-
based GPUs forces a full color-attachment store + (for MSAA) resolve
on every draw — heavy memory bandwidth that visibly tanks real-device
frame rate at retina resolution with `Conf.sample_count > 1`.
OpenGL absorbs this pattern transparently because re-binding an FBO
doesn't trigger a resolve; Metal's per-encoder load/store actions
make the cost explicit. Apple's own guidance is to minimize encoder
count for exactly this reason.
Defer `endEncoding` until the next `begin_pass` actually requires a
new encoder (different target, `Clear` action, or `commit_frame`). If
the next `begin_pass` continues the same target with
`PassAction::Nothing`, keep encoding into the existing encoder so the
whole sequence collapses into one Metal pass with a single store /
resolve at the real end. Each existing draw call's
`apply_pipeline` / `apply_bindings` / `apply_uniforms` already
re-sends its full state, so reusing the encoder is correctness-safe.
Tested on iPhone running iOS 27 with macroquad's per-draw-call begin/
end pattern at 4x MSAA — drops the per-frame encoder count from the
draw-call count down to one per render target.1 parent 1140738 commit 14a7978
1 file changed
Lines changed: 48 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
| |||
375 | 379 | | |
376 | 380 | | |
377 | 381 | | |
| 382 | + | |
| 383 | + | |
378 | 384 | | |
379 | 385 | | |
380 | 386 | | |
| |||
390 | 396 | | |
391 | 397 | | |
392 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
393 | 410 | | |
394 | 411 | | |
395 | 412 | | |
| |||
525 | 542 | | |
526 | 543 | | |
527 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
528 | 549 | | |
529 | 550 | | |
530 | 551 | | |
| |||
1205 | 1226 | | |
1206 | 1227 | | |
1207 | 1228 | | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
1208 | 1245 | | |
1209 | 1246 | | |
1210 | 1247 | | |
| |||
1288 | 1325 | | |
1289 | 1326 | | |
1290 | 1327 | | |
| 1328 | + | |
| 1329 | + | |
1291 | 1330 | | |
1292 | 1331 | | |
1293 | 1332 | | |
| |||
1297 | 1336 | | |
1298 | 1337 | | |
1299 | 1338 | | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
1304 | 1343 | | |
1305 | 1344 | | |
1306 | 1345 | | |
| |||
1332 | 1371 | | |
1333 | 1372 | | |
1334 | 1373 | | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
1335 | 1379 | | |
1336 | 1380 | | |
1337 | 1381 | | |
| |||
0 commit comments