Jump to content
  • Advertisement
Sign in to follow this  
bwhiting

shader assembly if statements

This topic is 2588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I currently write my shaders in an assembly language (Adobe's AGAL)

and so far so good, its pretty simple and quite powerful because it makes it really easy to chain shaders together etc...

but I would like to implement some if statement type logic, this is new to me and I ain't too sure how it works!

so far stuff looks like

add("ft3", "ft11, "ft2" )
mov(...
m44(..
...

that kinda stuff all pretty much linear.

anyone know how if statements should look?

i think these are the available conditionals:

"ifz";
"inz";
"ife";
"ine";
"ifg";
"ifl";
"ieg";
"iel";
"els";
"eif";
"rep";


anyone know how these should/could be used to do if statements or looping?!?!?

to be totally honest I am not sure if they are all even implemented yet but if someone can give me a heads up on how they might be used that would be great!!

thanks :D

Share this post


Link to post
Share on other sites
Advertisement
managed to find out a little about shader assembly and it seems that most older gpus still execute both sides of a conditional anyway.. they just reject the result somehow

hmmm

suppose you wanted to do this..

//pseudo code
if(uv.x > 0.5)
{
colour.rgb = 1;
}else{
colour.rgb = 0;
}

not really sure how you would convert that but i guess you could convert the stuff in the conditional into temps and then set either one temp or the other one to zero based on the conditional, and then add it to the colour?

would that be how its done? huh.gif

Share this post


Link to post
Share on other sites
Probably you can just use fxc.exe to compile the shader and then look at the generated assembly?

Edit: Nevermind. Somehow thought you were talking about HLSL.

Share this post


Link to post
Share on other sites

managed to find out a little about shader assembly and it seems that most older gpus still execute both sides of a conditional anyway.. they just reject the result somehow

hmmm

suppose you wanted to do this..

//pseudo code
if(uv.x > 0.5)
{
colour.rgb = 1;
}else{
colour.rgb = 0;
}

not really sure how you would convert that but i guess you could convert the stuff in the conditional into temps and then set either one temp or the other one to zero based on the conditional, and then add it to the colour?

would that be how its done? huh.gif


From what I understand, the way it is done is that you convert it all into a mathematical expression where all but one branch is always cancelled out.

Assuming a stupid compiler, your example would become:
colour.rgb = 1 * (uv.x > 0.5) + 0 * (uv.x <= 0.5)

There are obviously lots of optimizations that can be done on this, often in general too I believe.

However, you must take care when working with shaders if they do not support actual branches, because as you might figure from the expression above... INFINITY and special values don't play nice! Meaning, you might not be able to check a value against infinity and then use it in a branch if it isn't infinity. As it will still be part of the final expression and possibly also wrongfully messing up the result. This may not be an issue in your language, but I've had this happen to a friend of mine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!