AcademySoftwareFoundation / OpenRV

Open source version of RV, the Sci-Tech award-winning media review and playback software.
Other
577 stars 142 forks source link

[Bug]: OCIO failed to compile GL program with 1d luts with 2048 length in RV 2024.1.0 #457

Open kenmcgaugh opened 5 months ago

kenmcgaugh commented 5 months ago

What happened?

RV is failing to compile the GL program when OCIO is using 1D luts with length 2048 both in forwards and inverse directions. The error is:

ERROR: Multiple declarations of 'ocio_lut1d_0Sampler' have different types (sampler1D and sampler2D)

I think the 2048 length must be on the limit where OCIO decides to use a 1D GL texture for one direction and 2D for the other, causing a name clash with different types.

List all the operating systems versions where this is happening

macOS 14.3

On what computer hardware is this happening?

Apple macbook pro M1 16GB

Relevant console log output

//
// VERTEX PROGRAM
//
  1:  attribute vec2 in_Position;
  2:  uniform mat4 projMatrix, modelviewMatrix;
  3:  attribute vec2 in_TexCoord0;
  4:  varying vec2 TexCoord0;
  5:  void main()
  6:  {
  7:      TexCoord0 = in_TexCoord0;
  8:      gl_Position = projMatrix * modelviewMatrix * vec4(in_Position, 0, 1);
  9:  }
 10:  
//
// FUNCTION: OCIO_l_identity_2048_sourceGroup000000_lookPipeline_0_cd2b989b07871d0_0
//
  1:  

  2:  
  3:  uniform sampler1D ocio_lut1d_0Sampler;
  4:  
  5:                                            
  6:  
  7:  vec4 OCIO_l_identity_2048_sourceGroup000000_lookPipeline_0_cd2b989b07871d0_05dd560bf ( in vec4 inPixel,  in sampler1D ocio_lut1d_0Sampler)
  8:  {
  9:    vec4 outColor = inPixel;
 10:    
 11:                                             
 12:    
 13:    {
 14:      vec3 ocio_lut1d_0_coords = (outColor.rgb * vec3(2047., 2047., 2047.) + vec3(0.5, 0.5, 0.5) ) / vec3(2048., 2048., 2048.);
 15:      outColor.r = texture1D(ocio_lut1d_0Sampler, ocio_lut1d_0_coords.r).r;
 16:      outColor.g = texture1D(ocio_lut1d_0Sampler, ocio_lut1d_0_coords.g).r;
 17:      outColor.b = texture1D(ocio_lut1d_0Sampler, ocio_lut1d_0_coords.b).r;
 18:    }
 19:  
 20:    return outColor;
 21:  }
 22:  
//
// FUNCTION: OCIO_c_issue_space_2_scene_linear_sourceGroup000000_tolinPipeline_0_bc2bf30103610a81
//
  1:  

  2:  
  3:  uniform sampler2D ocio_lut1d_0Sampler;
  4:  
  5:                                      
  6:  
  7:  vec2 ocio_lut1d_0_computePos9fa4a6bb(float f)
  8:  {
  9:    float dep;
 10:    float abs_f = abs(f);
 11:    if (abs_f > 6.10351562e-05)
 12:    {
 13:      vec3 fComp = vec3(15., 15., 15.);
 14:      float absarr = min( abs_f, 65504.);
 15:      fComp.x = floor( log2( absarr ) );
 16:      float lower = pow( 2.0, fComp.x );
 17:      fComp.y = ( absarr - lower ) / lower;
 18:      vec3 scale = vec3(1024., 1024., 1024.);
 19:      dep = dot( fComp, scale );
 20:    }
 21:    else
 22:    {
 23:      dep = abs_f * 1023.0 / 6.09755516e-05;
 24:    }
 25:    dep += step(f, 0.0) * 32768.0;
 26:    vec2 retVal;
 27:    retVal.y = floor(dep / 4095.);
 28:    retVal.x = dep - retVal.y * 4095.;
 29:    retVal.x = (retVal.x + 0.5) / 4096.;
 30:    retVal.y = (retVal.y + 0.5) / 17.;
 31:    return retVal;
 32:  }
 33:  
 34:                                            
 35:  
 36:  vec4 OCIO_c_issue_space_2_scene_linear_sourceGroup000000_tolinPipeline_0_bc2bf30103610a819fa4a6bb ( in vec4 inPixel,  in sampler2D ocio_lut1d_0Sampler)
 37:  {
 38:    vec4 outColor = inPixel;
 39:    
 40:                                             
 41:    
 42:    {
 43:      outColor.r = texture2D(ocio_lut1d_0Sampler, ocio_lut1d_0_computePos9fa4a6bb(outColor.r)).r;
 44:      outColor.g = texture2D(ocio_lut1d_0Sampler, ocio_lut1d_0_computePos9fa4a6bb(outColor.g)).r;
 45:      outColor.b = texture2D(ocio_lut1d_0Sampler, ocio_lut1d_0_computePos9fa4a6bb(outColor.b)).r;
 46:    }
 47:  
 48:    return outColor;
 49:  }
 50:  
