Mesh: Parallelize extraction of UV maps #105793
No reviewers
Labels
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105793
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:mesh-extract-uv-parallel"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Since UVs are now stored as 2D vectors in meshes, they can be copied
directly to the vertex buffers. Somewhat surprisingly, multithreading
the copying into the vertex buffer provides a good speedup on a CPU
with many cores at least.
Here is a test uploading two UV maps created in geometry
nodes with a 1 million quad mesh, with a Ryzen 7950x:
I added the copying utilities to the array utils header, since the
need for them has come up in a few different places already, and the
existing function with a selection argument didn't make sense here.
I hope we can use this data-parallelism more in the mesh extraction
process in the future.
Mesh extractors already have their own way of handling multithreading (see
extractor.use_threading
).This is done in a way that avoids having to access, multiple times, distant addresses in the arrays of a Mesh and thus losing performance in the memory cache.
Using threading in a function that is already a callback to be used in multithreading can end up harming other areas.
I would suggest testing
extractor.use_threading = true
first.Looking back, I now see that the affected function is
extract_uv_init
(which isn't really used in multithreading), so the previous concern doesn't apply.I don't think it makes sense to introduce the overhead of a function call per face just to copy this array. We're not accessing "distant addresses multiple times" here, we're just copying data that probably isn't accessed elsewhere in the mesh extraction process anyway.
A while ago I tested refactoring most of the extraction system to work more like this and it was a nice improvement, since most extractors access are dealing with separate memory anyway, and most are quite simple, making the function call overhead significant.
I'm not sure I agree in general-- it seems generally good to have multiple methods of achieving parallelism. That's why, for example, multiple geometry nodes are evaluated in parallel, but each also uses parallelism on its own.
@ -13,0 +24,4 @@
inline void copy(const Span<T> src, MutableSpan<T> dst, const int64_t grain_size = 4096)
{
BLI_assert(src.size() == dst.size());
threading::parallel_for(src.index_range(), grain_size, [src, dst](const IndexRange range) {
Shouldn't really help to capture
src
anddst
explicitly here, just use&
.@ -77,6 +77,7 @@ static void extract_uv_init(const MeshRenderData *mr,
void *buf,
void * /*tls_data*/)
{
SCOPED_TIMER_AVERAGED(__func__);
Remove timer.
@ -113,3 +113,1 @@
CustomData_get_layer_n(cd_ldata, CD_PROP_FLOAT2, i));
for (int ml_index = 0; ml_index < mr->loop_len; ml_index++, uv_data++, layer_data++) {
memcpy(uv_data, layer_data, sizeof(*uv_data));
for (const int i : IndexRange(MAX_MTFACE)) {
I'm a bit confused why there is a nested loop now.
@ -113,3 +113,1 @@
CustomData_get_layer_n(cd_ldata, CD_PROP_FLOAT2, i));
for (int ml_index = 0; ml_index < mr->loop_len; ml_index++, uv_data++, layer_data++) {
memcpy(uv_data, layer_data, sizeof(*uv_data));
for (const int i : IndexRange(MAX_MTFACE)) {
Ah, yikes, sorry about that!
f6615dc456
to2b9822055f