Mesh: Store BMEditMesh in shared pointer #120276
No reviewers
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#120276
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:mesh-edit-mesh-shared-ptr"
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?
The main motivation for this is that it's part of a fix for #113377,
where I want to propagate the edit mesh pointers through copied
meshes in modifiers and geometry nodes, instead of just setting the
edit mesh pointer at the end of the modifier stack. That would have
two main benefits:
which means it can be shared directly among evaluated objects.
object during evaluation (with the object info node), the final edit
mesh pointer will not be "wrong", allowing us to skip index-mapped
GPU data extraction.
Beyond that, using a shared pointer just makes things more automatic.
Handling of edit mesh data is already complicated enough, this way some
of the worry and complexity can be handled by RAII.
One thing to keep in mind is that the edit mesh's BMesh is still freed
manually with
EDBM_mesh_free_data
when leaving edit mode. I figuredthat was a more conservative approach for now. Maybe eventually that
could be handled automatically with RAII too.
@blender-bot build
Evaluated state is kind of supposed to be read-only. All modifications are supposed to be done on the original ID, and the evaluated state is to be updated via a dependency graph tag/update.
Is this writing to evaluated mesh is something that already is done in the code? It would help pointing it out, because maybe goal of why it is done is to be reached somehow differently. Or, digging into it might demonstrate better what the actual intent of such writes is.
@ -851,7 +843,6 @@ Mesh *BKE_mesh_new_nomain_from_template(const Mesh *me_src,
void BKE_mesh_eval_delete(Mesh *mesh_eval)
{
/* Evaluated mesh may point to edit mesh, but never owns it. */
The comment is out-of-date?
Good point. It reminded me that this function is unnecessary now. I've replaced it with
BKE_id_free
@ -70,3 +70,2 @@
mesh->runtime->edit_mesh = static_cast<BMEditMesh *>(MEM_dupallocN(em));
mesh->runtime->edit_mesh->is_shallow_copy = true;
mesh->runtime->edit_mesh = std::make_shared<BMEditMesh>(*em);
This seems to be a wrong usage of usage of shared pointers. There are now code-paths which will get bare pointer from the
mesh->runtime->edit_mesh.get()
, pass it to theBKE_mesh_wrapper_from_editmesh
, and here a new shared pointer is created.From my understanding it defeats the original intent of an evaluated state sharing the same
em
pointer as the input.Indeed, thanks. It isn't harmful to correctness in this PR, but it might have messed with my future plans here (comparing edit mesh pointer equality to decide whether to use mapped GPU data extraction). I'll change this function to take a shared pointer argument. That should reduce memory usage too.
The writing I'm referring to in the PR description maybe isn't so obviously problematic:
However, I'd like to remove this for two reasons:
Ah, ok. It is quite clear the issues with the code you're pointing to, just wasn't as clear what the description is referring to exactly. Sounded a bit more problematic than it actually is.
What I am not sure about is how the replacing mesh in the modifier stack will work with the idea you've mentioned implemented. You still need to be able to see the editmesh somehow, in order to edit it. And to my knowledge drawing code uses evaluated mesh's editmesh structure. Would we need to make object to point to editmesh?
Can you explain it in a bit more details? I don't think I fully understand this sentence.
Forgot to mention. I do see the discussion might be going a bit on a bigger scope than the PR, but with such core side changes I think it is important we are all fully understanding each other. We can move the discussion somewhere outside of the PR, if you think it'll help clarity with it.
For the patch itself, I'd need to look into it again. While it does seems all the aspects are addressed, I'd like to give a bit more careful look and test before giving the final green.
Yes, the drawing code will need to change a bit too. Using the depsgraph to get the original object and then retrieving that object's data should work.
Sure! An object's final mesh should be able to be the same mesh as the output of any other object. In other words, if a geometry nodes setup does
final_mesh = other_object_geometry_set_eval.get_mesh_for_read()
, we shouldn't have to modifyfinal_mesh
, which would require copying it. If these final meshes are shared, all the GPU data will be shared between them automatically by the existing draw extraction.But you're right that this is a longer term goal that's a bit out of scope here, and shouldn't be necessary to justify the PR. I just wanted to give some background about why I was working on this.
Need to be careful with that. Render engine is not supposed to look into an original object, as it might not be existing anymore (like, artist deleted an object while render is going). But that is more of details, just wanted to mention it, to avoid possible regression in the thread safety, if someone is reading it out of context :)
There are definitely ways of achieving the goal, we can look into more details when we'll be ready to cross that bridge.
Thanks for explanation. I do think giving such background does help understanding where things are moving, and (more importantly) why.
Ah right, thanks! Still internalizing that fact here I guess. Anyway, yeah, stuff to look at later.