Geometry: speedup reverse UV sampler #118772
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118772
Loading…
Reference in New Issue
No description provided.
Delete Branch "JacquesLucke/blender:reverse-uv-sampler-speedup"
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?
This implements a new internal data structure for reverse uv sampling. Being better than the previous one was not particularly hard, because it was never really optimized and used a very simple approach. I found the new implementation to be about 10-20x faster in my tests. Simon was able to reproduce an comparable speedups in production files.
The speed-up is mainly achieved by a better memory layout and better multi-threading during construction. The lookup performance is mostly the same as before.
Like the old data structure, the new one also splits the uv space into uniformly sized cells. The size of the cells is based on the number of triangles. Then it sorts all triangles into the rows that they touch. Finally, it creates a flat array for each row that contains the triangle indices contained in each row.
There are still ways to optimize this further, but for now this is a good improvement already.
@blender-bot build
I found this pretty straightforward to understand. Nice job! Using a separate data structure for storing the triangles in a row while gathering them will help too.
Sorry if I preempted your future cleanup pass, I was just curious to read this anyway.
@ -26,3 +32,4 @@
public:
ReverseUVSampler(Span<float2> uv_map, Span<int3> corner_tris);
ReverseUVSampler(Span<float2> uv_map, Span<int3> corner_tris, const IndexMask &corner_tris_mask);
The user will probably give us a
faces_mask
BTW. Maybe you'll have some fun converting that to a triangle mask efficiently :P Or maybe you'll pass face offsets to this constructor in the endGood point, think I'll just remove the mask for now. This complexity can be added as part of another patch.
@ -15,0 +22,4 @@
struct Row {
int x_min = 0;
int x_max = 0;
Vector<int> offsets;
I'd use
Array
here. Looks like amortized growth isn't necessary. And why not save 16 bytes per row :)@ -15,0 +33,4 @@
struct TriWithRange {
int tri_index;
IndexRange range;
Feels like it would be worth storing the
IndexRange
in its 32 bit integer form here, saving at least 8 bytes per triangle@ -15,0 +44,4 @@
struct LocalRowData {
TriWithRangeGroup *tris = nullptr;
int x_min = INT32_MAX;
What about storing this as
Bounds<int>
directly? Same withRow
. Just makes the concepts simpler to read maybeWanted to that at first, but I wasn't sure if I'm allowed to initialize
Bounds<int>
with the same values were the min is larger than the max.@ -42,0 +81,4 @@
{
}
BLI_NOINLINE static void sort_into_y_buckets(
Might as well be
sort_into_y_rows
to avoid adding another term? Just an idea, don't have a strong opinion!@ -42,0 +98,4 @@
key_bounds.max.x);
const TriWithRange tri_with_range{tri_i, x_range};
for (const int key_y :
What do you think about changing from
key
tocell
in variable names? That naming feels a bit more visual@ -44,0 +125,4 @@
const Bounds<int> y_bounds,
ReverseUVSampler::LookupGrid &lookup_grid)
{
// SCOPED_TIMER_AVERAGED("fill rows");
If this comment is meant to stay, why not
SCOPED_TIMER_AVERAGED(__func__);
?@ -44,0 +189,4 @@
const IndexMask &corner_tris_mask)
: uv_map_(uv_map), corner_tris_(corner_tris), lookup_grid_(std::make_unique<LookupGrid>())
{
resolution_ = std::max<int>(3, std::sqrt(corner_tris.size()) * 3);
It would be nice to have some comment about the resolution heuristic
Great job! Getting a solid 8-15x performance improvement in our production files on modifiers that rely heavily on the UV sampling node without any regression in behavior afaict 👍
WIP: Geometry: speedup reverse uv samplerto Geometry: speedup reverse uv samplerHow this works in corner cases which was pretty worst for old implementation? For instance UV scale ~100x..
The worst case performance is still similarly bad to before, but not worse I think.
Geometry: speedup reverse uv samplerto Geometry: speedup reverse UV samplerCode is quite nice now! Didn't find any issues in my testing.
@ -6,6 +6,7 @@
#include <optional>
#include "BLI_index_mask_fwd.hh"
Unused header now
@ -4,2 +4,4 @@
#include <algorithm>
#include <fmt/format.h>
#include <mutex>
<mutex>
is unused