Commit fd9e269
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 fd9e269
1 file changed
Lines changed: 44 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 | | |
| |||
1205 | 1222 | | |
1206 | 1223 | | |
1207 | 1224 | | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
1208 | 1241 | | |
1209 | 1242 | | |
1210 | 1243 | | |
| |||
1288 | 1321 | | |
1289 | 1322 | | |
1290 | 1323 | | |
| 1324 | + | |
| 1325 | + | |
1291 | 1326 | | |
1292 | 1327 | | |
1293 | 1328 | | |
| |||
1297 | 1332 | | |
1298 | 1333 | | |
1299 | 1334 | | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
1304 | 1339 | | |
1305 | 1340 | | |
1306 | 1341 | | |
| |||
1332 | 1367 | | |
1333 | 1368 | | |
1334 | 1369 | | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
1335 | 1375 | | |
1336 | 1376 | | |
1337 | 1377 | | |
| |||
0 commit comments