cancel
Showing results for 
Search instead for 
Did you mean: 

OpenGL & Vulkan

Highlighted
Journeyman III
Journeyman III

sampler2D arguments and branching

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.

 

 

 

Tags (1)
0 Kudos
Reply
6 Replies
Highlighted
Staff
Staff

sampler2D arguments and branching

just to make sure, even though the title of the thread says branching, your sample is really about function inlining, right ?

the code seems correct, so it could be a regression.

Pierre B.

0 Kudos
Reply
Highlighted
Journeyman III
Journeyman III

sampler2D arguments and branching

Originally posted by: pboudier just to make sure, even though the title of the thread says branching, your sample is really about function inlining, right ?

 

 

yes, this version of the example considers only function calls, but i tried to replace the main function with

void main(void)
{
if ( fail )
gl_FragColor = colorKO(fire, noise);
else
gl_FragColor = colorOK(fire, noise);

}

and the result was fire*fire even in the OK case, so i suppose it is somehow related to branching too.

FT.

0 Kudos
Reply
Highlighted
Journeyman III
Journeyman III

sampler2D arguments and branching

Originally posted by: mrmacete  

 

 

 

void main(void) { if ( fail ) gl_FragColor = colorKO(fire, noise); else gl_FragColor = colorOK(fire, noise);

 

}

 

and the result was fire*fire even in the OK case, so i suppose it is somehow related to branching too.

 

ERRATA: the code wich fails on branching is

void main(void)

{
if ( fail )
gl_FragColor = colorKO2(fire, noise);
else
gl_FragColor = colorOK(fire, noise);
}

and it results always in noise*noise

FT.

0 Kudos
Reply
Highlighted
Journeyman III
Journeyman III

sampler2D arguments and branching

just tested with new 10.3 and this bug still exists.

0 Kudos
Reply
Highlighted
Staff
Staff

sampler2D arguments and branching

The bug is fixed in an upcoming driver, but not in 10.3. You have to wait for 2 or 3 months.

Frank

0 Kudos
Reply
Highlighted
Journeyman III
Journeyman III

sampler2D arguments and branching

Originally posted by: frali The bug is fixed in an upcoming driver, but not in 10.3. You have to wait for 2 or 3 months.


ok not a problem, i already workarounded it. the most of time/money waste is now relegated to past activity of detecting this bug

0 Kudos
Reply