Sign in to follow this  

loops in pixel shader--slow?

This topic is 3727 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 am implementing a pixel shader to ray trace a volume texture. So I loop a high number of times (say 50) to march through the cube in incremental steps. I do a test to see if the ray goes outside the cube, and I break if it is. The problem is that it is taking D3DXCreateEffectFromFile a very long time to compile. I also get the warning: volume.fx(130,45): warning X3553: Can't use gradient instructions in loops with break, forcing loop to unroll I'm not explicitly using gradient instructions, but I guess they are done by the texture loop-up? I am NOT using mipmaps--that filter is set to NONE. If I remove the break statement, it compiles fast (like normal). So I guess the loop unrolling is what is making it slow to compile. I am using VS/PS 3.0 with a Geforce 8800, so shouldn't I have dynamic branching support?

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
I'm not explicitly using gradient instructions, but I guess they are done by the texture loop-up? I am NOT using mipmaps--that filter is set to NONE.

In that case, use tex2Dlod or whatever it's called... pass an explicit texture LOD of "0". That way the compiler will know that you don't need implicit derivatives and not force the unroll.

You can also force a loop to be a "real" loop using:
[loop] for (...) {

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
The problem is that it is taking D3DXCreateEffectFromFile a very long time to compile.

That's because your loop is entirely unrolled (i.e. the body gets repeated 50 times). Anyway, you can also compile your shaders once and work with the binary format.

Share this post


Link to post
Share on other sites

This topic is 3727 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this