r/eli5_programming • • 1d ago

[ELI5] If source code is platform-agnostic, why computer games are not compiled for both Windows and Linux?

3 Upvotes

45 comments sorted by

6

u/pixel293 1d ago

The APIs to access the screen, i.e. the GPU are different. Also the file-system structure between Windows, Linux, and MacOS is different. There might also be 3rd party services like video codecs that are available on one platform by default but not on another platform.

3

u/yvrelna 21h ago

OpenGL and Vulkan are the same across OSes. Proton with WineD3D/DXVK/D7VK implements DirectX API in Linux.

Filesystem API differences are mostly file path syntax and handling of root drive, but most languages have ways to abstract those differences. The biggest difference here is mainly file system case sensitivity, and the filesystem convention on where to place config/temp/cache/etc files. 

The biggest platform differences are mainly the system call APIs. The Win32 API and the Linux/POSIX API are very different, and they often aren't just superficial differences where a simple cross platform wrapper can smooth out the differences. These are things handling differences around threads/processes (e.g. fork vs CreateProcess), IPC (e.g. socket inheritance), synchronisation primitives (e.g. file locking), ioctl, dealing with UAC/Polkit, etc.

And then there's also window/full screen/input handling, to create and manage GUI windows, handle alt-tab, etc but the most important of those are often handled by the game frameworks.

And then there's the idiomatic behaviour that users of each platform expects from applications, like keyboard shortcuts, etc. Most Linux aren't that much different to Windows in this respect, most of the more popular desktop environment has shortcut setup that's resembles Windows. But there are also other behaviour like dialogue button ordering and naming convention that differs between the systems. 

1

u/Alarming-Ad4082 20h ago

Most game use Direct3D not OpenGL or Vulkan

1

u/Square-Singer 19h ago

Most games use all three and let you toggle them in the graphics settings. The times when games were D3D only were the early 2000s.

1

u/Alarming-Ad4082 19h ago

Most games? I don't think so. And most AAA games use Direct3D

2

u/JamosMalez 21h ago edited 21h ago

This sounds like a small part of code—less than 1 percent. Why not put in a little extra effort to change the API and make versions of the program for other operating systems?

3

u/Poddster 21h ago

Vecause it's a lot of effort, despite being a small part of the code.

Also: no one really pays for anything on Linux, so it's a lot of effort for little reward.

2

u/diet_fat_bacon 19h ago

People think that is just "well it compjled, just ship". There is QA , platform specific code, debugging....

1

u/Narrow-Low-3137 20h ago

This is hyperbole. I and many others do infact pay for software such as games, which I play on my Linux machine. I even pay for games that don't officially support Linux, but work with Valve's proton layer.

The free software movement exists and is robust on Linux especially, but that doesn mean there isn't room for proprietary software too.

I hope more developers target Linux as a first class deployment target more as more mainstream crowds are beginning to realize you don't have to be a slave to Microsoft or Apple when it comes to your pc OS.

Especially with more and more cross platform frameworks and game engines starting to be the norm.

2

u/Poddster 18h ago

This is hyperbole. I and many others do infact pay for software such as games,

No, THIS is hyperbole, and it always has been. :)

The extremely loud but tiny minority of people that actually pay for Linux games has tricked many a game developer into porting things to Linux only to find out that they sell nothing and the entire porting effort is a net loss. So not only do game developers find no users to sell to, but those that do often amount to a colossal support cost that they often just ignore. Consoles are set targets, Windows is a set target with a few different hardware configurations, and Linux is a vague target with almost no consistency.

