Repository navigation
Add SkiaSharp bindings for the Graphite GPU backend (Vulkan/Metal/Dawn) - #3968
Conversation
📦 Try the packages from this PRWarning Do not run these scripts without first reviewing the code in this PR. Step 1 — Download the packages bash / macOS / Linux: curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 3968PowerShell / Windows: iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 3968"Step 2 — Add the local NuGet source dotnet nuget add source ~/.skiasharp/hives/pr-3968/packages --name skiasharp-pr-3968More options
Or download manually from Azure Pipelines — look for the Remove the source when you're done: dotnet nuget remove source skiasharp-pr-3968 |
|
/azp run |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
0468742 to
1731d7e
Compare
|
No pipelines are associated with this pull request. |
5 similar comments
|
No pipelines are associated with this pull request. |
|
No pipelines are associated with this pull request. |
|
No pipelines are associated with this pull request. |
|
No pipelines are associated with this pull request. |
|
No pipelines are associated with this pull request. |
26ff18b to
4a02f35
Compare
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
11 similar comments
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Filed #4555 for the iOS-simulator Graphite/Metal finding: Handled in this PR (commit cc @ramezgerges — it's your Graphite backend area if you want to dig into why the simulator's Metal can't compile the gradient pipeline Graphite emits (Ganesh/Metal handles the same scene on the same simulator). No action needed to land this PR. |
… args
Two correctness fixes surfaced by a full review pass:
1. SKGraphiteContext.Create{Vulkan,Metal,Dawn}(backendContext) (the no-options
overloads) passed default(SKGraphiteContextOptions), whose GpuBudgetInBytes is
0. The C shim treats a NON-NEGATIVE budget as an explicit value (the 'use Skia
default' sentinel is a negative number, per sk_graphite.h), so every no-options
context silently got a 0-byte GPU resource cache instead of Skia's 256 MB
default -> severe resource-cache thrashing. Seed the documented -1 sentinel via
a shared DefaultOptions so these factories get Skia's real default budget.
(InternalMultisampleCount 0 is already the 'use default' sentinel and the bool
fields match Skia's release defaults, so only the budget needed seeding.)
2. SKGraphiteImageCache.FindOrCreate dereferenced image.UniqueId with no null
check, throwing NullReferenceException instead of ArgumentNullException for a
null image/recorder. Add the standard argument guards.
Both are managed-only (no native/ABI change). Full local test suite green on the
graphite paths (the fixed no-options CreateMetal path included).
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 6deeff10-31d8-42fe-a033-e5fc9f47b339
|
Ran a full correctness re-review of the Graphite surface (this PR + skia#236). Overall clean — memory/ownership (ref-count vs manual-delete, the image-cache +1/-1 accounting, the Vulkan get-proc handle freed after context teardown), release-delegate GCHandle lifetimes, C-API↔managed signatures, ABI (additive only), and struct marshalling all check out. Fixed two things in
One design question for you (didn't change unilaterally, needs a native tweak): a caller who hand-builds |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Add C API shim for the Graphite GPU backend (#236) Context: mono/SkiaSharp#3968 Context: #295 Add an additive C ABI over Skia's Graphite APIs so SkiaSharp and other language bindings can use Graphite without binding directly to C++. The shim exposes backend-neutral context, recorder, recording, surface, image, texture, resource-management, image-provider, and asynchronous readback operations, with factories for Vulkan, Metal, and Dawn. Follow the existing Skia C API ownership and naming conventions and guard the implementation by SK_GRAPHITE and the corresponding backend defines. Disabled configurations retain fallback symbols so consumers can link the same ABI across platform builds. Add SkiaKeeper anchors to prevent static-linker stripping on Apple platforms. Use the backend-neutral asynchronous readback types introduced by #295 instead of maintaining Graphite-specific duplicates. This keeps CPU, Ganesh, and Graphite readback aligned and avoids divergent rescale enum mappings. Add Emscripten integration for Graphite-on-WebGPU, including support for the current emdawnwebgpu API while preserving the legacy bundled WebGPU path. Native Dawn build and feature assumptions are gated where they do not apply to browser builds. All exports are additive and remain inactive unless Graphite is enabled. Co-authored-by: Ramez Gerges <[email protected]> Co-authored-by: Ramez Gerges <[email protected]> Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Copilot App <[email protected]>
Point externals/skia at the merged Graphite C API PR mono#236 commit and keep the Component Governance registration aligned. The merged commit has the same source tree as the previously tested PR tip, so this only replaces the pre-merge branch commit with its canonical skiasharp commit. Co-authored-by: Copilot App <[email protected]> Copilot-Session: dfc94069-6b26-4b04-b82d-3e986f8abe10
Graphite landed in #3968 and skia_enable_graphite=true on every platform, with Vulkan on Windows/Linux/Android, Metal on Apple and Dawn on WASM. Six skills still told the reader to filter those changes out: * security-audit classed Graphite, Vulkan and Dawn as NOT_REACHABLE compile flags 'we don't use', which would dismiss a live CVE. It now points at the gn args in native/*/build.cake instead of naming a fixed list. * update-skia scored Graphite changes as SKIP, marked skgpu::graphite:: and Dawn/wgpu as irrelevant, and framed shared GpuTypes.h changes as a Graphite-only trap rather than a change reaching both families. * skia-analyst excluded Graphite and Dawn changes outright. * sample-scout classified any file naming Graphite or Dawn as low and called Graphite 'not SkiaSharp'. Backend-internal GMs are still low; the test is now whether it exercises internals, not which backend it names. * api-docs used 'Vulkan (not yet supported)' as a formatting example. Also documents the container legs' ganesh-gl opt-out, which this branch added to five legs without saying so in containerized-testing.md.
… + Linux (#4527) Add SkiaSharp.Vulkan.Silk.NET package and run Vulkan tests on Android + Linux (#4527) SkiaSharp's only managed Vulkan helper was SkiaSharp.Vulkan.SharpVk, pinned to SharpVk 0.4.2 (a 2018 release). SharpVk is effectively unmaintained and its native loader throws NotSupportedException on Android -- it only handles Windows and Linux -- so the Vulkan tests have always been desktop/Windows-only. With the Graphite GPU backend (#3968) bringing Vulkan to mobile, we need a managed Vulkan binding that actually works on Android. ~~ New package: SkiaSharp.Vulkan.Silk.NET ~~ Adds a convenience package (namespace SkiaSharp, netstandard2.0 -> net10.0) built on the actively maintained, cross-platform Silk.NET.Vulkan, mirroring the shape of the existing SharpVk package. GRSilkNetBackendContext maps Silk.NET's Instance/PhysicalDevice/Device/Queue (nint handles) plus a pinned PhysicalDeviceFeatures onto SkiaSharp's raw-IntPtr GRVkBackendContext and bridges the GetProcedureAddress delegate Skia uses to resolve Vulkan entry points. GRVkExtensionsSilkNetExtensions.Initialize(...) is a typed extension (plus an overload taking instance/device extension arrays). SkiaSharp.Vulkan.SharpVk is intentionally left untouched; nothing is removed. ~~ Core API: public GRVkExtensions constructor ~~ The parameterless GRVkExtensions() constructor is changed from private to public, mirroring native skgpu::VulkanExtensions (default-construct, then init) and SkiaSharp's own allocating SKPaint/SKPath constructors. This lets the Silk.NET helper expose a plain Initialize(...) extension instead of a bespoke Create(...) factory. GRVkExtensions.Create(...) is unchanged. This is the only change to a shipping package and is purely additive (a widened accessibility), so it is ABI/API-safe. ~~ Test restructuring: keep unsigned Vulkan deps off Apple + net48 ~~ The Vulkan tests bring Vulkan up through a headless Silk.NET context (SilkVkContext) that uses the OS-provided loader, so they run anywhere a Vulkan ICD is present. An earlier iteration folded the unsigned Silk.NET.Vulkan/SharpVk dependencies into the shared, strong-named SkiaSharp.Tests base library, which broke three CI legs: * iOS / Mac Catalyst -- the Apple AOT linker must resolve every native symbol at link time; there is no libvulkan on Apple, so the link failed with "clang++ ... Undefined symbols: _vkBindImageMemory" (and friends). * Windows .NET Framework (net48) -- the full framework enforces strong-name references at load time, so the strong-named host could not load the unsigned Silk.NET.Vulkan and threw FileLoadException "A strongly-named assembly is required" (0x80131044). .NET Core does not enforce this, which is why the net10 build was clean and the failure only surfaced at runtime on net48. To keep those dependencies out of the base library and out of every strong-named / Apple-linked assembly, the Vulkan tests now live in two dedicated, non-strong- named projects: * tests/SkiaSharp.Vulkan.Tests.Console -- a standalone Microsoft.Testing.Platform executable (net10.0 + net48, SignAssembly=false) that references the signed SkiaSharp.Tests.Console for shared infrastructure (unsigned -> signed is allowed) plus Silk.NET/SharpVk. This is the desktop runner (Linux/Lavapipe and Windows). * tests/SkiaSharp.Vulkan.Tests -- a library targeting only net10.0-android / -windows, referenced by the MAUI Devices host and registered in MauiProgram, so Vulkan never reaches the iOS/Mac Catalyst heads. Supporting changes so the separate assemblies integrate with the shared visual- regression harness: * CatalogReflection discovers renderers across the catalog, entry, and all loaded SkiaSharp.* assemblies, so the ganesh-vulkan renderer (in the separate Vulkan library) joins the shared VisualMatrixTests inside the single-process Devices host. This also preps the identical pattern for a future Direct3D test library: reference the library + register its assembly. * VisualMatrixTests matches only its own assembly's renderers (NamesIn(own assembly) instead of AllNames), so the base matrix and each satellite never double-run a cell when both are loaded in one process. * GPU rendering is serialized with an xUnit [Collection(DisableParallelization = true)] instead of the previous process-wide GpuRenderGate static lock. xUnit collections are scoped to a single assembly, so each assembly carries its own definition -- GpuRenderingCollection (base, GL/Metal) and VulkanGpuRenderingCollection (Vulkan). No cross-assembly lock is needed because the base and Vulkan tests never run concurrently: the Console hosts run them as separate processes, and DeviceRunners executes registered assemblies sequentially. * tests/Dockerfile.linux installs libvulkan1 + mesa-vulkan-drivers (Mesa Lavapipe software ICD) so the Vulkan GPU tests render headlessly in the container. ~~ Validation ~~ * Linux (repo test container + Mesa Lavapipe): Silk.NET Vulkan tests render and pass; the visual matrix is green against the seeded ganesh-vulkan.linux goldens. * Android (API 36 arm64 emulator, ranchu ICD): Vulkan comes up through libvulkan.so and all five ganesh-vulkan.android cells pass against seeded goldens -- the platform SharpVk could never reach -- with each renderer run exactly once (no double-run). * iOS / Mac Catalyst: the Devices heads build cleanly again; the earlier "Undefined symbols: _vk*" link failures are gone. * CI: green on the xamarin "SkiaSharp (Public)" pipeline; the previously-red iOS, Mac Catalyst, and Windows .NET Framework legs all report 0 failed tests. Windows Vulkan CI enablement (a software SwiftShader ICD + ganesh-vulkan.windows goldens) is delivered by the stacked follow-up #4531, which lands on top of this PR. Follow-up: the new public types and the now-public GRVkExtensions constructor still need generated mdoc XML via the normal docs flow. Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Copilot App <[email protected]>
…4545) Add backend-neutral async RequestReadPixels to SKImage and SKSurface (#4545) Requires: mono/skia#295 Related: #3968 (Graphite backend) Docs: mono/SkiaSharp-API-docs#184 GPU-backed surfaces need a way to read pixels back to the CPU, and on some backends (notably Graphite) the asynchronous rescale-and-read is the *only* readback path — Skia gates synchronous GPU ReadPixels behind GPU_TEST_UTILS. The in-flight Graphite PR (#3968) had added this under Graphite-prefixed names, but the underlying C++ types (SkImage::AsyncReadResult, SkImage::RescaleGamma, SkImage::RescaleMode) are core and shared by the raster, Ganesh and Graphite backends — SkSurface merely aliases the SkImage ones. So this lands the feature generically on main; #3968 can then drop its SKGraphite* copies and consume it. Add RequestReadPixels overloads on SKImage and SKSurface that deliver the pixels to an Action<SKImageReadPixelsResult>. Raster reads invoke the callback synchronously; Ganesh defers until the work is submitted and drained via the new GRContext.CheckAsyncWorkCompletion(). The result is a non-owning, callback-scoped view (deliberately not an SKObject — the native pointer is non-ref-counted and reused); it is invalidated when the callback returns and throws ObjectDisposedException afterwards. Failure is signalled by a null result, and there is no state argument (capture it in the closure). * SKImageReadPixelsResult: PlaneCount, GetPlaneRowBytes and a raw zero-copy GetPlaneData(ReadOnlySpan<byte>), plus copy-out helpers that outlive the callback — CopyPlaneTo (tightly packed, bounded), ToArray, ToImage, ToBitmap. * SKImageRescaleGamma { Src, Linear } and SKImageRescaleMode { Nearest, Linear, RepeatedLinear, RepeatedCubic }. The convenience overload defaults to (Src, Nearest) — the least-transform choice, matching what Skia itself forces when no rescale is required (SurfaceContext normalises to kSrc/kNearest at 1:1). * Bumps externals/skia to the C API (mono/skia#295) and regenerates the P/Invoke bindings; the only hand-written generated piece is the fire-once DelegateProxies async-read proxy. Scope is the RGBA (count()==1) read; YUV420/YUVA420 are a clean additive follow-up, as the result type and accessors are already multi-plane. Tested by 18 SKAsyncReadPixelsTest cases: per-pixel pattern correctness read from an offset srcRect, a deterministic padding-strip unit test, destination-size and invalid-plane-index edge cases, use-after-callback throwing cleanly, and Ganesh deferred completion (asserting the false -> pump -> true transition where the backend supports it). Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Copilot App <[email protected]>
Add Graphite GPU backend bindings for Vulkan, Metal, and Dawn (#3968) Context: mono/skia#236 Context: #4545 Tracking: #4555 Expose Skia's next-generation Graphite GPU backend through additive SkiaSharp APIs. The new surface follows Graphite's explicit record, snap, insert, and submit model while leaving the existing Ganesh APIs and behavior unchanged. Add managed wrappers for contexts, recorders, recordings, backend textures, texture information, and Vulkan, Metal, and Dawn backend contexts. Support wrapping caller-owned textures with release callbacks and provide SKGraphiteImageCache as the default image-provider strategy for uploading and reusing raster images. Enable Graphite in the native builds for supported desktop and mobile platforms. WebAssembly uses Dawn's emdawnwebgpu port so Graphite can render through browser WebGPU. Readback uses the existing backend-neutral asynchronous API because shipping Graphite surfaces do not support synchronous ReadPixels. Cover the new surface with API tests, backend-context and release callback tests, and a cross-backend visual regression matrix with platform-specific goldens. The iOS simulator's Graphite/Metal gradient limitation remains isolated to that environment and is tracked separately. Co-authored-by: Ramez Ragaa <[email protected]> Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Copilot App <[email protected]>
Graphite landed in #3968 and skia_enable_graphite=true on every platform, with Vulkan on Windows/Linux/Android, Metal on Apple and Dawn on WASM. Six skills still told the reader to filter those changes out: * security-audit classed Graphite, Vulkan and Dawn as NOT_REACHABLE compile flags 'we don't use', which would dismiss a live CVE. It now points at the gn args in native/*/build.cake instead of naming a fixed list. * update-skia scored Graphite changes as SKIP, marked skgpu::graphite:: and Dawn/wgpu as irrelevant, and framed shared GpuTypes.h changes as a Graphite-only trap rather than a change reaching both families. * skia-analyst excluded Graphite and Dawn changes outright. * sample-scout classified any file naming Graphite or Dawn as low and called Graphite 'not SkiaSharp'. Backend-internal GMs are still low; the test is now whether it exercises internals, not which backend it names. * api-docs used 'Vulkan (not yet supported)' as a formatting example. Also documents the container legs' ganesh-gl opt-out, which this branch added to five legs without saying so in containerized-testing.md.
…ll, iOS sim) Re-reviewed the Graphite guide against the current PR #3968 head (ed8d017) and its description, and folded in the details that were missing or now differ: - iOS Simulator: add the gradient-shader limitation. The simulator's Metal compiler cannot build some pipelines Graphite emits (notably gradient shaders), so recorder.Snap() returns null for that frame; the same content renders on macOS, real hardware, and with Ganesh/Metal. Keeps the existing supportsFamily under-reporting note. - Render loop: document that Snap() returns null on failure and null-check it in the example; point at the image provider for CPU-image draws. - GPU budget: note the no-options Create* factories use Skia's default budget (256 MB) via the -1 sentinel (a literal 0 disables budgeting), matching the sentinel fix in ed8d017; note MaxBudgetedBytes defaults to 256 MB. - Image provider: note SKGraphiteImageCache is an LRU cache (cap 256, keyed on unique id + mipmap), is IDisposable, and that FindOrCreate throws ArgumentNullException on null args (guard added in ed8d017). Verified against binding/SkiaSharp/Gpu/Graphite/*.cs and the generated structs at the current tip. Docs-only; links/anchors/TOC/xrefs re-validated. Co-authored-by: Copilot App <[email protected]> Copilot-Session: bdcc8d8b-500e-41ae-bb71-5e336ac92b1d
…n, skia.org refs Rebased onto main (Graphite PR #3968 is now merged) and added conceptual depth sourced from Skia's own docs, keeping every claim tied to the actual API: - Threading: correct the intro note to reflect Graphite's actual model — a single recorder is single-threaded, but (unlike a single-threaded Ganesh GRContext) Graphite is designed for parallel recording with one recorder per thread feeding a shared context; serialize InsertRecording/Submit. Align the migration guide's threading watch-out to match. - Add a "Pipeline compilation" section: Graphite compiles a GPU pipeline per unique draw/paint/blend/format combination on first use (cached after), so the first frame using a new combination costs more, and a driver that can't compile it makes Snap() return null — which is exactly the iOS-simulator gradient case. Note upstream Skia's pipeline precompilation exists but isn't surfaced in SkiaSharp yet. Cross-linked from the render loop and the iOS-simulator note. - Add authoritative skia.org "canvas creation" references to the raster, Ganesh, and Graphite Related Links. Docs-only; verified against the merged Graphite bindings on main (byte-identical to the reviewed ed8d017). Links/anchors/TOC/xrefs re-validated. Co-authored-by: Copilot App <[email protected]> Copilot-Session: bdcc8d8b-500e-41ae-bb71-5e336ac92b1d
…5316) (#5797) * [4.155] Backport four Skia CVE fixes and the emdawnwebgpu link fix (#5316) Pin externals/skia to an m155 backport carrying four more upstream Skia security fixes, and backport #5316 (and its Skia half, mono/skia#396) so WASM apps that link C sources build again. ~~ Skia security fixes (all Chrome-assigned, Chromium severity High) ~~ - CVE-2026-118340, integer overflow leaking cross-origin data. Chromium bug 568936530, upstream 8700229923 "[skif] Update SkImageFilter_Base uniqueID to 64-bit" (M156: c68d7fd343). - CVE-2026-119261, SkSL buffer overflow. Chromium bug 574213633, upstream 0a8b2fc486 "[SkSL] Reject invalid types when parsing" (M156: 961c7e83d9). - CVE-2026-121086, heap OOB write in SkRgnBuilder for conic paths. Chromium bug 569674218, upstream 50a301ac1c (M156: c433a0fce9). - CVE-2026-126912, heap-buffer-overflow in RunBasedAdditiveBlitter and the AAA convex walker. Chromium bug 569286603, upstream reland 866b61ca92 (M156: 0ac7dc6087). Google backported these to m156 and later but not m155. All four M156 cherry-picks applied to m155 without conflicts. ~~ Ship emdawnwebgpu's webgpu.cpp inside libSkiaSharp.a (#5316) ~~ 4.155 includes #3968, so its WASM targets compile Dawn's webgpu.cpp on the app's emcc link line with -std=c++20, which clang rejects for any C source the app links (for example Uno Platform 7's uno_gl_shim.c). Build the port into libSkiaSharp.a through mono/skia#396's skiasharp_emdawnwebgpu_dir GN argument instead, and stop putting the source, -std=c++20 and DEFAULT_TO_CXX on the link line. The targets and build.cake changes are identical to #5316; only the submodule and cgmanifest pins differ. C API declarations, DEPS, managed APIs and package versions are unchanged, and upstream_merge_commit still names the last incorporated chrome/m155 commit. (cherry picked from commit 9745920) Co-Authored-By: Claude Opus 5.5 <[email protected]> * [m155] Repin Skia to the ancestry-preserving CVE repair Context: mono/skia#465 Point externals/skia and the matching component manifest entry at e6cfc7a5d6dea7e8c21a59782c672a00b1fff28c. The repaired native history contains all seven original reviewed commits from mono/skia#461 and mono/skia#462 while retaining both squash landings. The native tree is identical to reviewed head 221ae11c5318. This changes only the two pins, not the security or WASM implementation. For this combined repair, verify original-commit ancestry and tree equality explicitly rather than requiring a direct-parent relationship. Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Copilot App <[email protected]>
Description of Change
Adds SkiaSharp bindings for Skia's Graphite GPU backend (Vulkan / Metal / Dawn-WebGPU). Depends on the companion C-shim PR in the skia submodule: mono/skia#236.
Graphite is Skia's next-generation GPU backend. Unlike Ganesh's auto-flushing draw stream, it uses an explicit record → snap → insert → submit model with a per-thread
Recorder. The managed surface mirrors that shape.API Changes
New types
10 new public types under
binding/SkiaSharp/Gpu/Graphite/(namespaceSkiaSharp):SKGraphiteContextskgpu::graphite::Context— staticCreateVulkan/CreateMetal/CreateDawnfactories (with/without options),IsBackendAvailable(...),CreateRecorder(...),InsertRecording(...),Submit(...),RequestReadPixels(...),CheckAsyncWorkCompletion(),FreeGpuResources(),PerformDeferredCleanup(...),DeleteBackendTexture(...)SKGraphiteRecorderskgpu::graphite::Recorder—Snap(),CreateBackendTexture(...),DeleteBackendTexture(...)SKGraphiteRecordingskgpu::graphite::RecordingSKGraphiteBackendTextureskgpu::graphite::BackendTexture—CreateVulkan/CreateMetal/CreateDawnfor wrapping a caller-allocated GPU texture;IsValid,BackendSKGraphiteTextureInfoskgpu::graphite::TextureInfo(per-backend construction);IsValid,Backend,SampleCount,MipmappedSKGraphiteImageCacheFindOrCreatesatisfies Graphite's image-provider hook (Graphite does not auto-upload non-Graphite images the way Ganesh does — see below)SKGraphiteVkBackendContextskgpu::VulkanBackendContext(instance / physical device / device / queue +GetProcedureAddress)SKGraphiteMtlBackendContextskgpu::graphite::MtlBackendContext(device + queue; also exposes strongly-typedIMTLDevice/IMTLCommandQueueon Apple TFMs)SKGraphiteDawnBackendContextskgpu::graphite::DawnBackendContext(instance / device / queue)SKGraphiteFindOrCreateImageDelegateEnums (generated):
SKGraphiteBackend,SKGraphiteInsertStatus.Option / info structs (generated):
SKGraphiteContextOptions,SKGraphiteSubmitInfo(Sync),SKGraphiteInsertRecordingInfo.Public delegates:
SKGraphiteFindOrCreateImageDelegate,SKGraphiteReleaseDelegate,SKGraphiteVkGetProcedureAddressDelegate.Async read-back uses the backend-neutral API (already on
main)Graphite surfaces don't support synchronous
SKSurface.ReadPixelsin shipping builds, so read-back goes through the backend-neutral async API that landed separately onmain(mono/SkiaSharp#4545 + mono/skia#295):SKImageReadPixelsResultand theSKImageRescaleGamma/SKImageRescaleModeenums. This PR consumes those (there is noSKGraphite-prefixed async-read type or rescale enum) and wires the async read onSKGraphiteContext,SKImage, andSKSurface. The default is(SKImageRescaleGamma.Src, SKImageRescaleMode.Nearest).Additive overloads on existing types
Additive only — no existing signature changes, ABI is preserved:
SKImage.FromTexture(SKGraphiteRecorder, SKGraphiteBackendTexture, SKColorType, SKAlphaType[, SKColorSpace][, SKGraphiteReleaseDelegate])SKImage.ToTextureImage(SKGraphiteRecorder[, bool mipmapped])SKImage.RequestReadPixels(SKImageInfo, SKRectI[, SKImageRescaleGamma, SKImageRescaleMode], Action<SKImageReadPixelsResult>)SKSurface.Create(SKGraphiteRecorder, SKImageInfo[, bool mipmapped][, SKSurfaceProperties])SKSurface.Create(SKGraphiteRecorder, SKGraphiteBackendTexture, SKColorType[, SKColorSpace][, SKSurfaceProperties][, SKGraphiteReleaseDelegate])SKSurface.RequestReadPixels(SKImageInfo, SKRectI[, SKImageRescaleGamma, SKImageRescaleMode], Action<SKImageReadPixelsResult>)The
FromTexture/ wrap-backend-textureCreateoverloads take an optionalSKGraphiteReleaseDelegatethat fires exactly once when Graphite releases the wrapped texture.SkiaApi.generated.csis regenerated against the new C headers — no hand-edits to generated files.Raster images on Graphite:
SKGraphiteImageCacheGanesh auto-uploads a raster
SKImageon first draw; Graphite instead calls back through a recorder image provider to obtain a GPU-backed version, and drops the draw if none answers. You supply that provider viaSKGraphiteContext.CreateRecorder(budget, SKGraphiteFindOrCreateImageDelegate).SKGraphiteImageCacheis the recommended default provider: an LRU-capped (256), ref-counted memoization ofSKImage.ToTextureImage(...)keyed on(UniqueId, mipmapped), so repeated draws of the same raster image don't re-upload every frame.Canonical render loop
Build-flag plumbing
skia_enable_graphite=trueis now set in the native build for every desktop/mobile platform (native/{linux,windows,macos,ios,tvos,android}/build.cake), with the per-backend switch enabled where it applies — Vulkan on Linux/Windows/Android, Metal on Apple. WebAssembly (native/wasm/build.cake) gates Graphite behindSUPPORT_GRAPHITEand, when on, builds Dawn-on-WebGPU using theemdawnwebgpuEmscripten port (scripts/infra/shared/emdawnwebgpu.cake).After this PR merges,
dotnet cake --target=externals-{platform}produces alibSkiaSharpwith Graphite linked in.Tests
tests/Tests/SkiaSharp/Visual/): a reflection-discoveredIRenderer× scene matrix. Renderers:raster,ganesh-gl,ganesh-metal,ganesh-vulkan,graphite-metal,graphite-vulkan,graphite-dawn; scenes:DiagonalLines,FilledCircle,GradientBlend,RedRoundedRectOnWhite,Text. Each cell renders and compares against a committed golden; a cell whose backend/GPU is unavailable on the host is skipped (not failed), so the matrix runs unchanged on CI agents without a Graphite-capable GPU. Graphite goldens are seeded forgraphite-metal(macOS + iOS-simulator) andgraphite-vulkan(Linux/lavapipe, Android, Windows/SwiftShader).SKGraphiteReleaseTestsBase+SKGraphiteReleaseMetalTests/SKGraphiteReleaseDawnTests/SKGraphiteReleaseVulkanTests): verify the wrap-backend-texture release delegate fires exactly once on dispose, across every Graphite backend the host can drive (skips cleanly where it can't).tests/VulkanTests/GraphiteVkBackendContextTest.cs): builds anSKGraphiteVkBackendContextfrom raw Vulkan handles (driven via Silk.NET) and brings up a Graphite Vulkan context.tests/Tests/ApiTests.cs): updated to cover the new types.Known platform note (tracked, not a blocker)
On the iOS simulator only,
graphite-metalcannot render the gradient-shader scene (GradientBlend): the simulator's Metal shader compiler fails to build the pipeline Graphite emits, soRecorder.Snap()returns null. Ganesh/Metal renders the same scene on the same simulator, and Graphite/Metal renders it on macOS — so it is a simulator-specific limitation. That one cell is skipped on the simulator (real hardware still fails hard, so genuine regressions aren't masked). Tracked in mono/SkiaSharp-API-docs#4555.Coexistence and compatibility
GR*(Ganesh) types are unchanged. Apps can use Ganesh and Graphite in the same process.Out of scope (follow-up PRs)
Layered features nothing here blocks:
PrecompileContext/precompile/*— pipeline-cache warming.PersistentPipelineStorage— client-supplied pipeline-cache blob.BackendSemaphore— cross-queue / cross-context sync.YUVABackendTextures— multi-plane Y′UV image wrapping.InsertRecordingInfotarget-surface retargeting.Behavioral Changes
None. All changes are additive; existing behavior is unchanged.
Required skia PR
mono/skia#236
PR Checklist