How to Change an Android Device's Resolution with ADB, and What It's Good For
Hello. I'm Hirayama from the Technology Department.
Today's topic is simply that
adb shell wm size 360x640
sets the resolution of an Android device connected via USB to 360x640.
The rest of this article is about why that's useful. For the how-to itself, you're probably better off with the sites that come up when you search for "ADB resolution".
Motivation
Lately I've been playing a fair number of casual games, and casual as they may be, many of them demand a lot of performance.
My Kyocera S2 is from 2017, so it's not that old, and its OS is Android 9, but its GPU performance is pretty hopeless. When Unity's standard shader draws the full screen (1280x720), it's guaranteed to drop below 30fps. Yet many casual games are hard to play at a low frame rate, so played as is, they're completely unplayable.
But if I could lower the resolution, things should improve. I looked up how, and the answer came up right away: the command above. Depending on the game, halving the resolution both horizontally and vertically can even quadruple the frame rate, just as theory says.
Casual games are just my own personal situation, but naturally this is useful for development too.
When a game is slow, the first thing to check is "fill"
When a game isn't hitting its frame rate, the very first thing to check is "whether it's caused by fill (= fragment shader processing) or not". Profiling can wait; fill comes first (though some may disagree). Why?
Because the difference in GPU performance is much bigger than the difference in CPU performance.
As I showed with numbers in an earlier benchmark article, the CPU performance difference between cheap and high-end devices is only about 5x at most, but for GPUs it can be dozens of times. Things like "a 50,000 yen device is 5 times faster than a 30,000 yen device, and a 100,000 yen device is 5 times faster than a 50,000 yen device" really happen, and that alone already makes a 25x performance difference.
Even if you profile, find the slow parts and fix them, it's rare to get as much as double the speed, and on a device with a slow GPU, no amount of CPU tweaking will help. If anything, I think the main purpose of CPU-side profiling is to find "load spikes", where "just this one frame is massively slow". If you want to raise the frame rate, the GPU comes first, by far.
An easy way to check whether it's fill
So how can you find out "whether the slowdown is caused by fill"?
Lower the resolution. If the frame rate goes up, you know it's because of fill. Lowering the resolution with adb lets you try this in tens of seconds. It's the best way.
Adding Screen.SetResolution() and making a build takes more than 10 minutes, and to try various resolutions you'd have to add debug features or rebuild.
Changing the resolution in the editor is easy, since you just change the Game view settings, but the editor runs on a PC, whose performance differs from a smartphone's.
With ADB, you can see it on the real device right away.
What's more, you can try it even on apps you didn't develop yourself. Just take an app you installed the normal way and play it at a few resolutions. Even without a frame rate display, you can roughly tell whether the frame rate is 60, 30 or 20. I tried it with several games, and in many of them, lowering the resolution raised the frame rate considerably. In other words, those games were dropping frames because the GPU wasn't fast enough. You can tell, without even looking at the code, that making the fragment shader work cheaper should raise the frame rate.
If it turns out to be fill
If this test shows that "the frame rate was dropping because of fill", what should you do?
One option is to "lower the product's resolution". As I wrote in an earlier article on the Fixed DPI setting, capping the resolution is a crude but low-cost measure. If you want to do it more properly, it's better to use Screen.SetResolution() and let players set it.
Of course, there's also the path of "optimizing properly": making shaders cheaper, reducing overdraw, and in some cases implementing feature toggles based on the device's performance. It's an unglamorous, costly path. In this case, changing the resolution also gives you an immediate estimate of "how many times faster it needs to be". You just see how far the resolution has to drop to reach the target FPS. If 1280x720 isn't enough and it reaches 60fps at 960x540, you can guess that making it about 1.8 times faster would let it hit 60fps at the original resolution. If at that point you think "nope, that's impossible", you'll lower the resolution or the target frame rate instead.
And if it doesn't reach the target "no matter how far you lower the resolution", you know the problem lies somewhere other than fill. For example, if there are too many DrawCalls and the CPU is the bottleneck, it won't get faster beyond a certain point however far you lower the resolution. Even then, you learn where the limits lie, like "with the current CPU load, lowering the resolution any further is pointless" and "with the current CPU load, speeding up pixel processing more than x times is pointless", and that's useful in its own way.
Guidelines for when it's not fill
While I'm at it, here's a list of things to suspect when "the problem wasn't fill after all".
- GPU
- Vertex processing. Are there too many vertices?
- CPU
- DrawCalls, SetPass calls and so on
- Scripts
- Physics
If you don't recall drawing an absurd number of vertices, it's almost certainly the CPU. That's when the profiler comes in. All you can do is pray that you find an obvious mistake you can fix right away.
Summary of related commands
You can find these in other articles, but for convenience, here are the related commands.
adb shell wm size
Shows the default size and the current setting.
adb shell wm size 360x640
Sets the resolution. By the way, 360x640 is my favorite; my impression is that it's about the lowest resolution at which you can still make out the pictures. Twitter and Slack are mostly usable too.
adb shell wm density
Shows the default and current pixel density. For example, on my device the default is 320. When I set the resolution to 360x640, lowering this to 160 with the next command makes the home screen layout the same as before.
adb shell wm density 160
Sets the pixel density. If you lower the resolution without changing this as well, the layout of the home screen and other screens changes.
In closing
My smartphone's original resolution is 720x1280, but I've been using it at 360x640 for over a week now. Otherwise games don't run properly. What's interesting is that casual games are overwhelmingly harder on it than the lavish games made by big companies. Slack and Twitter look rough, but I've gotten used to it. Game graphics look rough too, but that's better than a low frame rate.
The next time I replace my device, the resolution will probably exceed 1920x1080. Tall, narrow screens are in fashion lately, so it might be something like 2160x1080. Compared with the current 1280x720, that's more than twice the pixels, but as things stand, it's doubtful whether device performance will go up even 1.5 times, let alone 2. So I'll probably end up with a lower frame rate because I replaced my device.
I'd be grateful if game developers knew that brand-new devices that can't run games unless you lower their resolution with ADB are being sold as if that were perfectly normal. I'd also like it to be widely known that OS version and amount of memory have almost nothing to do with performance. Plenty of machines run Android 9 with 3GB of memory and still have a feeble GPU, and yet the one thing they do have is a high resolution. On that subject, the talk at CEDEC 2019 (direct link to the PPTX file) on tri-Ace's site should be a good reference (I'd love it if they put it on SlideShare!).
By the way, some of you may be thinking "Why are you so fixated on such a cheap device?"
It's not that I don't want to buy an expensive device. It's because I can say with 100% certainty that if I bought a high-end device, I'd lose interest in optimization. And because most people around me use iPhones, and hardly anyone uses a low-performance Android device day to day.
If everyone on the team had high-end devices, their sense of things would definitely get skewed. You may understand low-performance devices in your head, but you don't get them in your gut. Unless you actually feel the frustration yourself, you never get that sense of urgency: "we have to fix this! It's unplayable!"
Admittedly, I feel I could use something with a bit more performance. People using devices at this level probably don't play games. After all, they can't play without using ADB.
But looked at the other way, it also means that if you can make a game run comfortably even at this level, more players might play it, and I don't think that's all that hard. Especially for casual games.
Incidentally, the Kyocera S2 is really tough: it was fine after going under in the bath, it doesn't get hot, and I'm very fond of it. Come to think of it, I've been using Kyocera ever since the PHS days.