Skip to content

Conversation

@KevinJW
Copy link
Contributor

@KevinJW KevinJW commented Jan 12, 2026

This is a couple of changes related to improving the debug output of the optimiser.

Basically it outputs the results of each stage within the passes, that allows for better reasoning about what changes though the process, I've tried to ensure we don't suffer too much from the overhead from the extra logging during non-debug conditions.

I have not done any performance evaluation to confirm this so far.

As a side effect there is also a slight change to the includes to remove the dependency on pystring in the op/optimiser code.

Add sstream to LogUtils.cpp which was previously being included
by transitive dependency in Op.h

Signed-off-by: Kevin Wheatley <[email protected]>
…stage

Store the result of IsDebugLoggingEnabled() to avoid taking the internal mutex and to ensure either none or all the debugging will be output for the duration optimisation call.

Avoid calling operator<< between character string literals which can be combined by the preprocessor

Replace use of std::endl with "\n"

Signed-off-by: Kevin Wheatley <[email protected]>
@KevinJW KevinJW added the Needs Discussion Needs discussion before implmentation, which could result in changes, or a decision not to proceed. label Jan 12, 2026
@KevinJW KevinJW marked this pull request as draft January 13, 2026 09:36
@KevinJW KevinJW changed the title DRAFT: Feature/optimiser debugging improvements Feature/optimiser debugging improvements Jan 13, 2026
@KevinJW
Copy link
Contributor Author

KevinJW commented Jan 13, 2026

Sample output

  - !<ColorSpace>
    name: Test Case 3
    aliases: [test_3]
    family: Display
    equalitygroup: ""
    bitdepth: 32f
    description: Test Case 3
    isdata: false
    categories: [file-io]
    encoding: sdr-video
    allocation: uniform
    from_display_reference: !<GroupTransform>
        children:
          - !<BuiltinTransform> {style: DISPLAY - CIE-XYZ-D65_to_G2.6-P3-D65}
          - !<ExponentTransform> {value: [2.6, 2.6, 2.6, 1.0], style: pass_thru, direction: forward}
          - !<ExponentTransform> {value: [2.4, 2.4, 2.4, 1.0], style: pass_thru, direction: inverse}
