-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Android example very slow running on device following light transmission changes #10338
Comments
@coreh @superdump any ideas? |
Hmm my money is on the shader code, given that we don't run the transmission pass without transmissive materials. Maybe try commenting out the relevant branches/code blocks in ex: |
Commenting out suggested by @cart shader code makes it run faster but not as fast as before. |
For clarity: did you test the commit right before the Transmission commit? |
Yes, d67fbd5 |
So one quick (partial) fix would be to put all of that code behind a "shader def", which we set whenever diffuse transmission is above 0.0. |
It might be worth looking at a renderdoc capture of pre and post merge. Most significant changes (gpu-side) should be easy to spot there. |
Huawei P30 Lite |
According to GSMArena:
OS Android 9.0 (Pie), upgradable to Android 10, EMUI 10.0 |
I'm bumping this to 0.13. While this regression isn't ideal, it clearly doesn't apply to every device. We can iterate here (and consider doing a patch release once we identify the right fix) |
I don't have an android device available for now, but I can't reproduce on the emulator |
I've been testing compiling wasm and android on my phone, a OnePlus 7T Pro, and suspect I am running into this, however I noticed it performs better if I zoom out which, if related, may be helpful information? I took the mobile example, removed everything but the cube and the camera (no lights) and compiled it to android but also made a wasm build loaded in a cordova app and put that on my phone too. The android build hovers around 50fps, hits 60fps if I zoom out and drops to 40fps if I zoom in. Setting the camera transform to something like Transform::from_xyz(-22.0, 2.5, 25.0) gave me good performance, but even just a few units back was enough to notice a difference. I'll try out d67fbd5 with it over the weekend when I get a chance to see if it makes a difference. |
Zooming in makes the material cover more pixels, so the degraded performance confirms that the fragment shader is the bottleneck. |
I've noticed an extreme performance regression on quest 2. Not 100% sure if it's related but it did not occur prior to the 0.12 release at least a few weeks before hand, and now FPS with a very very minimal example is very bad. |
I can confirm now having a different shader on an objects completely fixes the performance issue |
Just to note that the issue affects PC as well. Less noticeable as they can handle the load, but with VSync off I see a drop in FPS from +300 to ~100 on laptops with Intel HD graphics and Nvidia discrete. see #11213 . Thanks! |
I noticed this too on my amd laptop. I can hit 120 frames, but if I get close to a cube so that it fills the screen, the frame rate drops 10-20 frames. Can't really tell if the refresh rate is locked at 60. |
@MalekiRe , can you share an example of said shader? Thanks! To be precise - which shader is the offending one? |
Ok, so I tried to isolate the issue while preserving original PBR/material features. I created a "blank" fragment shader (looking at extended_material.wsgl ), Applied that to my GLTF models as extended material (great guide & code on how to patch SceneBundle here, many thanks @nicopap!!!!)
With this frag shader the issue is non-existent on Android. High fps with many entities / zoomed in. It was clear that the offending function was So I went about trying to isolate the problem within this function. It applies all light sources, concating them here: bevy/crates/bevy_pbr/src/render/pbr_functions.wgsl Lines 375 to 379 in 22e39c4
I attempted to use only one light source at a time. Sadly, could not find a single culprit source or function that causes the massive fps drop. I can only say that direct_light has the biggest effect on fps (another shocker I'm sure 🤣 ),But even it caused only a 30% drop in fps. All combined and enabled the issue exists and fps tanks. For now, I stripped the Sorry I couldn't point out the root cause of the zoomed-in fps drop.. really tried removing line by line from pbr_functions but that didn't give anything. Just many calculations together lead to drop. Sorry. Anyway, if anyone needs a simple working shader, here's my stripped down
|
# Objective - Address #10338 ## Solution - When implementing specular and diffuse transmission, I inadvertently introduced a performance regression. On high-end hardware it is barely noticeable, but **for lower-end hardware it can be pretty brutal**. If I understand it correctly, this is likely due to use of masking by the GPU to implement control flow, which means that you still pay the price for the branches you don't take; - To avoid that, this PR introduces new shader defs (controlled via `StandardMaterialKey`) that conditionally include the transmission logic, that way the shader code for both types of transmission isn't even sent to the GPU if you're not using them; - This PR also renames ~~`STANDARDMATERIAL_NORMAL_MAP`~~ to `STANDARD_MATERIAL_NORMAL_MAP` for consistency with the naming convention used elsewhere in the codebase. (Drive-by fix) --- ## Changelog - Added new shader defs, set when using transmission in the `StandardMaterial`: - `STANDARD_MATERIAL_SPECULAR_TRANSMISSION`; - `STANDARD_MATERIAL_DIFFUSE_TRANSMISSION`; - `STANDARD_MATERIAL_SPECULAR_OR_DIFFUSE_TRANSMISSION`. - Fixed performance regression caused by the introduction of transmission, by gating transmission shader logic behind the newly introduced shader defs; - Renamed ~~`STANDARDMATERIAL_NORMAL_MAP`~~ to `STANDARD_MATERIAL_NORMAL_MAP` for consistency; ## Migration Guide - If you were using `#ifdef STANDARDMATERIAL_NORMAL_MAP` on your shader code, make sure to update the name to `STANDARD_MATERIAL_NORMAL_MAP`; (with an underscore between `STANDARD` and `MATERIAL`)
…#11627) # Objective - Address bevyengine#10338 ## Solution - When implementing specular and diffuse transmission, I inadvertently introduced a performance regression. On high-end hardware it is barely noticeable, but **for lower-end hardware it can be pretty brutal**. If I understand it correctly, this is likely due to use of masking by the GPU to implement control flow, which means that you still pay the price for the branches you don't take; - To avoid that, this PR introduces new shader defs (controlled via `StandardMaterialKey`) that conditionally include the transmission logic, that way the shader code for both types of transmission isn't even sent to the GPU if you're not using them; - This PR also renames ~~`STANDARDMATERIAL_NORMAL_MAP`~~ to `STANDARD_MATERIAL_NORMAL_MAP` for consistency with the naming convention used elsewhere in the codebase. (Drive-by fix) --- ## Changelog - Added new shader defs, set when using transmission in the `StandardMaterial`: - `STANDARD_MATERIAL_SPECULAR_TRANSMISSION`; - `STANDARD_MATERIAL_DIFFUSE_TRANSMISSION`; - `STANDARD_MATERIAL_SPECULAR_OR_DIFFUSE_TRANSMISSION`. - Fixed performance regression caused by the introduction of transmission, by gating transmission shader logic behind the newly introduced shader defs; - Renamed ~~`STANDARDMATERIAL_NORMAL_MAP`~~ to `STANDARD_MATERIAL_NORMAL_MAP` for consistency; ## Migration Guide - If you were using `#ifdef STANDARDMATERIAL_NORMAL_MAP` on your shader code, make sure to update the name to `STANDARD_MATERIAL_NORMAL_MAP`; (with an underscore between `STANDARD` and `MATERIAL`)
I wanted to try this out after #11627 was merged but I happened to break the phone I was using :( This issue unfortunately doesn't happen on my replacement, a pixel. I checked out the commit before and after #11627 and it behaved identically, roughly staying at 49-60FPS regardless of how close or far I was to objects. |
This issue should be fixed. Can anyone who ran into the original issue reproduce it on 0.13? |
There was a lengthy debug and discussion in Bevy #xr channel. At least in Oculus Quest, the performance with pointlight & shadows is still remarkably low (~60 fps with a simple cube-scene) Performance improves a lot (120fps) when either a) disabling shadows from the point light
or b) using directional light
Might related to GPU memory write bandwidth (4.4TB writes/s with 120fps if shadows disabled in contrast to 6.8TB writes/s and 60fps when shadows enabled) |
The commit 44928e0 makes mobile example run on android device at ~1 FPS (~20 before).
To reproduce:
The text was updated successfully, but these errors were encountered: