Sculpt: Refactor topology islands cache #125907

Merged
Hans Goudey merged 20 commits from HooglyBoogly/blender:sculpt-topology-island-refactor into main 2024-08-05 20:20:23 +02:00
Member

Part of #118145.

  • Specialize the algorithm for each geometry type.
  • Store the cache in an array instead of an attribute. Attributes are
    meant to store user-edited data, not derived data like caches.
  • Calculate the island IDs with a parallel disjoint set instead of a
    flood-fill algorithm.
  • Avoid storing the island ID array if there is only one island, saving
    1 byte per vertex.
Part of #118145. - Specialize the algorithm for each geometry type. - Store the cache in an array instead of an attribute. Attributes are meant to store user-edited data, not derived data like caches. - Calculate the island IDs with a parallel disjoint set instead of a flood-fill algorithm. - Avoid storing the island ID array if there is only one island, saving 1 byte per vertex.
Hans Goudey added 17 commits 2024-08-05 16:55:51 +02:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Sean Kim 2024-08-05 17:03:30 +02:00
Iliya Katushenock reviewed 2024-08-05 18:11:32 +02:00
@ -480,2 +478,4 @@
};
struct SculptTopologyIslandCache {
blender::Array<uint8_t> vert_island_ids;

Is there is some reason to have such limit for number of islands (or only legacy/)?

Is there is some reason to have such limit for number of islands (or only legacy/)?
Author
Member

Yeah, in the previous version of this branch I stored this in a full integer if necessary. I removed that for now to make the change smaller. It's easy to add later now if we want.

Yeah, in the previous version of this branch I stored this in a full integer if necessary. I removed that for now to make the change smaller. It's easy to add later now if we want.
mod_moder marked this conversation as resolved
Sean Kim requested changes 2024-08-05 19:43:05 +02:00
Dismissed
Sean Kim left a comment
Member

Main area of concern I think is the comments in vert_id_get

Main area of concern I think is the comments in `vert_id_get`
@ -144,2 +144,3 @@
* \return The total number of unique IDs.
*/
void calc_reduced_ids(MutableSpan<int> result) const;
int calc_reduced_ids(MutableSpan<int> result) const;
Member

Being a bit nitpicky here, but maybe this BLI change should be a separate PR? I don't think it'll have odd side effects, but it seems better to isolate it.

Being a bit nitpicky here, but maybe this BLI change should be a separate PR? I don't think it'll have odd side effects, but it seems better to isolate it.
Author
Member

I committed this separately.

I committed this separately.
HooglyBoogly marked this conversation as resolved
@ -6484,2 +6485,2 @@
if (ss.attrs.topology_island_key) {
return *static_cast<uint8_t *>(SCULPT_vertex_attr_get(vertex, ss.attrs.topology_island_key));
BLI_assert(ss.topology_island_cache);
const SculptTopologyIslandCache &cache = *ss.topology_island_cache;
Member

With this change, the updated code does crash in non-debug builds if topology_island_cache hasn't been set. Probably safer to still exit early with -1 or change this signature to std::optional<int>

With this change, the updated code does crash in non-debug builds if `topology_island_cache` hasn't been set. Probably safer to still exit early with `-1` or change this signature to `std::optional<int>`
Author
Member

I think developers should always make sure the cache is available before using it. However it's reasonable to avoid giving users crashes in release builds.

I think developers should always make sure the cache is available before using it. However it's reasonable to avoid giving users crashes in release builds.
HooglyBoogly marked this conversation as resolved
@ -6486,3 +6489,2 @@
}
return -1;
return 0;
Member

Related to the above comment, I think if we keep this method as returning only integers, it makes more sense keep it returning -1 as a not found indicator instead of changing this.

Related to the above comment, I think if we keep this method as returning only integers, it makes more sense keep it returning `-1` as a not found indicator instead of changing this.
Author
Member

The array is now empty when there is just one island, I think it's a little clearer to return 0 in that case

The array is now empty when there is just one island, I think it's a little clearer to return 0 in that case
Member

Ah, I completely missed your comment and the code that explained that. Might be worth a small comment in the ensure_cache function header or on the variable inside SculptSession

Ah, I completely missed your comment and the code that explained that. Might be worth a small comment in the `ensure_cache` function header or on the variable inside `SculptSession`
HooglyBoogly marked this conversation as resolved
@ -6543,0 +6553,4 @@
SubdivCCGNeighbors neighbors;
for (const short y : IndexRange(key.grid_size)) {
for (const short x : IndexRange(key.grid_size)) {
const SubdivCCGCoord coord{grid, x, y};
Member

Minor styling question - do we have a standardized way of writing struct initialization? For SubdivCCGCoord in general I think I've seen this, struct member assignment, and the named initializer list.

Minor styling question - do we have a standardized way of writing struct initialization? For `SubdivCCGCoord` in general I think I've seen this, struct member assignment, and the named initializer list.
Author
Member

Not really AFAIK. Others have expressed that they like the named initialization options, since this way it's easy to make a mistake when changing the struct. But I don't see SubdivCCGCoord changing without a larger refactor anyway. I hadn't done this before because I didn't use short in the grid iteration. Personally I like the single-line initialization and the ability to declare the variable const.

Not really AFAIK. Others have expressed that they like the named initialization options, since this way it's easy to make a mistake when changing the struct. But I don't see `SubdivCCGCoord` changing without a larger refactor anyway. I hadn't done this before because I didn't use `short` in the grid iteration. Personally I like the single-line initialization and the ability to declare the variable const.
Sean-Kim marked this conversation as resolved
Hans Goudey added 2 commits 2024-08-05 19:57:16 +02:00
Hans Goudey requested review from Sean Kim 2024-08-05 19:57:18 +02:00
Sean Kim approved these changes 2024-08-05 20:06:05 +02:00
Hans Goudey added 1 commit 2024-08-05 20:18:34 +02:00
Hans Goudey merged commit 79ad6a3148 into main 2024-08-05 20:20:23 +02:00
Hans Goudey deleted branch sculpt-topology-island-refactor 2024-08-05 20:20:26 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#125907
No description provided.