Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do GPUs support both OpenGL and DirectX API execution?

Im trying to understand how OpenGL and DirectX work with the graphic card.

If i write a program in OpenGL that do a triangle, and another one in DirectX that do the same thing, what exactly happen to the GPU side?

Does when we run the program, every call to the OpenGL library and every call to DirectX library will produce code for GPU, and the GPU's machine code produced from the two program will be the the same? (Like if the DirectX and OpenGL are like Java Bytecode, precompiled, then when its actually running, it produce the same thing)

Or does the GPU have 2 different instruction set, one for each. I mean, what is exaclty OpenGL and DirectX for the GPU, how can it do the difference between the 2 API?

Is this only different from programmer perspective?

like image 436
user1115057 Avatar asked Jun 06 '12 22:06

user1115057


People also ask

How does OpenGL work with GPU?

OpenGL accepts shaders written as text in the reasonably high level language GLSL, “OpenGL Shading Language”. The OpenGL graphics driver (the CPU portion of OpenGL) compiles the shader from GLSL source text to a binary shader program that can be run by the particular GPU that is installed in the computer.

Does OpenGL run on GPU?

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.

What do DirectX and its open source counterpart OpenGL do?

OpenGL is a functionally based API for the rendering of 2d and 3d graphics whereas DirectX includes that functionality which gives supported features for mouse, keyboard, joystick for input, and rendering of 2d, 3d graphics also.

What is API in GPU?

Introduction. The GPU Performance API (GPUPerfAPI, or GPA) is a powerful tool to help analyze the performance and execution characteristics of applications using the GPU. This API: • Supports DirectX10, DirectX11, and OpenGL on AMD Radeon™ 2000. series and newer graphics cards and APUs.


1 Answers

I already answered those here On Windows, how does OpenGL differ from DirectX?

full quote of one of the answers follows


This question is almost impossible to answer because OpenGL by itself is just a front end API, and as long as an implementations adheres to the specification and the outcome conforms to this it can be done any way you like.

The question may have been: How does an OpenGL driver work on the lowest level. Now this is again impossible to answer in general, as a driver is closely tied to some piece of hardware, which may again do things however the developer designed it.

So the question should have been: "How does it look on average behind the scenes of OpenGL and the graphics system?". Let's look at this from the bottom up:

  1. At the lowest level there's some graphics device. Nowadays these are GPUs which provide a set of registers controlling their operation (which registers exactly is device dependent) have some program memory for shaders, bulk memory for input data (vertices, textures, etc.) and an I/O channel to the rest of the system over which it recieves/sends data and command streams.

  2. The graphics driver keeps track of the GPUs state and all the resources application programs that make use of the GPU. Also it is responsible for conversion or any other processing the data sent by applications (convert textures into the pixelformat supported by the GPU, compile shaders in the machine code of the GPU). Furthermore it provides some abstract, driver dependent interface to application programs.

  3. Then there's the driver dependent OpenGL client library/driver. On Windows this gets loaded by proxy through opengl32.dll, on Unix systems this resides in two places:

    • X11 GLX module and driver dependent GLX driver
    • and /usr/lib/libGL.so may contain some driver dependent stuff for direct rendering

    On MacOS X this happens to be the "OpenGL Framework".

    It is this part that translates OpenGL calls how you do it into calls to the driver specific functions in the part of the driver described in (2).

  4. Finally the actual OpenGL API library, opengl32.dll in Windows, and on Unix /usr/lib/libGL.so; this mostly just passes down the commands to the OpenGL implementation proper.

How the actual communication happens can not be generalized:

In Unix the 3<->4 connection may happen either over Sockets (yes, it may, and does go over network if you want to) or through Shared Memory. In Windows the interface library and the driver client are both loaded into the process address space, so that's no so much communication but simple function calls and variable/pointer passing. In MacOS X this is similar to Windows, only that there's no separation between OpenGL interface and driver client (that's the reason why MacOS X is so slow to keep up with new OpenGL versions, it always requires a full operating system upgrade to deliver the new framework).

Communication betwen 3<->2 may go through ioctl, read/write, or through mapping some memory into process address space and configuring the MMU to trigger some driver code whenever changes to that memory are done. This is quite similar on any operating system since you always have to cross the kernel/userland boundary: Ultimately you go through some syscall.

Communication between system and GPU happen through the periphial bus and the access methods it defines, so PCI, AGP, PCI-E, etc, which work through Port-I/O, Memory Mapped I/O, DMA, IRQs.

like image 109
datenwolf Avatar answered Sep 19 '22 12:09

datenwolf