Jump to content
  • Advertisement
Sign in to follow this  
USA_NAAL

Is there a limit to the count of iterations in HLSL for loop?

This topic is 2628 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 All,

Assume i'm drawing a simple cube while applying the following pixel shader to it (ps_3_0):



float4 PS_Program(VertexShaderOutput input) : COLOR0
{

float4 clr = float4(0, 0, 0, 0);
float4 step = float4 (1.0f, 1.0f, 1.0f, 1.0f) / Iterations;

for (int i = 0; i < Iterations; ++i)
clr += step;

return clr;
}




and I'm controlling the count of Iterations from the application (change it in the range [1..1000])

As you may expect this should result in a white cube no matter what the Iterations value is (since it will sum to 1).
6715674.png


However, when the value of the Iterations goes greater than around 256-400 the white cube is no longer white but gray.

6715681.png


and it will decay more when I increase the count of Iterations.
which makes me believe that there is an upper limit to the count of iterations that can performed otherwise why this code doesn't always add up to white = float4(1, 1, 1, 1)?

Share this post


Link to post
Share on other sites
Advertisement
If actual looping instructions are used in conjunction with an integer register, the limit on the number of iterations is 255. The docs stating that are here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb174715%28v=vs.85%29.aspx. If you want to know what your shader is actually doing, then you can look at the disassembly either by using fxc.exe to compile the shader or by using PIX to inspect the pixel shader object in a captured frame.

Share this post


Link to post
Share on other sites
Thanks for the reply, that was helpful

Do you think nesting loops would be a good choice or you have a better workaround?

Share this post


Link to post
Share on other sites
Yeah nesting the loops should work, or just doing multiple loops in the shader.

Share this post


Link to post
Share on other sites
Hi! Watch out that if your loop gets unrolled, there's also an instruction slot count limit. It's GPU-dependant, but you have a minimum guaranteed of 512 instruction slots in Shader Model 3.0

You have to watch out of these because usually the Ati X1000 series have the bare minimum, and if you use more, your shaders will unexpectedly fail to load (with little information about the cause).
This is the kind of problem that makes a shader run in one GPU, and fail in another. Even though they are both SM 3.0 capable.
They're strange though, since you rarely hit the mark (specially since any DX10 capable HW can do a lot more); but it's disorienting when it happens; usually triggered by loops being unrolled.

Cheers
Dark Sylinc

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!