Mesh: Reimplement and unify topology maps #107861

Merged
Hans Goudey merged 14 commits from HooglyBoogly/blender:cleanup-unify-mesh-maps into main 2023-05-24 13:17:03 +02:00
Member

Combine the newer less efficient C++ implementations and the older
less convenient C functions. The maps now contain one large array of
indices, split into groups by a separate array of offset indices.
Though performance of creating the maps is relatively unchanged, the
new implementation uses 4 bytes less per source element than the C
maps, and 20 bytes less than the newer C++ functions (which also
had move overhead with larger N-gons). The usage syntax is simpler
than the C functions as well.

The reduced memory usage is helpful for when these maps are cached
in the near future. It will also allow sharing the offsets between
maps for different domains like vertex to corner and vertex to face.

A simple GroupedSpan class is introduced to make accessing the
topology maps much simpler. It combines offset indices and a separate
span, splitting it into chunks in an efficient way.

Combine the newer less efficient C++ implementations and the older less convenient C functions. The maps now contain one large array of indices, split into groups by a separate array of offset indices. Though performance of creating the maps is relatively unchanged, the new implementation uses 4 bytes less per source element than the C maps, and 20 bytes less than the newer C++ functions (which also had move overhead with larger N-gons). The usage syntax is simpler than the C functions as well. The reduced memory usage is helpful for when these maps are cached in the near future. It will also allow sharing the offsets between maps for different domains like vertex to corner and vertex to face. A simple `GroupedSpan` class is introduced to make accessing the topology maps much simpler. It combines offset indices and a separate span, splitting it into chunks in an efficient way.
Hans Goudey added 1 commit 2023-05-12 04:38:38 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
fe1f768805
Mesh: Reimplement and unify topology maps
Combine the newer less efficient C++ implementations and the older
less convenient C functions. The maps now contain one large array of
indices, split into groups by a separate array of offset indices.
Though performance of creating the maps is relatively unchanged, the
new implementation uses 4 bytes less per source element than the C
maps, and 20 bytes less than the newer C++ functions (which also
had move overhead with larger N-gons). The usage syntax is simpler
than the C functions as well.

The reduced memory usage is helpful for when these maps are cached
in the near future. It will also allow sharing the offsets between
maps for different domains like vertex to corner and vertex to face.

A simple `GroupedSpan` class is introduced to make accessing the
topology maps much simpler. It combines offset indices and a separate
span, splitting it into chunks in an efficient way.
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 2 commits 2023-05-12 14:40:45 +02:00
Hans Goudey requested review from Jacques Lucke 2023-05-12 14:41:21 +02:00
Hans Goudey added 1 commit 2023-05-12 18:14:27 +02:00
Hans Goudey added 1 commit 2023-05-12 18:15:06 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
fc85707f7f
Cleanup: Missing include
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2023-05-16 17:35:47 +02:00
Hans Goudey added 1 commit 2023-05-18 21:11:10 +02:00
Hans Goudey added 1 commit 2023-05-19 20:19:38 +02:00
Jacques Lucke requested changes 2023-05-22 13:31:42 +02:00
@ -226,3 +223,1 @@
MEM_SAFE_FREE(vlmap_);
MEM_SAFE_FREE(vlmap_mem_);
}
~MeshFairingContext() override {}
Member

Remove destructor because it's empty.

Remove destructor because it's empty.
HooglyBoogly marked this conversation as resolved
@ -95,0 +97,4 @@
* store many grouped arrays, without requiring many small allocations, giving the general benefits
* of using contiguous memory.
*/
template<typename T> struct GroupedSpan {
Member

My only very small concern with this type is that some might use multiple GroupSpan which all use the same offsets. In this case, it would be more efficient to lookup the range from the offsets only once. This is still possible of course, just a little less obvious.

My only very small concern with this type is that some might use multiple `GroupSpan` which all use the same `offsets`. In this case, it would be more efficient to lookup the range from the offsets only once. This is still possible of course, just a little less obvious.
Author
Member

Yeah, good point. Probably not necessary but I added a note in the classes description mentioning that.

Yeah, good point. Probably not necessary but I added a note in the classes description mentioning that.
@ -95,0 +104,4 @@
GroupedSpan() = default;
GroupedSpan(OffsetIndices<int> offsets, Span<T> data) : offsets(offsets), data(data)
{
BLI_assert(offsets.total_size() == data.size());
Member

Use this-> when refering to public data members.

Use `this->` when refering to public data members.
HooglyBoogly marked this conversation as resolved
@ -95,0 +107,4 @@
BLI_assert(offsets.total_size() == data.size());
}
Span<T> operator[](const int64_t vert_index) const
Member

vert_index -> index

`vert_index` -> `index`
HooglyBoogly marked this conversation as resolved
@ -95,0 +112,4 @@
return data.slice(offsets[vert_index]);
}
bool is_empty() const
Member

Also add a size and index_range method.

Also add a `size` and `index_range` method.
HooglyBoogly marked this conversation as resolved
@ -174,10 +174,6 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
SCULPT_vertex_random_access_ensure(ss);
if (!ob->sculpt->pmap) {
Member

I wonder if this is used as a check for emptyness or so and the code below depends on that, just a thought.

I wonder if this is used as a check for emptyness or so and the code below depends on that, just a thought.
Author
Member

Generally I think these are fairly paranoid checks and more likely hide bugs because some code didn't ensure the map was created before the operator was run. Removing them should be fine, and works in my tests.

Generally I think these are fairly paranoid checks and more likely hide bugs because some code didn't ensure the map was created before the operator was run. Removing them should be fine, and works in my tests.
@ -577,10 +577,6 @@ void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float
BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false);
if (!ss->pmap) {
Member

Might also be used as a check to detect the no-polygon case.

Might also be used as a check to detect the no-polygon case.
@ -141,2 +139,2 @@
}
return map;
bke::mesh::build_vert_to_edge_map(edges, verts_num, r_offsets, r_indices);
const OffsetIndices<int> offsets(r_offsets);
Member

Can you use GroupedSpan here?

Can you use `GroupedSpan` here?
Author
Member

Not without a MutableGroupedSpan, which I wanted to avoid for now.

Not without a `MutableGroupedSpan`, which I wanted to avoid for now.
@ -143,0 +142,4 @@
for (const int vert : range) {
MutableSpan<int> neighbors = r_indices.as_mutable_span().slice(offsets[vert]);
for (const int i : neighbors.index_range()) {
neighbors[i] = bke::mesh::edge_other_vert(edges[neighbors[i]], vert);
Member

Unrelated, but just noticed that here. Think edge_other_vert could be implemented in a branchless way (when the error case can be ignored, which it can in many cases).
other_vert = edge.v1 + edge.v2 - query_vert

Unrelated, but just noticed that here. Think `edge_other_vert` could be implemented in a branchless way (when the error case can be ignored, which it can in many cases). `other_vert = edge.v1 + edge.v2 - query_vert`
Author
Member

I wonder if we would care about potential overflow in that case. I guess it's crazy for a mesh to have 1-2 billion edges or so, but maybe it's possible.

I wonder if we would care about potential overflow in that case. I guess it's crazy for a mesh to have 1-2 billion edges or so, but maybe it's possible.
Hans Goudey added 6 commits 2023-05-23 18:53:48 +02:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Jacques Lucke 2023-05-23 18:54:23 +02:00
Jacques Lucke approved these changes 2023-05-24 08:42:56 +02:00
Hans Goudey merged commit 4d841e1b35 into main 2023-05-24 13:17:03 +02:00
Hans Goudey deleted branch cleanup-unify-mesh-maps 2023-05-24 13:17:04 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:37 +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
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#107861
No description provided.