Anim: run bezier handle calculation in parallel #119388
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#119388
Loading…
Reference in New Issue
No description provided.
Delete Branch "ChrisLend/blender:thread_recalc_handles"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bezier handles are recalculated in many places in the
animation code. Threading that code can give a performance
boost all over Blender.
Measuring
BKE_fcurve_handles_recalc_ex
with 10.000 keys (the numbers represent a run through a single FCurve)
When only measuring the threaded loop. So while the specific loop only takes a third of the time, the total function time is only reduced by ~30%
Test file used
https://download.blender.org/ftp/sybren/animation-rigging/heavy_mocap_test.blend
Grain Size Tests
BKE_nurb_handle_smooth_fcurve
can still be run in parallel,that's more complicated though, so for this patch I've kept the scope small.
Christoph Lendenfeld referenced this pull request2024-03-15 10:20:13 +01:00
WIP: Anim: run bezier handle calculation in parallelto Anim: run bezier handle calculation in parallel@blender-bot build
@ -1238,2 +1237,2 @@
BezTriple *prev = cycle_offset_triple(cycle, &tmp, &fcu->bezt[fcu->totvert - 2], last, first);
BezTriple *next = (bezt + 1);
IndexRange bezt_range(0, fcu->totvert);
threading::parallel_for(bezt_range, 128, [&](const IndexRange range) {
Have you tried different grain sizes in your measurements? I feel like this should be much greater like
4096
, but of course, feelings are meaningless when it comes to performance :DI did and surprisingly it got slower with 256 and 512.
But then again that's on a sample size of 1. Not sure if there are machine differences. And the difference wasn't huge, ~10% with quite a bit of noise
Right, I guess there is more going on in this loop than it seems.
I think 4096 is way too big for this use case. There typically aren't tens of thousands of keyframes, and the grain size needs to be low enough to give meaningful usage of multiple CPU cores.
where is the number 4096 coming from? hardware limits?
@HooglyBoogly Well only if the loop is actually doing enough work to justify the parallel loop in the first place. But yes I agree.
Right, true
@ChrisLend No just a higher power of two. Remember that the grain size is essentially "how many iterations are assigned to one thread". So in the case of 4096 it would (essentially) mean one thread is running 4096 iterations.
It's arbitrary, just a compromise between reducing overhead and more threading. I think I remember finding a while ago that using powers of two can actually give noticeable improvements. Also they just seem nice.
@ -1240,0 +1241,4 @@
BezTriple *bezt = &fcu->bezt[i];
BezTriple *prev = nullptr;
BezTriple *next = nullptr;
if (i > 0) {
How about pulling the special handling for the first and last keyframes out of the parallel loop, and skipping those two indices?
bezt_range.drop_front(1).drop_back(1)
To do that without duplicating the code within the loop I'd need to extract the logic into a function. Should I do this within this PR?
Definitely not a big deal either way, it could wait if you preferred!
@ -1240,0 +1245,4 @@
prev = (bezt - 1);
}
else {
prev = cycle_offset_triple(cycle, &tmp, &fcu->bezt[fcu->totvert - 2], last, first);
If
fcu->totvert == 2
thenprev
could be the same asbezt
. The old code didn't have that, as it usedprev = bezt
at the end of the loop (unless I'm missing something, which is entirely possible).The same goes for
next
below, that'll also be the same asbezt
whenbezt
is the last key andtotvert == 2
. That was already the case in the old code, though.Also (in the old code) the negative counting in
a
but the positive order of visiting the keys makes my head hurt. I'm glad you're resolving this.Checkout
From your project repository, check out a new branch and test the changes.