9

How does a computer draw anything to the screen at the lowest level (nothing about external libraries like X11)? Are there supposed to be assembly commands that do this? How exactly does the CPU control what appears on the screen?

10
  • The cpu doesn't the gpu does. Commented Sep 17, 2011 at 19:57
  • 2
    @Ash: That assumes there's a dedicated GPU. Commented Sep 17, 2011 at 19:58
  • fgiesen.wordpress.com/category/graphics-pipeline/page/2 might be of interest. Commented Sep 17, 2011 at 20:01
  • 1
    @Ash Burlaczenko on-board graphics != GPU -- in any case, this question is about communication with the graphics, be it a direct FB or sending the low-level GPU commands. Commented Sep 17, 2011 at 20:05
  • 1
    @pst No, in the older days there was a CGA or an Hercules :-) See for example stackoverflow.com/questions/5096620/please-explain-this-c-code/… Commented Sep 17, 2011 at 20:06

3 Answers 3

11

Fundamentally the same way it reads from the harddrive, or plays a sound effect.

By writing certain data to specific memory addresses which are mapped by the memory controller to the external hardware in question (harddrive, GPU or sound card in these cases). When the hardware receives those writes, it interprets the data written as instructions about what to do.

The CPU is really kind of isolated from the rest of the system. All it really knows about is the memory bus. It can read and write data on that bus, and that's basically it. Some of these reads/writes go to memory, and others can be mapped to the control registers of various hardware, or to the device's memory if such exists, allowing the CPU to communicate with other devices.

A modern GPU has its own dedicated RAM, which it can load data into. So the CPU sends off instructions to the GPU, specifying where in main memory it can find the data used to generate the screen contents and what to do with it. Then the GPU loads that data from main memory into its own RAM, where it performs the necessary transformations and computations, before writing it into its frame buffer, which the monitor is constantly reading from.

Sign up to request clarification or add additional context in comments.

Comments

6

Typically there is an area of memory called frame buffer in your video card. Writing a value there means to establish the color value of a pixel.

You can consider a frame buffer like a 2D array, where each bit represent a pixel on the screen. To represent colors are used different levels of buffer. Today a common frame buffer has 24 levels (8 for each RGB color component) and allows the definition of 2^24 possible colors.

Nowadays generally the access to the frame buffer occurs through the GPU for performance reasons: even if it is possible for the CPU to perform this task, it is quite expensive.

Comments

3

There is a memory somewhere that is dedicated to the video screen. Each pixel on the screen has a certain amount of memory. Avoiding historical solutions like palettes and black and white, there is typically a certain number of bits for red, some bits for blue and some for green. When those colors are added you can get everything including white (I know they are not the primary colors used with paint for example, dont worry it works). Typically you will find 24 bit color because it is easy to manage 8 bits, a byte, of red, a byte of green and a byte of blue, and wire up memory, etc.

The video hardware is constantly reading this memory and using whatever technology to send signals to the monitor that essentially tell it the amount of red, green, and blue to light up for a particular pixel, constantly scanning the screen with up to date information.

A couple of common techniques for using this memory are to either use something called dual ported, where two entities are able to read/write the memory. Or to have two memories and swap them. In either case there is another entity, a processor, either the CPU itself, or these days many little graphics processors in the video card/chip. In either case some software runs and these compute the location and color of all the pixels and write them to video memory, depending on the mechanism used the video/monitor side of the memory takes the changes when it makes sense. you dont want to have only some of the pixels of the letters you are typing to show up on one pass across the screen then have the rest show up on the next pass, might get a flicker the user notices.

The video memory is typically mapped like system memory, the processor would likely use the same instructions it uses to access non-video, system, memory. Certainly the gpus might, but a cpu normally does not have peripheral specific instructions, uart, gpio, video, usb, storage, etc. The peripherals are usually mapped as certain addresses in the cpu's memory space and normal memory read/write instructions are used.

Because of the specialized types of algorithms, and more importantly the sheer number of computations needed for video games the video cards use many, many, specialized, simple, graphics processors, these might, yesterday, today, or tomorrow, have video memory specific instructions for performance or size or power or other reasons. What probably will not change is the model of having framebuffer memory, a memory that holds a screens worth of pixels that the video hardware uses to create the signals to send to the monitor so that it can draw the screen.

3 Comments

True for current systems I know of, but some older ones did not have backing frame buffers. :-)
Thats why I said "avoiding historical solutions", I tried hard to stay on point and not get into the myriad of ways that dont have some sort of frame buffers or even cases with no frame buffers. I think the key question was are there assembly instructions (rarely), if not then what (memory mapped like most things). Might be a fun community type question, what solutions other than frame buffers have been used to implement computer video/graphics.
I actually just ran across a current (in production) system that doesn't use a backing frame buffer. The Propeller based "Hydra"!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.