Struct of Arrays Refactor for Mesh Vertices #93602

Closed
opened 2021-12-03 15:07:21 +01:00 by Hans Goudey · 17 comments
Member

Currently, MVert stores quite a bit of data:

typedef struct MVert {
  float co[3];
  short no[3];
  char flag, bweight;
} MVert;

This is inefficient, because it means vertex positions aren't stored in a contiguous array.
It also means all of the other data isn't stored contiguously. Because of that, access to all of the data
is slower than it should be. We also pay the cost of storing data when it's unused.

We should convert MVert to be the same as float3, and move the other elements into separate arrays.
This can significantly simplify code, and makes it easier to achieve better performance for mesh editing.

Normals

Normals are covered by #91186 (Move mesh vertex normals out of MVert). This task is for the rest of the data stored in the struct.

Bevel Weight

In the longer term, this should be stored as an optional named generic float attribute (see #89054).
In the shorter term, this can be stored as CD_BWEIGHT. This means slightly increased memory usage when this data is used,
but it also gives increased precision, and it doesn't have to be allocated when it isn't used.

291c313f80

Flag

In the flag is:

  /*  SELECT = (1 << 0), */
  ME_VERT_TMP_TAG = (1 << 2),
  ME_HIDE = (1 << 4),
  ME_VERT_FACEDOT = (1 << 5),
  ME_VERT_PBVH_UPDATE = (1 << 7),

Selection
It's not clear to me how selection interacts with mselect (MSelect), but perhaps it can be moved there.
It can also be moved to a separate boolean custom data layer with a name that keeps it from being displayed in the UI.

TMP_TAG 90a23dec46
Since this is only used locally in one area, it can be easily replaced with Array<bool> or the C equivalent.

ME_HIDE 2480b55f21
This can be moved to a separate boolean custom data layer, likely with a reserved name.

Face Dot 8c25889bb6
Currently this is only set by subdivision code. I'm not clear on the details.
Face dot vertices could be moved to a separate array, since they are just runtime data.

PBVH Update Tag 7682d7de04
This is just used in sculpt and paint code, it could be relatively simply moved to a bitmask or a separate boolean array.

Internal Mesh API

When there is a position attribute, functions that refer to mesh "coords" and "vertices" should be changed to refer to "positions" instead.
This makes the internal API consistent with more public naming of attributes. This should affect the functions added in D14760.

Currently, `MVert` stores quite a bit of data: ``` typedef struct MVert { float co[3]; short no[3]; char flag, bweight; } MVert; ``` This is inefficient, because it means vertex positions aren't stored in a contiguous array. It also means all of the other data isn't stored contiguously. Because of that, access to all of the data is slower than it should be. We also pay the cost of storing data when it's unused. We should convert `MVert` to be the same as `float3`, and move the other elements into separate arrays. This can significantly simplify code, and makes it easier to achieve better performance for mesh editing. ### Normals Normals are covered by #91186 (Move mesh vertex normals out of MVert). This task is for the rest of the data stored in the struct. ### Bevel Weight In the longer term, this should be stored as an optional named generic float attribute (see #89054). In the shorter term, this can be stored as `CD_BWEIGHT`. This means slightly increased memory usage when this data is used, but it also gives increased precision, and it doesn't have to be allocated when it isn't used. 291c313f80 ### Flag In the flag is: ``` /* SELECT = (1 << 0), */ ME_VERT_TMP_TAG = (1 << 2), ME_HIDE = (1 << 4), ME_VERT_FACEDOT = (1 << 5), ME_VERT_PBVH_UPDATE = (1 << 7), ``` **Selection** It's not clear to me how selection interacts with `mselect` (`MSelect`), but perhaps it can be moved there. It can also be moved to a separate boolean custom data layer with a name that keeps it from being displayed in the UI. **TMP_TAG** 90a23dec46 Since this is only used locally in one area, it can be easily replaced with `Array<bool>` or the C equivalent. **ME_HIDE** 2480b55f21 This can be moved to a separate boolean custom data layer, likely with a reserved name. **Face Dot** 8c25889bb6 Currently this is only set by subdivision code. I'm not clear on the details. Face dot vertices could be moved to a separate array, since they are just runtime data. **PBVH Update Tag** 7682d7de04 This is just used in sculpt and paint code, it could be relatively simply moved to a bitmask or a separate boolean array. ### Internal Mesh API When there is a `position` attribute, functions that refer to mesh "coords" and "vertices" should be changed to refer to "positions" instead. This makes the internal API consistent with more public naming of attributes. This should affect the functions added in [D14760](https://archive.blender.org/developer/D14760).
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly

Added subscriber: @GeorgiaPacific

Added subscriber: @GeorgiaPacific

This issue was referenced by cfa53e0fbe

This issue was referenced by cfa53e0fbeed7178c7876413e2010fd3347d7f72

Added subscriber: @Zeastin

Added subscriber: @Zeastin

Added subscriber: @Garek

Added subscriber: @Garek

Added subscriber: @Baardaap

Added subscriber: @Baardaap

This issue was referenced by 90a23dec46

This issue was referenced by 90a23dec4650d63a836cb9e9969aab4d0da4ba2f
Hans Goudey changed title from Convert Mesh vertex data into float3 to Performance: Convert Mesh vertex data into float3 2022-02-03 01:15:43 +01:00

This issue was referenced by 7682d7de04

This issue was referenced by 7682d7de046185382985999f8f6b6e7dcf860582

This issue was referenced by 22c60ac8b1

This issue was referenced by 22c60ac8b1583502a88a5a97d0017618cccb14df
Hans Goudey changed title from Performance: Convert Mesh vertex data into float3 to Convert Mesh vertex data into float3 2022-02-22 20:29:13 +01:00
Hans Goudey changed title from Convert Mesh vertex data into float3 to Struct of Arrays Refactor for Mesh Vertices 2022-04-18 19:41:24 +02:00

This issue was referenced by 8c25889bb6

This issue was referenced by 8c25889bb67db4c1d2f94bf85ca6d1c2a050fcfe

This issue was referenced by 2480b55f21

This issue was referenced by 2480b55f216c31373a84bc5c5d2b0cc158497c44

This issue was referenced by 291c313f80

This issue was referenced by 291c313f80b4cccc8fcce3035584caeaa654844f

This issue was referenced by 12becbf0df

This issue was referenced by 12becbf0dffe06b6f28c4cc444fe0312cf9249b9
Member

Added subscriber: @EAW

Added subscriber: @EAW

This issue was referenced by 1af62cb3bf

This issue was referenced by 1af62cb3bf46f0cd328ab0840a1363eca938c628
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Hans Goudey self-assigned this 2023-01-10 18:43:03 +01:00
Sign in to join this conversation.
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
7 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#93602
No description provided.