Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a graphics driver programmatically communicate from CPU to GPU?

Tags:

c++

c

assembly

cpu

gpu

I have wondered for quite some time how CPU instructions can interact with the GPU. As I understand things, the CPU has a certain set of instructions (machine code) that it understands and performs and a driver is a piece of software that communicates via the CPU to the GPU.

But how does this piece of software communicate? Does the CPU contain certain assembly instructions that explicitly tells it to communicate to another device?

Can I write assembly code or C/C++ code to communicate to the Graphics Card just like the driver does given one specific machine enviroment?

like image 769
vlind Avatar asked Jun 02 '16 09:06

vlind


1 Answers

Like any hardware device on a PC the graphics card will respond to reads and writes to certain memory addresses, and possibly input/output ports. The PCI bus defines how these are allocated.

There are no specific CPU instructions to communicate with graphics cards, in the case of writing to memory locations it just uses the ordinary instructions to do that and in the case of port IO it just uses the generic instructions to do that. In both cases there will be some CPU setup needed to "map" the memory locations into virtual address space or to allow access to the ports.

A write to memory location 1234567 could be directed to the graphics card to indicate a command to it for example. (That's just a made up example of course) You certainly could write your own driver that did just that, however you'd have to know exactly what the card expected in order to different things, and that generally is a secret only known to the manufacturer and they implement it in their driver software. Some cards are better documented than others, and some have been partially reverse engineered.

like image 179
jcoder Avatar answered Nov 15 '22 21:11

jcoder