Warning! Your devicePixelRatio
is not 1 (or your browser doesn't CSS media queries, in which case you can probably ignore this warning)!
Since HTML is as braindead as it can get, creating sites outside of diversity hires corporate art sphere is damn near impossible, so this site is not really optimized for HiDPI screens.
Some images might appear blurry.
Upscaling things on X11
Situation: you have some old game that only runs at 320x240 or something like that, and it looks very bad on your full-HD monitor. Or you were retarded enough to buy a meme 4k/8k monitor, and you can't run your game with acceptable speed on your toaster. Since I only have a full-HD monitor, I will focus on the first usecase, but there might be some useful here for the second usecase too.
Emulators#
If you're running the game in some kind of emulator, and the emulator has an option to upscale the graphics, use it. Really. Yes, this means separate setup for each emulator, but it's still much less pain than anything else in this guide.
If you're not so lucky, either because you're running some native Linux game or you're running some old Windows game in wine, continue reading.
Glide games#
This is partly the emulators category, but if you're using a nglide or dgvoodoo 2 (under wine), you can force a resolution in their settings panel, and the game will be upscaled to that resolution automatically. As a bonus, this will cause 3D geometry to be rendered at higher resolution, which usually means much better results than just upscaling the final image in 3D games.
xrandr#
The first option is using xrandr
and it's scale option. First run xrandr -q
to get a list of outputs, then you can run something like this:
xrandr --output DVI-D-0 --scale 0.5x0.5 --filter nearest
Replace DVI-D-0
with the actual name of your output. This will halve your
"virtual" resolution's width and height while the device will stay at the old
resolution, so your monitor will get a x2 scale. You can use
--scale 0.25x0.25
to get a x4 scale, etc.
Pros: no extra tools needed, works with every card (at least I tested with Nvidia, AMD, Intel), and minimal overhead.
Cons: oh, well. First, you'll have to get your game into windowed mode,
because if the game itself tries to change resolution, all hell will break
loose. Second, it fucks up your monitor resolution until you restore it with
--scale 1x1
, annoying if you want to check something quickly in another app.
But the real clusterfuck is if you have multiple monitors. First, using things
like --right-of
and friends will break, because xrandr
will use the
non-scaled resolution when positioning, which means that if, for example, you
have a 1920x1200 monitor but scaled to 960x600, and you use --right-of
to put
a 1920x1200 (not scaled) monitor to the right, xrandr
will place it at
+1920+0
, and you will have a 960 pixel wide dead area between your two
monitors. You have to use --pos 960x0
to place your monitor to a more sane
place, but of course that will break when you switch back to your original
resolution. What's worse, if you do this, from the right monitor you can only
move your cursor to the left in the upper half of the screen, because at the
lower half, there's "nothing" (virtually) to the left (that monitor is only 600
pixels height). Interestingly if you leave a 1 pixel dead area (i.e. use --pos
961x0
), you can move your mouse into these invisible areas, which I found much
less annoying than randomly hitting a wall with my mouse. Just don't be
surprised if your cursor disappears. Also, another annoyance, on your scaled
monitor, your mouse speed will be faster (it has a constant speed per pixel, but
since on one of your monitor a pixel is much bigger, it will appear to move
faster).
So yes, it works, if you have nothing better, but it's annoying.
gamescope#
TL;DR A hyped garbage.
Gamescope calls itself "the micro-compositor formerly known as steamcompmgr"—we already have marketing bullshit and no real info. Anyway what this does is create a wayland compositor with an Xwayland, then it will scale the app running inside the wayland to the size of the window.
Pros: it automatically resizes the game to the size of the window you have, effects are local to the window (you don't have to fuck up your screen resolution). Your game runs in an isolated X, so it won't fuck up your real X's resolution, capture your mouse when you don't want it, etc.
Cons: for a long time it was AMD/Intel only (allegedly, nvidia drivers
515.43.04+ are supported, but these drivers do not support my nvidia card, so I
could never try). If you get through that, the second thing you will notice that
it's full of nigger dependencies, like wayland, seatd... fortunately you can run
it without systemd, but it's still a clusterfuck. It has non-rebindable (well,
unless you edit the source) shortcuts that will conflict with all the shortcuts
your window manager has. But the worst, this shit only supports a single window.
Yes, if your app opens more than one window, it will just display one in full
screen. No Alt-Tab or anything. And since this is not normal X, but some
Xwayland pseudo X abomination, you can't even start a window manager inside. If
you have a Windows game, you can work around this by enabling "emulate a virtual
desktop" in winecfg
to get a Windows 3.1 level window manager, but otherwise
you're fucked. Basically useless if you want to run a game with a text hooker,
for example. With 30 years of evolution we managed to get back to the DOS
times, where you could only run one program at a time (TSR is not real
multitasking), except with ridiculously increased HW requirements.
This is what you probably get as "working" options, if you search the net. Some people suggested running an Xvnc and connecting to it with a VNC client that supports scaling, I haven't tried that, but I've tried xpra. For "office" work, it might work, but for any games, there's just too much lag and too low FPS to be usable, even when running localhost.
Patching Xephyr#
There's Xephyr, which is an X server that can be run inside an X window. Unfortunately, it doesn't support scaling out of the box. I think you could try running Xephyr inside gamescope, to get rid of the problems, but when I tried to use this, I did not have a HW where I could try this out (well, maybe my shitty notebook, but I didn't want to play on it), so that was out of question.
Then I had an idea. How hard would it be to edit the source of Xephyr to upscale the image? The answer: a few hours of messing around with the code, with zero prior knowledge about how Xorg internals work. I originally published it as a patch file on some obscure imageboards, but now here is it in a "proper" git repo: mirror a, mirror b. It's very rough, but it gets the job done.
Pros: it's a proper X server, not that soylent X-like crap that comes with gamescope. You can run whatever window manager you want. Like gamescope, it's an isolated X server, so the game won't fuck up your normal X server.
Cons: this is a hack I once threw together in a few hours and never touched afterwards. It received zero optimizations. You have to recompile it if you want a different scale ratio. No HW acceleration. You will have GLX and OpenGL inside Xephyr, but it will be a software implementation (llvmpipe), it won't use your GPU. This is a Xephyr limitation, that's unfortunately not trivial to solve. Also, no clipboard synchronization with your normal X's clipboard, which can be a problem if you want to use texthookers. But fortunately this is X, grab xclipsync, and it just werks.
So yes, use it at your own risk. I've used this with Didnapper and 黄昏の境界, without problems, but these two games don't even use HW acceleration as far as I can tell.
Future ideas#
Take weston (or any other wayland compositor that can run in an X window and supports Xwayland), and modify it to upscale the output. It's still overcomplicating things with wayland, but at least you would have a basic window manager, so it will work even if you would have more than one window. Such features in 2022!
Run the whole shit in a VM. With things like virtio-gpu you might get decent performance, if you run a Linux guest. But if you virtualize, and you have a Windows game, you're probably better with running a Windows in the VM. I've tried looking glass, but it had horrible performance (but this is more likely the problem of the monkeys at AMD not being able to write a fucking functioning driver, even obs-studio shits itself inside the VM, while it works perfectly on Linux using the open source driver).
And while we're at VMs and GPU passthrough, I could start a second X server on
the second card when needed, then write a mini VNC that displays the contents of
the second X server on the first one (a very simple PoC could be made with
x0vncserver
and a VNC client, but that would be highly inefficient). Like
looking glass above, but between two X servers, without a VM.
Maybe, one day, if I'll have too much free time.