Page MenuHome

PBVH task scheduler performance issues
Confirmed, NormalPublicTO DO

Tokens
"Yellow Medal" token, awarded by amonpaike."Love" token, awarded by lopoIsaac."Love" token, awarded by franMarz."Love" token, awarded by Fracture128."Like" token, awarded by MetinSeven."Like" token, awarded by billreynish.
Assigned To
None
Authored By

Description

This is a task to investigate a possible issue in the PBVH task scheduler.

Issues

  • Some users report bad performance in sculpt mode, while others can work without problems on really high poly meshes with similar hardware.
  • On my main computer, brush strokes with TBB disabled feel more responsive regardless the mesh vertex count. When TBB is enabled, strokes usually stop generating new samples in the middle of the stroke or take a fraction of a second to start. I know this is happening to some other users.
  • Simple operations that need to loop over all vertices on high poly meshes are extremely slow for no specific reason. (doing x = 1.0f - x on a 25M elements array often takes up to 5 seconds). When the operation is more complex (like updating the normals or updating the nodes on the GPU), this can take minutes to finish.

We are not getting the reports of people that may be affected by this issue because most of them assume that Blender sculpt mode performance is just bad by default, so I can't tell if this is a problem with a specific configuration of hardware/software or a general problem in how the scheduler works. It would be nice to have more data from this test (and sculpt mode performance in general) on different hardware/software configurations to have a better understanding of how we can improve it.

How to test:

  1. Apply this patch: P1202
  2. Add a cube, subdivide N number of times and apply
  3. Enter Sculpt Mode
  4. Run "Invert Mask" (press A + drag left)

My results

Operating system: Linux-5.4.2-1-MANJARO-x86_64-with-glibc2.29 64 Bits
CPU: Intel i7 6700K @ 4.00GHz x 8
RAM: 32GB
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 430.64

Subdivide default cube N number of times:

N SubdivisionsVerticesPBVH NodesTBB ON (seconds)TBB OFF (seconds)DIFF
112516582675962.4740730.571511432.90%
10629145819200.3079480.159395193.20%
915728664640.1114590.096845115.09%
83932161120.0022890.00729731.37%

Subdivide default cube 6 times, use multires to N level.

LevelVerticesPBVH NodesTBB ON (seconds)TBB OFF (seconds)DIFF
62676326436961.0766350.322183334.17%
571024649120.0745860.11330365.83%
419906562320.0129380.04827326.80%
3614400560.0040590.01277831.77%

As you can see, a simple loop over all vertices in the mesh is way faster on my setup with TBB disabled.

If I change the LEAF_LIMIT in pbvh.c to 100000 (x10) in order to increase the amount of work each node has and reduce the number of total nodes:

N SubdivisionsVerticesPBVH NodesTBB ON (seconds)TBB OFF (seconds)DIFF
11251658267600.1068680.21098550.65%
1062914581840.0290880.10537627.60%
91572866560.0071680.02965324.17%
839321680.0022610.00632135.77%

If we compare the two results with TBB on:

Vertices1000 LEAF_LIMIT (default)10000 LEAF_LIMIT (new)Perf. gain
251658262.4740730.1068682315.07%
62914580.3079480.0290881058.68%
15728660.1114590.0071681554.95%
3932160.0022890.002261101.24%

It seems like if we avoid starting TBB with a large number of nodes the performance improvement is huge. Increasing the leaf limit makes these kinds of operations up to 23 times faster, but that would be like disabling multithreading for small brush strokes.

  • Is there a way to fix this in the scheduler?
  • Can we do something like sending small chunks of nodes to TBB instead of starting the loop with 7000 nodes at the same time?
  • Can we find a better optimal leaf limit to get a better workload per core suitable for modern processors by comparing the results on different hardware? Dyntopo leaf limit is in 100 elements, which I think it does not make much sense.

Event Timeline

Exposing the leaf limit through the API might let you create a testing script to find the sweet-spots for different scenarios. If there isn't a workable middle ground between the ideal leaf limit for looping over all of the vertices in a high poly mesh and the ideal leaf limit for small brush strokes, you might be able to finesse it with a scaling factor. It'll depend on where the overhead comes from and how linearly that overhead changes, though, and we all know how that goes.

On an abstract level, It'd be interesting to see if we could extend and refit a BVH tree quickly and accurately enough to adjust the leaf limit without rebuilding the tree every time. That's more of a BIH thing than a BVH thing, though.

I only tested the subdivided cube but I can't seem to be able to reproduce your numbers.

System Information
CPU: Intel i7 3770K @ 3.40GHz x 8
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1660/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 441.28

Blender Version
Broken: version: 2.82 (sub 6), branch: master (modified), commit date: 2020-01-06 20:54, hash: rB3a35301fd16d

Subdivide default cube N number of times:

N SubdivisionsVerticesPBVH NodesTBB ON (seconds)TBB OFF (seconds)DIFF
11251658267598 (+2 from yours)0.383330s0.561035s68.33%
10629145819200.031481s0.074454s42.28%
915728664640.004428s0.013261s33.39%
83932161120.001029s0.002824s36.44%

Quite sure unrelated issues i ran into while testing:

I thought i save some time and save the subdivided cube and ran into some crashing behavior

  • Add a cube, subdivide N number of times and apply
  • Enter Sculpt Mode
  • Save Cube_N.blend
  • Quit Blender
  • Start Blender
  • Load Cube_N.blend
  • Run "Invert Mask" (press A + drag left)
  • Crash

Second thing i ran into is when you use the subdivision modifier i get the same 'PBVH nodes' as listed in your table, but when i used the subdivision set ... operator(?) i get MASK INVERT: 1 nodes - 0.000005s nice and fast, but and i pretty much can't sculpt cause blender keeps locking up for a couple of seconds every time i try to make a stroke

  • Add a cube
  • Ctrl-0
  • In UI Select the number of subdivisions
  • Enter Sculpt Mode
  • Run "Invert Mask" (press A + drag left)

I only tested the subdivided cube but I can't seem to be able to reproduce your numbers.
System Information
CPU: Intel i7 3770K @ 3.40GHz x 8
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1660/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 441.28
Blender Version
Broken: version: 2.82 (sub 6), branch: master (modified), commit date: 2020-01-06 20:54, hash: rB3a35301fd16d
Subdivide default cube N number of times:

N SubdivisionsVerticesPBVH NodesTBB ON (seconds)TBB OFF (seconds)DIFF
11251658267598 (+2 from yours)0.383330s0.561035s68.33%
10629145819200.031481s0.074454s42.28%
915728664640.004428s0.013261s33.39%
83932161120.001029s0.002824s36.44%

Quite sure unrelated issues i ran into while testing:
I thought i save some time and save the subdivided cube and ran into some crashing behavior

  • Add a cube, subdivide N number of times and apply
  • Enter Sculpt Mode
  • Save Cube_N.blend
  • Quit Blender
  • Start Blender
  • Load Cube_N.blend
  • Run "Invert Mask" (press A + drag left)
  • Crash

Second thing i ran into is when you use the subdivision modifier i get the same 'PBVH nodes' as listed in your table, but when i used the subdivision set ... operator(?) i get MASK INVERT: 1 nodes - 0.000005s nice and fast, but and i pretty much can't sculpt cause blender keeps locking up for a couple of seconds every time i try to make a stroke

  • Add a cube
  • Ctrl-0
  • In UI Select the number of subdivisions
  • Enter Sculpt Mode
  • Run "Invert Mask" (press A + drag left)

Yo Lazydodo i m in the middle of updating my windows 7 to windows 10, no time compiling, can you share your windows build with this patch so that i test it with different models?

Sorry, went to work on something else afterwards don't have the build anymore

Sorry, went to work on something else afterwards don't have the build anymore

No problemo :)

Likely what happens is that a thread working on a PBVH node is interrupted by the Linux scheduler, and then it takes too long for it to be scheduled again to complete the node, holding up all other threads. There is no direct way to prevent that kind of thing, you can only really ensure code is using good practices and tweak things to indirectly get the Linux scheduler to do what you want. And this is also affected by threads outside of Blender, like a music player or some other more obscure background process.

But you can look into the TBB docs and find some things to tweak:

I created a patch to debug Sculpt Mode performance and try to find better defaults. It exposes the settings from the scheduler and the PBVH in the UI: P1208

I would like to focus on:

  • Get rid of the periodic lag that appears in the middle of the strokes. It does not necessarily have to make the whole stroke faster, but the performance should be as consistent as possible.
  • Have a default configuration where is possible to debug sculpt mode performance reliably. I tried to implement some of the topics described in T68873 (consolidating the loops) in the past, but if a loop over 25M can randomly take 0.4 seconds or 5 seconds, it is hard to tell if the optimizations are working.

Is there any chance we can record some strokes (data from ghost perhaps?) on a standardized scene and play it back at a later point in time? having a repeatable scenario is generally a huge help when you are trying to nail down a flaky perf issue.

Been prodding around with this, with a with a 25M faces, 50M tris mesh (cube subdiv 11) couple of observations :

  1. Sculpting viewport uses 50% more gpu ram than the regular viewport, which brings me awfully close to the 6gb of ram i have on this card. causing performance issues when i swap from regular viewport to sculpting, i can pan at 7 fps at best, however if I save the file in the sculpting view and load it it'll happily pan at 33 fps.

kinda feels like it's backing up the GPU ram with regular ram.

  1. All being said and done, with this the base mesh loaded blender allocates almost 21GB of ram.

If you are having inconsistent performance check that when you are having this flaky behavior you are not out of ram and paging in/out like crazy, cause that would easily explain the performance swings you are seeing.

  1. OpenGL

3.0) while the sculpting is reasonably threaded, everybody idles when the main thread is talking to the GPU (first 7 threads are the TBB threads, 7984 is the main thread) having a colored block means the thread is running, single grey line the thread is sleeping.

the gap where it idles is mostly caused by 2 main offenders

3.1) workbench_deferred_draw_scene marked in blue below.

3.2) VertBuffer_upload_data (also marked in blue)

called from the following call-stack

Inside the scope of blender the GPU memory increases with 30 %. Draw performance linux+amd is the same but uses a lot of RAM. Might be a NVIDIA implementation issue. I will check if we can compress the data stream a bit.

Aaron Carlisle (Blendify) changed the task status from Needs Triage to Confirmed.Feb 17 2020, 8:39 PM
Aaron Carlisle (Blendify) changed the subtype of this task from "Report" to "To Do".