cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Align union ?

Hi,

I'm facing a problem, I have the following structure :
typedef struct __attribute__((packed))
{
float Ks;
clSpectrum Cs;
float exponent;
} ShaderParam_plastic;
But when I add 2 variables like this :
typedef struct __attribute__((packed))
{
float Kd;
clSpectrum Cd;
float Ks;
clSpectrum Cs;
float exponent;
} ShaderParam_plastic;
I got a crash ! I have checked for the data I send and they are aligned correctly !
In fact I use this structure :
typedef struct __attribute__((packed))
{
unsigned int shaderId;
union __attribute__((packed))
{
ShaderParam_emitter emitter;
ShaderParam_glass glass;
ShaderParam_matte matte;
ShaderParam_mirror mirror;
ShaderParam_plastic plastic;
ShaderParam_Textured_emitter Textured_emitter;
ShaderParam_Textured_glass Textured_glass;
ShaderParam_Textured_matte Textured_matte;
ShaderParam_Textured_mirror Textured_mirror;
ShaderParam_transmissive transmissive;
} params;
} ShaderParameters;
Even my union is aligned !!! If the syntax is correct ?
If someone has an idea ?
Thanks


0 Likes
9 Replies
himanshu_gautam
Grandmaster

Align union ?

Can you please post your system configuration: CPU,GPU,SDK,DRIVER,OS.

Also posting a nice testcase which reproduces the crash would be helpful.

Please refer to section 6.10.1 of OpenCL Spec for confirming any syntax issues you might be having.

0 Likes
spectral
Adept II

Align union ?

Thanks Himanshu,

Yes, I have refer to section 6.10.1 already 😛 and finally what I understand is that I have to also add "__attribute__((packed))" to my union.

Does the syntax is correct ? I want a structure that is fully packed as a normal C++ structure !

But, unfortunately it does not work ! I have checked the alignment with and it sounds correct 😛

 

 

NB: Also, have you been able to debug the "software" I've sent you ? The one that crash with SDK 2.4 ?

0 Likes
spectral
Adept II

Align union ?

I work under Win7 64 bits, on a Intel CPU !

0 Likes
himanshu_gautam
Grandmaster

Align union ?

Please post some code to show the crash or data corruption.

 

0 Likes
Jawed
Adept II

Align union ?

Suggest you try "aligned", not "packed".

0 Likes
moritz14
Journeyman III

Align union ?

Maybe your computer is running on a 64-bit CPU. Mine is 32-bit 

0 Likes
spectral
Adept II

Align union ?

Yes, for now I use a 64 bits computer.

But alignment should be the same ?

0 Likes
spectral
Adept II

Align union ?

In the OpenCL spec. page 199, they wrote this :

"You may only specify this attribute on the definition of a enum, struct or

union, not on a typedef which does not also define the enumerated type,

structure or union."



 

Does it mean that I cannot pack a "typedef" ? or that I can write :

    typedef struct __attribute__((packed)) MyStruct {...};

But not ?

    typedef __attribute__((packed)) struct MyStruct {...};

NB: I have replace my typedef with a struct, but it still crash !!!

NB2 :  I cannot use "align" because my OpenCL code is generated at run-time. So, it is difficult to do and error prone 😛 (Also, my buffer is generated from a malloc, then filled at run-time with memcpy !!)

0 Likes
spectral
Adept II

Align union ?

Even with this version... I still got a crash !!!

struct __attribute__((packed)) ShaderParam_transmissive { float Ks __attribute__((packed)); clSpectrum Cs __attribute__((packed)); float eta __attribute__((packed)); }; struct __attribute__((packed)) ShaderParametersStruct { uint shaderId __attribute__((packed)); union __attribute__((packed)) { struct ShaderParam_emitter emitter; struct ShaderParam_glass glass; struct ShaderParam_matte matte; struct ShaderParam_matte_rough matte_rough; struct ShaderParam_mirror mirror; struct ShaderParam_plastic plastic; struct ShaderParam_Textured_emitter Textured_emitter; struct ShaderParam_Textured_glass Textured_glass; struct ShaderParam_Textured_matte Textured_matte; struct ShaderParam_Textured_mirror Textured_mirror; struct ShaderParam_transmissive transmissive; } __attribute__((packed)) params __attribute__((packed)); };

0 Likes