Cycles geometry preparation and upload refactor #105372

Open
opened 2023-03-02 12:41:47 +01:00 by William Leeson · 4 comments
Member

Why

Cycle's geometry upload and preparation can be refactored to be easier to understand and also to improve its efficiency. By creating a single parallel_for for each device instead of one thread per copy operation the overhead of handling threading can be reduced thereby improving performance. Also, by splitting the host side work from the device side work it is easier to distribute the workload. Some calculations are performed twice or unnecessarily as they only needed for specific task but are performed regardless as this is hard to work out with the current code.

What

  • Break the geometry update into host and device update.
  • Re-order the update so that it is easier to understand
  • Create a parallel loop over each device and from there upload the data.
    • Create a DeviceScene per device instead of using the MultiDevice
    • Create a BVH per device instead of using the MultiDevice
  • Only perform calculations that are required
    This results in the program flow looking like the following
    This method works as follows:
  1. Calculate vertex normals and gather undisplaced vertices
  2. Tessellate mesh if needed
  3. Compute object bounds
  4. fill attribute buffers
  5. fill geometry buffers
    ----DEVICE SPECIFIC BEGIN----
  6. copy attribute buffers to device
  7. copy geometry buffers to device
    --- only run on the first device ---
  8. displace meshes and calculate shadow transparency if needed
    ----DEVICE SPECIFIC END----
  9. if displacement or shadow transparency then refill buffers and re-upload
    ----START OF MIXED DEVICE AND HOST CODE----
  10. build geometry BVHs
  11. build scene BVH
    ----HOST SPECIFIC BELOW THIS POINT
  12. Remove modified or update tags

The original flow and the new flow are shown in the files below. To achieve this a DeviceScene is created for each device. However, as this is just updating the geometry device update (and not all uses of the DeviceScene) the old DeviceScene needs to remain so other that buffers can be handled by the multi-device. The host side pointers are shared by all the DeviceScenes so they only need to be packed once. This is done using a method to update the host pointer of one DeviceScene from an existing DeviceScene.

## Why Cycle's geometry upload and preparation can be refactored to be easier to understand and also to improve its efficiency. By creating a single parallel_for for each device instead of one thread per copy operation the overhead of handling threading can be reduced thereby improving performance. Also, by splitting the host side work from the device side work it is easier to distribute the workload. Some calculations are performed twice or unnecessarily as they only needed for specific task but are performed regardless as this is hard to work out with the current code. ## What * Break the geometry update into host and device update. * Re-order the update so that it is easier to understand * Create a parallel loop over each device and from there upload the data. * Create a DeviceScene per device instead of using the MultiDevice * Create a BVH per device instead of using the MultiDevice * Only perform calculations that are required This results in the program flow looking like the following This method works as follows: 1. Calculate vertex normals and gather undisplaced vertices 2. Tessellate mesh if needed 3. Compute object bounds 4. fill attribute buffers 5. fill geometry buffers ----DEVICE SPECIFIC BEGIN---- 6. copy attribute buffers to device 7. copy geometry buffers to device --- only run on the first device --- 8. displace meshes and calculate shadow transparency if needed ----DEVICE SPECIFIC END---- 9. if displacement or shadow transparency then refill buffers and re-upload ----START OF MIXED DEVICE AND HOST CODE---- 10. build geometry BVHs 11. build scene BVH ----HOST SPECIFIC BELOW THIS POINT 12. Remove modified or update tags The original flow and the new flow are shown in the files below. To achieve this a DeviceScene is created for each device. However, as this is just updating the geometry device update (and not all uses of the DeviceScene) the old DeviceScene needs to remain so other that buffers can be handled by the multi-device. The host side pointers are shared by all the DeviceScenes so they only need to be packed once. This is done using a method to update the host pointer of one DeviceScene from an existing DeviceScene.
William Leeson added the
Type
Design
label 2023-03-02 12:41:48 +01:00

It would be nice to ever be able to calculate render attributes using buitin groups of geometry nodes. They are already trying to provide acceptable speed and unification for things like vertex normals, edge separation or island indices.

It would be nice to ever be able to calculate render attributes using buitin groups of geometry nodes. They are already trying to provide acceptable speed and unification for things like vertex normals, edge separation or island indices.
William Leeson added reference main 2023-03-02 15:31:26 +01:00
William Leeson added this to the Render & Cycles project 2023-03-02 15:31:37 +01:00
Author
Member

It would be nice to ever be able to calculate render attributes using buitin groups of geometry nodes. They are already trying to provide acceptable speed and unification for things like vertex normals, edge separation or island indices.

Yes that would be possible. However, Cycles currently uses it's own routines to calculate normals from the faces and vertices. I believe the attributes are filled from the existing data passed in from Blender some of which could come from the geometry nodes.

> It would be nice to ever be able to calculate render attributes using buitin groups of geometry nodes. They are already trying to provide acceptable speed and unification for things like vertex normals, edge separation or island indices. Yes that would be possible. However, Cycles currently uses it's own routines to calculate normals from the faces and vertices. I believe the attributes are filled from the existing data passed in from Blender some of which could come from the geometry nodes.
William Leeson added the
Module
Render & Cycles
Interest
Cycles
labels 2023-03-02 15:57:07 +01:00
Author
Member

@brecht This is the basic design for the parallel device update. I'll have a WIP commit hopefully by Monday.

@brecht This is the basic design for the parallel device update. I'll have a WIP commit hopefully by Monday.

Hi, any update ?

Hi, any update ?
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 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#105372
No description provided.