Mesh: Make edge_other_vert function branchless #114682
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#114682
Loading…
Reference in New Issue
No description provided.
Delete Branch "mod_moder/blender:tmp_cleanup_edge_other_vert"
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 function shouldn't return invalid index. Instead assertion in used.
I think this has limitations for large vertex indices. If it's not actually faster, might be better to stick with the existing code. In other words, the PR needs to be a bit more convincing I guess.
I did short research.
There is kind similar thing called swapping by using sum (Stack Overflow with explanation why that is not good approach: Stack Overflow: Answer to the question).
Lookup for another vertex of edge have the same bad side.
But that still works for me on godbolt.
I pretty sure that is not safe approath and this shouldn't used at all (even in already exist code).
But, current case have some differences, that can protect us:
This means that the order of operations matters.
tmp = (edge[0] - vert)
will never be undefined in case of limitation from above.tmp + edge[1]
the same case, if expected index is not an overflow then result will be correct too.Fixed version
About the code with regular branches:
Assembly code of functions without optimizations from godbolt (GCC x86-64) on godbolt
Version with branches is larger and contains at least one comparison.
Potential using of this function in hot loops and simd code could be less productive than it can be.
That means branchless function make sense in future respective at least.
That goal of that pull request is not an optimization. But just to measure impact of that change i did benchmark, but there is no any real change. I hope this will be occur in simd tests...
@ -280,2 +274,2 @@
}
return -1;
BLI_assert(ELEM(vert, edge[0], edge[1]));
BLI_assert(vert >= 0);
This assert seems to be redundant with the others.
@ -282,0 +275,4 @@
BLI_assert(vert >= 0);
BLI_assert(edge[0] >= 0);
BLI_assert(edge[1] >= 0);
return edge[0] + edge[1] - vert;
Seems best to prevent overflow explicitly here with the parentheses like you mentioned.
@blender-bot build
Cleanup: Mesh: Branchless function edge_other_vertto Mesh: Make edge_other_vert function branchless