[OpenColorIO Debug]: **
[OpenColorIO Debug]: Optimizing Op Vec...
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 74a8bf8b9e517364ed1ed1e3ae488c3 >
[OpenColorIO Debug]:     Op 1: <AllocationNoOp> uniform
[OpenColorIO Debug]:     Op 2: <MatrixOffsetOp> <MatrixOffsetOp forward 22473544333a34d83eecb6440b4cf493 >
[OpenColorIO Debug]:     Op 3: <MatrixOffsetOp> <MatrixOffsetOp forward 11618c158eed367da8141462bf68bd0e >
[OpenColorIO Debug]:     Op 4: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 5: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 6: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 7: <AllocationNoOp> uniform
[OpenColorIO Debug]:     Op 8: <GammaOp> <GammaOp basicFwd r:1 g:1 b:1 a:1  >
[OpenColorIO Debug]: RemoveNoOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 22473544333a34d83eecb6440b4cf493 >
[OpenColorIO Debug]:     Op 1: <MatrixOffsetOp> <MatrixOffsetOp forward 11618c158eed367da8141462bf68bd0e >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 4: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 5: <GammaOp> <GammaOp basicFwd r:1 g:1 b:1 a:1  >
[OpenColorIO Debug]: ReplaceOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 22473544333a34d83eecb6440b4cf493 >
[OpenColorIO Debug]:     Op 1: <MatrixOffsetOp> <MatrixOffsetOp forward 11618c158eed367da8141462bf68bd0e >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 4: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 5: <GammaOp> <GammaOp basicFwd r:1 g:1 b:1 a:1  >
[OpenColorIO Debug]: ReplaceIdentityOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 22473544333a34d83eecb6440b4cf493 >
[OpenColorIO Debug]:     Op 1: <MatrixOffsetOp> <MatrixOffsetOp forward 11618c158eed367da8141462bf68bd0e >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 4: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 5: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveInverseOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 22473544333a34d83eecb6440b4cf493 >
[OpenColorIO Debug]:     Op 1: <MatrixOffsetOp> <MatrixOffsetOp forward 11618c158eed367da8141462bf68bd0e >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 4: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 5: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: CombineOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 4: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveNoOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 4: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 4: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceIdentityOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 4: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveInverseOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicRev r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruFwd r:2.6 g:2.6 b:2.6 a:1  >
[OpenColorIO Debug]:     Op 3: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 4: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: CombineOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicFwd r:1 g:1 b:1 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveNoOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicFwd r:1 g:1 b:1 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <GammaOp> <GammaOp basicFwd r:1 g:1 b:1 a:1  >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceIdentityOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveInverseOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: CombineOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveNoOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceIdentityOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: RemoveInverseOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: CombineOps
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: ReplaceInverseLuts
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]: **
[OpenColorIO Debug]: Optimized 9->4, 3 passes, 2 no-op types removed, 1 no-ops removed, 0 ops replaced, 2 identity ops replaced, 0 inverse op pairs removed, 2 ops combined, 0 ops inverted
[OpenColorIO Debug]:     Op 0: <MatrixOffsetOp> <MatrixOffsetOp forward 57ce2b766d07caae17e91e40f8371777 >
[OpenColorIO Debug]:     Op 1: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:     Op 2: <GammaOp> <GammaOp basicPassThruRev r:2.4 g:2.4 b:2.4 a:1  >
[OpenColorIO Debug]:     Op 3: <RangeOp> <RangeOp forward [0, nan, 0, nan] >
[OpenColorIO Debug]:
[OpenColorIO Debug]: **

@KevinJW
Copy link
Contributor Author

KevinJW commented Jan 13, 2026

And the result from the shader

#version 120

// Declaration of the OCIO shader function

vec4 OCIODisplay(vec4 inPixel)
{
  vec4 outColor = inPixel;

  // Add Matrix processing

  {
    vec4 res = vec4(outColor.rgb.r, outColor.rgb.g, outColor.rgb.b, outColor.a);
    vec4 tmp = res;
    res = mat4(2.0249052859667822, -0.18359703225617749, 0.0090585611223476716, 0., -0.68906976103476791, 1.2895062077590191, -0.059279684057552288, 0., -0.33583552493201829, -0.10590917550284097, 1.0502211229352065, 0., 0., 0., 0., 1.) * tmp;
    outColor.rgb = vec3(res.x, res.y, res.z);
    outColor.a = res.w;
  }

  // Add Range processing

  {
    outColor.rgb = max(vec3(0., 0., 0.), outColor.rgb);
  }

  // Add Gamma 'basicPassThruRev' processing

  {
    vec4 gamma = vec4(0.41666666666666669, 0.41666666666666669, 0.41666666666666669, 1.);
    vec4 breakPnt = vec4(0., 0., 0., 0.);
    vec4 isAboveBreak = vec4(greaterThan( outColor, breakPnt));
    vec4 powSeg = pow(max( vec4(0., 0., 0., 0.), outColor ), gamma);
    vec4 res = isAboveBreak * powSeg + ( vec4(1., 1., 1., 1.) - isAboveBreak ) * outColor;
    outColor.rgb = vec3(res.x, res.y, res.z);
    outColor.a = res.w;
  }

  // Add Range processing

  {
    outColor.rgb = max(vec3(0., 0., 0.), outColor.rgb);
  }

  return outColor;
}


uniform sampler2D img;

void main()
{
    vec4 col = texture2D(img, gl_TexCoord[0].st);
    gl_FragColor = OCIODisplay(col);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Discussion Needs discussion before implmentation, which could result in changes, or a decision not to proceed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant