Hi,
I try to play with float4, float8 etc.... in c++ so I use cl_float4 by example.
Here is the definition in the cl files.
typedef union
{
cl_float CL_ALIGNED(16) s[4];
#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ )
__extension__ struct{ cl_float x, y, z, w; };
__extension__ struct{ cl_float s0, s1, s2, s3; };
__extension__ struct{ cl_float2 lo, hi; };
#endif
#if defined( __CL_FLOAT2__)
__cl_float2 v2[2];
#endif
#if defined( __CL_FLOAT4__)
__cl_float4 v4;
#endif
}cl_float4;
What is strange is that I have to access the cl_float4 like this :
cl_float4 val;
val.s[0] = 1.f;
val.s[1] = 2.f;
val.s[2] = 3.f;
And I have no ".x" , ".y", ... under MSVC
Except form GNUC where there is the x,y,z,x and s0, s1, s2, s3 !
Why we don't have this for all platforms ?
Thx
question is if MSVC support that. try remove that #define __GNUC__ if MSVC it will compile.
Thanks Nou,
But why I don' t have this directly ? Will it be fixed in a next version of the SDK ?
Or it is better to use s[0]... to be portable ?
Thx
Also, there is no function and no operator for cl_float_4 etc... like we have in the kernels.
I can't do :
cl_float4 a, b;
a = b;
if (a == b)
c = a / b;
...
It will be useful
yes usefull but not possible. plain C don't support such operator over struct. in C++ you can overload operators so you get a desired functionality. it is a limitation of the language.
Thanks Nou,
Now I have problems to transfer some cl_float4 to the kernel.
Before I was using a struct like this { float x,y,z; } and have replace it with cl_float3;
In the kernel I have replace with "float3".
But the values I retreive in the kernel are wrong !!!!
Here are my structures, they are aligned (I think) !!! So, what can be the problem ?
KERNEL VERSION -------------- typedef struct { float x,y,z; } Vector3; typedef struct { float turbidity; float thetaSun, phiSun; float zenith_x, zenith_y, zenith_Y; float perez_x[5]; float perez_y[5]; float perez_Y[5]; Vector3 sunDirection; Vector3 sunXaxis; Vector3 sunYaxis; float3 sunSpectralRadiance; float sunSolidAngle; float sunCosThetaMax; float overcast; float atmosphereAttenuation; float g1[2]; // Align float8 riS0Spectrum; float8 riS1Spectrum; float8 riS2Spectrum; float8 X; float8 Y; float8 Z; float8 beta_p; float8 beta_m; float yint; float skyPowerFactor; float sunPowerFactor; int isSunRendered; float g2[4]; // Align } PhysicalSkyLight; C++ VERSION ----------- typedef struct { float x,y,z; } clVector3; typedef struct { float turbidity; float thetaSun, phiSun; float zenith_x, zenith_y, zenith_Y; float perez_x[5]; float perez_y[5]; float perez_Y[5]; clVector3 sunDirection; clVector3 sunXaxis; clVector3 sunYaxis; cl_float3 sunSpectralRadiance; float sunSolidAngle; float sunCosThetaMax; float overcast; float atmosphereAttenuation; float g1[2]; cl_float8 riS0Spectrum; cl_float8 riS1Spectrum; cl_float8 riS2Spectrum; cl_float8 X; cl_float8 Y; cl_float8 Z; cl_float8 beta_p; cl_float8 beta_m; float yint; float skyPowerFactor; float sunPowerFactor; int isSunRendered; float g2[4]; } CLPhysicalSkyLight;
In fact, I do this :
printf("%f\n", physical.sunSpectralRadiance.x);
and it display the value of physical.sunSpectralRadiance[2] !!!
NB: I work on a 64 bits machine CPU
didn't i write you how to check proper aligment of data types? check a starting offset of sunSpectralRadiance. in fact cl_float3 is just a retyped cl_float4 that mean it has 4*float aligment and size.
before sunSpectralRadiance you have 33 float values. that mean sunSpectralRadiance should start at 36*4 bytes offset. but i don't know if MSVC proper align cl_float* types at C++ side as a gcc does.
Right... I've forgot some alignment 😛
Sorry and thx