PDA

View Full Version : Array initialization



frigopie
05-18-2011, 09:10 PM
Hi!

I have a little (big) problem initializing const arrays. On ATI cards only works this way:

const float vec[3]=vec[3](1.0,2.0,3.0); //Works :)

but in my Nvidia card this way only works with arrays bigger than 1 (stupid and strange, isīn it?), so:

const float vec[3]=vec[3](1.0,2.0,3.0); //It is fine
const float vec[1]=vec[1](1.0); //Fails! cast not allowed error


There is another C like way used in nvidia cg shaders that works on my nvidia card but not in on ATI, so it is unuseful.


Is there any standard way to init const arrays that works on all cards?

PD: I need const arrays with values known at compilation time, not uniforms, because of compiler optimizations

Thanks!

Alfonse Reinheart
05-18-2011, 09:33 PM
Is there any standard way to init const arrays that works on all cards?

Well, the specification just says what is supposed to happen. All you can do is avoid using arrays of length 1 for now and file a bug report to NVIDIA for not allowing 1-length arrays.

Dark Photon
05-19-2011, 05:55 AM
Try removing the const. NVidia drivers are pretty smart about seeing that things are const without you telling it and performing the appropriate optimizations. Not sure about ATI.

frigopie
05-19-2011, 07:33 AM
removing const doesnīt work, i have "solved" it making a 2 sized array when I need a 1 sized, it works in my program beacause of how it is made, but can be a bad solution for other programs, so I expect nvidia solve this issue...

Thanks for your help!

V-man
05-19-2011, 07:47 AM
Hi!

I have a little (big) problem initializing const arrays. On ATI cards only works this way:

const float vec[3]=vec[3](1.0,2.0,3.0); //Works :)

but in my Nvidia card this way only works with arrays bigger than 1 (stupid and strange, isīn it?), so:

const float vec[3]=vec[3](1.0,2.0,3.0); //It is fine
const float vec[1]=vec[1](1.0); //Fails! cast not allowed error


There is another C like way used in nvidia cg shaders that works on my nvidia card but not in on ATI, so it is unuseful.


Is there any standard way to init const arrays that works on all cards?

PD: I need const arrays with values known at compilation time, not uniforms, because of compiler optimizations

Thanks!


const float vec[3]=vec[3](1.0,2.0,3.0);???
What the [censored] is vec?
That should be
const float myarray[3]=float[3](1.0,2.0,3.0);

and
const float myotherarray[1]=float[1](1.0);