-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Get raw window handle only after Resume event #3639
Conversation
Thank you for investigating this! @mockersf, this is one of the main problems we need to fix to unbreak Android right? |
Yup that looks good! Even if pbr is still failing, if 2d and UI works on Android that would be nice. @Gordon-F to undraft that PR, could you re-add the various part of Bevy that you commented and are behind a feature (pbr, audio and gilrs I think)? Maybe setting up the android example to be like the iOS one and have its own Also you can insert the bevy/crates/bevy_render/src/options.rs Lines 13 to 20 in 130953c
|
Sure, nice idea. Something really strange with Vulkan on my device (driver bug?). 2D example flickering (on device screen image flickering faster). But now it possible to draw something. Better than panic :) vulkan.mp4opengl.mp4 |
Would it make sense to request the adapter and surface again after every |
winit executing Can we remove https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/lib.rs#L39 |
|
facf222
to
11309fd
Compare
CI is happy now 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's nothing obviously wrong (other than the exceedingly strange implementation of indexing), but I'm not confident to fully sign off on all these changes. It seems like some potentially risky changes for 0.6.1
.
Agreed, this needs more eyes. However, (even partially) unbreaking Android would be very nice. |
It would be nice if you could clarify this. I think I remember it was needed on one of the platform, but I'm not sure. |
Based on my tests (Windows, Android, WASM, MacOS, iOS), it is required for WASM target. I think |
let preferred_gpu_index = match options.power_preference { | ||
wgpu::PowerPreference::LowPower => { | ||
integrated.or(other).or(discrete).or(virt).or(cpu) | ||
} | ||
wgpu::PowerPreference::HighPerformance => { | ||
discrete.or(other).or(integrated).or(virt).or(cpu) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels like recoding what https://docs.rs/wgpu/0.12.0/wgpu/struct.Instance.html#method.request_adapter should be doing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's a copy-pasted code from wgpu
. But we should enumerate adapters here to make sure that we can use default texture format and default depth format as a render target for the selected adapter (for example, on my Android device Vulkan adapter can't use Depth32Float as a render target). request adapter
just return first adapter which meets requirements of RequestAdapterOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that makes me sad... I think we should either:
- switch from
Depth32Float
toDepth24Plus
as the comment suggest, and which should be supported on Vulkan android (maybe with a cfg to check target architecture?) - upstream to wgpu a way to select an adapter based on the texture format it supports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch from Depth32Float to Depth24Plus as the comment suggest, and which should be supported on Vulkan android (maybe with a cfg to check target architecture?)
As far as I know, only VK_FORMAT_D16_UNORM
supported across all Vulkan powered devices (99% based on gpuinfo https://vulkan.gpuinfo.org/listoptimaltilingformats.php?platform=android)
upstream to wgpu a way to select an adapter based on the texture format it supports
request_adapter
is implemented following by WebGPU spec. I don't think we can change it.
That's why wgpu-rs
exposed enumerate_adapters
function. It's allowed users to select adapter based on their options. Perhaps in the future, we will need to check if the adapter supports any other features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really be picking devices based on what texture / depth formats they support? That seems like a pretty trivial criteria relative to things like gpu features and performance. Wouldn't it make more sense to do runtime queries of supported formats and then pick the best one? Every device will support "something".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cart I implemented this behavior because bevy uses Depth32Float
as a default depth format and it's required for bevy_renderer
. When I tested this on a real device, it have Depth32Float
format on OpenGL adapter, but Vulkan adapter doesn't support it. (Android 8.0).
We can remove this part from PR. It unblocks some Android devices (maybe most of the devices, but definitely not all of them).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah short term if we can move this forward without this behavior I think we should. I do acknowledge that this is a problem that needs solving, but I think it should be solved via querying supported depth formats at runtime after we've selected our device based on more substantial criteria.
Anything that currently consumes hard-coded Depth32Float constants could call something like RenderDevice::get_preferred_depth_format()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything that currently consumes hard-coded Depth32Float constants could call something like RenderDevice::get_preferred_depth_format() instead.
Sorry, maybe I confused you. We can query depth format only from adapter (correct me, if I'am wrong). For example, on real device:
- Create instance with Vulkan and GL backend
- Enumerate adapters:
- Vulkan (Depth32Float is not available)
- OpenGL (Depth32Float is available)
What we should do in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would choose vulkan (if that is what wgpu recommends based on the wgpu config) and pick a different depth format supported by the device.
Could you add a comment mentioning it is needed on wasm? |
+1 I tried running the android example, now a 2D animated sprite, on my android phone and it works. I also tried replacing the example code with the Landscape: Portrait: I think this fix is very useful and this branch should be updated to fix the merge conflicts and merged in EDIT: Small suggestion, having both 3D and 3D examples could be useful I think |
I tried to apply this PR changes on the But I have a black screen, and after a few seconds android telling me the app is not responding: adb logcat:
So I don't know what's missing |
This |
@superdump thank you that was indeed the issue ! I'll open a duplicate PR without the conflicts |
Closing PR, since initial android support already merged in #5130 |
Objective
An attempt to fix #3249.
Solution
Resumed
event.On my device it works only with OpenGL and disabled PBR (broken due to gfx-rs/wgpu#4455).
Vulkan error with 3D scene example and enabled pbr:(My device doesn't supportsDEPTH_STENCIL_ATTACHMENT
forVK_FORMAT_D32_SFLOAT
)