Add generic external GPU interop for MewVG#117
Add generic external GPU interop for MewVG#117wieslawsoltes wants to merge 8 commits intoaprillz:mainfrom
Conversation
|
This PR is experimental work, main problem to solve here is to enable easy integration of third party libraries like SkiaSharp into rendering pipeline in the UI, all SkiaSharp parts can be removed from this PR and just parts refactoring rendering api. But for sake of discussion and testing SkiaSharp bits are here for now. Here is my reasoning for this work #116 (comment) |
|
I splitted original code into separate repo https://github.com/wieslawsoltes/Skia.MewUI and now its only GPU interop. |
|
@al6uiz Those changes are not set in stone, I am open for any way this can be done to enable GPU interop work third party libraries, this way it makes easy to build on top on MewUI while making core follow its goals. |
|
Hello @wieslawsoltes , |
|
Thank you for the PR. I also appreciate that you already addressed some of the points I was planning to comment on in the earlier version. The direction I have in mind is also closer to exposing backend-native resource implementations through common interfaces, rather than letting a specific graphics library penetrate into the backend itself, and then having those resources consumed externally in a way that avoids CPU copies as much as possible. From the core side, I see this PR as being about the changes needed to provide those kinds of interfaces. That is also something I had in mind within the same broader direction. I do have one question related to this. In the Metal-side code, I am curious about the reasoning behind introducing the |
Full disclosure the metal integration is not by expertise so here is summary for my work with Codex that did heavy lifting integration, the ideas is basically to have fastest path to rendering into GPU texture via metal when using SkiaSharp (or other third party graphics library): The short version is that On GL, the flow is relatively straightforward:
That is why the GL-side interop can stay at the level of On Metal, I was missing that same capability boundary. The retained Given that constraint, the zero-copy option available to me was:
That is what So the reason for the pattern is not that direct drawable composition is inherently the ideal final API. It is more that, with the current backend surface model, I wanted to satisfy these constraints at the same time:
If the preferred long-term direction is to let the backend consume the
In other words, I see |
…platform-packages # Conflicts: # src/MewUI.Backend.MewVG.MacOS/MewUI.Backend.MewVG.MacOS.csproj # src/MewUI/Shared/Rendering/MewVG/MewVGGraphicsFactory.Metal.MacOS.cs
PR Summary: Add generic external GPU interop for MewVG
Overview
This PR reduces the
MewUIside of the Skia work to the generic pieces only.It does not add:
SkiaSharppackage referencesThose parts were moved into the separate public repository:
This PR keeps only the backend and factory changes that make fast external GPU interop possible.
Why this split
The Skia integration needed two different layers:
MewUIKeeping the generic layer in
MewUImakes the backends reusable for future external renderers, while the Skia-specific packages can evolve independently inSkia.MewUI.What this PR adds
1. Graphics service resolution
This PR adds a lightweight graphics-service extension model:
IGraphicsServiceProviderGraphicsServiceRegistryTryGetGraphicsService<T>()That allows external packages to attach services to backend factories without modifying the backend’s public type or introducing a direct dependency from the base backend assembly.
2. Generic MewVG window-resource interop
This PR adds backend-neutral contracts for external GPU renderers:
IMewVGWindowResourceResolverIMewVGExternalImageInteropIMewVGGlWindowInteropIMewVGMetalWindowInteropThese expose only the native interop needed to share textures and execute work on the correct GL or Metal device/context.
3. Generic frame-composition interop
This PR adds a generic active-context contract:
IMewVGExternalImageContextThe GL and Metal backends now both expose external GPU content as normal backend images. That keeps the drawing model consistent across platforms and avoids the earlier Metal-only suspend/restart composition path.
This is the final shape of the branch. Earlier iterations used a Metal-specific
TryBeginExternalComposite(...)fallback, but that has been removed in favor of the same external-image model used on GL.4. Backend implementation changes
The Win32, X11, and macOS MewVG backends now implement those generic interop contracts directly.
That includes:
On Metal, there is still one backend-private implementation detail: a small internal bridge that registers the shared
MTLTexturewith the current MewVG Metal image model. That detail stays inside the backend and does not leak into the public interop surface.5. macOS handle-resolution support
The existing macOS resource-lookup behavior is preserved so that the framework can resolve the live Metal window resources when the visual root handle and the actual
CAMetalLayerhandle differ.What this PR intentionally removes
This branch originally contained the SkiaSharp projects and sample app, but they were moved out before finalizing the PR.
The following are now external to
MewUI:MewUI.SkiaSharpMewUI.Backend.MewVG.SkiaMewUI.Backend.MewVG.Win32.SkiaMewUI.Backend.MewVG.X11.SkiaMewUI.Backend.MewVG.MacOS.SkiaMewUI.SkiaSharp.SampleThe implementation of those projects now lives in:
That repo consumes this PR’s generic interop APIs through a git submodule pinned to this branch.
Files of interest
Generic service model
src/MewUI/Rendering/IGraphicsServiceProvider.csGeneric MewVG interop contracts
src/MewUI/Rendering/MewVG/IMewVGGraphicsInterop.csFactory-side resource resolution
src/MewUI/Shared/Rendering/MewVG/MewVGGraphicsFactory.cssrc/MewUI/Shared/Rendering/MewVG/MewVGGraphicsFactory.Metal.MacOS.csGeneric context/resource implementations
src/MewUI/Shared/Rendering/MewVG/MewVGGraphicsContext.Common.cssrc/MewUI/Shared/Rendering/MewVG/Win32/MewVGWindowResources.cssrc/MewUI/Shared/Rendering/MewVG/Win32/MewVGWin32GraphicsContext.cssrc/MewUI/Shared/Rendering/MewVG/X11/MewVGX11WindowResources.cssrc/MewUI/Shared/Rendering/MewVG/X11/MewVGX11GraphicsContext.cssrc/MewUI/Shared/Rendering/MewVG/Metal/MewVGMetalExternalImageBridge.cssrc/MewUI/Shared/Rendering/MewVG/Metal/MewVGMetalWindowResources.cssrc/MewUI/Shared/Rendering/MewVG/Metal/MewVGMetalGraphicsContext.csResult
After this PR:
MewUIexposes a clean, generic external GPU interop surfaceMewUIremains free ofSkiaSharpdependencies and public Skia APISkia.MewUIcan provide the full SkiaSharp experience while consuming the same external-image path on GL and MetalValidation
Built successfully on this branch:
dotnet build src/MewUI/MewUI.csproj -f net8.0dotnet build src/MewUI.Backend.MewVG.Win32/MewUI.Backend.MewVG.Win32.csproj -f net8.0dotnet build src/MewUI.Backend.MewVG.X11/MewUI.Backend.MewVG.X11.csproj -f net8.0dotnet build src/MewUI.Backend.MewVG.MacOS/MewUI.Backend.MewVG.MacOS.csproj -f net8.0The extracted Skia integration was also validated in the external repo:
dotnet build src/MewUI.Backend.MewVG.Skia/MewUI.Backend.MewVG.Skia.csproj -f net8.0dotnet build samples/MewUI.SkiaSharp.Sample/MewUI.SkiaSharp.Sample.csproj -f net10.0External companion repo
mainfeature/mewvg-skia-platform-packages