AnsweredAssumed Answered

Weird values when passing an array of structs as an openCL kernel argument

Question asked by theblang on Apr 16, 2012
Latest reply on Apr 16, 2012 by pesh

When passing an array of structs to my kernel as an argument, I get weird values for the items after the first (array[1], array[2], etc).  It seems to be an alignment issue maybe?

 

 

Here is the struct:

 

 

    typedef struct Sphere

    {

              float3 color;

              float3 position;

              float3 reflectivity;

              float radius;

              int phong;

              bool isReflective;

    } Sphere;

 

 

What happens is that the color for the second Sphere struct in the array will actually have the last value of what I set color to on the host side (s3 or z), a non initialized zero value, and the first value of what I set position to on the host side (s0 or x).  I noticed that the float3 datatype actually still has a fourth value (s3) that does not get initialized.  I think that is where the non initialized zero value is coming from.  So it seems that it is an alignment issue.  I really am at a loss as to what I could do to fix it.  I was hoping maybe someone could shed some light on this problem.  I have ensured that my struct definitions are exactly the same on both sides.

Outcomes