r/ProgrammingLanguages • • 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

81 comments sorted by

View all comments

Show parent comment

3

u/P-39_Airacobra 29d ago

curious if you have any insights on what the next shift will be?

7

u/delta_p_delta_x 29d ago edited 29d ago

This seems to be the latest hotness. Basically, getting rid of the extreme verbosity and explicitness in modern graphics APIs, everything is a pointer or index offset into a buffer, no more pipeline state objects; no more explicitly setting pixel and image formats, they're all just numbers in a buffer, etc.

3

u/msqrt 29d ago

Yeah, this is essentially what I was referring to. (Desktop) GPUs have gotten much more free-form in the way things are accessed, so it would make sense for the APIs to reflect that.

1

u/P-39_Airacobra 27d ago

Thank you for this article! Extremely interesting stuff. I always get excited when I get to see industries change in realtime.

1

u/arthurno1 29d ago

Does not look to me as "modern", honestly. They still want to expose pointers and raw memory and let user manage explicitly hardware.

With all the speed of hardware we have today, and advances in programming language research, one would believe we are automating things and leaving pointers and raw memory behind us. But no, there we are another version of "my C" is nicer looking than "your C". What they offer is a cleanup, which is certainly welcome, but not really a change on programming language level.

7

u/delta_p_delta_x 29d ago

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

2

u/Inconstant_Moo 🧿 Pipefish 28d ago

But no, there we are another version of "my C" is nicer looking than "your C".

But for the use-cases people write those things for, that's kind of what they want. People are going to want to say "Yes your abstractions are very nice but I want to do <thing> to make hot loop go brr. I need to get these scissors from here to there very quickly and no programming language is going to stop me from running with them."

And so you delegate the creation of abstractions to the writers of libraries and frameworks and the language primitives expose the metal.

The sameness of the projects is that most indie langdevs who aren't me have followed similar career trajectories that led them to want to solve similar problems.

3

u/arthurno1 28d ago edited 28d ago

Interestingly enough, I am downvoted to death in another thread about similar topic, where I say exactly the same as you say here: some people want their hot loops go brrr and they refuse any higher-level overhead.

I think personally, for the security and productivity reasones, people would have to accept they have to give up the direct access to their hardware. I remember 90s and game development discussions: people claimed there will never be serious games made in Windows OS and DOS will continue to live because games need total access to the hardware to go brrr. We all know the history.

Yes, that is the controversy of today's software dev: you have experts and scientists who propagate higher level languages and abstractions for safety and productivity, and than you have an indie developer who just learned programming, did a benchmark and found the benchmark runs faster in an unsafe language, and they want that. I am guilty myself of the same: I wrote a fast software in Lisp which equals the optimized C++ version (by someone else) just to demonstrate this exact thing. Now, that does not mean I advocate for unsafe languages. What I truly believe is that most people don't really need those 5% ~ 10% of the performance, especially not in the interactive applications like games or office software. While yes, we do need system languages, that let us access low level hardware, like C++, C, or Rust, I don't think that people need to develop user-facing software in those languages. In my opinion, they are better left to system development, like drivers and kernels, low-level systems, where you need to access low-level hardware registers and systems.

Look at Quake I; back on the hardware of the time, they achieved interactive frame rates in OpenGL. Carmack wasn't complaining about getting access to low-level hardware. Back in that time Carmack even invented Quake C, because well, the speed was enough. If you ask an indie dev today: only pure C, Rust, C++ ... insert compiled language is enough for everything.

So yeah, I agree with you, the flavor of the day is what shapes discussions and what people do to.

2

u/Inconstant_Moo 🧿 Pipefish 28d ago

What I truly believe is that most people don't really need those 5% ~ 10% of the performance, especially not in the interactive applications like games or office software.

Games though have an unlimited ability to use up clock cycles, you can always use them to render things better.

2

u/P-39_Airacobra 27d ago

The irony of the issue is that if we just relinquished control, hardware could arguably become much faster. So much of hardware advances are being spent trying to run C fast, when the problem with C is that ANYTHING can happen, which makes it inherently difficult to optimize while still being correct.

C compilers themselves run into this problem consistently, where optimization needs to be opt-in because there’s no way to optimize C without breaking its semantics in some subtle way.

This is the problem with languages that expose everything: ultimately when you give the programmer the choice, you also give them the responsibility; that is, the compiler/architecture can no longer step in and make assumptions for you.

Is this a bad thing? Not inherently; though it is a costly trade-off for sure.

2

u/arthurno1 27d ago

Yes, definitely; that is a good take on it. People have different priorities and make different choices, sometimes even contradictory, so if language designers will cater to everyone, they have to have to make a tradeoff.