Cycles: Avoid overhead from RNA when extracting mesh data #106275

Merged
Hans Goudey merged 14 commits from HooglyBoogly/blender:cycles-mesh-cleanup into main 2023-04-03 17:05:10 +02:00
Member

Use raw Blender structs and mesh data rather than using the RNA API.
There isn't any benefit from using the RNA when Cycles is compiled
with Blender anyway.

This gives a significant improvement in performance when ingesting
meshes, since using the RNA API rather than random access with
pointers was very expensive.

Some tests of the runtime of the create_mesh function (in seconds):

Before After
Grid 0.66 0.11
Many realized cubes 2.60 0.48
Large curve to mesh setup 4.18 1.14

Here is a profile from before the change showing the overhead
from function calls and string lookups:

image

Also change to resizing the arrays and filling them by index rather
than appending. This makes the parallel aspect of the logic clearer,
and makes the loops easier to parallelize in the future, and makes
it easier to have a performance benefit when an attribute like
sharp_face doesn't exist.

Use raw Blender structs and mesh data rather than using the RNA API. There isn't any benefit from using the RNA when Cycles is compiled with Blender anyway. This gives a significant improvement in performance when ingesting meshes, since using the RNA API rather than random access with pointers was very expensive. Some tests of the runtime of the `create_mesh` function (in seconds): | | Before | After | | ------------------------- | ------ | ----- | | Grid | 0.66 | 0.11 | | Many realized cubes | 2.60 | 0.48 | | Large curve to mesh setup | 4.18 | 1.14 | Here is a profile from before the change showing the overhead from function calls and string lookups: ![image](/attachments/b5abc284-02d6-411c-927d-a811a8371902) Also change to resizing the arrays and filling them by index rather than appending. This makes the parallel aspect of the logic clearer, and makes the loops easier to parallelize in the future, and makes it easier to have a performance benefit when an attribute like `sharp_face` doesn't exist.
Hans Goudey added 5 commits 2023-03-29 19:18:45 +02:00
Hans Goudey added this to the Render & Cycles project 2023-03-29 19:21:18 +02:00
Hans Goudey added the
Module
Render & Cycles
Interest
Performance
labels 2023-03-29 19:21:33 +02:00
Hans Goudey changed title from Cycles: Avoid overhead from RNA when extracting mesh data to WIP: Cycles: Avoid overhead from RNA when extracting mesh data 2023-03-29 19:21:38 +02:00
First-time contributor

:)

:)
Hans Goudey added 2 commits 2023-03-30 17:29:52 +02:00
Hans Goudey changed title from WIP: Cycles: Avoid overhead from RNA when extracting mesh data to Cycles: Avoid overhead from RNA when extracting mesh data 2023-03-30 20:14:14 +02:00
Hans Goudey added 2 commits 2023-03-30 20:14:16 +02:00
Hans Goudey requested review from Brecht Van Lommel 2023-03-30 20:15:28 +02:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2023-03-31 13:52:02 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
522680ca28
Merge branch 'main' into cycles-mesh-cleanup
Author
Member

@blender-bot build macos

@blender-bot build macos
Hans Goudey force-pushed cycles-mesh-cleanup from 3f04908084 to 522680ca28 2023-03-31 14:15:50 +02:00 Compare
Brecht Van Lommel requested changes 2023-04-03 16:08:31 +02:00
@ -412,43 +412,43 @@ static void attr_create_generic(Scene *scene,
switch (b_data_type) {
case BL::Attribute::data_type_FLOAT: {
BL::FloatAttribute b_float_attribute{b_attribute};
const float *src = static_cast<const float *>(b_float_attribute.data[0].ptr.data);

Is this safe when the number of elements is 0? It seems fragile regardless, seems better to use:

if (b_float_attribute.data.length()) {
  const float *src = static_cast<const float *>(b_float_attribute.data[0].ptr.data);
  fill_generic_attribute(b_mesh, data, b_domain, subdivision, [&](int i) { return src[i]; });
}
Is this safe when the number of elements is 0? It seems fragile regardless, seems better to use: ``` if (b_float_attribute.data.length()) { const float *src = static_cast<const float *>(b_float_attribute.data[0].ptr.data); fill_generic_attribute(b_mesh, data, b_domain, subdivision, [&](int i) { return src[i]; }); } ```
HooglyBoogly marked this conversation as resolved
Hans Goudey added 3 commits 2023-04-03 16:46:23 +02:00
Hans Goudey added 1 commit 2023-04-03 16:54:37 +02:00
Hans Goudey requested review from Brecht Van Lommel 2023-04-03 16:56:47 +02:00
Brecht Van Lommel approved these changes 2023-04-03 17:01:27 +02:00
Hans Goudey merged commit 4bcd59d644 into main 2023-04-03 17:05:10 +02:00
Hans Goudey deleted branch cycles-mesh-cleanup 2023-04-03 17:05:11 +02:00
Brecht Van Lommel removed this from the Render & Cycles project 2023-05-24 19:05:21 +02:00
Sign in to join this conversation.
No reviewers
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#106275
No description provided.