In Linux, do I need an X server to do off-screen rendering?
Asked Answered
C

2

8

And if so why? What does X do for me beyond piping my rendering commands to the graphics card driver?

I'm not clear on the relationship X - OpenGL. I've searched the internet but couldn't find a concise answer.

If it matters, assuming a minimal modern distribution, like a headless Ubuntu 13 machine.

Calcite answered 27/9, 2013 at 9:5 Comment(1)
Related: #3192478 Vulkan seems to support offscreen rendering.Hippocrates
O
9

With the current drivers: Yes.

And if so why?

Because the X server is the host for the actual graphics driver talking to the GPU. At the moment Linux GPU drivers require a X server that gives them an environment to live in and a channel to the kernel interfaces to talk through with the GPU.

On the DRI/DRM/Gallium front a new driver model has been created that allows to use the GPU without an X server, for example using the EGL-API. However only a small range of GPUs is supported by this right now; most Intel and AMD; none NVidia.

I'm not clear on the relationship X - OpenGL

I covered that in detail in the SO answers found at https://mcmap.net/q/551269/-how-interfacing-with-graphics-card-work-with-c-or-c and https://mcmap.net/q/925934/-how-does-gui-output-work-from-application-to-hardware-level

In short the X server acts like a "proxy" to the GPU. You send the X server commands like "open a window" or "draw a line there". And there's an extension to the X protocol called "GLX", where each OpenGL command gets translated into a stream of GLX/X opcodes and the X server executes those commands on the GPU on behalf of the calling client. Also most OpenGL/GLX implementations provide a mechanism to bypass the X server if the client process could actually talk directly to the GPU (because it runs on the same machine as the X server and has permissions to access the kernel API); that is called Direct Rendering. It however still requires the X server for opening the window, creating the context and to general housekeeping.

Update due to comment

Also if you can live without GPU acceleration, you can use Mesa3D using the osmesa (off-screen mesa) mode and the LLVMpipe software rasterizer.

Osseous answered 27/9, 2013 at 9:19 Comment(7)
I'm pretty sure that you can do offscreen SOFTWARE rendering without X server. I think svgalib and directfb can be used for that, plus there's mesa3d. You might want to mention that.Hawkshaw
@SigTerm: Both svgalib and directfb are APIs specifically for on-screen buffer access. You can do offscreen rendering using Mesa3D using osmesa (_o_ff _s_creen mesa). Currently it's using the software rasterizer, ideally LLVMpipe. However hopefully we'll get fully off-screen GPU state tracker support in Mesa soon, so that we can do off-screen rendering using the GPU as a co-processor, regardless of being used for driving a screen.Osseous
I admit I wasn't quite clear... I wanted to say that: 1. you can do onscreen software rendering without X (svgalib, etc). 2. You can do offscreen software rendering using mesa3d. 3. It is worth mentioning software rendering (and it would improve the answer), because OP didn't explicitly mention that he wants acceleration.Hawkshaw
@SigTerm, maybe you can show an example of that? Because I don't think it is possible as gl requires you to have a rendering context and you can't create one unless you have X running.Envelopment
@BjörnLindqvist: In the meantime (it's been over 3 years) all the necessary things have been implemented and you can now have GPU accelerated OpenGL without a X server running. Here's an example that does on-screen rendering (without X) github.com/datenwolf/kmscube – but it's not that difficult to change in a way that it's purely off-screen.Osseous
thats awesome but thats not OpenGL, thats OpenGLES. the question remains, if you have an OpenGL program, do you need to port it to OpenGLES to get it to work with X-less renderingRiddick
@Osseous mesa3d offscreen is fine, but if you need libglew, which a big majority of old GL programs do, you will have a hard time building glew against OSMesa. i have done it but it took hours. see also #23451935Riddick
R
3

With Linux 3.12: Not any more.

Offscreen rendering is what DRM render nodes are for, according to the commit. See the developer's blog for a better explanation.

TLDR:
A render node (/dev/dri/renderD<num>) appears as a GPU with no screens attached.

As for how exactly one is supposed to make use of this, the (kernel) developer only has very general advice for userspace infrastructure. Nevertheless, it is fair to assume the feature to be nothing short of a show-enabler for Wayland and Mir, as clients won't be able to render on-screen any more.

The wikipedia entry has some more pointers.

Recruitment answered 26/11, 2013 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.