//
// FUNCTION: SourcePlanarYUV
//
  1:    
  2:                                                             
  3:     
  4:                                         
  5:    
  6:    
  7:                                     
  8:    
  9:  
 10:                                                                        
 11:                                                                
 12:  
 13:  vec4 SourcePlanarYUVe3d70750 (const in sampler2DRect Y_sampler, const in sampler2DRect U_sampler, const in sampler2DRect V_sampler, const in vec2 ST, const in vec2 ratio0, const in vec2 ratio1, const in mat4 YUVmatrix, const in vec2 offset, const in vec2 Y_samplerSize, const in float orientation)
 14:  {
 15:                                                                
 16:                                                                
 17:      vec2 st = ST + offset;
 18:      if (st.x < 0.0 || st.y < 0.0 || st.x >= Y_samplerSize.x || st.y >= Y_samplerSize.y)
 19:          return vec4(0.0);                             
 20:  
 21:      if (orientation == 1.0)      
 22:      {
 23:          st.y = Y_samplerSize.y - st.y;
 24:      }
 25:      else if (orientation == 2.0)      
 26:      {
 27:          st.x = Y_samplerSize.x - st.x;
 28:      }
 29:      else if (orientation == 3.0)      
 30:      {
 31:          st.x = Y_samplerSize.x - st.x;
 32:          st.y = Y_samplerSize.y - st.y;
 33:      }
 34:      
 35:      return YUVmatrix * vec4( texture2DRect(Y_sampler, st).r,
 36:                               texture2DRect(U_sampler, st * ratio0).r,
 37:                               texture2DRect(V_sampler, st * ratio1).r,
 38:                               1.0 );
 39:  }
 40:  
 41:  
//
// FUNCTION: ResizeDownSampleDerivative
//
  1:    
  2:                                                             
  3:     
  4:                                         
  5:    
  6:  vec4 ResizeDownSampleDerivativea67083a4 (const in vec2 _offset)
  7:  {
  8:                                                                   
  9:      vec2 absDer = fwidth( in0.st );
 10:  
 11:                                                
 12:      float maxAbsDer = max( absDer.x, absDer.y );
 13:  
 14:                                                            
 15:                                                                              
 16:                               
 17:      int KERNEL_SIZE = int( maxAbsDer / 2.0 );
 18:  
 19:                                                                              
 20:                     
 21:         
 22:                                                          
 23:                                                     
 24:                                                     
 25:                                  
 26:                                                     
 27:                                     
 28:                                     
 29:                                     
 30:                                                       
 31:                                     
 32:                                     
 33:                                     
 34:                                     
 35:                                     
 36:                                     
 37:                                     
 38:                                                       
 39:  
 40:      if ( KERNEL_SIZE < 0 )
 41:      {
 42:          KERNEL_SIZE = 0;
 43:      }
 44:      else if ( KERNEL_SIZE > 16 )
 45:      {
 46:          KERNEL_SIZE = 16;
 47:      }
 48:  
 49:                                       
 50:      vec4 averageColor=vec4(0.0,0.0,0.0,0.0);
 51:      for ( int x = -KERNEL_SIZE ; x <= KERNEL_SIZE ; x++ )
 52:      {
 53:          for ( int y = -KERNEL_SIZE ; y <= KERNEL_SIZE ; y++ )
 54:          {
 55:              averageColor+= in0( vec2 ( x , y ) );
 56:          }
 57:      }
 58:  
 59:                                        
 60:      float nbSamples = float( ( KERNEL_SIZE * 2 + 1 )* ( KERNEL_SIZE * 2 + 1 ) );
 61:      averageColor /= vec4(nbSamples);
 62:  
 63:      return averageColor;
 64:  }
 65:  
 66:  
