• Advertisement
Sign in to follow this  

How to express while looping in ARB_fragment_program?

This topic is 4521 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

Hi, I am writing a fragment shader using ARB_fragment_program + NV_fragment_program2. I am sure that there must be a way of expressring while loops in fragment programs. Could someone shed some light on how to write the following instruction "while (condition-expression)" which is in high-level language into NV_fragment_program2 instruction. Thanks. - FMS

Share this post


Link to post
Share on other sites
Advertisement
The "while" keyword doesn't have a direct translation into the native instruction set of NV4x. What you have to do is use either a REP or LOOP instruction and put a BRK instruction somewhere inside the loop to conditionally break out. REP and LOOP both take a static loop count, so you'll need to know the maximum number of iterations ahead of time.

Share this post


Link to post
Share on other sites
Hi,

What is the maximum number of iterations that can be performed on GeForce6 Series hardware? Is it possible to use LOOP instruction without knowing the exact number of iterations that one needs to perform? I am writing a general purpose computation on the GPU and there is no way I really how many iterations will be performed for every fragment.

Thanks,
- FMS

Share this post


Link to post
Share on other sites
On a GF6, the REP and LOOP instructions can each use a maximum of 255 iterations and can be nested 4 deep. You can't actually get up to 255^4 total iterations, though -- the fragment program will terminate after around 65000 instructions are executed.

You need to determine the maximum number of iterations that you'll ever need ahead of time and program that into the REP or LOOP instruction. Then run your own counter in a temp register and use the BRK instruction to exit the loop after the right number of iterations.


[Edited by - Eric Lengyel on September 5, 2005 2:24:31 PM]

Share this post


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

  • Advertisement