Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebased iOS Metal support branch #369

Closed
wants to merge 9 commits into from

Conversation

username0x0a
Copy link

@username0x0a username0x0a commented Jul 12, 2022

TL;DR:

  • reconstructed metal-support branch
  • rebased on top of up-to-date main
  • reverted some rendering flow changes
    • so that it runs on the ± same code like the current metal-support branch
    • without crashes experienced in the current main which might be caused by the same set of changes
  • built around a bundled MetalANGLE.xcframework
    • binary with no need for building
    • stripped non-64-bit architectures
  • a couple of WIP commits with changes required to run the framework with basic features

In this state it's definitely not meant to be merged, more like added as an official branch after some polishing. Feel free to post suggestions & push improvements so that the Metal support could be pushed forward for once. 👍

From my experience, the Metal-backed runtime is quite smooth, yet I've experienced some FPS drops to ~40fps, maybe caused by the reverted rendering flow code & synchronisation of UIKit/CoreAnimation layers. Hopefully somebody way more experienced in OpenGL/Metal field will be able to help optimising it.

A couple of link references so that this PR gets some attention:

P.S.: When checking the code, skip the vendor folder as that currently contains the bundled MetalANGLE framework with quite heavy header files. 😅 That's why the abysmal +/- stats of this PR.

@username0x0a username0x0a force-pushed the metal-support-new branch 2 times, most recently from c4356be to b67639c Compare July 12, 2022 23:23
@username0x0a username0x0a changed the title Rebased Metal support branch Rebased iOS Metal support branch Jul 12, 2022
@roblabs
Copy link
Collaborator

roblabs commented Jul 13, 2022

I've kicked off the GitHub Action check(s). It looks like we will have a new branch called metal-support-new, which we can tag like we did with the Metal Support branch (example, ios-v5.13.0-pre.1).

I recommend that we lock the metal-support branch and let this new branch be the latest effort for Metal Support.

@ntadej
Copy link
Collaborator

ntadej commented Jul 13, 2022

I vote that we merge this into main, but this means we should not attach full MetalANGLE library. This can be an external dependency.

@username0x0a
Copy link
Author

username0x0a commented Jul 13, 2022

All [wip] comments are pretty much hackins which need to be addressed somehow, either in main as it's a general change (like non-64-bit dropping or invalid references) or by updating this PR.

MetalANGLE could be integrated either as a source (Git submodule) or as a precompiled binary (xcframework hosted somewhere), that's to be decided. I switched to the bundled binary so that I can provide it really optimised (and don't have to compile it all the time 💥). The size increase caused by it isn't really dramatical, in my MinSizeRel builds I even got a smaller footprint than with previously built Mapbox binaries, but somewhere I also seen an idea to only use what's needed from the MetalANGLE source to keep it as thin as possible – but that's definitely not necessary from the beginning & I'm also a bit skeptical that a significant part of MetalANGLE would be thrown away.

@@ -4,11 +4,7 @@

#include <mbgl/gl/renderable_resource.hpp>
Copy link

@nvanfleet nvanfleet Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this file should be renamed MGLMapView+OpenGL.mm

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is still pretty much OpenGL 🤔 it's really just the overriding header files and bundled MetalANGLE doing the transition magic. I think there's a plan to rewrite the SDK in native Metal, that would be a good opportunity for changes – till that time, the SDK is formally still OpenGL.

@nvanfleet
Copy link

nvanfleet commented Aug 17, 2022

I seems like platform/darwin/src/gl_functions.cpp and platform/darwin/src/headlessbackend_eagle.mm still have a dependency on OpenGLES. Is this something that needs to also be migrated to use Metal?

https://github.com/maplibre/maplibre-gl-native/blob/main/platform/darwin/src/gl_functions.cpp
https://github.com/maplibre/maplibre-gl-native/blob/main/platform/darwin/src/headless_backend_eagl.mm

@nvanfleet
Copy link

I tried out a build of this and I see the following things in the terminal. It seem to all come out of the SDK when the map is initially initialized. The SDK warnings require you to hook into collecting logs from the SDK itself but the other things appear to just appear in Xcode without that.

  • SDK Log Warning 1
