6 Replies Latest reply on Apr 6, 2010 6:39 PM by mrmacete

    sampler2D arguments and branching

    mrmacete
      unpredictable behaviour on HD 4850 and 10.2

      hi to all!

      i'm porting my GLSL shaders to ATI cards.

      If i use sampler2D as function argument, when i nest function calls sometimes it happens to not "refresh" argument value across different call stacks.

      notice that compiler and linker doesn't complain, glsl validate returns success, and with 10.1 drivers package it worked. It also worked on older x1300 hardware.

      I also tried 10.3 beta stuff and the problem persists.

      for a quick test you can try this RenderMonkey project:

      http://user.augmented-reality.it/temp/sampler2d_branching_bug.zip

      but i post here the code to clarify my words:

       

      #version 110

      uniform sampler2D noise;
      uniform sampler2D fire;
      uniform bool fail;

      varying vec2 texcoords;


      vec4 nest1( sampler2D texture, vec2 uv )
      {
      return texture2D( texture, uv );
      }

      vec4 nest2( sampler2D texture, vec2 uv )
      {
      return nest1( texture, uv );
      }

      vec4 nest3( sampler2D texture, vec2 uv )
      {
      return nest2( texture, uv );
      }

      vec4 nest4( sampler2D texture, vec2 uv )
      {
      return nest3( texture, uv );
      }

      /*
      result is fire*noise
      */
      vec4 colorOK( sampler2D fire, sampler2D noise )
      {
      vec4 color = nest4( fire, texcoords.xy );
      return color * nest1( noise, texcoords.xy );
      }

      /*
      result is noise*noise
      */
      vec4 colorKO2( sampler2D fire, sampler2D noise )
      {
      vec4 color = nest4( fire, texcoords.xy );
      return color * nest2( noise, texcoords.xy );
      }

      /*
      result is fire*fire
      */
      vec4 colorKO( sampler2D fire, sampler2D noise )
      {
      vec4 color = nest2( fire, texcoords.xy );
      return color * nest2( noise, texcoords.xy );
      }

       

      void main(void)
      {
      //gl_FragColor = colorKO2(fire, noise);
      //gl_FragColor = colorKO(fire, noise);
      gl_FragColor = colorOK(fire, noise);

      //gl_FragColor = nest1( fire, texcoords.xy );
      //gl_FragColor = nest1( noise, texcoords.xy );

      }

       

      thanks for your time.

      Let me know if this is not the place to discuss about this.