Skip to content

fix(android): Fall back to OpenGL ES when Vulkan initialization fails - #23941

Merged
ramezgerges merged 1 commit into
feature/breakingchangesfrom
dev/rara/android-vulkan-gl-fallback
Aug 3, 2026
Merged

ramezgerges merged 1 commit into
feature/breakingchangesfrom
dev/rara/android-vulkan-gl-fallback

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #23940

PR Type:

🐞 Bugfix

What changed? 🚀

On Android with the Skia renderer, any Vulkan initialization failure left a permanent black screen: the only fallback to OpenGL ES was a try/catch around the UnoSKVulkanView constructor, but the constructor did no Vulkan work — actual initialization happened later on the render thread, where failures were logged and swallowed. The HasSystemFeature(FEATURE_VULKAN_HARDWARE_LEVEL) gate doesn't help because emulator images declare Vulkan feature flags as static configuration even when the driver can't render (see #23940 for the three reproduced failure flavors, including a stock API-33 emulator with -gpu swiftshader_indirect).

This PR makes the Vulkan/GL decision sequential and synchronous by splitting VulkanContext initialization into a window-independent and a window-scoped phase:

  • VulkanContext.InitializeDevice(factory) creates the instance, device, and SkiaSharp GRContext, and throws when the driver is unusable. It is called directly in the UnoSKVulkanView constructor, so the existing try/catch in ApplicationActivity.CreateRenderView() becomes a real fallback site: all three failure flavors from Android Skia: black screen instead of OpenGL ES fallback when Vulkan initialization fails #23940 now surface there and the app falls back to UnoSKCanvasView (OpenGL ES).
  • VulkanContext.InitializeSurface(window, width, height) creates the swapchain and intermediate render image on the render thread once the surface exists, reusing the device created by the constructor (previously the context was fully re-initialized).
  • SurfaceDestroyed now disposes only the window-scoped resources (DisposeSurfaceResources), keeping the instance/device/GRContext alive across surface destroy/recreate cycles (e.g. backgrounding).

The pre-existing VulkanContext.Initialize(...) single-shot path used by the Win32/X11 hosts is unchanged.

Runtime-validated on Android emulators (API 33 x86_64, -gpu swiftshader_indirect, where GRContext creation fails on the SwiftShader guest device): before — black screen with a dead render thread; after — logcat shows Vulkan rendering not available: Unable to create SkiaSharp GRContext from Vulkan device. Falling back to OpenGL ES. and SamplesApp renders and responds to input. The API-28 path (image declares no Vulkan features → existing feature-flag fallback) still behaves as before.

Known limitation (by design, to keep the fallback decision synchronous): a failure in the window-scoped phase on the render thread (vkCreateAndroidSurfaceKHR/swapchain creation) is logged but does not fall back; no such failure was observed across the tested configurations, which all fail during device/GRContext creation.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — not applicable: the behavior depends on the host's Vulkan driver failing, which can't be arranged from a runtime test; validated manually on emulators as described above.
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — not applicable: no public API or documented behavior change; the fix makes the existing UseVulkanOnSkiaAndroid documented fallback behavior actually work.
  • 🖼️ Validated PR Screenshots Compare Test Run results.

🤖 Generated with Claude Code

Vulkan feature flags are static device configuration and can be declared
even when the driver cannot render (common on emulators). Probe for a
usable device + GRContext before committing to the Vulkan view, and swap
in the OpenGL ES view if render-thread initialization still fails,
instead of leaving a permanently black SurfaceView.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia labels Aug 1, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 225321 found UI Test snapshots differences: skia-linux-screenshots: 74, skia-windows-screenshots: 127

Details
  • skia-linux-screenshots: 74 changed over 2392

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • DamageRegion_ShadowChildPaintingCaster.png-dark
    • DynamicFont.png-dark
    • ClipboardTests.png-dark
    • Gamepad_CurrentReading.png-dark
    • Image_UseTargetSizeLate.png-dark
    • Image_UseTargetSizeLate.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • DoubleImageBrushInList.png-dark
    • Gamepad_Enumeration.png-dark
    • ImageBrush_Stretch.png
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ImageBrushWithRotateTransform.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • Buttons.png
    • DropDownButtonPage.png-dark
    • Image_Margin_Large.png
  • skia-windows-screenshots: 127 changed over 2392

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Basics Pivot Test.png-dark
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ContentPresenter_TextProperties.png-dark
    • ContentPresenter_TextProperties.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DynamicBrushes_On_Shapes.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Basics Pivot Test.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DataTemplate_Update_Sample.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 225321 has failed on Uno.UI - CI.

@ramezgerges
ramezgerges enabled auto-merge August 3, 2026 17:10
@ramezgerges
ramezgerges merged commit d16dc12 into feature/breakingchanges Aug 3, 2026
48 checks passed
@ramezgerges
ramezgerges deleted the dev/rara/android-vulkan-gl-fallback branch August 3, 2026 18:00
MartinZikmund added a commit to ramezgerges/uno that referenced this pull request Sep 21, 2026
Master's unoplatform#23941 split VulkanContext into InitializeDevice (instance
+ device, window-independent) and InitializeSurface (swapchain),
and called InitializeDevice from the view constructor so a driver
that advertises Vulkan but can't render throws synchronously,
letting ApplicationActivity fall back to the GLES view. The branch
never received this split - UnoVulkanView deferred all Vulkan work
to the render thread, where a failure only got logged and could no
longer reach the caller's try/catch.

Ported the split onto the branch's neutral VulkanContext (GRContext
stays out of it - that's the Skia backend's concern - so
InitializeDevice only creates instance+device). UnoVulkanView now
owns a persistent VulkanContext, initializes the device eagerly in
its constructor, and hands it to AndroidVulkanGraphicsContext (which
now completes/tears down only the window-scoped swapchain via
InitializeSurface/DisposeSurfaceResources, instead of owning a
whole VulkanContext of its own). Win32 and X11's Vulkan contexts are
untouched - they keep constructing and owning their own VulkanContext
via the combined Initialize path.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XsQppKuZgijApgJxaTZt81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants