godot icon indicating copy to clipboard operation
godot copied to clipboard

iOS Mobile Renderer Black Screen

Open TCROC opened this issue 1 year ago • 27 comments

Tested versions

  • Reproduceable In: 4.4.dev.mono.custom_build.f0e971730

System information

Godot v4.4.dev.mono (f0e971730) - macOS 15.0.1 - Multi-window, 1 monitor - Metal (Forward+) - integrated Apple M2 (Apple8) - Apple M2 (8 threads)

Issue description

When exporting to iOS set to use the mobile renderer, it renders with a black screen:

Image

When exporting to iOS set to use the Forward+ renderer, it renders just fine:

Image

Here are the respective logs:

Note

The Forward+ Renderer Log has many errors, but that is the one that actually renders correctly. The Mobile Renderer log only has 1 error, but renders with a black screen.

Mobile Renderer Log

Godot Engine v4.4.dev.mono.custom_build.f0e971730 (2024-11-16 22:16:24 UTC) - https://godotengine.org
Metal 3.1 - Forward Mobile - Using Device #0: Apple - Apple A12 GPU (Apple5)

ERROR: Mouse is not supported by this display server.
at: mouse_get_position (servers/display_server.cpp:508)

Forward+ Renderer Log

forward_plus_log.txt

Steps to reproduce

  1. Use Godot with double precision and mono support.
    • I'm not certain if this is necessary as I haven't tested other builds, but that is what I am currently using.
  2. Open the MRP
  3. Export to iOS
  4. Install to an iPhone
  5. See that a black screen renders
  6. Change project settings mobile rendering method to Forward+
  7. Export to IOS
  8. Install to an iPhone
  9. See that cube renders

Minimal reproduction project (MRP)

mrp.zip

Edit:

Here's the table of tested snapshots:

✅ = ~vulkan~ mobile works as expected ❌ = ~vulkan~ mobile blank screen

Version Status
4.3.stable
4.4-dev1
4.4-dev2 ?
4.4-dev3 ?
4.4-dev4 ?
4.4-dev5

Edit:

I crossed out ~vulkan~ above. @bruvzg pointed out here that we are actually defaulting to the metal rendering device on ios now. Changing it back to use Vulkan in the project settings as described in that comment makes the MRP work. So it appears to be specifically related to the metal driver introduced in this pr: https://github.com/godotengine/godot/pull/88199

TCROC avatar Nov 25 '24 15:11 TCROC

Can you reproduce this on 4.3.stable?

Calinou avatar Nov 25 '24 15:11 Calinou

I will go check

TCROC avatar Nov 25 '24 15:11 TCROC

I initially tried to test in 4.3 by building from source but was unable to because my Mac OS received an LLVM update. And this version of LLVM can no longer compile code prior to that fix we put in a while back where LLVM rolled out some breaking changes. But I do have good news! I was able to reproduce the issue with dev snapshots and confirm that things work as expected in 4.3-stable. So this is indeed a regression. I'm going to start bisecting, but there is the table of what I have tested so far:

✅ = vulkan mobile works as expected ❌ = vulkan mobile blank screen ? = untested

Version Status
4.3.stable
4.4-dev1 ?
4.4-dev2 ?
4.4-dev3 ?
4.4-dev4 ?
4.4-dev5

TCROC avatar Nov 25 '24 19:11 TCROC

Also note that I reproduced this with normal Godot. It occurred in the 4.4-dev5 snapshot without mono support. And I believe those snapshots do not have double precision either right? Which would lead me to believe this issue is not related to mono support or double precision.

TCROC avatar Nov 25 '24 19:11 TCROC

Version Status
4.3.stable
4.4-dev1
4.4-dev2 ?
4.4-dev3 ?
4.4-dev4 ?
4.4-dev5

So it was first introduced somewhere between 4.3.stable and 4.4-dev1.

@Calinou I found where it was introduced in regards to snapshots :).

