mihzaha

help aligning struct for sending array of structs to the GPU

Discussion created by mihzaha on Aug 24, 2010
Latest reply on Sep 2, 2010 by redditisgreat

Hi there

I have some structures, and I didn't understand how I should align them. 

On the CPU I have an array of structures (voxel *VoxelList) and I want to send it to the GPU, where I copy the elements into another array which is on the GPU (GPUVoxelList). Then I want to access from the kernel each element with GPUVoxelList.

 

here are the structures, organised as good as I could understand:

 

 

 

typedef struct __attribute__ ((aligned(16))) Raza  

{

cl_uint4 pozitie;    ->x

cl_float4 directie;  ->x + 16

cl_float dimensiune;  ->x + 32

cl_float fov; ->x + 36

cl_uchar4 mediu_parcurs; ->x + 40

cl_uchar4 mediu_curent; ->x + 44

cl_ushort2 pixel; ->x + 48

cl_ushort influenta; ->x + 52

cl_ushort luminozitate_curenta; ->x + 54

cl_uchar padd[8]; ->x + 56

}raza; ->x + 64




typedef struct Material

{

cl_uchar4 culoare; ->x

cl_char4 normala; ->x + 4

cl_uchar2 reflexivitate; ->x + 8

cl_uchar2 transparenta; ->x + 12

cl_ushort luminozitate; ->x + 16

cl_uchar densitate; ->x + 18

}material; ->x + 19




typedef struct __attribute__ ((aligned(16))) Voxel 

{

cl_uint fiu[8]; ->x

cl_uint parinte; ->x + 32

material m; ->x + 36

cl_uchar padd[9]; ->x + 55

}voxel; ->x + 64

 


I am only sending the raza and the voxel structs. The material struct doesn't have to be padded because I padd at the end of the voxel struct and it starts at 36, right?

 



Outcomes