简体   繁体   English

iOS 14 解决方案中的 SceneKit Metal 着色器编译性能错误

[英]SceneKit Metal shader compilation performance bug in iOS 14 workaround ideas

I'm looking for a SceneKit expert to suggest some way to work around the bad performance bug in SceneKit's built-in Metal shader compilation in iOS 14.x and macOS Catalyst 11.x.我正在寻找 SceneKit 专家来建议一些方法来解决 iOS 14.x 和 macOS Catalyst 11.x 中 SceneKit 的内置 Metal 着色器编译中的不良性能错误。 Since I've tried everything I can think of to get Apple to fix the problem (TSI, Feedback, Twitter, Developer Forums, Apple Evangelist), we need a workaround.由于我已经尝试了所有我能想到的方法来让 Apple 解决问题(TSI、反馈、Twitter、开发者论坛、Apple Evangelist),我们需要一个解决方法。

Using the Xcode Instruments app with SceneKit tracing, it appears that SceneKit shader compilation can about 100x slower in iOS 14.0, 14.1 and 14.2 Beta (including Beta 4) vs. iOS 13.7.使用带有 SceneKit 跟踪功能的 Xcode Instruments 应用程序,在 iOS 14.0、14.1 和 14.2 Beta(包括 Beta 4)中,SceneKit 着色器编译似乎比 iOS 13.7 慢了大约 100 倍。 For example, it typically takes SceneKit 1-2ms to compile a shader in iOS 13.7 whereas it can take as much as 200ms in iOS 14.例如,在 iOS 13.7 中编译着色器通常需要 SceneKit 1-2 毫秒,而在 iOS 14 中可能需要多达 200 毫秒。

SceneKit appears to automatically compile a shader each time we add a new model node tree to a parent node in a visible scene.每次我们向可见场景中的父节点添加新模型节点树时,SceneKit 似乎都会自动编译着色器。

Loading a typical SceneKit scene of dozens of model nodes in our app can go from taking less than 2 seconds to well over 30 seconds.在我们的应用程序中加载几十个模型节点的典型 SceneKit 场景可以从不到 2 秒到超过 30 秒。 And since SceneKit shader compilation occurs on the render thread which which appears to be invoked by a CADisplayLink handler, the entire app UI can be completely frozen for many seconds (30+ in testing).由于 SceneKit 着色器编译发生在似乎由 CADisplayLink 处理程序调用的渲染线程上,因此整个应用程序 UI 可能会完全冻结数秒(测试中为 30+)。 This drastically affects the usability of our SceneKit-based app.这极大地影响了我们基于 SceneKit 的应用程序的可用性。

