Mesh: Improvements to position and normal draw extraction #116902

Merged
Hans Goudey merged 23 commits from HooglyBoogly/blender:mesh-extract-normal-fix into main 2024-02-26 16:01:25 +01:00
Member

Currently there are two vertex buffers that contain mesh normals. First, the
normals are extracted and stored interleaved with positions. Then there is
a second vertex buffer for just normals. Interleaving them makes some
sense, since they change together, but it fights with the contiguous storage
benefits of Mesh and generally makes code more difficult to optimize.

This PR removes the normals interleaved with the positions and changes
the code for extracting positions and normals from meshes to be simpler
and faster, mainly by not using the "extract iterators" as described by the
#116901 design task. That moves most of the branching outside of hot
loops, so we don't do the same work for every mesh element. This also
gives us the option of not calculating or extracting normals in more
situations like wireframe display in the future.

This is only a small part of the work for #116901, so the state of the code
after this PR will have more design inconsistencies. I'll keep working to
resolve those in the future.

In general I observed at least a 5-40% improvement in FPS in playback
of files with large meshes.


Some performance numbers with various test files I had locally:

2m face sculpt
15 FPS
21 FPS

crab monster:
rdata 0ms iter 19ms (frame 24ms)
rdata 0ms iter 18ms (frame 22ms)

16m grid:
rdata 0ms iter 182ms (frame 892ms)
rdata 0ms iter 107ms (frame 457ms)

large molecular nodes mesh:
93 FPS playback
97 FPS playback

Currently there are two vertex buffers that contain mesh normals. First, the normals are extracted and stored interleaved with positions. Then there is a second vertex buffer for just normals. Interleaving them makes some sense, since they change together, but it fights with the contiguous storage benefits of `Mesh` and generally makes code more difficult to optimize. This PR removes the normals interleaved with the positions and changes the code for extracting positions and normals from meshes to be simpler and faster, mainly by not using the "extract iterators" as described by the #116901 design task. That moves most of the branching outside of hot loops, so we don't do the same work for every mesh element. This also gives us the option of not calculating or extracting normals in more situations like wireframe display in the future. This is only a small part of the work for #116901, so the state of the code after this PR will have more design inconsistencies. I'll keep working to resolve those in the future. In general I observed at least a 5-40% improvement in FPS in playback of files with large meshes. --- Some performance numbers with various test files I had locally: 2m face sculpt 15 FPS 21 FPS crab monster: rdata 0ms iter 19ms (frame 24ms) rdata 0ms iter 18ms (frame 22ms) 16m grid: rdata 0ms iter 182ms (frame 892ms) rdata 0ms iter 107ms (frame 457ms) large molecular nodes mesh: 93 FPS playback 97 FPS playback
Hans Goudey added 1 commit 2024-01-08 15:30:51 +01:00
RedMser reviewed 2024-01-08 16:26:13 +01:00
@ -33,3 +33,3 @@
#include "mesh_extractors/extract_mesh.hh"
// #define DEBUG_TIME
#define DEBUG_TIME
Contributor

Seems like an unintended change.

Seems like an unintended change.
Author
Member

Thanks, yeah I still have some more cleanup to do here :)

Thanks, yeah I still have some more cleanup to do here :)
HooglyBoogly marked this conversation as resolved
Hans Goudey changed title from Mesh: Improvements to position and normal draw extraction to WIP: Mesh: Improvements to position and normal draw extraction 2024-01-08 16:45:12 +01:00
Hans Goudey added 1 commit 2024-01-10 16:35:15 +01:00
Hans Goudey added 2 commits 2024-01-11 03:38:41 +01:00
Hans Goudey added 1 commit 2024-01-11 03:47:27 +01:00
Hans Goudey changed title from WIP: Mesh: Improvements to position and normal draw extraction to Mesh: Improvements to position and normal draw extraction 2024-01-11 03:53:59 +01:00
Hans Goudey added this to the EEVEE & Viewport project 2024-01-11 03:54:04 +01:00
Hans Goudey added 1 commit 2024-01-11 04:07:26 +01:00
Hans Goudey requested review from Jeroen Bakker 2024-01-11 04:07:26 +01:00
Hans Goudey requested review from Clément Foucault 2024-01-11 04:07:27 +01:00
Hans Goudey changed title from Mesh: Improvements to position and normal draw extraction to WIP: Mesh: Improvements to position and normal draw extraction 2024-01-11 04:13:41 +01:00
Hans Goudey added 1 commit 2024-01-11 16:36:28 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
5da24ac53c
Simplify mesh position extraction as well
Hans Goudey changed title from WIP: Mesh: Improvements to position and normal draw extraction to Mesh: Improvements to position and normal draw extraction 2024-01-11 16:37:41 +01:00
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2024-01-11 16:44:10 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
78c75cedda
Merge branch 'main' into mesh-extract-normal-fix
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 1 commit 2024-01-11 21:31:03 +01:00
Hans Goudey added 1 commit 2024-01-14 22:35:52 +01:00
Hans Goudey added 2 commits 2024-01-15 17:45:10 +01:00
Hans Goudey added 1 commit 2024-01-16 16:49:45 +01:00
Clément Foucault requested changes 2024-01-23 16:08:08 +01:00
Dismissed
@ -39,4 +43,2 @@
/* WARNING Adjust #PosNorLoop struct accordingly. */
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I10, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
GPU_vertformat_alias_add(&format, "vnor");

vnor should be kept as alias to vertex normal for edit mode. I don't know where this resides after this patch.

Here, removing GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I10, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); makes the alias vnor and alias of pos

If nor is present in multiple VBO, the latest VBO in a GPUBatch takes predecence.
I guess this is no longer wanted after this patch, where only one of the normal (vnor/lnor) would be bound to a GPUBatch.

`vnor` should be kept as alias to vertex normal for edit mode. I don't know where this resides after this patch. Here, removing `GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I10, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);` makes the alias `vnor` and alias of `pos` If `nor` is present in multiple VBO, the latest VBO in a `GPUBatch` takes predecence. I guess this is no longer wanted after this patch, where only one of the normal (vnor/lnor) would be bound to a `GPUBatch`.
Hans Goudey added 2 commits 2024-02-13 18:38:30 +01:00
Hans Goudey added 4 commits 2024-02-19 16:10:35 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
b0dfa6182a
Don't make "vnor" an alias for "pos"
Hans Goudey requested review from Clément Foucault 2024-02-19 16:23:09 +01:00
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault requested changes 2024-02-24 14:18:12 +01:00
Dismissed
Clément Foucault left a comment
Member

As discussed in person, this breaks everything using vertex normals.
Vertex normals need to be introduced back in some common batches for that to work.

As discussed in person, this breaks everything using vertex normals. Vertex normals need to be introduced back in some common batches for that to work.
Hans Goudey added 4 commits 2024-02-24 20:53:20 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
818f80aa13
Fix vertex normal overlay for GPU subdivision
Hans Goudey requested review from Clément Foucault 2024-02-24 20:54:29 +01:00
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault approved these changes 2024-02-24 21:29:31 +01:00
Hans Goudey merged commit bace4c9a29 into main 2024-02-26 16:01:25 +01:00
Hans Goudey deleted branch mesh-extract-normal-fix 2024-02-26 16:01:27 +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 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#116902
No description provided.