Nvidia flex data transfer

249 views Asked by At

So I'm trying to use the flex API by NVIDIA for my game engine(as a core gameplay mechanic) and I'm now arranging my data structures. I've already read the flex Manual, but the descriptions are rather sparsely. Because I'm also using CUDA, I need to know if the flex API calls like flexSetParticles etc. also accept device pointers as inputs. Also, it would be nice if someone could tell me, what exactly flexUpdateSolver does. Does it compute the velocities itself? Does it calculate gravity? If no, and you have to calculate the updated velocities yourself, what does the Solver even do?

At the moment, I calculate the new positions and velocities myself(without flex) like this:

void updateParticle(int i, float deltaTime)
{
    velocities[i] = types[i].getVelocity(deltaTime);
    //calculates the currently fixed velocity at a given time
    positions[i] = positions[i] + velocities[i];
}

All the arrays in the function above are device pointers and the function is actually a kernel. If I now have to calculate the velocities myself, I would have to

1.) update the arrays by adding new particles if necessary(from host to device) and calculate velocities(device)

2.) copy the new positions (and velocities) back to the CPU and hand them over to flex

3.) after flex has finished, copy the new positions from flexGetParticles back to the GPU (an OpenGL buffer for rendering)

This seems pretty inefficient, so I would like to know if there is an easier solution.

1

There are 1 answers

0
Amrollah On

Yes, the flexUpdateSolver will calculate the positions and velocities for the particles internally. So, you must not do that yourself. Remember that, you have to call NvFlexGetParticles(particleBuffer, n) to get the updated positions and velocities after each time step.

As for the flexSetParticles, it takes either a Host or Device buffer pointer. You can create the buffer using NvFlexAllocBuffer by passing the appropriate NvFlexBufferType enum.