//
// PROGRAM:
//
  1:  uniform sampler2DRect Y_sampler_1;
  2:  uniform float orientation_1;
  3:  uniform sampler1D ocio_lut1d_0Sampler_2;
  4:  uniform sampler2D ocio_lut1d_0Sampler_1;
  5:  uniform vec2 samplerSize_1;
  6:  uniform sampler2DRect U_sampler_1;
  7:  uniform sampler2DRect V_sampler_1;
  8:  uniform vec2 ratio1_1;
  9:  uniform vec2 ratio0_1;
 10:  uniform mat4 YUVmatrix_1;
 11:  varying vec2 TexCoord0;
 12:  vec4 OCIO_l_identity_2048_sourceGroup000000_lookPipeline_0_cd2b989b07871d0_05dd560bf(in vec4, in sampler1D);
 13:  vec4 OCIO_c_issue_space_2_scene_linear_sourceGroup000000_tolinPipeline_0_bc2bf30103610a819fa4a6bb(in vec4, in sampler2D);
 14:  vec4 SourcePlanarYUVe3d70750(const in sampler2DRect, const in sampler2DRect, const in sampler2DRect, const in vec2, const in vec2, const in vec2, const in mat4, const in vec2, const in vec2, const in float);
 15:  
 16:  vec4 ResizeDownSampleDerivativea67083a4_0(const in vec2);
 17:  
 18:  vec4 _samplerExpr1 (const in vec2 _offset)
 19:  {
 20:      return SourcePlanarYUVe3d70750(Y_sampler_1, U_sampler_1, V_sampler_1, TexCoord0.xy, ratio0_1, ratio1_1, YUVmatrix_1, _offset, samplerSize_1, orientation_1);
 21:  }
 22:  
 23:    
 24:                                                             
 25:     
 26:                                         
 27:    
 28:  vec4 ResizeDownSampleDerivativea67083a4_0 (const in vec2 _offset)
 29:  {
 30:                                                                   
 31:      vec2 absDer = fwidth( TexCoord0.st );
 32:  
 33:                                                
 34:      float maxAbsDer = max( absDer.x, absDer.y );
 35:  
 36:                                                            
 37:                                                                              
 38:                               
 39:      int KERNEL_SIZE = int( maxAbsDer / 2.0 );
 40:  
 41:                                                                              
 42:                     
 43:         
 44:                                                          
 45:                                                     
 46:                                                     
 47:                                  
 48:                                                     
 49:                                     
 50:                                     
 51:                                     
 52:                                                       
 53:                                     
 54:                                     
 55:                                     
 56:                                     
 57:                                     
 58:                                     
 59:                                     
 60:                                                       
 61:  
 62:      if ( KERNEL_SIZE < 0 )
 63:      {
 64:          KERNEL_SIZE = 0;
 65:      }
 66:      else if ( KERNEL_SIZE > 16 )
 67:      {
 68:          KERNEL_SIZE = 16;
 69:      }
 70:  
 71:                                       
 72:      vec4 averageColor=vec4(0.0,0.0,0.0,0.0);
 73:      for ( int x = -KERNEL_SIZE ; x <= KERNEL_SIZE ; x++ )
 74:      {
 75:          for ( int y = -KERNEL_SIZE ; y <= KERNEL_SIZE ; y++ )
 76:          {
 77:              averageColor+= _samplerExpr1(_offset +  vec2 ( x , y ) );
 78:          }
 79:      }
 80:  
 81:                                        
 82:      float nbSamples = float( ( KERNEL_SIZE * 2 + 1 )* ( KERNEL_SIZE * 2 + 1 ) );
 83:      averageColor /= vec4(nbSamples);
 84:  
 85:      return averageColor;
 86:  }
 87:  
 88:  
 89:  void main ()
 90:  {
 91:      gl_FragColor = OCIO_l_identity_2048_sourceGroup000000_lookPipeline_0_cd2b989b07871d0_05dd560bf(OCIO_c_issue_space_2_scene_linear_sourceGroup000000_tolinPipeline_0_bc2bf30103610a819fa4a6bb(ResizeDownSampleDerivativea67083a4_0(vec2(0.0, 0.0)), ocio_lut1d_0Sampler_1), ocio_lut1d_0Sampler_2);
 92:  }
 93:  
