0
\$\begingroup\$

Say I want to come up with a way to replace what OpenGL and DirectX specifications do: communicate with GPU to get some functions done that help hardware-acceleration and rapid drawing of screen data. Is it possible to write some mock-up copy that can communicate with the GPU the same way that, say, an OpenGL specification could or DX to drive the same functions (or similar ones)?

What I'm saying is, somebody somehow made a way to communicate with a device driver to get acceleration and faster graphics, 3-D functions, etc. Is it possible one can create the same "inbetween" library or software that can do pretty much the same thing -- interact with the device driver and drive OpenGL/DX similar operations or some other specification, but using my own self-written procedures to do so?

In other words, is it possible to replace OpenGL/DX code that communicates with a graphics driver with your own code that does the same thing, but is instead written by you?

I'm not asking about writing a device driver, but writing something that communicates with it, such as how DX/OpenGL does. OpenGL is 100% open-source and you can see how every single function/operation/line of code works when you link with it and use a debugger, etc.

We know OpenGL usually doesn't directly interact with a GPU most of the time, and although it does sometimes, the identic function can easily be replaced by debugging.

\$\endgroup\$
  • 3
    \$\begingroup\$ I'm not sure what you really get what OpenGL (DirectX) is. OpenGL is just an API specification. It is implemented by a device driver. So basically to get that you want you need a device driver. \$\endgroup\$ – Petr Abdulin Oct 18 '14 at 19:41
  • 4
    \$\begingroup\$ Your question is missing one important piece of information: Why would you want to do this? Not because people are curious, but because that will change the tone of the answers. \$\endgroup\$ – RecursiveCall Oct 18 '14 at 20:05
  • \$\begingroup\$ What you are looking for is a way to more closely control what you are doing with the GPU. My answer is to wait for D3D12 and OpenGL Next ;) \$\endgroup\$ – jmegaffin Oct 19 '14 at 8:20
9
\$\begingroup\$

You have some fundamental misunderstandings.

What I'm saying is, somebody somehow made a way to communicate with a device driver to get acceleration and faster graphics, 3-D functions, etc.

This is incorrect; it is the driver that provides access to the acceleration hardware (the GPU). It isn't OpenGL or D3D itself, which are simply API specifications (with corresponding implementations). GPU vendors, such as Nvidia, will provide drivers that implement OpenGL/D3D in a fashion that communicates to their hardware via the driver (typically there is both a kernel mode driver and a user-mode DLL involved in this implementation).

OpenGL is 100% open-source and you can see how every single function/operation/line of code works when you link with it and use a debugger, etc.

OpenGL is not open-source at all. There is no "source" to OpenGL, it's just a specification. Individual implementations may or may not be open-source (most, such as those offered by Microsoft, Apple, AMD, et cetera, are not); Mesa is a common open-source OpenGL implementation.

You can see how any function of any library, open or closed, works in the debugger - debuggers often have the ability to disassembly machine language even if there's no mapping back to higher-level source available.


So, as for your actual question, yes, it's possible to write something that communicates with the device driver for a GPU. This is how Mesa works; it runs against a handful of drivers. If you knew the exposed endpoints of other drivers you could write user-mode DLLs to communicate with them.

This is generally a waste of time though, and will not get you to your stated goal because it's the driver that actually "helps with the hardware acceleration," and it's the driver you say you don't want to write (correctly so, because it's a huge amount of work requiring extensive knowledge of the details of individual hardware that is not easily accessible).

\$\endgroup\$
-1
\$\begingroup\$

Theoretically yes, it is possible. People here love to dislike similar questions, but such project can be a nice practice in graphics programming, getting you from zero to an expert in the field, if you won't abandon it half way.

Although industry already began standardizing and exposing bare metal features, under say Vulkan API. But such work could help making emulators for older GPUs, so it would have more value than say reverse engineering some older video game to make it run on modern hardware.

  1. You will have to reverse engineer existing driver, or convince GPU producing company to share their source code with you.
  2. Design your own graphics API with its own rationale.
  3. Have enough patience to undertake the project.
  4. Publish the findings.

That is in principle all that is required. Although I would suggest finding some debug version of a driver, which retains symbol table. People are lazy and sometimes leave such stuff inside the release product. Symbol names and source file lines greatly simplify reverse engineering.

So yeah, do it, if you want to improve your skills and to understand how it all works.

\$\endgroup\$
  • 1
    \$\begingroup\$ You seem to be describing making a custom driver that works with the new API, which OP has said they do not want to do. \$\endgroup\$ – DMGregory Aug 11 at 15:33
  • \$\begingroup\$ AFAIK, OpenGL/DirectX internal implementations are part of a driver or at least heavily spliced together, so OP will have to deal with the driver, which in itself has no API at all, not speaking about stable API (that is why Vulkan was introduced). I.e. OP will have to reverse the driver. \$\endgroup\$ – SmugLispWeenie Aug 11 at 15:53
  • \$\begingroup\$ That's effectively what Josh's answer from five years ago explains: that OpenGL/DirectX APIs aren't libraries that run between the game and the driver, they're specifications implemented by the driver, so OP's idea of making a new API without making a new driver is based in a misunderstanding of what graphics APIs are. \$\endgroup\$ – DMGregory Aug 11 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.