Commit 3e5c402
authored
fix: Improve scrubbing annotated frames (#1197)
### Fix bug overwriting cached Paint FBOs between frames
### Summarize your change.
There was a bug that was causing cached Paint FBOs to be released
between frames. In the original code, the paint FBOs were explicitly
ignored when cleaning garbage collecting from the cache. However, they
were still marked as available, allowing them to be reused. This fix
simply avoids that call for Paint FBOs so they remain cached when
changing frames (ie when scrubbing or playing back in a loop). That is
the core of the fix, but I also implemented some safety mechanisms that
were not done in the original implementation to be on the safe side.
Everything but the one `continue` statement to avoid marking the FBO as
available is related to that.
The first safety check is to set an age limit in the Paint FBOs. If we
haven't seen them in 300 renders (chosen rather arbitrarily by me, but
can be adjusted), it's not likely we'll see them again, so we can safely
evict them.
I also added a second safety check against unbound cache growth. If
there are many large annotated frames all in a row, we can end up
generating a huge cache. Although this scenario is unlikely as under
normal circumstances the age limit will free the cached FBOs, we don't
want to cause problems for the GPU by caching too much, so let's set a
limit of 32 Paint FBOs in the cache. If we reach this limit, we'll sort
by age and evict the oldest entries, effectively creating an LRU cache
for the Paint FBOs.
Other than that, I just did some cleanup:
- The FBO deletion code was cut-pasted everywhere so I just made a
helper function to do it
- Found all the FBO deletion code and made it use the new method
- Fixed an assert I encountered in src/lib/geometry/TwkPaint/Path.cpp
when testing it: rDirectionCoords was getting dir pushed to it twice.
This didn't cause any issues, but does trigger an assert in debug.
### Describe the reason for the change.
Improve playback performance with annotated frames
### Describe what you have tested and on which operating system.
Mac OS 26.3.1 Mac Pro M4
I created a test scenario with 500 annotations per frame and 15 points
per stroke on 5 sequential frames.
Rendering speed before changes: 6.8 fps
Rendering speed after changes: 59.8 fps
Nearly a 10x speedup.
### Add a list of changes, and note any that might need special
attention during the review.
### If possible, provide screenshots.
<img width="331" height="608" alt="Screenshot 2026-03-11 at 15 02 36"
src="https://github.com/user-attachments/assets/7b06e1fc-568d-4fdd-9b3f-25de21e9ee6a"
/>
<img width="327" height="614" alt="Screenshot 2026-03-11 at 15 40 01"
src="https://github.com/user-attachments/assets/a64a5398-7c77-46bc-9c9e-be26981a7f50"
/>
---------
Signed-off-by: Roger Nelson <roger.nelson@autodesk.com>1 parent 780ae2a commit 3e5c402
3 files changed
Lines changed: 153 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
9 | 17 | | |
10 | 18 | | |
11 | 19 | | |
| |||
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
55 | 63 | | |
56 | 64 | | |
57 | | - | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
89 | | - | |
90 | | - | |
91 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
92 | 100 | | |
93 | 101 | | |
94 | | - | |
| 102 | + | |
95 | 103 | | |
96 | 104 | | |
97 | 105 | | |
| |||
197 | 205 | | |
198 | 206 | | |
199 | 207 | | |
200 | | - | |
201 | | - | |
| 208 | + | |
| 209 | + | |
202 | 210 | | |
203 | 211 | | |
204 | 212 | | |
| |||
225 | 233 | | |
226 | 234 | | |
227 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
228 | 244 | | |
229 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
230 | 267 | | |
231 | 268 | | |
232 | 269 | | |
233 | 270 | | |
234 | 271 | | |
235 | 272 | | |
| 273 | + | |
236 | 274 | | |
237 | 275 | | |
238 | 276 | | |
239 | 277 | | |
240 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
241 | 316 | | |
242 | 317 | | |
243 | 318 | | |
244 | | - | |
245 | | - | |
| 319 | + | |
246 | 320 | | |
247 | 321 | | |
248 | 322 | | |
249 | | - | |
250 | | - | |
251 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
252 | 326 | | |
253 | 327 | | |
254 | | - | |
| 328 | + | |
255 | 329 | | |
256 | 330 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
| 331 | + | |
262 | 332 | | |
263 | 333 | | |
264 | 334 | | |
265 | 335 | | |
266 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
267 | 389 | | |
268 | 390 | | |
269 | 391 | | |
| |||
407 | 529 | | |
408 | 530 | | |
409 | 531 | | |
410 | | - | |
411 | | - | |
412 | | - | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
413 | 535 | | |
414 | | - | |
| 536 | + | |
415 | 537 | | |
416 | 538 | | |
417 | 539 | | |
| |||
421 | 543 | | |
422 | 544 | | |
423 | 545 | | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 546 | + | |
434 | 547 | | |
435 | 548 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
| 549 | + | |
446 | 550 | | |
447 | 551 | | |
448 | 552 | | |
| |||
0 commit comments