r/GraphicsProgramming • • Dec 20 '21

Question x64 instructions for GPU stuff?

I am thinking about creating an OS, just for myself, but I wanna do 3D games on it. Can I just write my own driver for one specific GPU (nevermind the logistics, this is a hobby project. I just want to know if it is POSSIBLE), and how would I do that?

3 Upvotes

29 comments sorted by

View all comments

13

u/Mason-B Dec 20 '21

Is it possible? Yes, in theory... with infinite time and resources. Is it likely or easy? Absolutely not. Even now the two major GPU suppliers (NVidia and AMD) require loading of proprietary microcode to perform 3d acceleration and function correctly. There are people who try to reverse engineer this stuff from scratch, and I think they've made some progress. But the reality is that it's very very hard to reverse engineer a chipset and assembly from scratch. I say this as someone who shoots the shit with multiple people who reverse engineer stuff for a day job. Even they have a starting point, a manual or documented prior art. For most parts of what you would want to do, that would not exist.

And to be clear, the GPU is a separate chipset, with it's own instruction set, hence "x64 instructions for GPU stuff" is a nonsensical statement, as x64 describes the CPU chipset.

1

u/TheNextJohnCarmack Dec 20 '21

Well when I said "x64 instructions for GPU stuff" I meant x64 instructions for sending stuff on the bus to the GPU. Do you have any idea where would be a good place to start? Scale is irrelevant, this is sort of a magnum opus project I fully expect to die before I properly complete.

1

u/the_Demongod Dec 20 '21

The problem is that, to my knowledge, the graphics driver doesn't expose any bare metal API that you can use directly. The driver implements OpenGL, Vulkan, DirectX, etc. and you use that. It looks like you can get closer to Nvidia GPUs with NVAPI but this is still fairly abstract and as it mentions on the page, half the interesting features require you to sign an NDA. Based on that I'm going to go ahead and say that it's effectively impossible to do any direct communication with a modern GPU. As the other guys said, you'd be better off mucking around in OS dev or some other thing that will scratch this itch. GPUs are way too complicated to reasonably reverse engineer yourself. If you want to do something fun, I would suggest building your own GPU in an FPGA or in a hardware simulator and writing your own graphics driver.

0

u/TheNextJohnCarmack Dec 20 '21

I just don't understand how this is possible. This sounds like a hacker (FOSS enthusiast)'s nightmare if it is true. How is it possible that vendors have made a completely impenetrable software lock on their entire GPU? Surely there must be code that a CPU executes that somehow results in a response in the GPU directly? I mean, how else is it possible for the CPU and GPU to interact?

I am not strictly talking about human-readable APIs either. I'm talking any software that allows direct communication between CPU and GPU at a sub-operating system level. I am willing to painstakingly integrate pure binary into my OS from drivers.

3

u/the_Demongod Dec 20 '21

Obviously nothing is completely impenetrable, I'm sure Nvidia and AMD have teams of experts trying to reverse engineer each others' ISAs. It's just probably outside the capabilities of one person. Modern hardware is definitely a FOSS enthusiast's worst nightmare, it's absurdly complicated and the fine details of the architecture represent the company's entire value on the market. That's why if you work in e.g. an Intel fab, it's incredibly silo'd and you're not allowed to know anything beyond the immediate knowledge required to do your job. In principle you can sniff the packets being sent to the GPU, but I don't see how you could manage to make the GPU do anything useful with the information you'd be able to glean from that.

I don't know why you'd want to do this anyways, if you want to learn more about GPUs you should just build your own. I don't imagine you'd be able to eke any real capability out of a full-size GPU from the information you'd garner by sniffing binary on the PCIe bus, so by building your own you'd learn a whole lot more and wouldn't be sacrificing much hardware capability since you're not going to be able to make a real GPU do anything interesting this way anyways.

-9

u/TheNextJohnCarmack Dec 20 '21

That sucks. Fuck AMD and fuck NVIDIA, and most of all fuck their hardware. And fuck their software too. Sounds like it'll be easier to develop an entire computer entirely from scratch than to develop just a fucking driver.

Well anyway, thanks for the help. I appreciate it.

3

u/IQueryVisiC Dec 20 '21

There are FOSS drivers for Linux. AMD always opened their spec and NVIDIA has been reverse engineered at least the old models in my old notebooks which cannot run the new Windows.

At least Vulkan should be possible. I still believe that the drivers mostly cater to some games and guess what they want. With Vulkan you are much closer to the metal.

May I invite you to write an OS for r/AtariJaguar . They are completely open about the Spec. No NDA like on Japanese stuff. Also Intel integrated graphics is completely open I think. And it is quite good in its later iterations.