How does graphics work in protected mode?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

How does graphics work in protected mode?

Post by mrjbom »

Hello.

I use grub2 to boot, boot into graphics mode like this:

Code: Select all

multiboot_header:
    dd MULTIBOOT_MAGIC
    dd MULTIBOOT_FLAGS
    dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS)
    dd 0
    dd 0
    dd 0
    dd 0
    dd 0
    dd 0
    dd 800 ; width
    dd 600 ; height
    dd 32 ; bbp
Then using the resulting multibootinfo, I take the address of the video buffer and record the pixels.

I have such questions:
1. What's it? Is it VESA or SVGA or something else? What is the name of this mechanism?
2. What draws this graphic? Video card or processor?
3. How universal is this method? On what systems will it work and on what not?
4. I want to write a system of rendering 3D scenes, polygons, cubes. Something like OpenGL. Is this a good way to display graphics? Or should I choose something more powerful?

Thanks.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How does graphics work in protected mode?

Post by iansjack »

Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: How does graphics work in protected mode?

Post by Octocontrabass »

mrjbom wrote:1. What's it? Is it VESA or SVGA or something else? What is the name of this mechanism?
Linear frame buffer. GRUB uses the firmware to configure the LFB, so it might use VBE or UGA or GOP depending on what's available.
mrjbom wrote:2. What draws this graphic? Video card or processor?
The processor puts pixels into the buffer. The video card puts the buffer on the screen.
mrjbom wrote:3. How universal is this method? On what systems will it work and on what not?
GRUB can set up a LFB on pretty much any PC GRUB can run on. On very old computers, the LFB won't be very nice, but it will be linear and it will be a frame buffer.

On any PC from the past 20 years, GRUB will be able to set up at least 800x600 with at least 15 bits per pixel (though firmware limitations may prevent you from getting exactly the mode you request).
mrjbom wrote:4. I want to write a system of rendering 3D scenes, polygons, cubes. Something like OpenGL. Is this a good way to display graphics? Or should I choose something more powerful?
If you want to offload any of the 3D rendering work to the graphics card, you'll need to write a driver for it. Different graphics cards will require different drivers.
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

Re: How does graphics work in protected mode?

Post by mrjbom »

Octocontrabass wrote:
mrjbom wrote:4. I want to write a system of rendering 3D scenes, polygons, cubes. Something like OpenGL. Is this a good way to display graphics? Or should I choose something more powerful?
If you want to offload any of the 3D rendering work to the graphics card, you'll need to write a driver for it. Different graphics cards will require different drivers.
Thanks for the answers. About the fourth question. You said that me will need write driver for each video card, but I think you me not correctly understood. I suppose you thought I wanted to use the built-in OpenGL graphics card for this task, but it's not, I want to write everything from scratch and I'm wondering if there's enough performance for this. Since you said that the graphics card is engaged in rendering, it is obvious that it is enough. Right? I don't have to write a driver for each video card because I don't want to use the built-in OpenGL specification, right?
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How does graphics work in protected mode?

Post by iansjack »

If you want good performance you need the video card to do the work. This means that you need to write a driver for it - not a simple task.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: How does graphics work in protected mode?

Post by Octocontrabass »

If you don't want to offload any of the 3D rendering work to the graphics card, you don't need to write a driver for it.

Typical 3D rendering algorithms are much faster on a GPU than on the CPU. If you're only creating a new API on top of existing rendering algorithms, you will most likely see higher speeds once you write a graphics driver. On the other hand, if you're also coming up with new rendering algorithms, you might not be able to use a graphics driver to increase the speed.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: How does graphics work in protected mode?

Post by Korona »

OpenGL is a library-level interface. At runtime, OpenGL calls and shaders are translated to the register interface and ISA that your GPU understands (for the open source drivers in Linux, this translation layer sits inside Mesa; it uses vendor-specific ioctl()s in libdrm to communicate with the GPU). Those interfaces are GPU-specific (usually, even GPU model-specific) and require a driver for your GPU.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

Re: How does graphics work in protected mode?

Post by mrjbom »

Okay, I get it. I guess I'll have to work with the video card and make it vicelat.
But it is difficult to write a driver for each video card model. Can I use code from Mesa? How hard is it to embed it in my kernel?
Post Reply