And if you consider that to get anything like 60-30 fps scene updating, you need to spend no more than 16-33 msec per frame to avoid frame drops, spending 200 msec each for many frames is really bad.如果您认为要获得 60-30 fps 的场景更新,您需要每帧花费不超过 16-33 毫秒以避免丢帧,多帧每花费 200 毫秒真的很糟糕。 (And if you're trying to get 120 fps on an iPad Pro...) (如果您想在 iPad Pro 上获得 120 fps...)

One issue with this is bug is that it's very inconsistent: I can do one run of the app with Instruments and the compile times will be fine (1-2 msec) and I'll do another few runs and it will be bad for each shader compile (100-200 msec).这个问题的一个问题是它非常不一致:我可以用 Instruments 运行一次应用程序,编译时间会很好(1-2 毫秒),我会再运行几次,每次运行都会很糟糕着色器编译(100-200 毫秒)。 I think there is some Metal shader caching going on, but I don't know how it works and what causes it to be invalidated.我认为有一些 Metal 着色器缓存正在进行,但我不知道它是如何工作的以及是什么导致它失效。

I've tried dozens of ways to work around this: multiple queues/threads/operations, transactions, deferring node adds to add multiple nodes at once, using perform (avoid: fatal crash bugs), etc. I've tried adding nodes with lights before all other nodes or after all other nodes.我已经尝试了几十种方法来解决这个问题:多个队列/线程/操作、事务、延迟节点添加以一次添加多个节点、使用执行(避免:致命的崩溃错误)等。我尝试添加节点在所有其他节点之前或在所有其他节点之后点亮。

We use PBR materials throughout our models and we have multiple lights with shadows enabled in most scenes (eg sun or moon outdoors, lamps indoors) along with environment lighting.我们在整个模型中使用 PBR 材料,并且在大多数场景(例如室外的太阳或月亮、室内的灯)以及环境照明中启用了多个带阴影的灯光。 Reflections are not enabled in SCNView non-AR mode, though apparently ARSceneView does enable them.在 SCNView 非 AR 模式下不启用反射,但显然 ARSceneView 确实启用了它们。 We don't typically use any of our own shaders, though a few scenes use custom shader modifiers, which don't appear to have any effect when removed.我们通常不使用我们自己的任何着色器,但有一些场景使用自定义着色器修改器,这些修改器在移除后似乎没有任何效果。

Any and all suggestions are greatly appreciated.任何和所有建议都非常感谢。 Thanks!谢谢!

Here is a sample scene screenshot and the shader compile times from Instruments 12.1 running the app on a iPad Pro 11 (2018) with iOS 14:以下是在装有 iOS 14 的 iPad Pro 11 (2018) 上运行该应用程序的 Instruments 12.1 的示例场景屏幕截图和着色器编译时间:

在此处输入图片说明

00:01.347.989   667.58 µs   Compile shader  
00:01.349.275   579.62 µs   Compile shader  
00:01.350.529   779.17 µs   Compile shader  
00:01.353.772   809.92 µs   Compile shader  
00:01.358.928   909.54 µs   Compile shader  
00:01.361.232   831.96 µs   Compile shader  
00:01.363.443   779.17 µs   Compile shader  
00:01.371.931     1.09 ms   Compile shader  
00:02.336.543   786.88 µs   Compile shader  
00:02.338.079   594.67 µs   Compile shader  
00:02.344.969   805.38 µs   Compile shader  
00:02.349.393   845.71 µs   Compile shader  
00:02.351.679   775.33 µs   Compile shader  
00:02.353.969   714.75 µs   Compile shader  
00:02.355.389   578.96 µs   Compile shader  
00:02.374.813   243.54 ms   Compile shader  
00:02.619.090   204.87 ms   Compile shader  
00:02.824.654   203.34 ms   Compile shader  
00:03.033.721   203.22 ms   Compile shader  
00:03.245.523   199.92 ms   Compile shader  
00:03.446.541   641.67 µs   Compile shader  
00:03.458.231   200.25 ms   Compile shader  
00:03.670.527   202.03 ms   Compile shader  
00:03.875.402   200.12 ms   Compile shader  
00:04.089.184   725.21 µs   Compile shader  
00:04.091.070   201.98 ms   Compile shader  
00:04.297.075   212.00 ms   Compile shader  
00:04.509.799   200.11 ms   Compile shader  
00:04.710.886   203.88 ms   Compile shader  
00:04.915.507   199.86 ms   Compile shader  
00:05.116.368   199.27 ms   Compile shader  
00:05.316.424   200.51 ms   Compile shader  
00:05.517.957   203.45 ms   Compile shader  
00:05.722.065   646.38 µs   Compile shader  
00:05.723.205   582.29 µs   Compile shader  
00:05.802.072   831.96 µs   Compile shader  
00:05.808.265   203.29 ms   Compile shader  

I've seen similar performance regressions in iOS 14. There are even complete freezes occurring on a SceneKit based ARKit project running in an App Clip.我在 iOS 14 中看到了类似的性能回归。在 App Clip 中运行的基于 SceneKit 的 ARKit 项目甚至发生了完全冻结。 Have you heard about any improvements or workarounds recently?您最近是否听说过任何改进或解决方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM