Fix #109583: Avoid allocation new custom loop normals for write #109671

Closed
Iliya Katushenock wants to merge 3 commits from mod_moder:tmp_fix_data_race_to_compute_normals into blender-v3.6-release

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Curve Deform node has never worked correctly.
This used to be a leaked copy made by each node
to write its own version of the custom loop normals.
Const correctness and sharing increased the chances of a crash.

Curve Deform node has never worked correctly. This used to be a leaked copy made by each node to write its own version of the custom loop normals. Const correctness and sharing increased the chances of a crash.
Iliya Katushenock added the
Interest
Geometry Nodes
Interest
Modeling
labels 2023-07-03 22:20:37 +02:00
Iliya Katushenock requested review from Jacques Lucke 2023-07-03 22:20:55 +02:00
Iliya Katushenock requested review from Hans Goudey 2023-07-03 22:20:55 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2023-07-03 22:20:59 +02:00
Iliya Katushenock force-pushed tmp_fix_data_race_to_compute_normals from e42064db77 to a61d126618 2023-07-03 22:29:35 +02:00 Compare
Iliya Katushenock changed title from Fix #109583: Const version of mesh_calc_normals to only eval normals in geometry nodes to Fix #109583: Const version of mesh_calc_normals to only eval normals in geometry nodes 2023-07-03 22:29:39 +02:00
mod_moder changed target branch from main to blender-v3.6-release 2023-07-03 22:29:50 +02:00
Iliya Katushenock added 1 commit 2023-07-03 22:30:56 +02:00
Iliya Katushenock added 1 commit 2023-07-04 01:24:19 +02:00
Iliya Katushenock changed title from Fix #109583: Const version of mesh_calc_normals to only eval normals in geometry nodes to Fix #109583: Avoid allocation new custom loop normals for write 2023-07-04 02:07:17 +02:00
Jacques Lucke reviewed 2023-07-04 10:13:24 +02:00
@ -1890,0 +1887,4 @@
/* May be nullptr. Const_cast to avoid data race while normals computing from different threads
* for the same mesh. */
blender::short2 *clnors = const_cast<blender::short2 *>(static_cast<const blender::short2 *>(
CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL)));
Member

That does not seem quite right to me. How can BKE_mesh_calc_normals_split_ex know that it is allowed to use const_cast and ignore implicit sharing?

That does not seem quite right to me. How can `BKE_mesh_calc_normals_split_ex` know that it is allowed to use `const_cast` and ignore implicit sharing?
Author
Member

The problem was exactly that 10 nodes were taking it for the writing. Since there is only one real owner (only the object itself), different threads create new owners (that is, they simply add a reference count) and copy the data. But the data itself must continue to belong to the object. That is, now, the object must own all copies of this data for different threads. I really don't know how to fix this...
This doesn't look right.
For this reason, I'd rather just have a different version of the function (which would ignore this data). But Hans' suggestion was that it doesn't work just because of const correctness. If the streams will only read, everything should be fine. But they can still make a changes...
And a future normal refactoring might fix that..

The problem was exactly that 10 nodes were taking it for the writing. Since there is only one real owner (only the object itself), different threads create new owners (that is, they simply add a reference count) and copy the data. But the data itself must continue to belong to the object. That is, now, the object must own all copies of this data for different threads. I really don't know how to fix this... This doesn't look right. For this reason, I'd rather just have a different version of the function (which would ignore this data). But Hans' suggestion was that it doesn't work just because of const correctness. If the streams will only read, everything should be fine. But they can still make a changes... And a future normal refactoring might fix that..
Member

If this is just a cache, then it should be protected by a mutex. I probably don't fully understand what's going on here right now.

If this is just a cache, then it should be protected by a mutex. I probably don't fully understand what's going on here right now.
Author
Member

10 curve deform nodes are asked to compute normals on a single object. Each of the nodes, through this function, requires the creation of local data for writing. And either a leak occurs, or now the reference counter is causing a crash ...

10 curve deform nodes are asked to compute normals on a single object. Each of the nodes, through this function, requires the creation of local data for writing. And either a leak occurs, or now the reference counter is causing a crash ...
Author
Member

Although, now it seems to me that if each node creates its own copy of the mesh, implicit sharing will work correctly here.

Although, now it seems to me that if each node creates its own copy of the mesh, implicit sharing will work correctly here.
Author
Member
https://projects.blender.org/blender/blender/pulls/109695
Iliya Katushenock changed title from Fix #109583: Avoid allocation new custom loop normals for write to Fix #109583: Avoid allocation new custom loop normals for write 2023-07-04 15:11:41 +02:00
Iliya Katushenock changed title from Fix #109583: Avoid allocation new custom loop normals for write to Fix #109583: Avoid allocation new custom loop normals for write 2023-07-04 15:15:57 +02:00

Pull request closed

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
2 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#109671
No description provided.