copy struct, function vs direct, as_uchar4(float)
Hi there
I bumped in a lot of small problems, and I don't know why and how to evoid them:
1)
I have some structures:
typedef struct Material
{
uchar4 culoare;
char4 normala;
uchar2 reflexivitate;
uchar2 transparenta;
ushort luminozitate;
uchar densitate;
}__attribute__((aligned(16))) material;
typedef struct Voxel
{
uint fiu[8];
material m;
uchar padd1[5];
uint parinte;
uchar padd2[4];
}__attribute__((aligned(16))) voxel;
If I try to do :
voxel new_voxel=old_voxel;
some of the fields don't copy correctly (new_voxel.m.densitate differs from old_voxel.m.densitate)
Copying the fields one by one works.
So I decided to make a function CopyVoxel(voxel *dest, voxel source); which copies the fields one by one. Which curiously, it seamed to work (even thou source is sent by value...). Which leads to the second problem:
2) The copy function doesn't always work, sometimes it works and sometimes it doesn't and I have to copy the fields inside my code, which isn't very nice. Using 'inline' before the copy function doesn't work either (but I understand it is implicit so that's why it works ... sometimes).
3)I have another struct 'raza' which has a float member 'dim'. whenever I try to do as_uchar4(raza->dim), at runtime, the program crashes (llc.exe has stopped working). I have to do: cl_int temp=raza->dim*100; as_uchar4(temp); and /100 the rez to save some decimals. (doesn't seam to work with float directly either)
Any idea, the struct part is important, because I can't get it to work and I don't know which of them is the problem.
Mihai Zaharescu