cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

eklund_n
Journeyman III

Vector type, variable component choice

Hi.

Is there a way to dynamically chose which vector component to use? ie. code alternative 1 vs. alternative 2.

I have a function that does swizzling on a char4 depending on a value. I calculate the different components to use (i.xyzw) and would like to write something like the //swizzling part.

uint i, j; uint2 m; //alternative 1 if (i==0) j = m.s0; else j = m.s1; //alternative 2 j = m.s; or j = m; uchar4 obj; uint4 i; //swizzle obj = obj.s[i.x][i.y][i.z][i.w]; or obj = (uchar4)(obj[i.x],obj[i.y],obj[i.z],obj[i.w]);

0 Likes
2 Replies
LeeHowes
Staff

A vector is explicitly not an array. It's an opaque containter, that's a very important design decision. Any approach that would allow you to do what you want would have to compile on most hardware to either accesses in a memory buffer or exactly what you would do as a work around. I'd be prone to say it should stay as a workaround in code rather than pretending it's a more efficient operation than it really is.

0 Likes

You can use the shuffle function which is provided by OpenCL to do this for you. Dynamic indexing into a vector is not allowed because a vector is a single unit and not an array.
0 Likes