You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All operating systems have comparable performance when running on comparable hardware.
Actual result
Several people are reporting that the macOS version of OpenTTD has unreasonably poor performance, and the framerate window does not reveal any obvious reason.
This bug covers the situation when all of the following occur at the same time:
Game is running on macOS
Frame rate on a new game (256x256) with no mods is below 30 fps (typically even below 10 fps)
Sum of "Game loop", "Drawing" and "Video output" times in the Frame rate window is below 10 ms
Toggling "Full animation" does not have a significant impact on performance
Note that this is not related to #7247, as this bug manifests even when there are zero vehicles in game. The poor performance is also caused by something not being measured, since the sum of the game loop, drawing, and video output times do not add up to the time it should to cause the total frame rate.
Steps to reproduce
Run official OpenTTD builds on a macOS 10.14 system.
Reacted by Dima, László, Kevin Schiffer, Logan Giorda, Charles Fulton, Sven Mayer and Tomas Nesrovnal
Reacted by Romain Quencez, Ivan, Glenn Jacobsen, László, Kevin Schiffer, Logan Giorda and Thomas
The total frame time budget in OpenTTD is 30 ms. The target frame rate is 33.33 fps, which is reached by having on average 30 ms between each frame.
This means that as long as the total of game loop (time taken simulating the game world), drawing (time producing the graphics for display on screen), and video output (time taken copying the produced graphics to the OS display driver) is less than 30 ms, the frame rate should be roughly 33.33 fps, when not in fast-forward mode.
Converting frame rate to frame time: ft = 1000 / fps
Converting frame time to frame rate: fps = 1000 / ft
When not in fast-forward mode, the OpenTTD "video driver" component inserts delays between frames to reach an average of 30 ms frame time.
When fast-forward mode is enabled, these delays are not inserted and instead the game is simulated and drawn as fast as the computer can handle.
Example, taken from times measured on my Windows system running 1.9.2 64 bit:
Frame rate on the title screen is about 32.96 fps, so the frame time is about 30.33 ms
The game loop, drawing, and video output times are 0.50 ms, 2.62 ms, 2.50 ms, the sum is 5.62 ms, so if I could enable fast-forward on the title screen, the expected rate would be at least 177.94 fps.
The actual rate in fast-forward mode can be higher, since a recent change allows multiple game ticks to be simulated between each draw, so the total game loop rate might end up closer to 2000 fps.
The frame rate window (and fps console command) also display a line for Sound mixing, this is generally not relevant, since sound mixing is run in a separate thread. It should never affect total frame rate. (It could get relevant if someone reported crackling/popping sound.)
ProductName: Mac OS X
ProductVersion: 10.14.5
BuildVersion: 18F132
1.8.0
No issues
Both with Full Animation Enabled or Disabled the game runs smoothly. (No fps command in 1.8.0)
1.9.0
Full animation Enabled:
Game loop rate: 14.94fps (expected 33.33fps)
Drawing rate: 14.96fps (expected 33.33fps)
Video output rate: 35.99fps (expected 60.00fps)
Full animation Disabled:
Game loop rate: 29.18fps (expected 33.33fps)
Drawing rate: 29.28fps (expected 33.33fps)
Video output rate: 155.36fps (expected 60.00fps)
1.9.2
Full animation Enabled:
Game loop rate: 14.70fps (expected 33.33fps)
Drawing rate: 14.66fps (expected 33.33fps)
Video output rate: 54.38fps (expected 60.00fps)
Full animation Disabled:
Game loop rate: 30.87fps (expected 33.33fps)
Drawing rate: 30.88fps (expected 33.33fps)
Video output rate: 195.84fps (expected 60.00fps)
I'd like to add that this only occurs when playing full-screen or full window. If I reduce the window size to 1/4 of the screen, the FPS increases to ~30.
OpenTTD is causing color space / pixel format conversion in the background. Likely due to mismatch of backing surface format chosen by OpenTTD and native surface format of the display/OS.
The slowdown scales with OpenTTD resolution and Mac machine's high resolution exacerbates the problem. This format/color space conversion happens on OpenTTDs main thread after a call to CGContextDrawImageWithOptions.
I don't have time to look at this in the source, but that is where the problem comes from. Perhaps these pointers are enough information?
So if the rendering was changed to use explicit GPU acceleration instead of blitting 2D surfaces, it might resolve the issue? Since the GPU could receive texture data in our native pixel format, and a shader could convert it as necessary.
You could indeed switch to a MTKView (or other Metal view) and use Metal to do the transfer while having a shader convert the image to the final format. This would work just fine.
Though I don't think you have to do it via Metal as it should be possible to set things up correctly without requiring Metal. This new behaviour likely has to do with changes to Layer Backed Views introduced in 10.14 SDK, I'll see if I can find out what exactly introduces the observed behavior.
In the end it's just a choice but I could imagine not wanting to introduce a new dependency if it's not necessary.
Trying to track this down but having issues getting a build working. Built master repo without any compression libs, build succeeded, but when executing I immediately encounter an error in libdyld: stack_not_16_byte_aligned.
Probably missing some steps getting the build running. Can dig further if someone can help me out here :)
Anything I can test?
If anything I can at least confirm the issue on a 5K iMac 2019 - 1.9.2 is unplayable, 1.8.0 seems to work as normal (but slower with 1440p resolution, which might actually be twice the resolution due to Retina)
I see this issue just got closed, but I don't understand why. I tested this fix and it didn't work for me. The last commit that got added is identical to the one I tested. Has anyone else tested it?
That's weird, because the patch definitely did not bring back 1.8.0 performance for me, to the point where I could tell with the naked eye easily. Did anybody else test it? And did they get the same performance as 1.8.0 or simply "better" performance without being too specific? I'm sorry if I sound a bit disappointed. I can log the difference in FPS to get hard numbers for this.
The difference in colors in the screenshot is an example of colors being interpreted as the wrong profile. The screenshot has "Display P3" as the embedded profile which is the user's system profile. Here's what happens when I take the left half of the image into Photoshop, convert it to sRGB, and then assign it the Display P3 profile without converting the color values:
They look identical again (minus some loss from the conversion roundtrip). The color differences could be greater or smaller than that of the user who posted the original image, depending on what color profile they use.
I am happy in principle to have this or another issue open.
It would be helpful though to have quantified the issues. It's unclear whether there is one mac performance issue or several.
Apple is pretty much the only vendor where we can rely on there being 2 OS versions and only a handful of hardware versions :)
It should be possible to categorise and reproduce the issues more reliably. :) Currently we lack consistency, e.g. a common set of FPS numbers on a common set of savegames (or something like that).
It needs to generate clear diagnostics and results.
Testers need to accurately report hardware version, software versions, and display configuration the game is running on.
Need to use a known config file for the game so settings like resolution, blitter, news messages, and full animation don't affect different testers' results differently.
Probably involves running the game with the dummy video driver on a known savegame, for some number of ticks, to get the hardware's simulation rate capability when no graphics is involved. Then compare loading the same savegame in graphical mode and look at performance numbers.
It would be helpful though to have quantified the issues. It's unclear whether there is one mac performance issue or several.
You're absolutely right.
I'm sorry to say I tried to get some numbers on this but I haven't quite gotten them yet, because I tried to compile 1.8.0 to have a baseline and somehow that one doesn't run well on my system either (the official release does). It ran basically like the 1.9.0 release. So I'm not sure what's going on. I need to investigate this further.
I'd love to help out in some way so I'll be looking into this when I've got some more time. 🙂
Well, the official 1.8.0 release was build using a very old cross-compiler using and targeting the 10.6 (or maybe even 10.5) SDK. The current builds are done with a real native compiler on Azure infrastructure, using a SDK 10.10+ (not sure which exact versions Azure provides).
It it entirely possible that macOS exhibits different app compatibility changes depending on the OS version the app was compiled against.
Activity
andythenorth commentedon Jul 8, 2019
This manifests for me on Mojave (10.14) and did not occur on High Sierra (10.13).
Notably:
nielsmh commentedon Jul 8, 2019
Some additional notes:
Example, taken from times measured on my Windows system running 1.9.2 64 bit:
The frame rate window (and fps console command) also display a line for Sound mixing, this is generally not relevant, since sound mixing is run in a separate thread. It should never affect total frame rate. (It could get relevant if someone reported crackling/popping sound.)
wousser commentedon Jul 9, 2019
As requested:
1.8.0
No issues
Both with Full Animation Enabled or Disabled the game runs smoothly. (No fps command in 1.8.0)
1.9.0
Full animation Enabled:
Full animation Disabled:
1.9.2
Full animation Enabled:
Full animation Disabled:
I'd like to add that this only occurs when playing full-screen or full window. If I reduce the window size to 1/4 of the screen, the FPS increases to ~30.
drebroff commentedon Jul 12, 2019
Confirm
ProductName: Mac OS X
ProductVersion: 10.14.5
MacBook Pro 15 2017
AbeWJS commentedon Aug 16, 2019
OpenTTD is causing color space / pixel format conversion in the background. Likely due to mismatch of backing surface format chosen by OpenTTD and native surface format of the display/OS.
The slowdown scales with OpenTTD resolution and Mac machine's high resolution exacerbates the problem. This format/color space conversion happens on OpenTTDs main thread after a call to CGContextDrawImageWithOptions.
I don't have time to look at this in the source, but that is where the problem comes from. Perhaps these pointers are enough information?
andythenorth commentedon Aug 16, 2019
I don't have any skills in Mac debugging, but I used Apple instructions to set up an Instruments run, long paste of results here: https://paste.openttdcoop.org/pef0g4kgn/mnd7ty/raw
TL;DR
A cursory google search turns up a few other people with similar issue, nothing conclusive
Apple developer guide is here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaViewsGuide/Optimizing/Optimizing.html#//apple_ref/doc/uid/TP40002978-CH11-SW4
My results are for macOS 10.14, on a 2.7Ghz i7
nielsmh commentedon Aug 16, 2019
So if the rendering was changed to use explicit GPU acceleration instead of blitting 2D surfaces, it might resolve the issue? Since the GPU could receive texture data in our native pixel format, and a shader could convert it as necessary.
SoothedTau commentedon Aug 16, 2019
@nielsmh
You could indeed switch to a MTKView (or other Metal view) and use Metal to do the transfer while having a shader convert the image to the final format. This would work just fine.
Though I don't think you have to do it via Metal as it should be possible to set things up correctly without requiring Metal. This new behaviour likely has to do with changes to Layer Backed Views introduced in 10.14 SDK, I'll see if I can find out what exactly introduces the observed behavior.
In the end it's just a choice but I could imagine not wanting to introduce a new dependency if it's not necessary.
nielsmh commentedon Aug 16, 2019
I think we definitely want to support macOS versions as far back as reasonably possible, at least not having hard dependencies on newer features.
faeton commentedon Aug 21, 2019
Just wanted to confirm here that the issue is important and in place. Tested on 10.14 and 10.13 both showing bad results, low fps, mouse pointer lags.
SoothedTau commentedon Aug 22, 2019
Trying to track this down but having issues getting a build working. Built master repo without any compression libs, build succeeded, but when executing I immediately encounter an error in libdyld: stack_not_16_byte_aligned.
Probably missing some steps getting the build running. Can dig further if someone can help me out here :)
DIYglenn commentedon Aug 23, 2019
Anything I can test?
If anything I can at least confirm the issue on a 5K iMac 2019 - 1.9.2 is unplayable, 1.8.0 seems to work as normal (but slower with 1440p resolution, which might actually be twice the resolution due to Retina)
101 remaining items
msikma commentedon Mar 31, 2020
I see this issue just got closed, but I don't understand why. I tested this fix and it didn't work for me. The last commit that got added is identical to the one I tested. Has anyone else tested it?
andythenorth commentedon Mar 31, 2020
I commented on the pull request here #8023 (comment)
TL;DR. For me:
Fix #7644: [Cocoa] Manually set colorspace to sRGB
msikma commentedon Mar 31, 2020
That's weird, because the patch definitely did not bring back 1.8.0 performance for me, to the point where I could tell with the naked eye easily. Did anybody else test it? And did they get the same performance as 1.8.0 or simply "better" performance without being too specific? I'm sorry if I sound a bit disappointed. I can log the difference in FPS to get hard numbers for this.
The difference in colors in the screenshot is an example of colors being interpreted as the wrong profile. The screenshot has "Display P3" as the embedded profile which is the user's system profile. Here's what happens when I take the left half of the image into Photoshop, convert it to sRGB, and then assign it the Display P3 profile without converting the color values:
They look identical again (minus some loss from the conversion roundtrip). The color differences could be greater or smaller than that of the user who posted the original image, depending on what color profile they use.
spauka commentedon Apr 2, 2020
FWIW I think it might be worth reopening this issue, or opening a new issue regarding the colorspace issue and continuing performance problems on OSX.
The patch above makes the game playable but it does seem to fix all the issues that have been raised...
nielsmh commentedon Apr 3, 2020
I think it would be a better use of time to work on an OpenGL based renderer which would most likely avoid all these issues.
andythenorth commentedon Apr 3, 2020
I am happy in principle to have this or another issue open.
It would be helpful though to have quantified the issues. It's unclear whether there is one mac performance issue or several.
Apple is pretty much the only vendor where we can rely on there being 2 OS versions and only a handful of hardware versions :)
It should be possible to categorise and reproduce the issues more reliably. :) Currently we lack consistency, e.g. a common set of FPS numbers on a common set of savegames (or something like that).
nielsmh commentedon Apr 3, 2020
Ideas for what might be a useful test:
SoothedTau commentedon Apr 3, 2020
OpenGL is deprecated on macOS. I wouldn't recommend developing new features with it.
msikma commentedon Apr 6, 2020
You're absolutely right.
I'm sorry to say I tried to get some numbers on this but I haven't quite gotten them yet, because I tried to compile 1.8.0 to have a baseline and somehow that one doesn't run well on my system either (the official release does). It ran basically like the 1.9.0 release. So I'm not sure what's going on. I need to investigate this further.
I'd love to help out in some way so I'll be looking into this when I've got some more time. 🙂
michicc commentedon Apr 6, 2020
Well, the official 1.8.0 release was build using a very old cross-compiler using and targeting the 10.6 (or maybe even 10.5) SDK. The current builds are done with a real native compiler on Azure infrastructure, using a SDK 10.10+ (not sure which exact versions Azure provides).
It it entirely possible that macOS exhibits different app compatibility changes depending on the OS version the app was compiled against.
msikma commentedon Apr 8, 2020
Yeah, that's what I was thinking too. Could it be that this bug is really a result of SDK changes?
I'll look into compiling with an older SDK to see what happens.
Fix: change Quartz driver colorSpace handling to address certain macO…
Fix OpenTTD#7644: [OSX] Try to use system colour space to avoid video…
Fix OpenTTD#7644: [Cocoa] Manually set colorspace to sRGB