Page MenuHome

Compositor: Constant folding
ClosedPublic

Authored by Manuel Castilla (manzanilla) on Jun 3 2021, 11:29 PM.

Details

Summary

Currently there is no clear way to know if an operation is constant,
i.e. when all rendered elements (or pixels) have same values.
Operations may need to get constant inputs values before rendering
to determine their resolution or areas of interest. This is the case
of input parameters for scale, rotate and translate operations. Only
"set operations" are known to be constant but there are many more
operations that are constant when all their inputs are so.
Such cases can be optimized by only rendering one element.

Current solution for tiled implementation is to get first element
from input. This works only for root execution groups, others
need previous groups to be rendered.

On full frame implementation this is not possible, because buffers
are created on rendering to reduce peak memory and there is
no per pixel calls.

This patch solution is to evaluate all operations that are constant
into primitive operations (Value/Vector/Color) before
determining resolutions.


I haven't enabled can_be_constant flag on any operation.
The idea is check which ones can be constant for each full frame
node patch.

Test case enabling can_be_constant flag on brightness operation:

Graphviz prior folding:

Graphviz after folding:

Diff Detail

Repository
rB Blender
Branch
cmp-constant-folding (branched from master)
Build Status
Buildable 15334
Build 15334: arc lint + arc unit

Event Timeline

Manuel Castilla (manzanilla) requested review of this revision.Jun 3 2021, 11:29 PM
Manuel Castilla (manzanilla) created this revision.
Manuel Castilla (manzanilla) edited the summary of this revision. (Show Details)
  • Cleanup: Unneeded block
Jeroen Bakker (jbakker) requested changes to this revision.Jun 21 2021, 11:33 AM
Jeroen Bakker (jbakker) added inline comments.
source/blender/compositor/intern/COM_ConstantFolder.cc
44

For clarity I would almost reverse this function:

if (operation->get_flags().can_be_constant && ! operation->get_flags().is_constant_operation) {
   for....
    break
  return true;
}
return false
source/blender/compositor/operations/COM_ConstantOperation.cc
25

Shouldn't this be false?

An operation initially is constant or can be made constant.

This revision now requires changes to proceed.Jun 21 2021, 11:33 AM
  • Merge branch 'master' into cmp-constant-folding
  • Improve is_constant_foldable clarity
  • Unset can_be_constant flag in ConstantOperation
Manuel Castilla (manzanilla) marked 2 inline comments as done.Jun 21 2021, 4:18 PM
  • Fix constant operations id not being set
This revision is now accepted and ready to land.Jul 5 2021, 7:32 AM
This revision was automatically updated to reflect the committed changes.