Graphics – How Does a Program Talk to a Graphics Card?

cpugraphics

I have heard that GPU's are better at performing certain tasks than a CPU. My question is, how does a program tell a graphics card to process something instead of the CPU? Does the program talk to the GPU directly? Or does the CPU determine what to give the graphics card? It seems like the benefits of processing with a GPU would be negated somewhat if the CPU had to tell the GPU each instruction to process.

Best Answer

My question is, how does a program tell a graphics card to process something instead of the CPU?

The short answer is that every graphics card must come with a driver implementing a standard graphics API such as OpenGL or DirectX, so that the code running on the CPU can call standard functions from that API. When writing your code, this is largely indistinguishable from coding against any other library.

However, a huge part of graphics programming involves passing special programs called "shaders" over to the graphics card, so they can be executed there. These are generally written in a different language specifically designed for shaders.

Does the program talk to the GPU directly? Or does the CPU determine what to give the graphics card?

"The program" is already running on the CPU (and any shaders it provided are running on the GPU) so I'm not sure what this is trying to ask.

It seems like the benefits of processing with a GPU would be negated somewhat if the CPU had to tell the GPU each instruction to process.

Indeed, this can happen. Moving data from the CPU to the GPU is a common bottleneck in graphically intensive programs. In fact, some features in more recent OpenGL versions are specifically designed to generate data on the GPU, so that you don't have to pass as much from the CPU.

Of course, whether the bottleneck is in the CPU, the GPU, or the communication between the two depends entirely on the individual program.

Related Topic