Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphics driver "hello world" example? [closed]

What are the steps necessary to create a GPU driver that render pixels on a display? Basically just the simplest "hello world" example of creating a GPU driver, such as turning the screen red or just showing a single pixel. Where do you start?

I would like to hack on the GPU directly, without any C or OpenGL abstraction or any of that. I am using Mac OSX, and I think I have the Intel HD i7 graphics card, so these docs seemed like a good fit:

  • Volume 1 Part 1: Graphics Core
  • Volume 1 Part 2: Graphics Core – MMIO, Media Registers & Programming Environment
  • Volume 1 Part 3: Graphics Core – Memory Interface and Commands Render Engine
  • Volume 1 Part 4: Graphics Core – Video Codec Engine
  • Volume 1 Part 5: Graphics Core – Blitter Engine
  • Volume 2 Part 1: 3D/Media – 3D Pipeline
  • Volume 2 Part 2: 3D/Media – Media
  • Volume 3 Part 1: Display Registers – VGA Registers
  • Volume 3 Part 2: Display Registers – CPU Registers
  • Volume 3 Part 3: PCH Display Registers
  • Volume 4 Part 1: Subsystem and Cores – Shared Functions
  • Volume 4 Part 2: Subsystem and Cores – Message Gateway, URB, Video Motion, and IS

The Mesa3D project says that there are a number of open source graphics drivers, and Wikipedia says that Intel produces these docs so that you can write an open source driver if you want, but don't explain how.

I also came across Michael Abrash's Graphics Programming Black Book, which explains a lot.

However that is a bit much to bite off all at once. And there doesn't seem to be any information on how to get started hacking on a GPU driver, a "hello world" project.

For example:

  • To learn assembly, you can just brew install nasm, write some assembly, compile, and run it to print "hello world".
  • To learn Arduino, you can plug in an Arduino board into your computer via a USB cable, install their software, and upload some C code directly to the board and run it, to show a blinking LED light.

How do you do that same sort of thing for the graphics card?

The hello world example doesn't necessarily have to work (though that would be cool if it did!); even just outlining what it would take in a higher-level/practical sense would be helpful. If it's not possible on a Mac, or even on Linux, that would be good to know. But even then the question remains, where do you start in writing a graphics driver?

like image 732
Lance Avatar asked Jan 07 '15 03:01

Lance


People also ask

What are common graphics driver problems?

The Nvidia “Warning: Known issues with graphics driver” error message means that the currently installed GPU driver version (XXX. XX) is known to cause problems with the application that is being booted.

What is a graphic card driver?

A graphics driver is the software that allow your operating system and programs to use your computer's graphics hardware. If you play PC games, you should keep your computer's graphics drivers updated to get the best performance out of your hardware.


Video Answer


1 Answers

  • Step 1: Understand the particular GPU you are targetting (Architecture, register and stream details). I am afraid for many of the GPUs these details may be proprietary and you may not get it. (But as you mentioned, in your case specs are available)
  • Step 2: Add some calls in your driver that are able to query registers / details from the driver.
  • Step 3: Add some calls in your driver to modify registers. (Change mode etc)
  • Step 4: You can check how to draw a triangle / quad on your GPU with a constant color. Try to implement screen clear (functionality similar to glClear) by drawing a big quad or 2 triangles or 1 triangle of dimension double of the screen or sending some clear command. (whichever method is supported by the GPU) If you are drawing a triangle or quad, use NDC (normalized device coordinate) system and prefer to work in Raw windowing system or NWS (Null windowing system). Windowing system is responsible for displaying your output framebuffer after compositing or some post processing. By Raw or NWS, I mean display the framebuffer directly to screen.
  • Step 5 (most of the things are optional): Implement some complex drawing. This may involve support of other drawing modes like pixel, line, triangular strip, triangular fan etc and support of texture, lighting, transformation, interaction with other windowing system. For this step you will need to learn assembly. But do notice, this is not x86 or arm (CPU) assembly, rather it is GPU assembly which is specialized in handling SIMD.
  • Step 6: Implement stencil functionality. Prepare a stencil of hello world in your program. Clear the screen with color 1. Apply the stencil and clear the screen again with color 2. Now you have hello world written in color 2 with color 1 as background.

Mottivation to do this all is: You want to do this. And this will be cool.

Demotivation to do this is: Possible unavailability of GPU specifications, learning curve for GPU assembly, complexity of graphics.

My Recommendation: If GPU specs (along with assembly) is available to you, I would suggest implement subset of any available API set (open vg and open GLES 1.1) for example. To read more about these API set, please visit khronos website.

like image 60
Mohit Jain Avatar answered Oct 23 '22 00:10

Mohit Jain