3
\$\begingroup\$

Is it considered standard to push all the vertices and an interpolation of the next position onto the GPU?

Suppose a sector is moving up every game tick at 50 units per second. You could put on the shader something like (good old parametric equation-like formulas):

pos.x = a*x1 + (1 - a)*x0;

Where you'd calculate a as a uniform and only send this value to the GPU in an uncapped fashion, like so:

while (true) {
    a = percentage of the way between frames [in range from 0.0 to 1.0]
    updateGLUniform(..., a);
    render();

    // Rest of stuff

    delay();
}

The other way of doing it was to manually set each entity and sector every single time you loop, but then you might have to update the position of a lot of things every game cycle. Just setting one value seems way more efficient.

However, I don't know if there's any downsides to this. Are there any negatives to shoving interpolation off to the GPU to save computation time in the game? Or is there something that I'm missing? What do major games do?

\$\endgroup\$
3
\$\begingroup\$

As written, your formula for pos.x always returns x no matter what value a takes:

pos.x = a*x + (1 - a)*x;

To get meaningful interpolation, we need to tell the GPU two positions to interpolate between,x0 and x1, yielding:

pos.x = a*x1 + (1-a)*x0;

So now that's three variables we need to tell the GPU about, instead of just one position for this frame.

So if our x0 and x1 change frequently (as is the case for many types of motion we want to represent in games - think dynamic physics, nonlinear animations, anything with player input or AI), then we haven't really saved ourselves any bandwidth this way. In some cases, doing the interpolation GPU-side might require sending double the transformation data compared to computing a single set of interpolated transforms CPU-side.

This transform data also tends to be fairly sparse - one matrix per dynamic object - so compared to the massive workloads GPUs handle projecting, rasterizing, and shading every pixel of the scene, interpolating movement on the CPU is usually not a major bottleneck.

That's not to say there aren't many cases where interpolating a value on the GPU makes sense - there are indeed many. It's just not quite as universal a solution for all movement as it might appear at first.

\$\endgroup\$
  • \$\begingroup\$ Good catch, I forgot the subscripts (d'oh). You brought up a really good point about sending double the vertex data. \$\endgroup\$ – Water Apr 30 '17 at 3:57
2
\$\begingroup\$

This is a trade off.

With interpolation on the CPU you get to use a smaller vertex format, but you must dynamically update your vertex buffers from system memory to GPU memory every time.

With interpolation on the GPU you have a fatter vertex format but your vertex buffers can remain static.

In general the latter will be the more performant option. The amount of data transferred from system memory to GPU memory is unlikely to be an arbiter of performance, but on the other hand being able to avoid CPU/GPU synchronization is very important; particularly with APIs like older versions of OpenGL which are especially prone to synchronization.

As always, this is simple enough to code up both options and benchmark with your own workload and data.

\$\endgroup\$
  • \$\begingroup\$ I'm not sure how you benchmark the GPU though? I've tried looking for tools to do so and I haven't been able to find them, the only stuff I could find was how to profile the graphics card, but not code. If you know of a way to do this or have any resources it would be a great help because I could actually profile stuff and do some simple tests to see what works and doesn't. \$\endgroup\$ – Water May 1 '17 at 3:00
  • \$\begingroup\$ @Water - you'll get a better response if you ask that as a separate question; multiple people (including game dev pros) who have real experience with this kind of work will be able to see it. Just be careful to not phrase it as a "what tools should I use" question. I'd also encourage using the search facility on this site (before asking) to see what questions about GPU profiling have been asked before, and if they answer your question. \$\endgroup\$ – Maximus Minimus May 2 '17 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.