Hi. First post so I hope I'm asking this in the right place.
I was wondering if there are any known issues with loop limit conditions in HLSL shader model 5?
The reason I ask is because I had an issue today with precisely this, and it appears to be some kind of compiler issue. Unfortunately this is part of a piece of university coursework and so I can't really post all the code up here but the basic idea was that I was passing in the number of lights I was using (with a maximum of 5) using a cbuffer. When I wrote the for loop to iterate over the lights using the light count in the cbuffer, I got a static/noise effect on the screen. However when the limit was set using a literal with the same value, the issue disappeared.
That is to say, this caused an error:
for (uint c = 0; c < lightCount; c++)
{
// lighting calculations here
}
whilst this didn't
for (uint c = 0; c < 1; c++)
{
// lighting calculations here
}
The final solution I settled on was something like this, which works fine
for (uint c = 0; c < MAX_LIGHTS; c++)
{
if (c >= lightCount)
break;
// lighting calculations here
}
Incidentally I had the exact same problem when restructured to use while loops like so
uint c = 0;
while (c < lightCount)
{
// lighting calculations here
c++;
}
So yes basically, I wondered, is this a known issue? Or is it not even allowed by the language? All I know is that it compilers without an error. I spoke to some other people about this issue and they said that such problems were known, but only in much lower shader models (like 2 or something). However I'm definitely compiling with shader model 5 ("ps_5_0" is the parameter is the compile shader from file function).
Anyhow if anyone has any thoughts on what might be happening here, it would be greatly appreciated. Thanks!