adrian
adrian

Reputation: 1457

How to pass an array of structs to kernel with JOCL

I'm writing an OpenCL raytracer using JOCL (OpenCL bindings for Java). I want to pass an array of structs to my kernel. The struct looks like this:

struct Sphere {
    float3 center;
    float radius;
    int materialIndex;
};

and the kernel takes it as this:

__kernel void raytraceKernel(
    __constant struct Sphere *spheres,
    etc...

What is the best way to do this? Initially, the struct did not have the materialIndex field, so I simply created an array of floats in Java, populated it with center, radius, and padding, and sent it to the kernel. However, when I added materialIndex I decided to convert my program to use NIO buffers, which didn't work (data was corrupted).

Is there a better approach to passing an array of structs to a kernel with JOCL?

Upvotes: 2

Views: 211

Answers (0)

Related Questions