If you plan for specific Linux platforms from day 1 and have a QA pipeline built around it then it can work out ok. But I've seen numerous accounts of major developers taking the punt and it completely failing. It's not worth the opportunity cost for them. (ones I remember: Pillars of Eternity and Planetary Annihilation.

SteamOS is good in this regard: If people target nothing but the Steam Deck (and later Valve hardware) they can avoid the usual support issues of 1% of your player base accounting for 50% of your support tickets. However, that also brought Proton, which many developers see as an easy way to support Linux without the effort.

2

u/yahluc 21h ago

Making things work with the components you can't directly control is the most pain in the ass part of software development.

1

u/Brudaks 20h ago

Well no, it's not small part of code and nowhere near 1 percent. In modern AAA games the majority of code is used for the various nuances of the pretty graphical effects, much more than on the gameplay logic.

1

u/pixel293 1h ago

There is also QA to consider, if you want to make your program run on multiple OSes then you also need to test your program on all those OSes.

3

u/Technical_Goose_8160 1d ago

Code has to be turned into machine language when we compile it. Different systems speak different languages, even hardware can affect it.

Java is hardware agnostic, so every machine needs a Java virtual machine that will turn it into machine language when the code runs.

This is very useful when developing for disparate hardware, Java is very popular with medical machines. But, compiling when it runs is slower and video games can be pretty heavy.

2

u/Doug2825 22h ago

This misses the question. Linux and Windows are usually in the same hardware. The machine code is the same. The problem is the commands the OS supports are different.

2

u/shadow-battle-crab 1d ago edited 1d ago

Source code isn't totally platform agnostic.

Most of a program is written in a generic way, but the parts that actually communicate to the screen, use the keyboard, etc are written specifically for whatever environment it is designed to run in.

Lets take a video game. So you make a car racing game. Does that game use a game controller? A keyboard? A touch screen? A racing wheel? You, as the game programmer have to design a special connector for your games software for each kind of thing it connects to.

Operating systems are just another kind of connector, because each has its quirks. On windows, you need a different kind of installer than linux, you also need a different kind of way to interface with the windows manager, a different kind of way to accessing the GPU, etc. Where the save game files and temporary files go is different in each environment. How a "Save As" dialog works is different for each environment. How do those screens even work on a game console? How does a switch work differently than a PC?

Modern game engines like unreal and unity do a lot of the heavy lifting of this stuff for you, but not all of it.

Each one of these things requires an extra layer of work, and testing - and if you know your market is going to be mostly people that play the game on Windows, it's easy to decide to not want to do this work.

1

u/wiggle_room1337 22h ago

Even stuff like "what time is it right now" needs some sort of compatibility layer.

2

u/Polyxeno 21h ago

My games are, because I use a cross-platform library: OpenFrameworks.

Pretty much all of the platform-specific work is already done in OpenFrameworks, and wrapped in library functions, so my code uses those functions and does not need to change per platform.

I can build the same game for Linux, Mac, Windows, iOS, or Android, and there are rarely any serious technical issues in doing so . . . BUT the Google Play, Apple, Windows, and Steam platforms all have annoying hurdles to face, and testing to do. So I tend to skip iOS, and Mac, and will probably never do Android again, for those reasons.

1

u/Key_River7180 1d ago

Win32, basically we cant agree on how to make a window and put pixels into it with the gpu between platforms.

Read XKCD 927: https://xkcd.com/927/

1

u/yvrelna 21h ago

Well there's POSIX, where most of the major and even many minor OSes generally roughly agree about the major behaviours. 

And then there's Win32 who does everything their own way. 

1

u/Key_River7180 11h ago

Yeah basically.

1

u/mredding 1d ago

Source code CAN be, platform specific APIs aren't inherently.

If you need memory, you need to ask the OS, and how you get memory from an OS depends on THAT OS.

The next best thing you can do is compile the code following some platform agnostic API, and you implement the platform specifics behind the API. That's a lot of what software tries to do.

But video games try to squeeze every last bit of performance out of a machine, and that means you cut the bullshit and get platform specific. You would sacrifice universality for performance.

1

u/DiodeInc 22h ago

platform specific APIs aren't platform agnostic

:P

1

u/Frequent-Sir-6942 22h ago

Neither source code nor binaries are platform-agnostic in the general case.

1

u/Lonely-Restaurant986 21h ago

How the computer reads the code is largely the same.
Windows developers at Microsoft say “Let’s write this function to allocate memory”. They create that standard (windows api). When a game dev writes code they use the standards the windows developers created.

Linux developers say “Let’s write this function to write memory”. So all Linux apps use that standard.

So the problem isn’t the code, the issue is how that code interacts with the hardware.

So when you run a windows program, the code says, “Run this windows function in the windows api” but Linux has no idea what that is or how to do it.

This has been largely fixed by compatibility layers like wine. But kernel level code is where the issues lie.

There’s more nuance to it but that’s simply put.

1

u/Technical_Ideal_5439 21h ago

Source code is not platform agnostic, most code is written for a platform with specific parts of it written to deal with platform differences.

Sure you can write some code as platform ignostic but as soon as you start needing hardware, code normally gets locked into the platform unless you are very careful.

1

u/NZAuthor 21h ago

Source code is not fully platform-agnostic. I'd say 99% of it is unless you are playing around with memory on a very technical level.

The other 1% is for edge cases and could be anything from specific libraries being used that aren't universal, very specific low level language commands, or simply how characters work with the file system. It could be anything simple or complex.
But yes, this CAN be easily worked around most of the time. The developer just needs to decide if it's worth doing or not.
More often then not, it's the choice early on to use a windows specific library for drawing graphics that becomes a barrier.

1

u/kutac56 21h ago

Because certaint low level libraries are different for both operating systems like graphics libraries

1

u/Superb_Raccoon 21h ago

Spoiler: It's not.

1

u/Pale_Height_1251 20h ago

Source code is often platform agnostic but games can be a sore point because GPU shaders are often not platforms agnostic, i.e they are different on Windows, Nintendo, Mac etc. The CPU stuff is much the same, but the GPU stuff often isn't.

1

u/OpeningQuail2483 20h ago

if it is platform agnostic then it compiles and ships for both, if no then no

1

u/bubba-yo 20h ago

I don't think we've had platform agnostic games since Nethack.

But every platform has unique APIs. Linux doesn't have DirectX. Mac uses Metal.

Every platform has different bottlenecks which requires different coding solutions for performance. The Mac has faster single core performance and faster RAM and storage, but slower GPUs. Linux can be 20% faster than Windows for memory read/write. Windows threading is much slower. So a game that is performant on Windows may not be on Linux or Mac without changes, breaking the platform agnosticism.

And every target requires testing, so going from one platform to two doubles your testing overhead, and requires a level of expertise from your team to target it. It's why there were porting houses full of platform experts to figure out how to get that Windows game to run on Linux or Mac.

1

u/grizzlor_ 18h ago

>Linux doesn't have DirectX.

It actually does these days via Proton’s translation layers: DXVK for DirectX 9-11 and vkd3d-proton for DX12. Translates the calls to Vulkan in real time.

It’s pretty amazing honestly — basically every Windows game just runs on Linux now (with the exception of ones using kernel level anticheat).

This also really makes it unnecessary to do Linux ports of any game. Even games that do have native Linux ports tend to work better using their Windows version under Proton.

1

u/bubba-yo 17h ago

No, it doesn't, because that still needs to be tested for. You might say it's good enough, but it's not going to be good enough for Rockstar to promise the $80 game will work.

1

u/grizzlor_ 17h ago

Testing the win32 version under Proton is a lot easier than developing and maintaining a Linux port. Plus there’s already a comprehensive community database of Proton compatibility reports.

Steam runs just fine on Linux — Valve has no problem selling Windows games to Linux users. Their gaming hardware (SteamDeck, SteamMachine) runs Linux.

1

u/bubba-yo 15h ago

Testing costs the same. It might be easier to make it work, but you still need the build chain.

1

u/vitimiti 19h ago

It takes effort. You have to use cross platform libraries that your team may not be used to if they are used to Windows only. Then each platform has particular quirks that may bite you back. To make matters more difficult, Windows is very backwards compatible, while Linux desktops aren't due to the dependence on glib (the equivalent to the Windows Runtime in a way, you need it) which doesn't have a "don't break user space" policy but rather "Welp, you should upgrade your build then" policy. Moreover, each compiler (on Windows you probably use MSVC while on Linux you probably use GCC) has its peculiarities.

All in all, companies just don't consider Linux support profitable enough, especially because Linux users are VERY used to creating bug reports instead of restarting or ignoring problems, so most bug reports will come from the smallest user base (and this has happened before), increasing workload for a tiny market share.

Basically, it's about money, investment Vs benefit

1

u/fiddle_styx 19h ago
  1. Not all source code is platform-agnostic
  2. Games are often compiled for both Windows and Linux (and macos, web, android, etc)

1

u/tecnofauno 19h ago

Source code Is never platform agnostic. It can be portable when simple, and games are not simple. It can be multiplatform, but needs extra effort.

1

u/Quick-Penalty4883 19h ago

A book doesn't care what language it is written in, but for you to understand it it needs to be translated to a language you do understand

1

u/Bo_Jim 18h ago

The core of the programming language is platform independent. System services, like 3D rendering and audio mixing, are very much system dependent. Each operating system has it's own programming interface for accessing those services. A significant portion of any game's code is setting up for those system calls, and those calls are not portable between systems.

Games intended to be ported to multiple platforms usually use an intermediate API that is consistent to the application on every platform, and connects to the platform-specific OS services on each different platform, like OpenGL or Vulkan. They still might require some platform-specific system calls, but these can usually be surrounded by conditionals so that the proper code is compiled on each platform.

Text based applications that use standard libraries are generally fully portable at the source level. A large percentage of the console tools used on Linux are ported directly from sources originally written for Unix.

1

u/mxldevs 18h ago

Source code isn't platform agnostic.

If your code requires windows libraries to run for example, then it's not going to compile on other platforms unless you provide the required libraries.

You can certainly write code in a way that's more platform agnostic, but it's not the fact that it's code that makes it that way.

1

u/Odds-and-Ns 18h ago

Source code isn’t necessarily platform agnostic in general. It can be, and Id argue it usually should be, but it takes active consideration to make it that way

1

u/fltfathin 12h ago

There is lots of game engine and languages so let's start on what is source code, let's call code for short

Code is like cooking recipes, it can be written in different language, say american or spanish, human understand those

But the one cooking is not human, but some kind of robot, for the recipe to be run correctly by the robot, we need to translate it to robot language. There are many kinds of robots with different cooking appliances available to them.

This is the part that usually get stuck, because the different kind of appliance and tools, the food doesn't always make the same taste around. So the human making the recipe decide that they only support one kind of robot. Because adjusting the taste on multiple robot is expensive and change one affect the other.

Sometimes the are cookbook have the same base cooking flow, imagine the recipe about cakes have common baking recipes, and can work on all robots, sometimes the maker just hate one type of robot and refuse to allow people to translate to that robot, despite there is no adjustments needed just one checklist to click. Oh they also refuse to acknowledge when someone can make one robot acts like the other citing that food is gonna be used for poisoning others.

1

u/henke37 8h ago

One thing the others neglect to mention is hardware differences. While things are relatively same these days with "everything" being derived from "IBM compatible" machines, it was a much bigger mess back in the day. While others have pointed out api differences, sometimes there were fundamental design differences in the hardware itself.

Consider a platform such as the GBA, that thing did not have general purpose graphics hardware with a frame buffer. Instead it had exactly four tilemap layers and 128 "objects". It also didn't have a keyboard, it had a d-pad and some buttons.

Modern operating systems can generally abstract away these differences today, but on more limited systems, which might not even have an OS, it was much more visible to the application programmer.