Fix #129598: Resample curves node missing type alignment handling #129628

Merged
Hans Goudey merged 10 commits from HooglyBoogly/blender:fix-resample-curves-matrix-alignment into blender-v4.3-release 2024-11-04 11:44:18 +01:00
Member

The 4x4 matrix type has a larger alignment requirement of 16 bytes
than the default, but it was stored in a generic vector of bytes. There
are a few solutions that reduce the memory reuse in this code path--
the chosen solution uses a custom allocator which always allocates
with an alignment that should be large enough for anything.

Generally I think this resampling loop could be rewritten to be a bit
simpler, avoiding these problems in the first place. Some performance
testing would show whether this "fancy" memory use between types
and loop structure is actually worth it. For now though, just correcting
the existing logic seems like the best choice.

The 4x4 matrix type has a larger alignment requirement of 16 bytes than the default, but it was stored in a generic vector of bytes. There are a few solutions that reduce the memory reuse in this code path-- the chosen solution uses a custom allocator which always allocates with an alignment that should be large enough for anything. Generally I think this resampling loop could be rewritten to be a bit simpler, avoiding these problems in the first place. Some performance testing would show whether this "fancy" memory use between types and loop structure is actually worth it. For now though, just correcting the existing logic seems like the best choice.
Hans Goudey added 1 commit 2024-10-31 12:53:56 +01:00
Fix #129598: Resample curves node missing type alignment handling
Some checks failed
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
09b507c074
The 4x4 matrix type has a larger alignment requirement of 16 bytes
than the default, but it was stored in a generic vector of bytes. There
are a few solutions that reduce the memory reuse in this code path--
the chosen solution uses a custom allocator which always allocates
with an alignment that should be large enough for anything.
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Jacques Lucke 2024-10-31 13:02:40 +01:00
Jacques Lucke approved these changes 2024-10-31 13:03:26 +01:00
Hans Goudey added 2 commits 2024-10-31 14:09:36 +01:00
Merge branch 'blender-v4.3-release' into fix-resample-curves-matrix-alignment
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
c32b0d3c98
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 2 commits 2024-10-31 14:47:05 +01:00
Use decltype instead of typeof
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-windows-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
369cbce82b
Author
Member

@blender-bot build windows

@blender-bot build windows
Hans Goudey added 1 commit 2024-10-31 15:12:17 +01:00
More build fixes
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
9ecca0effe
Author
Member

@blender-bot build

@blender-bot build
Iliya Katushenock reviewed 2024-10-31 15:59:05 +01:00
@ -54,0 +57,4 @@
* reusing an allocation between multiple types that have different alignment requirements. The
* default alignment template parameter should be large enough for any type in practice.
*/
template<size_t Alignment = 64ul> class GuardedAlignedAllocator {

I think this can be part of GuardedAllocator with compile time switch in allocate()/
(Maybe in 4.4 only...)

I think this can be part of `GuardedAllocator` with compile time switch in `allocate()`/ (Maybe in 4.4 only...)
@ -284,2 +284,3 @@
selection.foreach_segment(GrainSize(512), [&](const IndexMaskSegment selection_segment) {
Vector<std::byte> evaluated_buffer;
/* Use a default alignment that works for all attribute types. */
Vector<std::byte, 512, GuardedAlignedAllocator<>> evaluated_buffer;

I see fix of heap allocation alignment.
Before there was 4 inline byte's so matrix never fit into inline buffere.
But now there is large inline buffere and i do not see how its aligment is ensured for matrix.

I see fix of heap allocation alignment. Before there was 4 inline `byte`'s so matrix never fit into inline buffere. But now there is large inline buffere and i do not see how its aligment is ensured for matrix.
Author
Member

Hmm, good point! I'll split the inline buffer to a separate std::array and use the vector just for when it doesn't fit

Hmm, good point! I'll split the inline buffer to a separate `std::array` and use the vector just for when it doesn't fit

+1 to something like bke::attribute_math::least_aligment instead of hardcoded constant/

+1 to something like `bke::attribute_math::least_aligment` instead of hardcoded constant/
Hans Goudey added 2 commits 2024-11-01 12:25:55 +01:00
Move logic to a struct
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
082c0f0ef9
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Jacques Lucke 2024-11-01 12:27:54 +01:00
Jacques Lucke approved these changes 2024-11-03 11:19:30 +01:00
@ -246,0 +247,4 @@
* Buffer for temporary evaluated curve data, used for memory reuse between multiple attributes of
* different types.
*/
struct EvalDataBuffer {
Member

Seems to be something that could be abstracted further for use in other files. For now this is fine though.

Seems to be something that could be abstracted further for use in other files. For now this is fine though.
Author
Member

Yeah, agreed. I'd like to try refactoring this code first to see if the abstraction sticks. Feels like a shared abstraction should be on a slightly lower level like GVector.

Yeah, agreed. I'd like to try refactoring this code first to see if the abstraction sticks. Feels like a shared abstraction should be on a slightly lower level like `GVector`.
@ -246,0 +254,4 @@
Vector<std::byte, 0, AllocatorType> heap_allocated;
alignas(AllocatorType::min_alignment) std::array<std::byte, 1024> inline_buffer;
template<typename T> MutableSpan<T> get_size(const int64_t size)
Member

get_size seems like a a somewhat bad name. I'd probably call it resize or so.

`get_size` seems like a a somewhat bad name. I'd probably call it `resize` or so.
Author
Member

Much better, thanks.

Much better, thanks.
Hans Goudey added 2 commits 2024-11-04 11:07:49 +01:00
Rename get_size to resize
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
3a9663f08e
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey merged commit af58c223a4 into blender-v4.3-release 2024-11-04 11:44:18 +01:00
Hans Goudey deleted branch fix-resample-curves-matrix-alignment 2024-11-04 11:44:26 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
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#129628
No description provided.