Repository navigation
fix(wasm): Fix GLCanvasElement (WebGL) under WASM AOT - #23834
Conversation
The nine >8-arg GL functions (glTexImage2D, glTexSubImage2D, glTexImage3D,
glTexSubImage3D, glCopyTexSubImage3D, glCompressed{Tex,TexSub}Image*, and
glBlitFramebuffer) crashed under WebAssembly full AOT with "null function or
function signature mismatch" on the first GLCanvasElement render.
Root cause: the shim routed Silk.NET's >8-arg calli into a C wrapper that
called back into a managed [UnmanagedCallersOnly] dispatcher resolved by
EntryPoint name. That native-to-interp callback has no valid entry under full
AOT (the managed->native calli hop itself works). The [UnmanagedCallersOnly]
8-arg cap (dotnet/runtime#109338) and the SignaturePrimer never addressed this.
Fix: the C shim now forwards straight to the JS WebGL layer via EM_JS, removing
the managed callback hop entirely. Silk.NET still calli's into the C wrappers
(the hop that already works). Removes the now-dead managed dispatchers, their
JSImports, and the ILLink descriptor that preserved them.
Validated against the unoplatform/kahua-private#520 repro: renders correctly on
both WASM full AOT (Release publish) and the interpreter (Debug), no crash.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
A lit sphere encircled by a tilted ring, ported from the kahua-private#520 repro. Exercises the framebuffer color-attachment and texture-upload paths that regressed under WebAssembly full AOT, so it doubles as the regression artifact for a future full-AOT WASM validation leg. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Serve GL entry points (including the >8-arg texture functions) from emscripten's native C GL library - shared with SkiaSharp via -lGL - through uno_gl_resolve, instead of forwarding each one to JS via EM_JS. Small C wrappers remain only for glTexImage2D/glTexImage3D to add the WebGL2 unsized->sized internal-format promotion emscripten omits; every other name falls back to the hand-written JS shim only when the native proc table has no entry. Silk.NET still calli's into the resolved addresses, so the build-time SignaturePrimer is kept to emit the matching interp->native trampolines. See unoplatform/kahua-private#520 Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes GLCanvasElement WebGL crashes under WebAssembly full AOT by switching GL entry-point resolution to prefer emscripten’s native C GL (-lGL) via a new uno_gl_resolve resolver, with the JS shim kept only as a fallback for missing proc-table entries.
Changes:
- Updated
WasmGLFunctions.GetProcAddressto resolve GL entry points viauno_gl_resolvefirst, falling back to the existing JS shim when needed (with debug logging). - Simplified the large-arity shim path by removing the managed
[UnmanagedCallersOnly]dispatchers and retaining only the signature-priming DllImports required for interpreter trampolines. - Added a new SamplesApp “ModelViewer” manual sample to exercise the 9-arg texture upload path.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Uno.UI.Runtime.Skia.WebAssembly.Browser.csproj | Removes the embedded ILLink descriptor previously used to preserve managed GL shim exports. |
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Graphics/WasmGLShim.ILLink.Descriptors.xml | Deletes the trimmer descriptor now that the C shim no longer depends on managed exports. |
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Graphics/WasmGLFunctions.LargeArityShims.cs | Removes the packed-args managed dispatchers and keeps only signature priming for interpreter trampolines. |
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Graphics/WasmGLFunctions.cs | Prefers native proc resolution via uno_gl_resolve, with JS shim fallback and logging. |
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/build/native/uno_gl_shim.c | Implements uno_gl_resolve and keeps small promotion wrappers + signature-primer dummy exports. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/ModelViewerGlCanvasElement.cs | Adds a GLCanvasElement-based “model viewer” element for manual/visual validation. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/GLCanvasElement_ModelViewer.xaml.cs | Registers the new manual sample via [Sample]. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/GLCanvasElement_ModelViewer.xaml | Adds the XAML surface for the sample, following existing GLCanvasElement sample patterns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
- Rewrite the WasmGLFunctions header and fix stale comments that still described the old packed-argument managed dispatcher path; document the native-first uno_gl_resolve resolution instead. - Cache the logger in a local in the GetProcAddress fallback path instead of resolving it twice. - Replace the private-tracker references in code/comments/sample metadata with generic internal-tracking wording, and fix the "calli's" wording. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks for the review. Addressed in f978c1d:
Note: the failing Uno.UI - CI / Analyze (csharp) checks are unrelated to this PR — they fail on |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23834/wasm-skia-net9/index.html |
Guard the uno_gl_resolve P/Invoke in ResolveNative against DllNotFoundException/EntryPointNotFoundException so a missing or unlinked native shim degrades to the JS-shim fallback instead of crashing GetProcAddress. A latched flag short-circuits subsequent lookups and the condition is logged once. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Uno.UI.Runtime.Skia.WebAssembly.Browser.csproj:70
- PR description currently references a private issue ("closes unoplatform/kahua-private#520"). This repo’s PR requirements call for a public, fully-qualified issue URL in the Fixes/Closes/Related footer, or an explicit "No related issue" note (with approver) if this is internal maintenance.
<ItemGroup>
<_UnoInjectedResource Include="WasmScripts\**\*.js" LogicalName="$(RootNamespace).WasmScripts.%(FileName)%(Extension)" />
<EmbeddedResource Include="WasmCSS\**\*.css" />
<TypeScriptCompile Include="ts\**\*.ts;ts\**\*.tsx" />
<TypeScriptCompile Include="..\Uno.UI\ts\types\**\*.ts" />
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23834/wasm-skia-net9/index.html |
It no longer registered any proc addresses (uno_gl_resolve serves those); it only forwarded to KeepSignaturePrimer. Call KeepSignaturePrimer directly from the static ctor so the initialization flow reflects what actually happens. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23834/wasm-skia-net9/index.html |
|
|
Group the native-resolver flag with _addresses at the top of the class instead of declaring it mid-file next to ResolveNative. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Graphics/WasmGLFunctions.cs:91
- The error log in the ResolveNative fallback path claims the JS shim will be used for all GL entry points, but key names (e.g. glTexImage2D/glTexImage3D and other >8-arg functions) are not registered in the JS fallback dictionary and will still resolve to IntPtr.Zero. This message is misleading for diagnosing missing native shim linkage/symbols.
if (typeof(WasmGLFunctions).Log().IsEnabled(LogLevel.Error))
{
typeof(WasmGLFunctions).Log().Error("Native GL resolver (uno_gl_shim) is unavailable; falling back to the JS shim for all GL entry points.", e);
}
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23834/wasm-skia-net9/index.html |
GitHub Issue: closes unoplatform/kahua-private#520
PR Type:
🐞 Bugfix
What changed? 🚀
GLCanvasElement(WebGL on the Skia WebAssembly target) crashed under fullWASM AOT (
RunAOTCompilation=true/WasmBuildNative). GL functions withmore than 8 arguments (the texture upload family —
glTexImage2D/3D,glTexSubImage2D/3D,glCompressedTexImage/SubImage*,glCopyTexSubImage3D,glBlitFramebuffer) cannot round-trip through a managed[UnmanagedCallersOnly]dispatcher on browser-wasm (8-arg cap,
dotnet/runtime#109338), and under AOT aC→managed callback resolved by name has no valid native-to-interp entry.
This PR resolves GL the other way around:
-lGL, the same oneSkiaSharp links) via a new
uno_gl_resolveentry point, instead of forwardingevery large-arity function to JS through
EM_JS.GetProcAddressnow prefersthe native address for each name.
glTexImage2D/glTexImage3D, which addthe WebGL2 unsized→sized internal-format promotion emscripten doesn't perform.
proc table doesn't expose (logged at
Debugso a validation run shows exactlywhat still needs it).
SignaturePrimerretained: Silk.NET stillcallis into theresolved addresses, so under the interpreter those managed→native calls need
matching invoke trampolines. The always-false-guarded
[DllImport]s prime thefloat-bearing and 9/10/11-arg all-i32 signatures at build time.
GLCanvasElementModelViewer sample in the SamplesApp formanual/visual validation of the texturing + >8-arg path.
Validation
Uno.UI.Runtime.Skia.WebAssembly.Browserbuilds clean (net10.0).emscripten AOT; the native link (
wasm-ld) resolves with no undefined symbolsand the >8-arg texture path runs. Broader per-sample AOT sweep across the
GLCanvasElement samples is in progress.
PR Checklist ✅
Screenshots Compare Test Runresults.