r/ProgrammingLanguages • • Oct 29 '26

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

81 comments sorted by

View all comments

Show parent comment

7

u/delta_p_delta_x Oct 29 '26

'Raw pointers' aren't necessarily a bad thing. The idea here is less programming language syntax sugar, and more exposing a simpler programming model for GPUs.

Consider CPUs. They are fundamentally still Von Neumann machines, essentially unchanged from the 1960s. A unified memory exposing a list of instructions, and that same list of instructions operating on data in CPU registers and data in memory, and shuffling between the registers and memory if necessary. That's all CPUs boil down to. You can expose any programming language on top of that simple abstraction.

GPUs are complicated because of their much less open development, and because of what they initially were—essentially hardware implementations of the 3D graphics pipeline. They had (still have) 3D graphics-specific hardware intersection calculation, hardware rasterisation, hardware texture mapping units, and in terms of API, all of these have handles that can be individually tuned. Of course, we have shaders as well, but then we have to manually set up buffers and descriptor sets telling the shaders what those buffers all contain. The idea of GPGPU has been shoehorned onto this, and this is still the case.

Why should this be the case? Why can't we expose a more general programming model, and then special-case the video game and 3D graphics use-case? This is what 'modern graphics API' means, and less 'Rust, Box<>, Rc, Arc<> and std::unique_ptr. Once a sufficiently general and powerful machine model has been exposed, we can write abstractions in any language. Again, see what happened with CPU programming—we moved to RAII, GCs, JIT VMs and interpreters, and more.

1

u/arthurno1 Oct 29 '26 edited Oct 29 '26

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 :).