r/ProgrammingLanguages • u/ThomasMertes • 29d ago
How programming languages approach graphics
Many general-purpose languages delegate graphics to third-party libraries (like SDL, Raylib, or OpenGL). Seed7 integrates portable 2-D graphics right into its standard library. This IMHO improves portability. I also thought about introducing operators / statements to do graphics, but until now I don't use operators or statements to do graphics.
29
Upvotes
View all comments
Show parent comment
1
u/arthurno1 29d ago edited 29d ago
At the fundamental level a modern GPU is a stored-program computer, just like CPU, derived from the von Neumann model too. If you want it the other way around even CPU can also execute SIMD model computations like GPUs just at a smaller scale.
Also note that the hardware ISA on modern CPUs exposed to the compiler is really just an architectural illusion, for the programmers convenience. Standard CPU architectures like x86-64 are register-file machines rather than stack machines, but even that register model is just a surface-level contract. Under the hood, the hardware relies on out-of-order execution, register renaming, and complex load/store queues to execute a dynamically scheduled dataflow graph. The physical hardware is vastly more complex than what typical programming languages like C, C++ or Java expose. So I don't think you really want to base a PL on "von Neumann-ness" so to say :).
Compare C to for example Lisp(s), notably Common Lisp which does not expose memory to the appliation programmer at all. You can of course create objects, but there is no linear memory space, pointers and addresses. The language hides the memory model completely and could be implemented on any kind of hardware really.
In the world of graphics OpenGL is similar to that model (in concepts only). It also manages memory for programmers, which was reason for what people called "overhead". Compared to Vulkan which exposes the hardware.
Typically high-level languages (in the case of OpenGL API) sacrifice a small amount of performance to implement automation in form of resource management. On the opposite the languages like C give you explicit access to hardware and minimal automation but put burden of hardware management on the programmer. The slogan of C is that "the programmer is always correct". It means the compiler won't prevent you from shooting yourself in the foot.
The modern research tryes to provide as much of explicit control in "safe way" and modern programming languages typically varies from each other too which degree they can provide automation without sacrificing performance. I am think on C vs Rust in this particular case.
For a specialized graphics programming language, I think something like Lisp and OpenGL is much better than raw pointers. When I say OpenGL, I really think of the graphics language it exposes, not of the C API; it should have been it's own language interoperable with C, not C API from the beginning. Shading languages are more like what I am talking about, and we have had such long before Geforce 256 came (which I remember when it was launched), for example Renderman. My first graphics card was TNT2 by the way :).