passing custom structure to opencl

Viewed 38

I have the following structures in host visual c++

#pragma pack (push,1)

struct AABB {
    float min[3];
    float max[3];
};
#pragma pack (push,1)
#pragma pop

struct VertexIn {
    float pos[3];
    float nor[3];
    float col[3];
};
#pragma pop

#pragma pack (push,1)

struct VertexOut {
    float pos[3];
    float nor[3];
    float col[3];
    float mpos[3];
};
#pragma pop

#pragma pack (push,1)

struct Triangle_ {
    VertexOut v[3];
    AABB box;
    bool isPoint;
    bool isLine;
    bool isValidGeom;
    float signedArea;
    float minDepth;
};
#pragma pop

and In OpenCL Kernel:

struct AABB {
    float min[3];
    float max[3];
}__attribute__((packed));

struct  VertexIn {
    float pos[3];
    float nor[3];
    float col[3];
}__attribute__((packed));

struct  VertexOut {
    float pos[3];
    float nor[3];
    float col[3];
    float mpos[3];
}__attribute__((packed));
struct Triangle_ {
    struct VertexOut v[3];
    struct  AABB box;
    bool isPoint;
    bool isLine;
    bool isValidGeom;
    float signedArea;
    float minDepth;
}__attribute__((packed));

This is how do I allocate the buffer and setting the kernel argument:

std::vector<Triangle_> triangles;

    err = clEnqueueWriteBuffer(queue, triangle_buf_mem, CL_TRUE, 0, triangles.size() * sizeof(Triangle_), &triangles[0], 0, NULL, NULL);

err = clSetKernelArg(kernel_sendImageToPBO, 1, sizeof(cl_mem), &triangle_buf_mem);
if (err < 0) {
    printf("Couldn't set a kernel argument vbo_mem");
    exit(1);
};

Kernel prototype:

__kernel void sendImageToPBO(__global uchar4* dst_buffer,  __global struct Triangle_ *triangles, int triCount)

Now the problem is I get all the elements of the structure with empty values. However I initialized the vector of Triangle_ correctly.

EDIT: The size of structure in Host and Device is the same 180 bytes.

0 Answers
Related