Compositor: implement bicubic interpolation for Stabilize2DNode #122288

Merged
Habib Gahbiche merged 5 commits from zazizizou/blender:fix-bicubic-interp into main 2024-05-30 17:38:51 +02:00
Member

This patch also fixes a crash when image input of Stabilize2DNode is unconnected and interpolation is set to bicubic.

Differences to GPU compositor:

  • ~1px difference is observed due to different rounding of domain size vs. canvas size. This difference is constant for all image sizes.
  • If image input is unconnected but other inputs are, CPU compositor doesn't consider the operation to be constant, whereas GPU compositor still outputs a constant result.

Todos:

  • update tests
This patch also fixes a crash when image input of `Stabilize2DNode` is unconnected and interpolation is set to bicubic. Differences to GPU compositor: - ~1px difference is observed due to different rounding of domain size vs. canvas size. This difference is constant for all image sizes. - If image input is unconnected but other inputs are, CPU compositor doesn't consider the operation to be constant, whereas GPU compositor still outputs a constant result. Todos: - [x] update tests
Habib Gahbiche added 3 commits 2024-05-26 19:44:22 +02:00
Fix: unconnected Stabilize2dNode crashes with bicubic interp
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
051029a1b7
Habib Gahbiche requested review from Omar Emara 2024-05-26 19:49:24 +02:00
Omar Emara requested changes 2024-05-27 09:48:05 +02:00
Dismissed
Omar Emara left a comment
Member

Didn't a similar change introduce bad results according to a past bug report? (I can't find it right now)
Do you remember that report?

Didn't a similar change introduce bad results according to a past bug report? (I can't find it right now) Do you remember that report?
@ -291,2 +291,2 @@
math::interpolate_cubic_bspline_fl(
buffer_, out, this->get_width(), this->get_height(), num_channels_, x, y);
if (is_a_single_elem_) {
memcpy(out, buffer_, get_elem_bytes_len());
Member

This probably won't be optimized away by the compiler, so I would rather hard code it using a switch case or something.

This probably won't be optimized away by the compiler, so I would rather hard code it using a switch case or something.
Author
Member

This is the same way read_elem_bilinear() is implemented. I'll see if there is a better way.

This is the same way `read_elem_bilinear()` is implemented. I'll see if there is a better way.
Author
Member

From a quick test, the following code slows down Stabilize 2D Node from 220ms to 280ms (disconnected image input) and translate node (image input disconnected, X input connected to image) from 1ms to 20ms on a 8000x4000 image:

if (is_a_single_elem_) {
  switch (datatype_) {
    case DataType::Value:
      out[0] = buffer_[0];
      break;
    case DataType::Float2:
      copy_v2_v2(out, buffer_);
      break;
    case DataType::Vector:
      copy_v3_v3(out, buffer_);
      break;
    case DataType::Color:
    default:
      copy_v4_v4(out, buffer_);
  }
  return;
}

So hardcoding doesn't seem faster. Or did you have something else in mind?

Also, I think these are rather exotic cases, in most cases the code inside if (is_a_single_elem_) will either get called once (unconnected node) or not at all (node connected to valid input). So I suggest to keep it simple and use memcpy()

From a quick test, the following code slows down Stabilize 2D Node from 220ms to 280ms (disconnected image input) and translate node (image input disconnected, X input connected to image) from 1ms to 20ms on a 8000x4000 image: ```cpp if (is_a_single_elem_) { switch (datatype_) { case DataType::Value: out[0] = buffer_[0]; break; case DataType::Float2: copy_v2_v2(out, buffer_); break; case DataType::Vector: copy_v3_v3(out, buffer_); break; case DataType::Color: default: copy_v4_v4(out, buffer_); } return; } ``` So hardcoding doesn't seem faster. Or did you have something else in mind? Also, I think these are rather exotic cases, in most cases the code inside `if (is_a_single_elem_)` will either get called once (unconnected node) or not at all (node connected to valid input). So I suggest to keep it simple and use `memcpy()`
Member

That doesn't make sense, see: https://quick-bench.com/q/cgUMr8uXSU4PxLbwjiGohYnzImg.

But since this is copied from similar code, we can look into it later.

That doesn't make sense, see: https://quick-bench.com/q/cgUMr8uXSU4PxLbwjiGohYnzImg. But since this is copied from similar code, we can look into it later.
Author
Member

My tests only include the case where datatype_ == Color and the value to be copied is always the same. For number_of_elements = 4 results look different: https://quick-bench.com/q/FV5Ai_bHNldJ6aw3kLZKEBpWWPU

My tests only include the case where `datatype_ == Color` and the value to be copied is always the same. For `number_of_elements = 4` results look different: https://quick-bench.com/q/FV5Ai_bHNldJ6aw3kLZKEBpWWPU
Member

@zazizizou Well the benchmark is not very useful when you set number_of_elements to 4 in the source, because the compiler will detect that and remove the memcpy call entirely. While this is not known at compile time in real world cases.

@zazizizou Well the benchmark is not very useful when you set number_of_elements to 4 in the source, because the compiler will detect that and remove the memcpy call entirely. While this is not known at compile time in real world cases.
Author
Member

Ah yes true. It's still not completely random though and that might play a role.

Ah yes true. It's still not completely random though and that might play a role.
OmarEmaraDev marked this conversation as resolved
Member

@blender-bot build

@blender-bot build
Author
Member

Yes, a previous patch for translate node introduced this bug: #121436.
The difference now is the argument get_relative_x(x) is given to the function interpolate_cubic_bspline_fl() instead of just x. So this is the proper fix for the bug above.

Yes, a previous patch for translate node introduced this bug: https://projects.blender.org/blender/blender/issues/121436. The difference now is the argument `get_relative_x(x)` is given to the function `interpolate_cubic_bspline_fl()` instead of just `x`. So this is the proper fix for the bug above.
Omar Emara approved these changes 2024-05-30 14:57:31 +02:00
Habib Gahbiche added 2 commits 2024-05-30 17:11:01 +02:00
Update tests
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
9b1955217b
Author
Member

@blender-bot build

@blender-bot build
Habib Gahbiche merged commit 192d4dc9dc into main 2024-05-30 17:38:51 +02:00
Habib Gahbiche deleted branch fix-bicubic-interp 2024-05-30 17:38:54 +02: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
2 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#122288
No description provided.