r/computerscience • u/Neat_Shopping_2662 • Jun 15 '25
Graphics cards confuse the hell out of me :(
I've been getting into computer science as of late and i've pretty much understand how cpus work, i even built a funnctioning one in minecraft, just as a test. but anyways my problem is that I can't find an in depth description of how a gpu works. I can only get surface level information like how they perform simple arithmetic on large amounts of data at once. thats useful info and all but i want to know how it renders 3d shapes? I understand how one might go about rendering shapes with a cpu, just by procederally drawing line betweens specified points, but how do gpus do it without the more complex instructions? also what instructions does a gpu even use? Everything i find just mentions how they manipulate images, not how they actually generate them. I dont expect a fully explaination of exactly how they work since i think that would be a lot to put in a reddit comment but can someone point out some resource i could use? preferably a video since reading sucks?
PS Ive already watched all the Branch education videos and it didnt really help since it didnt really go through the actual step by step process gpus use to draw shapes. i want to know what kind of data is fed into the gpu,, what exactly is done with it, and what it outputs?
26
u/Somniferus Jun 15 '25
I googled "how do graphics cards work" and found these slides which provide a nice overview. Let me know if you still have questions.
https://www.cs.cmu.edu/afs/cs/academic/class/15462-f11/www/lec_slides/lec19.pdf
7
u/dumdub Jun 15 '25
25 YOE graphics engineer here. Learn how to draw 3d graphics with a CPU. Then you'll be in a good position to learn how gpus do it faster. Starting with gpus is going to be very very difficult. They used to be non-programmable asic chips that embodied the graphics algorithms in physical hardware. Then they became programmable, but actually the programmable bit still sits inside a massive piece of fixed function asic transistor logic.
6
u/AutonomousOrganism Jun 15 '25
Rasterization is the trivial part. In GPUs it's done by fixed function hardware. Typically it will be a variant of half-space rasterization, as it is very simple to implement.
Here a paper if you are interested in the details: https://www.montis.pmf.ac.me/allissues/47/Mathematica-Montisnigri-47-13.pdf
2
u/Neat_Shopping_2662 Jun 15 '25
Thanks everyone for the comments! I’ll have a lot to look into. I think where Im probably thinking about this wrong is in the abstraction. It’s a similar problem I ran into when learning about CPU’s. I guess no one really goes into the specifics of how a cpu or gpu works because, there are technically not any one way it has to work(and specific design are kinda trade secrets), and they are all abstracted anyways in code. I’ve noticed a lot in computing that the answer to how computers work is kinda just, if you can make a design that works then you made a computer correctly. I’ll try not to get bogged down in the nitty gritty stuff from now on since differing designs exist anyways.
2
u/treeman857 Jun 16 '25
If you don't mind me asking, where did you learn how CPUs work? I've been trying to understand the course material my college provided but everything is so scattered I can't see how all of it is orchestrated at once.
29
u/ArtOfBBQ Jun 15 '25
You may be confusing abstractions with what chips actually do - chips do things like adding, subtracting, multiplying, etc., up to something as complex as a square root. (This is an oversimplification because there are some more complex instructions now, but it was true 25ish years ago)
GPU's appear to be doing much more complex things (because everything is hidden in a company secret black box), but really they are essentially doing the same basic operations with 2 differences:
All of the manufacturers are trying to construct a walled garden and protect their IPs in walled gardens, it's evolved in the opposite direction of CPU's where pretty much everything is open and understood. This is also why there are constantly new indie programming languages to control your CPU, but never for the GPU
36
u/Silly_Guidance_8871 Jun 15 '25
Honestly, at this point they basically work the same way as CPUs, with one caveat: Everything computation instruction is SIMD; there are no scalar computation instructions. If you need a scalar operation, you use a SIMD instruction, then mask off whatever you don't need.
3
u/Cheap_Ad_9846 Jun 15 '25
hi ; read realtime rendering
2
u/paperic Jun 15 '25
Think of it as a lot of CPUs working in parallel, but sharing a control unit. They each have their own registers and ALU, but the decoding and execution of instructions happens somewhere else.
So, the same instruction is always executed on many "CPUs" at the same time, and they all do the same thing.
But they each also have an access to the "cpu number", which is 0 in the first CPU, 1 in the second, 2 in the third, etc.
So, they can use this number to calculate an offset in memory reads and writes, so each of these "cpus" then does the operations on different memory address. That way, you can do massively parallel computation, which speeds up all the repetitive trigonometry during rendering.
2
u/monocasa Jun 16 '25
This is probably the best doc from a "I know how a CPU works, but gpus still seem mysterious" perspective.
Almost 15 years (jeeze, I remember reading it as it came out), but still broadly applicable.
https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/
4
u/jak0b345 Jun 15 '25
Basically, a instead of having a single (or 16 or whatever) powerful central processing units (CPUs) that can do all kinds of things, GPUs contain hundreds or thousands of less powerful processing units. Each of those can do a lot less different kinds of operations, but since there are so many of them you get a really nice speedup in tasks that can be parallelized well, e.g., calculate how to draw and color 10 milion triangles
1
u/turtleXD Jun 15 '25
If you want to get real deep into how GPUs work, look into CUDA
1
u/ButchDeanCA Jun 15 '25
There is a lot you are asking for knowledge about here that seems to revolve around rasterization. Rasterization (taking the final data and transforms on that data to color “fragments” (loosely known as “pixels” but they are not the same thing) is the process of presenting the data to the frame buffer to display.
The reason why all this is not done on the CPU is simply because CPUs are not specifically designed to run thousands of processes in parallel. When you want to render a scene there are two mandatory programs that must be present to run on the GPU that is nothing more than a highly parallelized piece of hardware:
When rendering geometry there is one vertex shader per vertex and for the scene finalization there is the fragment shader. Sometimes you will see the fragment shader called the pixel shader which is technically inaccurate. These two programs are compiled on the CPU but run on the GPU. The required data comes from passing vertices to these programs that represent:
Where the magic comes in is through “interpolation” where given two points, for example, “missing data” is calculated between those two points to calculate what colors the pixels should be. Interpolation is a key concept in graphics programming as well as linear algebra.
What I suggest you look into are fragment shaders and the concept of interpolation - that should give you a fair idea of how all this works.
1
u/stacked_wendy-chan Jun 19 '25
To put it simply, a GPU is just as CPU but focus on graphics, obviously as the name implies. While a regular computer CPU does calculations for all functions of the computer, from simple calculations, logic, timing, resource allocation, I/O, ect. The GPU its just concerned with graphic calculations since they are so extensive and complex. Still, a good textbook would be of great help in the matter.
1
u/Double_Sherbert3326 Jun 16 '25
Did you ask gpt?