TCROC avatar Nov 25 '24 21:11 TCROC

Metal 3.1 - Forward Mobile - Using Device #0: Apple - Apple A12 GPU (Apple5)

Default backend for Mobile/Forward+ on macOS and iOS was changed to new Metal renderer. While Vulkan renderer should support A12 (it is the oldest SOC it should run on), I'm not sure what's the minimum requirement for Metal renderer. Try setting rendering/rendering_device/driver.ios in the project settings to vulkan.

bruvzg avatar Nov 26 '24 09:11 bruvzg

@bruvzg I will give this a shot

@Calinou I bisected and found the PR that introduced this issue. Looks like it @stuartcarnie 's pr here: https://github.com/godotengine/godot/pull/88199

Thank you btw @stuartcarnie for the metal support! I love getting as close to the native drivers for target platforms as possible! :). I just believe I may have found an issue with this PR that introduces black screen on ios.

TCROC avatar Nov 26 '24 15:11 TCROC

@bruvzg I can confirm that changing the rendering_device/driver.ios back to vulkan fixes and is a workaround while the metal renderer is being debugged :)

TCROC avatar Nov 26 '24 16:11 TCROC

For the reference, Metal render seems to be working fine on A14 (10. gen. iPad) and M4 Pro. Unlike A12, these devices have Metal 3.2 printed when starting, not Metal 3.1. So this might be the requirement.

Metal 3.1 - Forward Mobile - Using Device #0: Apple - Apple A12 GPU (Apple5)

Metal 3.2 - Forward Mobile - Using Device #0: Apple - Apple A14 GPU (Apple7)
Metal 3.2 - Forward+ - Using Device #0: Apple - Apple M4 Pro (Apple9)

Officially supported Metal 3 devices are A12X/A13+, so base A12 might be too old and have incomplete Metal implementation. We probably should update documentation with new min. system requirements for Metal renderer.

bruvzg avatar Nov 27 '24 09:11 bruvzg

@bruvzg Should we have it automatically fall back to Vulkan if we detect at startup that it is the old one?

Also something to note, Forward+ works without issue. I was only having issues with the Mobile renderer

TCROC avatar Nov 27 '24 18:11 TCROC

Should we have it automatically fall back to Vulkan if we detect at startup that it is the old one?

Yes, but currently fallback only works if a specific renderer is completely missing, in this case renderer init works, but shader compiler fails.

Also something to note, Forward+ works without issue. I was only having issues with the Mobile renderer

In this case, it probably is a Metal renderer bug, not a hardware limitation.

bruvzg avatar Nov 27 '24 18:11 bruvzg

I tried the 2D lights and shadows demo, as I already had that setup, and it is still working with the Forward Mobile renderer, but Forward+ is definitely returning a lot of errors, so I don't believe it is working without issue. I'll try your MRP next.

stuartcarnie avatar Nov 27 '24 19:11 stuartcarnie

For some extra info, my phone is:

iOS Version: 17.6.1
Model Name: iPhone XR
Model Number: MT362LL/A

TCROC avatar Nov 27 '24 20:11 TCROC

Also something to note, Forward+ works without issue. I was only having issues with the Mobile renderer

In this case, it probably is a Metal renderer bug, not a hardware limitation.

Forward+ is not working correctly, as many of the pipelines are failing to compile, which are in the logs @TCROC included. I was able to replicate that on my iPhone 13. I'll have to take a look and see why it's failing, as I expect it should work.

I'm mostly interested in why the mobile renderer isn't working for you, as there are no logs and no errors / warnings suggesting it is even compiling anything.

stuartcarnie avatar Nov 27 '24 20:11 stuartcarnie

Also something to note, Forward+ works without issue. I was only having issues with the Mobile renderer

In this case, it probably is a Metal renderer bug, not a hardware limitation.

