Struct of Arrays Refactor for Mesh Vertices #93602

Closed
opened 1 year ago by HooglyBoogly · 17 comments
Collaborator

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).
Poster
Collaborator

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

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

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly

Added subscriber: @GeorgiaPacific

Added subscriber: @GeorgiaPacific
Collaborator

This issue was referenced by cfa53e0fbe

This issue was referenced by cfa53e0fbeed7178c7876413e2010fd3347d7f72
Zeastin commented 1 year ago

Added subscriber: @Zeastin

Added subscriber: @Zeastin
Garek commented 1 year ago

Added subscriber: @Garek

Added subscriber: @Garek
Collaborator

Added subscriber: @Baardaap

Added subscriber: @Baardaap
Collaborator

This issue was referenced by 90a23dec46

This issue was referenced by 90a23dec4650d63a836cb9e9969aab4d0da4ba2f
HooglyBoogly changed title from Convert Mesh vertex data into float3 to Performance: Convert Mesh vertex data into float3 1 year ago
Collaborator

This issue was referenced by 7682d7de04

This issue was referenced by 7682d7de046185382985999f8f6b6e7dcf860582
Collaborator

This issue was referenced by 22c60ac8b1

This issue was referenced by 22c60ac8b1583502a88a5a97d0017618cccb14df
HooglyBoogly changed title from Performance: Convert Mesh vertex data into float3 to Convert Mesh vertex data into float3 12 months ago
HooglyBoogly changed title from Convert Mesh vertex data into float3 to Struct of Arrays Refactor for Mesh Vertices 10 months ago
Collaborator

This issue was referenced by 8c25889bb6

This issue was referenced by 8c25889bb67db4c1d2f94bf85ca6d1c2a050fcfe
Collaborator

This issue was referenced by 2480b55f21

This issue was referenced by 2480b55f216c31373a84bc5c5d2b0cc158497c44
Collaborator

This issue was referenced by 291c313f80

This issue was referenced by 291c313f80b4cccc8fcce3035584caeaa654844f
Collaborator

This issue was referenced by 12becbf0df

This issue was referenced by 12becbf0dffe06b6f28c4cc444fe0312cf9249b9
EAW commented 1 month ago

Added subscriber: @EAW

Added subscriber: @EAW
Collaborator

This issue was referenced by 1af62cb3bf

This issue was referenced by 1af62cb3bf46f0cd328ab0840a1363eca938c628
Poster
Collaborator

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
HooglyBoogly closed this issue 1 month ago
HooglyBoogly self-assigned this 1 month ago
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/Collada
Interest/Compositing
Interest/Core
Interest/Cycles
Interest/Dependency Graph
Interest/Development Management
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/Modeling
Interest/Modifiers
Interest/Motion Tracking
Interest/Nodes & Physics
Interest/Overrides
Interest/Performance
Interest/Performance
Interest/Physics
Interest/Pipeline, Assets & I/O
Interest/Platforms, Builds, Tests & Devices
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
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/Triaging
legacy module/User Interface
legacy module/VFX & Video
legacy project/1.0.0-beta.2
legacy project/Asset Browser (Archived)
legacy project/BF Blender: 2.8
legacy project/BF Blender: After Release
legacy project/BF Blender: Next
legacy project/BF Blender: Regressions
legacy project/BF Blender: Unconfirmed
legacy project/Blender 2.70
legacy project/Code Quest
legacy project/Datablocks and Libraries
legacy project/Eevee
legacy project/Game Animation
legacy project/Game Audio
legacy project/Game Data Conversion
legacy project/Game Engine
legacy project/Game Logic
legacy project/Game Physics
legacy project/Game Python
legacy project/Game Rendering
legacy project/Game UI
legacy project/GPU / Viewport
legacy project/GSoC
legacy project/Infrastructure: Websites
legacy project/LibOverrides - Usability and UX
legacy project/Milestone 1: Basic, Local Asset Browser
legacy project/Nodes
legacy project/OpenGL Error
legacy project/Papercut
legacy project/Pose Library Basics
legacy project/Retrospective
legacy project/Tracker Curfew
legacy project/Wintab High Frequency
Meta/Good First Issue
Meta/Papercut
migration/requires-manual-verification
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 & Devices
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 Information 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

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#93602
Loading…
There is no content yet.