Can you make your own rendering pipeline?

Viewed 1479

I want to write a renderer, but do i really have to use the OpenGL pipeline, cant i make my own? Is there a way i can write all the code for the GPU and CPU, from memory management to rasterization, or do i have to use the already provided pipeline? If i cant do it in OpenGL where can i? Can i get some directions? In what language do i write the GPU code and how do i use it on the GPU?

2 Answers

Consumer-grade GPUs as they currently standard are not CPUs. You don't "program" a graphics pipeline. The graphics pipeline is what it is because that's how GPUs are designed to work. Obviously, different specific GPUs will have different implementations, but basic elements of the rendering pipeline are all fundamental parts of the hardware. The parts of the pipeline which are programmable are only programmable to the extent the GPU allows it and for the purpose for which that stage is intended (with some flexibility).

Future GPUs may be more flexible, and there are even some alternative pipelines for vertex processing in certain modern GPUs. But we're not at the point yet where you can just make things up as you like. GPUs are designed for efficiency; their limitations are there to help things stay on an efficient path.

Memory management is an entirely separate issue. Vulkan and similar command-buffer APIs allow much more low-level memory management functionality compared to immediate APIs like OpenGL. However, it should be well understood that command buffer APIs are not for hobby programmers. These APIs are not friendly in the slightest; they require you to be keenly aware of many details that immediate APIs hide from you, and they will not tell you when you break their rules.

You could write a library that makes calls directly to the graphics drivers, or you could write a custom pipeline that runs on the cpu, which would functionally be an emulator for dedicated graphics hardware, but it would be complex, unreliable, slow, and would likely cost you a lot of time to implement, with very little return on investment.

As has been mentioned in comments, GPU's work the way they do, because they were designed on a hardware level to do it that way. The OpenGL/DirectX/Vulkan api's just allow you to have more, or less control over that pipeline, and to plug custom shader stages in.

The reason you cannot write your own rasterizer, is because it is a stage in the pipeline, in which is is pretty much as efficient as it can be. Your version is unlikely to be better.

Don't concern yourself too much with the non-programmable parts of the pipeline. That is the purview of hardware engineers and driver programmers.

If you want lots of control over the existing hardware, try DX12 or Vulkan/Metal. They're about as close as you can get to the hardware as a programmer, without writing custom drivers.

Related