Intro to Low-Level Graphics on Linux
betteros.org
betteros.org
That's how things work in Windows as well. That's how userland talks to kernel mode drivers.
Well, except everything is an object.
GPU drivers are different. Basically, Windows have Direct3D already in the kernel, exposing relatively large API surface for the userland half of the driver.
https://docs.microsoft.com/en-us/windows-hardware/drivers/di...
There's netlink. It's "more structured", in that it has a lot more structures.
Modules of common subsystems already support the same ioctl structs where this makes sense. Any mechanism replacing ioctls would only change the way you call it, it cannot reduce the inherent differences between modules. Well, one could use D-Bus or some generic property / key-value system, but this would only be generic on the surface.
To your overall point though: do you think there's something better?
The operations required by user-mode drivers and APIs just don't map well to file operations. On the other hand, creating dedicated syscalls for graphics isn't very attractive either, because many of the ioctls are quite hardware-specific.
Using ioctls is a pragmatic solution, and I doubt you can really come up with something much better, though I'd be interested in being proven wrong.
Just look at the absolute abortion that is "netlink". Very deeply nested structures with self-referencing pointers and sizeofs everywhere. You are looking at 300 LoC for the most trivial operations unless you want to use a shitty (like extfs tools shitty) library.
I actually prefer the ioctl, it keeps the insanity in check of these structure astronauts that gave us netlink.
Just as a side node to your ioctl criticism, I don't say ioctls are great.
Also note, that Mir is now basically gone, Canonical decided now to stop that rift and stick to Wayland.
It's a bit outdated and honestly needs replacing at this point. Xplain[0] replaces parts of it, and some of my newer blog posts[1][2] replace other parts. I can also answer any questions people have about the stack.
[0] http://magcius.github.io/xplain/article/
I assume that the interfaces discussed here are Linux specific, and the BSDs have something different.
Does POSIX have anything to say about graphics interfaces?
What is the lowest-level portable way to draw graphics? X11?
It's funny, because I always thought of X as being more of a windowing abstraction, rather than graphics in general. Perhaps I am making a distinction that does not really exist.
Obviously I am not a graphics guy :)
If you want portable you're going to want something like SDL probably.
Looking through the source of libhybris it looks like very little of it has anything to do with bionic itself.
libhybris is more things like converting Surfaceflinger calls into Wayland ones. Looks like there's some media, camera, and input stuff, too, which is all outside the realm of bionic/glibc.
Can you please prove me wrong?
The very fact that you cannot prove me wrong, tells it all.
Given that I also work with Android, are you so naive to think I need to search for whatever you want me to find?!?
Sure there is Mesa on the emulator, which is deprecated by the way.
Oh and in those Intel devices that are no longer being sold.
No it doesn't.
"Android Studio: The Mesa software renderer is deprecated. Use Swiftshader for software rendering"
https://stackoverflow.com/questions/39568455/android-studio-...
Intel has dropped out of Android market.
[1] https://github.com/freebsd/freebsd/blob/master/sys/dev/drm/d...
[2] https://github.com/openbsd/src/blob/master/sys/dev/pci/drm/d...
[3] https://github.com/illumos/illumos-gate/blob/master/usr/src/...
Not at all. Writing 100% compliant POSIX code means sticking to the PDP-11 model of what an application is supposed to be, meaning either a terminal text application or a daemon.
Anything graphical related is a separate standard.
Weston is the reference implementation of Wayland, but it is not the only one - KDE's KWin is another.
Xorg is the current most common implementation of the X11 protocol, however - again - it is not the only one (although almost all Linux desktop systems today use it) and there are other implementations.
So how do X11 and Wayland relate to each other? Well, they are both protocols for providing a windowing system. They each do things differently, with pros and cons to each approach. They are different enough so that one can be implemented on top of the other, so compatibility should not be a problem, although obviously features are lost or crippled when doing so.
There is this misconception that Wayland obsoletes X11, but they are very different systems designed by different people and worked by (mostly) different developers that only superficially provide the same features (showing windows on screen) that - at least personally - i do not see that happenning any time soon, if ever. Personally the way i see it is similar to asking if Atom (or VSCode, if that is your poison) obsoletes Emacs (or Vim).
Yes, Firefox and Chrome are open source, but they're atypical of open source projects in that (a) the amount of implementation effort required to make the kind of changes under discussion here are much larger than for typical open-source projects and (b) institutional users and knowledgeable (or simply well-advised) individual users of Firefox and Chrome won't use your fork unless you have a credible story about how you can protect them from 0days. I know of no fork of either Firefox or Chrome that has ever had a credible story, but I've spent only a couple of hours looking.
Google has their own replacement for X11 which they use in some Chromebooks, which reduces the probability that they'll throw in behind Wayland.
Not every OS install needs a mainstream browser (in-vehicle entertainment systems do not seem to: they're heavy users of Wayland) but if your OS install does, and you're waiting for Wayland (more precisely, software that uses the Wayland protocol) to replace xorg or X11, you might be waiting a long time.
"mainstream": provides a decent experience on most popular web sites including e-commerce sites.
I'm also waiting for Firefox to start supporting Wayland without X11, but it's progressing really slowly.
Besides browsers another very major work is required for Wine. It's not even moving anywhere now, since developers aren't sure how to address it. They are too dependent on X11 for windows placements and etc.
So XWayland will need to be adequate, to address these cases, including gaming, until the time major projects will complete all that work.
Not the last I heard (579 days ago):
Except SurfaceFlinger predates Wayland by years. Kinda hard to use something that doesn't exist. ;)
At the time the complaint was that Android didn't use X11 but I think it's safe to say that was a good decision at the time. As for merging them at this point they both have too much inertia combined with some fundamental design differences that'd be hard to reconcile.
In contrast, Nokia didn't want to make such rift, and until it went bust, used common graphics stack (with SailfishOS becoming Meego descendant, using Wayland).
Wayland was started the same year that Android shipped and Wayland didn't have it's first release until 4 years later. That's obviously way too late for Android to have used it or collaborated on it.
> but the fact that they didn't want to work on big problem that benefits Linux as a whole (replacing X11), but made something that benefits only them, and that created a huge and damaging rift. That they can be blamed for.
At the time nobody wanted a replacement to X11. That was a big complaint against Wayland, too.
Getting into mailing list wars and trying to make everyone happy ensures you end up like Nokia - too late to matter and with no more money. That's not helpful to anyone.
Also please explain how Google created a "huge and damaging rift"? What damage resulted from this at all?
Hardware becoming Android only. See https://lwn.net/Articles/504865/
A major part of that problem is that rift that created incompatibility and prevented reusing of the existing progress. That was the whole reason for making libhybris, to unblock that issue.
But that's also wholly unrelated to the specific context here which was Wayland vs. SurfaceFlinger.
Wayland was your "huge damaging rift" here if anything. Divorcing itself from both xorg and surface flinger, for no particular reason at the time in the case of the later.
Not arguing about the rest of your post, but the above is incorrect.
Nokia didn't go bust because they tried to cooperate with the rest of the world. You can be cooperative and still say no to people.
If I'm not mistaken Android was developed in submerged mode for a long time, for business reasons.
https://bugs.chromium.org/p/chromium/issues/detail?id=549781
There's already a Wayland version of Firefox available: https://firefox-flatpak.mojefedora.cz/
Relevant bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=635134
[1]: https://project-insanity.org/blog/2017/02/14/try-out-firefox...
That is what Wayland's developers want, but that doesn't mean it will happen :-P
EGL if you use OpenGL, and WSI if Vulkan, if I understand correctly.
For something more modern, grabbing an ESP32 coupled with a LCD screen, for example.
My first rotating cube "exploded" due to numerical errors, as I was modifying the geometry instead of using matrix projections.
That made me appreciate the linear algebra classes much more.
I used it for a while, if I remember correctly I even wrote a pixmap loader.
Why not just use SDL, or would you like to port old games?
Nowadays on macOS I would just use SpriteKit.
Very different from Digital Rights Management.
https://en.m.wikipedia.org/wiki/High-bandwidth_Digital_Conte...
https://github.com/torvalds/linux/blob/master/drivers/gpu/dr...
Things just seem to break in nasty ways if i do not manage to get the kernel and userspace stuff to line up within a certain range of minor versions, and i can't seem to find a good straight list of just what those lineups are.
Effectively DRI/DRM seems to be developed for the major dev, by the major devs, and screw anyone and everyone that do not read every damn mailing list and IRC channel with religious fervor.
Between that and the udev stuff i fear that Torvalds have gotten too trusting of his sub-system maintainers in recent years, thus resulting in interface churn because both the kernel and userspace parts are done by the same people with no regard for anyone but themselves.
The structs use the types like __u32 or __u16. I know the kernel defines its own types for internal usage[1], but why redefine types exposed to user-space? Why not use C99 <stdint.h> types?
Is it only historical?
And why are they double-underscore?
[1] because... reasons? I never really understood why
Example:
This is because `stdint.h` isn't 100% compatible with _every_ platform Linux supports. This gets in hair brained definitions of pointers lengths on some obscure platforms. For example SPARC64's `long`, `long long`, `void\`, and `uint64_t` aren't all the same size (`long long` is `uint64_t`, while void\ and `long` are `uint32_t`, but in kernel land `void\*` is `uint64_t`).
Just like C11 Atomics can fail on ARM and PPC under some scenarios so the kernel doesn't use these as well.
Its my understand the Kernel supports more platforms then the C standardization committee xD
---
So the kernel likes to define its own primitives, and when you interface with it its is generally best to just use those definitions. Or if you want to use _standard_ types, you have to understand you are hurting portability.
I would imagine that if someone's platform doesn't support C11 at this point it pretty much hasn't been updated in 7 years and pretty much can't custom build GCC. I mean I know how to build GCC on a Sega Dreamcast so it has to be more esoteric than that.
Also, not supporting C11 probably also means not supporting lots of other things that modern applications might want like Vulkan, IPv6 or multiple threads.
One thing I still don't understand though:
> This is because `stdint.h` isn't 100% compatible with _every_ platform Linux supports. This gets in hair brained definitions of pointers lengths on some obscure platforms. For example SPARC64's `long`, `long long`, `void` , and `uint64_t` aren't all the same size (`long long` is `uint64_t`, while void\ and `long` are `uint32_t`, but in kernel land `voidx` is `uint64_t`).
In these cases, you just defined the variably-lengthed types (void* ) using the fixed-length types (uint64_t). This would just demonstrate that the fixed-length types are absolute, and IMO then good candidates to base absolute-sized types on. And yet that's still not good enough?
A bit of googling brings up the book Linux Device Drivers 3rd Ed (2005)[1], in which chap11 specifically addresses the topic of types. It argues against the usage of standard C types (int, long, etc) specifically because of their size variability. That's all well and good, but it doesn't make any mention of stdint.h!
A hypothesis comes up: maybe stdtint.h is meant to be a user-space header exposed by the system/compiler, and the kernel, having to be entirely bootstrapped, can't even depend on that? So it just redefines the types for itself? With the side-effect of exposing those to userspace at the API?
The problem with that idea is that the kernel cannot count on those types being consistently defined for all configurations, and cannot create its own definitions for the standard types. So the kernel/user interface must continue to be defined using kernel-specific types (__u16 and such).
From: https://lwn.net/Articles/113349/
And as close to Word Of God as I can get:
The moment it loaded my eyes felt out of focus and everything had a certain fuzziness to it.
The color combinations don't seem to agree with font smoothing, at least not on OS X w/ Safari on a 3440x1440 monitor
Really? I found it quite difficult to read due to the text color being too close to the background color.