filepath = "-[MGLStyle initWithRawStyle:stylable:]"
line = 121
filepath = "virtual bool mbgl::MGLCoreLoggingObserver::onRecord(mbgl::EventSeverity, mbgl::Event, int64_t, const std::string &)"
message = "[event]:OpenGL [code]:-1 [message]:Not using Vertex Array Objects"
  • SDK Log Warning 2 (see the line it refers to is different)
filepath = "-[MGLStyle initWithRawStyle:stylable:]"
line = 27
filepath = "virtual bool mbgl::MGLCoreLoggingObserver::onRecord(mbgl::EventSeverity, mbgl::Event, int64_t, const std::string &)"
message = "[event]:OpenGL [code]:-1 [message]:Not using Vertex Array Objects"
  • Terminal error
[Unknown process name] CGBitmapContextGetColorSpace: invalid context 0x2814edf80. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
  • Metal compiler warning 1
2022-09-14 15:32:16.621421-0700 Lyft[6245:469664] [Metal Compiler Warning] Warning: Compilation succeeded with: 
program_source:79:11: warning: unused variable '_uv_linesofar'
    float _uv_linesofar = (floor(in._ua_data.z / 4.0) + (in._ua_data.w * 64.0)) * 2.0;
          ^
  • Metal compiler warning 2 (see the line it refers to is different)
2022-09-14 15:32:16.897243-0700 Lyft[6245:469664] [Metal Compiler Warning] Warning: Compilation succeeded with: 

program_source:104:11: warning: unused variable '_uv_linesofar'
    float _uv_linesofar = (floor(in._ua_data.z / 4.0) + (in._ua_data.w * 64.0)) * 2.0;
          ^

@nvanfleet
Copy link

I also get a blue or black map on simulator. I'm not sure if you get that as well. On device it appears to work fine though.

@username0x0a username0x0a force-pushed the metal-support-new branch 2 times, most recently from 3871094 to 3203e75 Compare September 22, 2022 19:24
@username0x0a
Copy link
Author

username0x0a commented Sep 22, 2022

Thanks for your feedback, @nvanfleet!

Ad the vertex array warnings:

bool Context::supportsVertexArrays() const {
    // TODO: Metal: Metal does not work with vertex arrays.
    return false;
}
...
        if (!supportsVertexArrays()) {
            Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
        }

Citation from the WIP Metal code here, I'd say this warning could be just dropped at this point if linked against Metal? The guys will figure out.


Ad Metal/shader code warnings: I know about these, but I haven't yet found where these are stored, I'm suspecting these to be coded somewhere (possibly in some shared context) so I'm not sure how to handle that against all platforms – again, somebody smarter needs to do it right. 😄


Ad blue or black map: do you refer to the iosapp in the MapLibre project? 🤔 The provided default styles can't resolve the domain at this point so you'd probably need to provide some working style instead. But last time I tested it, those styles worked (before domain was unreachable), the same goes to our internal (heavily customised) style. 👌

Update: the up-to-date MapLibre Basic style works, in terms of showing something relevant when running. 😄 The branch is now rebased with it.


My job here (for our project's purpose) is just to make it buildable & usable while considering its state at this point, but I'm sure MapLibre guys will polish it as needed. 👌

@username0x0a
Copy link
Author

username0x0a commented Sep 23, 2022

Rebased once again, replacing the bundled MetalANGLE.xcframework with a wrapping Swift package referencing it as a binary target so that the Pull request content is reduced to a necessary minimum for further polishing & optimisation. 👌

Later on, it would probably be best to include MetalANGLE directly as a submodule & bake it right into the library (it builds pretty fast, at least on my M2 Air 😅) so that there's minimal overhead & both static and dynamic libraries are full-fledged in all cases with no another framework to carry around/embed.

@louwers
Copy link
Collaborator

louwers commented Jun 7, 2023

Please see the proposals below for the design of the upcoming Metal support:

A team of graphics engineers is implementing this approach right now in favour of MetalANGLE, so I don't think it makes sense to merge this at this point in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants