Cycles: Use Blender headers to access geometry data, avoid copy #112306

Merged
Hans Goudey merged 7 commits from HooglyBoogly/blender:cycles-blender-geometry-no-copy into main 2023-09-18 02:50:16 +02:00
Member

Since 34b4487844, attributes are always made mutable when
accessed from the RNA API. This can result in unnecessary copies, which
increases memory usage and reduces performance.

Cycles is the only user of the C++ RNA API, which we'd like to remove
in the future since it doesn't really make sense in the big picture. Hydra is
now a better alternative for external render engines.

To start that change and fix the unnecessary copies, this commit
moves to use Blender headers directly for accessing attribute and other
geometry data. This also removes the few places that still had
overhead from the RNA API after the changes (0) in 3.6. In a simple
test with a large grid, I observed a 1.76x performance improvement,
from 1.04 to 0.59 seconds to extract the mesh data to Cycles.

Pull Request: #112306

Since 34b44878449d67a56fd2, attributes are always made mutable when accessed from the RNA API. This can result in unnecessary copies, which increases memory usage and reduces performance. Cycles is the only user of the C++ RNA API, which we'd like to remove in the future since it doesn't really make sense in the big picture. Hydra is now a better alternative for external render engines. To start that change and fix the unnecessary copies, this commit moves to use Blender headers directly for accessing attribute and other geometry data. This also removes the few places that still had overhead from the RNA API after the changes ([0]) in 3.6. In a simple test with a large grid, I observed a 1.76x performance improvement, from 1.04 to 0.59 seconds to extract the mesh data to Cycles. [0]: https://wiki.blender.org/wiki/Reference/Release_Notes/3.6/Cycles#Performance Pull Request: https://projects.blender.org/blender/blender/pulls/112306
Hans Goudey added 2 commits 2023-09-12 22:54:43 +02:00
Hans Goudey requested review from Brecht Van Lommel 2023-09-12 22:54:57 +02:00
Hans Goudey added this to the Render & Cycles project 2023-09-12 22:55:13 +02:00
Author
Member

@blender-bot build

@blender-bot build
Author
Member

image

I have no clue about the freestyle test failures yet. I'll have to figure out how that could be related to these changes

![image](/attachments/627ac20a-7fbc-4de5-9cc2-80339c7f889d) I have no clue about the freestyle test failures yet. I'll have to figure out how that could be related to these changes
152 KiB
Hans Goudey added 2 commits 2023-09-13 02:16:36 +02:00
Sergey Sharybin reviewed 2023-09-13 16:23:36 +02:00
@ -0,0 +2,4 @@
*
* SPDX-License-Identifier: Apache-2.0 */
#ifndef __BLENDER_ATTRIBUTE_CONVERT_H__

In the new code we use #pragma once.
Perhaps we should just go ahead and convert the header guards to uniform case, similar to what we did in Blender.

In the new code we use `#pragma once`. Perhaps we should just go ahead and convert the header guards to uniform case, similar to what we did in Blender.
@ -399,0 +331,4 @@
src[tri.tri[0]][0], src[tri.tri[0]][1], src[tri.tri[0]][2], src[tri.tri[0]][3]);
data[i * 3 + 1] = make_uchar4(
src[tri.tri[1]][0], src[tri.tri[1]][1], src[tri.tri[1]][2], src[tri.tri[1]][3]);
data[i * 3 + 1] = make_uchar4(

data[i * 3 + 2] = make_uchar4(

`data[i * 3 + 2] = make_uchar4(`
HooglyBoogly marked this conversation as resolved
Hans Goudey added 1 commit 2023-09-13 17:29:28 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
607b8793c1
Fix index in corner by color special case
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2023-09-13 19:38:34 +02:00
Author
Member

@blender-bot build

@blender-bot build
Author
Member

Now it's the script_validate_keymap test failing, that happens in main though, so I think this PR is ready.

Now it's the `script_validate_keymap` test failing, that happens in main though, so I think this PR is ready.
Hans Goudey added 1 commit 2023-09-15 14:42:21 +02:00
Brecht Van Lommel approved these changes 2023-09-15 17:49:33 +02:00
Hans Goudey merged commit 2fac2228d0 into main 2023-09-18 02:50:16 +02:00
Hans Goudey deleted branch cycles-blender-geometry-no-copy 2023-09-18 02:50:17 +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 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#112306
No description provided.