ERROR: compiling program: 
      with functions:  OCIO_l_identity_2048_sourceGroup000000_lookPipeline_0_cd2b989b07871d0_0 OCIO_c_issue_space_2_scene_linear_sourceGroup000000_tolinPipeline_0_bc2bf30103610a81 SourcePlanarYUV ResizeDownSampleDerivative
ERROR: Multiple declarations of 'ocio_lut1d_0Sampler' have different types (sampler2D and sampler1D)
ERROR: failed to compile/select GL program: ERROR: failed to select the GL program

Environment variables

DISPLAY=/private/tmp/com.apple.launchd.Ho7Xi9pMTK/org.xquartz:0 EDITOR=emacs GROUP=unknown HOME=/Users/ken HOST=legospace HOSTTYPE=unknown IOCIN_ARGS= --format RGB8_PLANAR --useChromaticities 0 --ioSize 61440 --ioMethod 2 --ioMaxAsync 16 IODPX_ARGS= --format RGB8_PLANAR --useChromaticities 0 --ioSize 61440 --ioMethod 2 --ioMaxAsync 16 IOEXR_ARGS= --rgbaOnly 0 --inherit 1 --noOneChannel 0 --readWindowIsDisplayWindow 0 --readWindow 3 --planar3channel 0 --stripAlpha 0 --convertYRYBY 0 --ioSize 61440 --ioMethod 3 --ioMaxAsync 16 IOJPEG_ARGS= --ioSize 61440 --ioMethod 0 --ioMaxAsync 16 IOTARGA_ARGS= --ioSize 61440 --ioMethod 2 --ioMaxAsync 16 IOTIFF_ARGS= --ioSize 61440 --ioMethod 2 LANG=C LC_ALL=C LOGNAME=ken MACHTYPE=unknown MOVIEFFMPEG_ARGS= --defaultFPS 24 MOVIEMISTIKA_ARGS= --format RGB8_PLANAR MU_MODULE_PATH=/Users/ken/Library/Application Support/RV/Mu:/Library/Application Support/RV/Mu:/Applications/RV.app/Contents/PlugIns/Mu OCIO=/Users/ken/Downloads/ocio_issue/config.ocio OIIO_LIBRARY_PATH=/Users/ken/Library/Application Support/RV/OIIO:/Library/Application Support/RV/OIIO:/Applications/RV.app/Contents/PlugIns/OIIO:/Applications/RV.app/Contents/PlugIns/OIIO ORIGINALLOCAL=en_NZ.UTF-8 OSTYPE=darwin OTIO_PLUGIN_MANIFEST_PATH=/Applications/RV.app/Contents/PlugIns/Python/../SupportFiles/otio_reader/manifest.json PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/usr/local/munki:/usr/local/munkireport:/opt/puppetlabs/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin/ PWD=/Users/ken/Downloads/ocio_issue PYTHONPATH=/Users/ken/Library/Application Support/RV/Python:/Users/ken/Library/Application Support/RV/MediaLibrary:/Library/Application Support/RV/Python:/Library/Application Support/RV/MediaLibrary:/Applications/RV.app/Contents/PlugIns/Python:/Applications/RV.app/Contents/PlugIns/MediaLibrary QT_MAC_WANTS_BEST_RESOLUTION_OPENGL_SURFACE=0 QT_QUICK_BACKEND=software RV_APP_GTO_REFERENCE= RV_APP_INIT=/Applications/RV.app/Contents/Resources/English.lproj/rvrc.mu RV_APP_LICENSES_NOTES= RV_APP_MANUAL= RV_APP_MANUAL_HTML= RV_APP_MU_MANUAL= RV_APP_PYINIT=/Applications/RV.app/Contents/Resources/English.lproj/rvrc.py RV_APP_REFERENCE_MANUAL= RV_APP_REFERENCE_MANUAL_HTML= RV_APP_RELEASE_NOTES= RV_APP_RV=/Applications/RV.app/Contents/MacOS/RV RV_APP_RVIO=/Applications/RV.app/Contents/MacOS/rvio RV_APP_RV_SHORT_NAME=RV RV_APP_SDI_MANUAL= RV_APP_SDI_MANUAL_HTML= RV_DARK=1 RV_OS_VERSION_MAJOR=10 RV_OS_VERSION_MINOR=19 RV_OS_VERSION_REVISION=0 RV_OTIO_CHECKSUM=PDpnQkVYVFw+UA4IaQBSDFU8AVoJFBFXSkI5A1hbBgk5bUJGPgdUTBBeblMJC1JSbT1ERDkRQA5EXFJuAVULBQ== RV_PYTHONPATH_EXTERNAL= RV_SHOTGUN_AUTH_ALLOW_TOGGLE=1 RV_SHOTGUN_DEFAULT_LOGIN= RV_SHOTGUN_DEFAULT_SERVER_URL=https://shotgun.wetafx.co.nz SGTK_DEFAULT_AUTH_METHOD=app_session_launcher SHELL=/bin/tcsh SHLVL=2 SHOTGUN_API_CACERTS=/tmp/.rv_ca_file.pem SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.uElpMljAUj/Listeners SSL_CERT_FILE=/Applications/RV.app/Contents/lib/python3.10/site-packages/certifi/cacert.pem TANK_CURRENT_PC=/Applications/RV.app/Contents/src/sgtk/baked/plugin/bundle_cache/baked/tk-config-rv/v2.1.0-rc1 TERM=xterm-256color TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=453 TERM_SESSION_ID=05E3B9E3-7ED1-4085-995A-795845424C0B TK_AUTH_PRODUCT=RV TK_RV_MODE_NAME=sgtk_bootstrap TMPDIR=/var/folders/9z/cc23rvc90b9g0lqtps2f558h00037j/T/ TWK_APP_SUPPORT_PATH=/Users/ken/Library/Application Support/RV:/Library/Application Support/RV:/Network/Library/Application Support/RV:/Applications/RV.app/Contents/PlugIns TWK_APP_VERSION=2024.1.0 TWK_FB_PLUGIN_PATH=/Users/ken/Library/Application Support/RV/ImageFormats:/Library/Application Support/RV/ImageFormats:/Applications/RV.app/Contents/PlugIns/ImageFormats TWK_MEDIA_LIBRARY_PLUGIN_PATH=/Users/ken/Library/Application Support/RV/MediaLibrary:/Library/Application Support/RV/MediaLibrary:/Applications/RV.app/Contents/PlugIns/MediaLibrary TWK_MOVIE_PLUGIN_PATH=/Users/ken/Library/Application Support/RV/MovieFormats:/Library/Application Support/RV/MovieFormats:/Applications/RV.app/Contents/PlugIns/MovieFormats TWK_NODE_PLUGIN_PATH=/Users/ken/Library/Application Support/RV/Nodes:/Library/Application Support/RV/Nodes:/Applications/RV.app/Contents/PlugIns/Nodes TWK_OUTPUT_PLUGIN_PATH=/Users/ken/Library/Application Support/RV/Output:/Library/Application Support/RV/Output:/Applications/RV.app/Contents/PlugIns/Output TWK_PROFILE_PLUGIN_PATH=/Users/ken/Library/Application Support/RV/Profiles:/Library/Application Support/RV/Profiles:/Applications/RV.app/Contents/PlugIns/Profiles TWK_RVIO_SETUP=10413 USER=ken VENDOR=apple XPC_FLAGS=0x0 XPC_SERVICENAME=0 =/Applications/RV.app/Contents/MacOS/RV.real CFBundleIdentifier=com.apple.Terminal CF_USER_TEXT_ENCODING=0xCF1:0x0:0x0 **** Build Info **** OS: DARWIN Arch:
Compiler: AppleClang


Extra information

Attached are a config.ocio and issue_2048.spi1d. Enable basic OCIO package in RV, then point OCIO to this config.ocio file with the spi1d lut in the same directory. Activate both the file color space and the look and the errors will appear. rv_ocio_issue.zip

Code of Conduct

doug-walker commented 5 months ago

I think the 2048 length must be on the limit where OCIO decides to use a 1D GL texture for one direction and 2D for the other, causing a name clash with different types.

Good guess @kenmcgaugh , but not quite. When OCIO needs to invert a Lut1D, it usually converts the inverse into a 65536 entry half-domain Lut1D in which it may do a normal forward interpolation (and that is what happens in your example). And 64k is above the transition point to 2D.

(This is still a valid bug, just wanted to provide that extra bit of information.)

bernie-laberge commented 5 months ago

Thank you Doug for the information !

Great catch @kenmcgaugh !

I guess that the fix might consist in appending a sha1 to the uniform ocio_lut1d_0Sampler to make it unique. Similar to this fix: https://github.com/AcademySoftwareFoundation/OpenRV/commit/c7d1cd495c0340b1590e02884419f38c7f9c5d6a