Cycles: build Light Tree in parallel #105862

Merged
Weizhen Huang merged 4 commits from weizhen/blender:parallel_light_tree into main 2023-03-20 18:02:23 +01:00
Member

Push a task to TaskPool when more than MIN_PRIMS_PER_THREAD primitives are to be processed. The nodes are rearranged in a depth-first order when copied to the device.
Tested with the scene in #105550 on an Apple M1 Ultra (20 cores), about 11x speedup.

Push a task to `TaskPool` when more than `MIN_PRIMS_PER_THREAD` primitives are to be processed. The nodes are rearranged in a depth-first order when copied to the device. Tested with the scene in #105550 on an Apple M1 Ultra (20 cores), about 11x speedup.
Weizhen Huang added the
Module
Render & Cycles
label 2023-03-17 20:08:28 +01:00
Weizhen Huang force-pushed parallel_light_tree from 26d66945c6 to 8bd9a5bf0a 2023-03-20 11:39:52 +01:00 Compare
Weizhen Huang force-pushed parallel_light_tree from 8bd9a5bf0a to 66b46eee66 2023-03-20 11:42:47 +01:00 Compare
Author
Member

@blender-bot build

@blender-bot build
Weizhen Huang force-pushed parallel_light_tree from 66b46eee66 to 1b9d56ce9c 2023-03-20 12:29:06 +01:00 Compare
Author
Member

Build again with MIN_PRIMS_PER_THREAD set to INT_MAX to test the parallel build.

@blender-bot build

Build again with `MIN_PRIMS_PER_THREAD` set to `INT_MAX` to test the parallel build. @blender-bot build
Weizhen Huang force-pushed parallel_light_tree from 1b9d56ce9c to 2539258099 2023-03-20 14:44:00 +01:00 Compare
Weizhen Huang changed title from WIP: Cycles: build Light Tree in parallel to Cycles: build Light Tree in parallel 2023-03-20 14:44:50 +01:00
Weizhen Huang requested review from Brecht Van Lommel 2023-03-20 14:45:11 +01:00
Weizhen Huang requested review from Sergey Sharybin 2023-03-20 14:51:51 +01:00
Brecht Van Lommel requested changes 2023-03-20 15:48:34 +01:00
Brecht Van Lommel left a comment
Owner

This looks generally fine, just some comments on implementation details.

Eventually we can also parallelize the loops in nodes with many prims. I suggest to add that as a separate bullet point in #77889 and make a comment in the code.

This looks generally fine, just some comments on implementation details. Eventually we can also parallelize the loops in nodes with many prims. I suggest to add that as a separate bullet point in #77889 and make a comment in the code.
@ -235,3 +230,1 @@
int LightTree::recursive_build(
int start, int end, vector<LightTreePrimitive> &prims, uint bit_trail, int depth)
template<Child child>

Is there a reason this is a template argument instead of a regular function argument?

It's only used for parent->children[child], not worth specializing the function for as far as I can see.

Is there a reason this is a template argument instead of a regular function argument? It's only used for `parent->children[child]`, not worth specializing the function for as far as I can see.
brecht marked this conversation as resolved
@ -53,2 +54,4 @@
*/
/* Left or right child of an inner node. */
enum Child {

This name is too generic to put in the global Cycles namespace. Should be either defined inside the LightTree class, or named LightTreeChild.

This name is too generic to put in the global Cycles namespace. Should be either defined inside the `LightTree` class, or named `LightTreeChild`.
brecht marked this conversation as resolved
@ -143,0 +160,4 @@
const uint &bit_trial)
{
num_nodes++;
return new LightTreeNode(bbox, bcone, energy, bit_trial);

We try to avoid new and delete in new code to avoid potential memory allocation bugs. Instead unique_ptr and make_unique can be used.

We try to avoid `new` and `delete` in new code to avoid potential memory allocation bugs. Instead `unique_ptr` and `make_unique` can be used.
brecht marked this conversation as resolved
Weizhen Huang reviewed 2023-03-20 15:51:38 +01:00
@ -235,3 +230,1 @@
int LightTree::recursive_build(
int start, int end, vector<LightTreePrimitive> &prims, uint bit_trail, int depth)
template<Child child>
Author
Member

It's also used for recursive_build<left>(current_node, start, middle, prims, bit_trail, depth + 1);, I think it looks better than recursive_build(0, current_node, start, middle, prims, bit_trail, depth + 1);

It's also used for `recursive_build<left>(current_node, start, middle, prims, bit_trail, depth + 1);`, I think it looks better than `recursive_build(0, current_node, start, middle, prims, bit_trail, depth + 1);`
brecht marked this conversation as resolved
Author
Member

Eventually we can also parallelize the loops in nodes with many prims.

I tried to parallelize that too, but I saw almost no performance improvement.
After this pull request is merged, I'll build another one upon it that computes the bounding box (and so on) of a node by summing up the buckets, then it should be fine.

> Eventually we can also parallelize the loops in nodes with many prims. I tried to parallelize that too, but I saw almost no performance improvement. After this pull request is merged, I'll build another one upon it that computes the bounding box (and so on) of a node by summing up the buckets, then it should be fine.
Brecht Van Lommel reviewed 2023-03-20 16:22:57 +01:00
@ -235,3 +230,1 @@
int LightTree::recursive_build(
int start, int end, vector<LightTreePrimitive> &prims, uint bit_trail, int depth)
template<Child child>

I think this would look ok too?

recursive_build(left, current_node, start, middle, prims, bit_trail, depth + 1);

Generally there should be a performance reason for using templates like this. Not a big deal for any individual function, but still would rather not do it here.

I think this would look ok too? ``` recursive_build(left, current_node, start, middle, prims, bit_trail, depth + 1); ``` Generally there should be a performance reason for using templates like this. Not a big deal for any individual function, but still would rather not do it here.
brecht marked this conversation as resolved
Weizhen Huang added 1 commit 2023-03-20 17:11:58 +01:00
Weizhen Huang added 1 commit 2023-03-20 17:54:18 +01:00
Brecht Van Lommel approved these changes 2023-03-20 17:57:42 +01:00
Weizhen Huang added 1 commit 2023-03-20 18:01:17 +01:00
Weizhen Huang merged commit 23c5e06932 into main 2023-03-20 18:02:22 +01:00
Weizhen Huang deleted branch parallel_light_tree 2023-03-20 18:02:23 +01:00
Sign in to join this conversation.
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
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105862
No description provided.