The compiler is happy and the shader works. Of course for larger arrays this is impractical. Also, I must go through a similar contortion to write to an array.
I can’t figure out what and where my profile is, let alone how to change it. Or is there another way around the kludge I’m using?
The answer raises other questions. What is “branching” and “unraveled”?
I am used to having a pretty good feel for what my ordinary c code will compile to on an ordinary CPU and how it interacts with the hardware. Certainly vertex and fragment programs compile to a different computer hardware architecture which in some cases appears to restrict what can be programmed. Another example: I put a return in a conditional statement and the fragment program compiler complains:
error c5051: profile does not support conditional returns.
Now the OpenGL Shading Language specification indicates that it is ok to have such returns and doesn’t mention the possibility that in some cases it isn’t ok. The error message mentions a “profile”. Is this like the OpenGL ES common and common light profiles? Is it something I can get a hold of and read so I know what I can and can’t do?
I guess I’m after some understanding of what the compiler does with a shader program and some model of the hardware this compiled program interacts with. This is because it appears to be very different than the CPU model I am used to.
Sorry for the long post. Any references I can be pointed at would be much appreciated.
You need to understand that nvidia GLSL compiler is basically the Cg (nvidia shading language) compiler embedded into the driver. Cg can be compiled to various output formats (or profiles) for different hardware. Some profiles(hardware) support more functionality, some - less. In your case it means that your graphic card hardware is not able of executing conditional code (branching) or performing indexed array access in the fragment shader. It can, however, do conditional writes (data selection). Basically, code like
if (e) x = a else x = b
will be treated
x1 = a
x2 = b
x = iif(e, x1, x2)
It is true that the driver behavior is not really spec-conformant, but I think it is still better then forcing software mode… Consider buying a better video card