| ... | ... | @@ -671,6 +671,27 @@ fn view_pixels(size: [f32; 2], scale: f32, limit: u32) -> Result<[u32; 2]> { |
| 671 | 671 | Ok(pixels.map(|side| side as u32)) |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | /// The GPU instance the first view starts. On Android it offers one backend, Vulkan where the |
| 675 | /// device has it, else GL: Android's Vulkan loader connects a window to make its surface, and |
| 676 | /// EGL then can't make one on the same window. |
| 677 | fn instance() -> wgpu::Instance { |
| 678 | let with = |backends| { |
| 679 | wgpu::Instance::new(wgpu::InstanceDescriptor { |
| 680 | backends, |
| 681 | ..wgpu::InstanceDescriptor::new_without_display_handle() |
| 682 | }) |
| 683 | }; |
| 684 | if !cfg!(target_os = "android") { |
| 685 | return with(wgpu::Backends::all()); |
| 686 | } |
| 687 | let vulkan = with(wgpu::Backends::VULKAN); |
| 688 | if pollster::block_on(vulkan.enumerate_adapters(wgpu::Backends::VULKAN)).is_empty() { |
| 689 | with(wgpu::Backends::GL) |
| 690 | } else { |
| 691 | vulkan |
| 692 | } |
| 693 | } |
| 694 | |
| 674 | 695 | struct Presentation { |
| 675 | 696 | surface: wgpu::Surface<'static>, |
| 676 | 697 | /// Field order keeps the acquired window alive until the surface has dropped. |
| ... | ... | @@ -700,7 +721,7 @@ impl Presentation { |
| 700 | 721 | let mut gpu = gpu(); |
| 701 | 722 | let instance = match &*gpu { |
| 702 | 723 | Some(gpu) => gpu.instance.clone(), |
| 703 | | None => wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle()), |
| 724 | None => instance(), |
| 704 | 725 | }; |
| 705 | 726 | // SAFETY: Android retains its window; the Apple caller keeps its layer alive. |
| 706 | 727 | let surface = unsafe { instance.create_surface_unsafe(target) }?; |