Forward+ is not working correctly, as many of the pipelines are failing to compile, which are in the logs @TCROC included. I was able to replicate that on my iPhone 13. I'll have to take a look and see why it's failing, as I expect it should work.

I'm mostly interested in why the mobile renderer isn't working for you, as there are no logs and no errors / warnings suggesting it is even compiling anything.

Did the MRP work on your iPhone 13 with mobile renderer?

TCROC avatar Nov 27 '24 20:11 TCROC

Did the MRP work on your iPhone 13 with mobile renderer?

Just trying that now

stuartcarnie avatar Nov 27 '24 20:11 stuartcarnie

It is reproducible – the issue is in the Metal renderer and related to how SPIRV-Cross generates the shader interface for iOS vs macOS for certain shaders. Turns out that the mobile renderer is also partially rendering (like Forward+), a full-screen quad is rendering black for mobile.

stuartcarnie avatar Nov 28 '24 20:11 stuartcarnie

Perfect! Thank you for reproducing @stuartcarnie! And happy Thanksgiving if you celebrate it! :) I guess we can update the tags now that it has been confirmed :)

TCROC avatar Nov 28 '24 21:11 TCROC

Fix coming via #99820

stuartcarnie avatar Nov 29 '24 04:11 stuartcarnie

@stuartcarnie I'm not saying you are "the man". But if the "the man" were to hypothetically exist, he would likely look something like you 😎

I'll try out your PR in my fork in the morning! 🔥

TCROC avatar Nov 29 '24 05:11 TCROC

@TCROC I think I see that you have an Apple5 GPU device (2018), which is unfortunately too low for the change I had to make. The minimum version is now an Apple6 family GPU, which is from 2019. SPIRV-Cross has some issues with mixing Apple GPU features between Apple5 and Apple6 era GPUs, which directly affect the Metal renderer 😔

~~I'm hoping we can support some sort of automatic fall-back to MoltenVK.~~

I'm going to investigate adding support for 2017+ era devices in a separate PR.

stuartcarnie avatar Nov 29 '24 05:11 stuartcarnie

@stuartcarnie Perfect! Let me know what solution you come to and I'll gladly test it out :) Thank you! You are the best! :)

TCROC avatar Nov 29 '24 14:11 TCROC

Version Status
4.3.stable
4.4-dev1
4.4-dev2
4.4-dev3 ?
4.4-dev4 ?
4.4-dev5
4.4-dev6


hi, I trying export on iPhone14 to iOS , and black screen too. Metal.

Provisioning in export not working too in 4.4dev-. Must set it / correct on xcode project, error in log when exporting. Editor export not using dev id. Id is correct. in 4.3 stable is ok, works.

maxelusgit avatar Dec 10 '24 11:12 maxelusgit

@maxelusgit try changing your rendering driver to vulkan:

Image

TCROC avatar Dec 12 '24 00:12 TCROC

@TCROC thx, yes, on vulkan works 😀

maxelusgit avatar Dec 12 '24 07:12 maxelusgit

@TCROC #99820 will now support your iPhone

stuartcarnie avatar Dec 15 '24 18:12 stuartcarnie

@stuartcarnie perfect! I'll try that tomorrow :)

TCROC avatar Dec 15 '24 18:12 TCROC

In my tests...

using Metal: now :

  • Node2D is visible (my gui, joysticks on screen ...)

  • Node3D or all 3d is - BLACK

before :

  • all BLACK

using Volkan :

  • all visible

maxelusgit avatar Dec 16 '24 13:12 maxelusgit

@maxelusgit do you have a MRP we can look at, as that will help us troubleshoot the problem. It is also likely a separate issue, as an iPhone 14 should be a Tier 2 device and won't use the new code path

stuartcarnie avatar Dec 16 '24 17:12 stuartcarnie

@maxelusgit you should also clear out your Godot shader_cache directory.

stuartcarnie avatar Dec 17 '24 14:12 stuartcarnie