Cycles Procedural API and faster scene update #79174
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
7 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#79174
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
This design task is for discussing ideas regarding procedural nodes and improvements to the scene update for faster interactive rendering.
Procedural API
A procedural is a node that can create geometry nodes in the scene before rendering. Such nodes can be used to import data from Alembic or USD files, or even a custom file format, without Cycles needing to explicitly know about those formats. The API for such a node can be as simple as deriving a base class and overriding a virtual function as suggested in D3089 or it could be more granular with various functions to know what they would create (e.g. number and types of nodes). Internally, the procedural nodes will use the Cycles API (#79131) to create or update data.
With procedurals the current approach to updating the scene data would need to be changed. Currently, scene updates start by iterating over the geometry nodes and their shaders before calling
Scene::device_update()
, but procedurals would need to be updated first.Managing the procedurals, and the nodes that they create is bit unclear at the moment. When working on updating D3089, I run into issues with the Blender scene synchronization stage where Cycles objects not known by the synchronization system would be deleted between frames, or during viewport updates in interactive rendering. I did add some mechanisms to preserve those objects but it is not a nice approach I think.
Faster scene update
Scene update is too slow for real time applications or interactive rendering. Currently, Cycles is using a very conservative approach to updating scene data, especially for mesh nodes: if anything is changed, the entire device memory is freed and recreated. Ideally, if we only changed the vertices of a mesh, without using any displacement, we should be able to just copy the new data directly into the device memory, and recreate the BVH. For mesh objects, the device memory may also be recreated if displacement is used and has been applied, which leads to a double update of the device memory for every frame.
To perform the updates, we iterate over all of the objects and shaders in the scene in a certain order to account for dependencies between them. Because of the dependencies, we may iterate multiple times over the same container. For example, mesh objects are iterated over multiple times during a single update :
And a few more times to gather metrics to allocate and copy their data to the device. Most of the times though, after the first frame has been rendered, these loops skip over the meshes that do not need an update.
To accelerate data processing, temporary multithreaded task pools are used in various places. For example, there exist dedicated task pools for loading 3d volume textures, images, or compiling SVM shaders.
To improve performance regarding scene updates, we could reduce the number of loops, parallelize object updates, and avoid unnecessary memory reallocations and data copying.
What needs to be known to granularize updates for geometry objects:
Those flags would be set automatically when modifying data through the API to free clients from setting them directly (#79131).
Ideas for improvements
Separate geometries in different arrays based on what needs to be done : geometries_to_displace, geometries_needing_bvh, gometries_needing_volumes, etc. And process arrays separately. This would apply to all the managers: each one would keep a list of managed objects that were modified.
This is the system that best fits a case where procedurals can recursively generate other procedurals.
Scene updates could be handled by a multithreaded task sheduler, replacing the various specific task pools currently used, and making the entire process multithreaded.
Tasks would be initially created for the objects (and the procedurals) which need to be updated. These would create other tasks, if needed, for the shaders that they use, and these in turn would create tasks for loading images, etc. This way, we would remove a lot of the manual iterations over containers to know what is needed. This essentially creates a dependency graph and processes it at the same time.
Tasks can be granular, and some node types can have multiple tasks. A mesh node could have one task for its general data update (computing normals, etc.) one for creating displacement data, and a final one to compute its BVH.
Dependencies between tasks can be noted: a displacement task requiring an image to be processed should wait for the image data to be available. The task scheduler can also segregate tasks by type and hand tasks to worker threads in an order similar to that presently used in Scene::device_update, i.e. image tasks would be processed before displacement tasks.
When all tasks are done, and data about what they did has been gathered, we can then at once decide whether to recreate the device memory or override it with new data and hand it over to the device for rendering.
Added subscribers: @kevindietrich, @fx
Added subscriber: @KenzieMac130
Added subscriber: @BartekMoniewski
This issue was referenced by blender/cycles@50fe70268a
This issue was referenced by
edd1164575
This issue was referenced by blender/cycles@d4567df044
This issue was referenced by
527f8b32b3
Changed status from 'Needs Triage' to: 'Confirmed'
This issue was referenced by blender/cycles@588eb94148
This issue was referenced by
31a620b942
Added subscriber: @EAW
This issue was referenced by blender/cycles@0a013f4a0a
This issue was referenced by
bbe6d44928
This issue was referenced by
2e67191c86
This issue was referenced by
b64f0fab06
Added subscriber: @SteffenD
This issue was referenced by
51862c8445
Added subscriber: @brecht
Changed status from 'Confirmed' to: 'Resolved'
We can consider this project finished now, thanks @kevindietrich for the many optimizations. There will be a blog post on code.blender.org later summarizing the results.
Optimizations are of course always happening, and the Alembic procedural may be incrementally improved further, but this particular project is now finished.