Jump to content
  • Advertisement
Sign in to follow this  
george7378

Unrestricted while loop?

This topic is 1130 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 suspect the answer to this is going to be 'no', but I'll ask anyway. Is it possible to have a while loop in HLSL which continues indefinitely? I'm making an iterative path tracer which, for each initial ray, bounces it around the scene until it either hits a light or until its colour becomes close enough to black that I can just ignore it. At the moment, I am having to impose a maximum number of bounces because the shader refuses to compile unless I do. Has anyone done a similar project where they can share a solution?

 

Thanks a lot!

Share this post


Link to post
Share on other sites
Advertisement

you can use 2 interleaved while loops with [loop] tag

 

[loop]while(expr)
[loop]while(expr)

{
 // your code
}

 

EDIT one "[loop]while(expr)" is enough for SM4+

Edited by imoogiBG

Share this post


Link to post
Share on other sites

I accidentally had a shader loop than never ended and as Matias pointed out TDR kicked in. This was with an Nvidia card which recovered itself.

Share this post


Link to post
Share on other sites

Most GPU's are non-preemptive, meaning that once your shader is running... it will run to completion no matter what, without letting other stuff like, say, rendering your desktop, run in parallel. In other words your screen will freeze and if you have a driver watchdog it will reset the driver after some number of seconds.

 

To do what you want you should just get each invocation of the shader to do N passes on each pixel, and accumulate the results, where N is a reasonable number (large enough that you're not invoking a shader run for every pass, but not too large that your shader takes too long to run). If you are using a dedicated second graphics card not connected to a monitor then N can be as large as you want.

 

That way you can see the results of the iterative passes, N passes at a time. You'll know if N is too large if your desktop feels choppy to use.

Share this post


Link to post
Share on other sites

Could you you the same technique used in GPU particle system. the particle could live for ever or normally you give it a life time value.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!