quangle

05-13-2011, 09:53 AM

hi,

I'm creating a kernel function to update the positions of vertices of an 3d object when a sphere collides and deforms the object. Basically, my function was:

/*

* center - position of the center of the sphere

* vList - list of vertices

* fList - list of faces of the object.

* Each face has 3 vertex indices vIndex1, vIndex2, vIndex3 refer to the list of vertices

* vNewList - list of new vertices to be readback

*/

__kernel void

update(Point3f force, Point3f center, float radius, __global Point3f * vList, __global Face * fList, __global Point3f * vNewList)

{

...

int nIndex = get_global_id(0);

...

// calculating the new positions for vertices of a face and store in p1 p2 p3

// and update the vertex list to vNewList

vNewList[fList[nIndex].vIndex1] = p1;

vNewList[fList[nIndex].vIndex2] = p2;

vNewList[fList[nIndex].vIndex3] = p3;

}

However, the vNewList array elements were all NaN. I tried to comment some lines in my code:

vNewList[fList[nIndex].vIndex1] = p1;

// vNewList[fList[nIndex].vIndex2] = p2;

// vNewList[fList[nIndex].vIndex3] = p3;

And I received some vertices having correct values and the others are all zeros. Then I tried to test my code by just accessing vIndex1 three times (I've tested with twice):

vNewList[fList[nIndex].vIndex1] = p1;

vNewList[fList[nIndex].vIndex1] = p2; // access vIndex1 only

vNewList[fList[nIndex].vIndex1] = p3; //

The result was the same with the first trial (all NaN).

I guess I've made some memory conflicts, but I don't know how to fix. Could you guys help me on this? Thank you very much!

I'm creating a kernel function to update the positions of vertices of an 3d object when a sphere collides and deforms the object. Basically, my function was:

/*

* center - position of the center of the sphere

* vList - list of vertices

* fList - list of faces of the object.

* Each face has 3 vertex indices vIndex1, vIndex2, vIndex3 refer to the list of vertices

* vNewList - list of new vertices to be readback

*/

__kernel void

update(Point3f force, Point3f center, float radius, __global Point3f * vList, __global Face * fList, __global Point3f * vNewList)

{

...

int nIndex = get_global_id(0);

...

// calculating the new positions for vertices of a face and store in p1 p2 p3

// and update the vertex list to vNewList

vNewList[fList[nIndex].vIndex1] = p1;

vNewList[fList[nIndex].vIndex2] = p2;

vNewList[fList[nIndex].vIndex3] = p3;

}

However, the vNewList array elements were all NaN. I tried to comment some lines in my code:

vNewList[fList[nIndex].vIndex1] = p1;

// vNewList[fList[nIndex].vIndex2] = p2;

// vNewList[fList[nIndex].vIndex3] = p3;

And I received some vertices having correct values and the others are all zeros. Then I tried to test my code by just accessing vIndex1 three times (I've tested with twice):

vNewList[fList[nIndex].vIndex1] = p1;

vNewList[fList[nIndex].vIndex1] = p2; // access vIndex1 only

vNewList[fList[nIndex].vIndex1] = p3; //

The result was the same with the first trial (all NaN).

I guess I've made some memory conflicts, but I don't know how to fix. Could you guys help me on this? Thank you very much!