スラストcudaでfloat4を使用しているときにメモリの問題が発生しました
float4 "buggyVariable"をファンクターのメンバーとして追加すると、floatデータが1floatだけ左にシフトするように見えます。
CUDA_animateParticlesで、Yを0に、Zを1に明確に設定しました
しかし、ファンクターを実行してOpenGLで描画する場合。Xposition = 1のパーティクルを取得します。これは、ファンクター内でYが1であることを示しています。
float2とfloat3でもテストしましたが、正常に動作しているようです。
したがって、メモリアライメントの問題またはバグのようです。
誰かがこれに光を当てることができますか?助けてくれてありがとう。
#include <thrust/sort.h>
#include <thrust/random.h>
#include <thrust/device_vector.h>
#include "cutil_math.h"
struct animateParticles_functor
{
float4 buggyVariable; //why does adding this variable cause following floats to get wrong values???
float pex, pey, pez, pew;
__host__ __device__
animateParticles_functor( float x, float y, float z, float w) :
pex(x), pey(y), pez(z), pew(w)
{
}
template <typename Tuple>
__host__ __device__
void operator()(Tuple t)
{
if(pey > 0)
thrust::get<0>(t) = make_float4(1, 0, 0, 0); //true if y is bugged
else
thrust::get<0>(t) = make_float4(0, 0, 0, 0); //false if its not bugged
return;
}
}
void CUDA_animateParticles(float4* cuda_devicePointer_vboPosition, float3* cuda_devicePointer_particleVelocitys, unsigned int numParticles, float4 particleEmitter)
{
thrust::device_ptr<float4> d_pos(cuda_devicePointer_vboPosition);
thrust::device_ptr<float3> d_vel(cuda_devicePointer_particleVelocitys);
thrust::for_each(
thrust::make_zip_iterator(thrust::make_tuple(d_pos, d_vel)),
thrust::make_zip_iterator(thrust::make_tuple(d_pos + numParticles, d_vel + numParticles)),
animateParticles_functor(0, 0, 1, 0) //notice that i set Z to 1 and not Y to 0
);
}