Skip to content

Add SkiaSharp bindings for the Graphite GPU backend (Vulkan/Metal/Dawn) - #3968

Merged
mattleibow merged 82 commits into
mono:mainfrom
ramezgerges:dev/graphite-backend
Jul 28, 2026
Merged

mattleibow merged 82 commits into
mono:mainfrom
ramezgerges:dev/graphite-backend

Conversation

@ramezgerges

@ramezgerges ramezgerges commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

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/ (namespace SkiaSharp):

Type Wraps / role
SKGraphiteContext skgpu::graphite::Context — static CreateVulkan / CreateMetal / CreateDawn factories (with/without options), IsBackendAvailable(...), CreateRecorder(...), InsertRecording(...), Submit(...), RequestReadPixels(...), CheckAsyncWorkCompletion(), FreeGpuResources(), PerformDeferredCleanup(...), DeleteBackendTexture(...)
SKGraphiteRecorder skgpu::graphite::Recorder — Snap(), CreateBackendTexture(...), DeleteBackendTexture(...)
SKGraphiteRecording skgpu::graphite::Recording
SKGraphiteBackendTexture skgpu::graphite::BackendTexture — CreateVulkan / CreateMetal / CreateDawn for wrapping a caller-allocated GPU texture; IsValid, Backend
SKGraphiteTextureInfo skgpu::graphite::TextureInfo (per-backend construction); IsValid, Backend, SampleCount, Mipmapped
SKGraphiteImageCache managed helper: an LRU image cache whose FindOrCreate satisfies Graphite's image-provider hook (Graphite does not auto-upload non-Graphite images the way Ganesh does — see below)
SKGraphiteVkBackendContext skgpu::VulkanBackendContext (instance / physical device / device / queue + GetProcedureAddress)
SKGraphiteMtlBackendContext skgpu::graphite::MtlBackendContext (device + queue; also exposes strongly-typed IMTLDevice / IMTLCommandQueue on Apple TFMs)
SKGraphiteDawnBackendContext skgpu::graphite::DawnBackendContext (instance / device / queue)
SKGraphiteFindOrCreateImageDelegate delegate for the image-provider callback

Enums (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.ReadPixels in shipping builds, so read-back goes through the backend-neutral async API that landed separately on main (mono/SkiaSharp#4545 + mono/skia#295): SKImageReadPixelsResult and the SKImageRescaleGamma / SKImageRescaleMode enums. This PR consumes those (there is no SKGraphite-prefixed async-read type or rescale enum) and wires the async read on SKGraphiteContext, SKImage, and SKSurface. 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-texture Create overloads take an optional SKGraphiteReleaseDelegate that fires exactly once when Graphite releases the wrapped texture.

SkiaApi.generated.cs is regenerated against the new C headers — no hand-edits to generated files.

Raster images on Graphite: SKGraphiteImageCache

Ganesh auto-uploads a raster SKImage on 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 via SKGraphiteContext.CreateRecorder(budget, SKGraphiteFindOrCreateImageDelegate). SKGraphiteImageCache is the recommended default provider: an LRU-capped (256), ref-counted memoization of SKImage.ToTextureImage(...) keyed on (UniqueId, mipmapped), so repeated draws of the same raster image don't re-upload every frame.

Canonical render loop

using var context = SKGraphiteContext.CreateVulkan(backendContext);
using var imageCache = new SKGraphiteImageCache();
using var recorder = context.CreateRecorder(-1, (rec, img, mip) => imageCache.FindOrCreate(rec, img, mip));

using var surface = SKSurface.Create(recorder, new SKImageInfo(width, height));
surface.Canvas.DrawRoundRect(...);

using var recording = recorder.Snap();
context.InsertRecording(recording);
context.Submit(new SKGraphiteSubmitInfo { Sync = true });

// Graphite surfaces do NOT support synchronous SKSurface.ReadPixels in shipping
// builds; read back through the async path instead (backend-neutral result type):
context.RequestReadPixels(surface, info, srcRect, result => { /* result.ToArray() */ });
context.CheckAsyncWorkCompletion();

Build-flag plumbing

skia_enable_graphite=true is 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 behind SUPPORT_GRAPHITE and, when on, builds Dawn-on-WebGPU using the emdawnwebgpu Emscripten port (scripts/infra/shared/emdawnwebgpu.cake).

After this PR merges, dotnet cake --target=externals-{platform} produces a libSkiaSharp with Graphite linked in.

Tests

  • Visual regression matrix (tests/Tests/SkiaSharp/Visual/): a reflection-discovered IRenderer × 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 for graphite-metal (macOS + iOS-simulator) and graphite-vulkan (Linux/lavapipe, Android, Windows/SwiftShader).
  • Release-callback tests (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).
  • Vulkan backend-context test (tests/VulkanTests/GraphiteVkBackendContextTest.cs): builds an SKGraphiteVkBackendContext from raw Vulkan handles (driven via Silk.NET) and brings up a Graphite Vulkan context.
  • API surface test (tests/Tests/ApiTests.cs): updated to cover the new types.

Known platform note (tracked, not a blocker)

On the iOS simulator only, graphite-metal cannot render the gradient-shader scene (GradientBlend): the simulator's Metal shader compiler fails to build the pipeline Graphite emits, so Recorder.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

  • All existing GR* (Ganesh) types are unchanged. Apps can use Ganesh and Graphite in the same process.
  • No public signatures changed — only additive overloads / new types / a new namespace. ABI stays stable for downstream consumers.
  • Non-Graphite legs of CI are untouched.

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.
  • InsertRecordingInfo target-surface retargeting.
  • Direct3D — Skia upstream doesn't ship a Graphite/D3D backend.
  • Public API documentation (authored separately in mono/SkiaSharp-API-docs; prose reconciled, XML skeletons generated post-merge).

Behavioral Changes

None. All changes are additive; existing behavior is unchanged.

Required skia PR

mono/skia#236

PR Checklist

  • Has tests (visual regression matrix + release-callback tests + Vulkan backend-context test)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation (in progress in mono/SkiaSharp-API-docs — prose reconciled; XML docs generated after merge)

@github-actions

github-actions Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

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 -- 3968

PowerShell / 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-3968
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-3968

@mattleibow

mattleibow commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
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.

@ramezgerges
ramezgerges force-pushed the dev/graphite-backend branch from 0468742 to 1731d7e Compare May 12, 2026 23:51
@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

5 similar comments
@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@ramezgerges
ramezgerges force-pushed the dev/graphite-backend branch 4 times, most recently from 26ff18b to 4a02f35 Compare May 25, 2026 23:55
@azure-pipelines

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mattleibow

Copy link
Copy Markdown
Contributor

Filed #4555 for the iOS-simulator Graphite/Metal finding: Recorder.Snap() returns null for the gradient scene (GradientBlend) on the iOS 26.2 simulator.

Handled in this PR (commit bd78469) — seeded the 4 working graphite-metal.ios goldens and skip just that one cell on the simulator via RendererUnavailableException (real hardware still hard-fails, so regressions aren't masked). Full scoping, repro, and logs are in #4555.

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
@mattleibow

Copy link
Copy Markdown
Contributor

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 ed8d017 (managed-only, no ABI/native change):

  1. Default GPU budget sentinel. SKGraphiteContext.Create{Vulkan,Metal,Dawn}(backendContext) (the no-options overloads) passed default(SKGraphiteContextOptions), so GpuBudgetInBytes = 0. The shim overwrites the budget whenever it's >= 0 (the "use Skia default" sentinel is negative, per sk_graphite.h), so every no-options context silently got a 0-byte GPU resource cache instead of Skia's 256 MB default → resource-cache thrashing. Now seeds the documented -1. (InternalMultisampleCount 0 is already the "use default" sentinel and the bools match Skia's release defaults, so only the budget needed it.)
  2. SKGraphiteImageCache.FindOrCreate dereferenced image.UniqueId with no null check — added the standard ArgumentNullException guards.

One design question for you (didn't change unilaterally, needs a native tweak): a caller who hand-builds SKGraphiteContextOptions and sets only, say, InternalMultisampleCount (leaving GpuBudgetInBytes = 0) still hits the 0-byte-budget footgun, since 0 is a valid "explicit 0" under the C sentinel. MSAA already treats 0 as "use default" — want to align the budget the same way (treat managed 0 as "use default", in the shim or by mapping in the managed layer) so partially-built/default options just work? Left that to you.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

mattleibow added a commit to mono/skia that referenced this pull request Jul 28, 2026
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
@mattleibow
mattleibow merged commit 3047f3a into mono:main Jul 28, 2026
111 of 115 checks passed
mattleibow added a commit that referenced this pull request Jul 29, 2026
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.
mattleibow added a commit that referenced this pull request Aug 4, 2026
… + 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]>
mattleibow added a commit that referenced this pull request Aug 4, 2026
…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]>
mattleibow added a commit that referenced this pull request Aug 4, 2026
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]>
mattleibow added a commit that referenced this pull request Aug 4, 2026
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.
@ramezgerges
ramezgerges deleted the dev/graphite-backend branch August 5, 2026 15:46
mattleibow pushed a commit that referenced this pull request Aug 6, 2026
…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
mattleibow pushed a commit that referenced this pull request Aug 6, 2026
…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
mattleibow added a commit that referenced this pull request Nov 17, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ partner/unoplatform Issues and PRs that are/should being looked at or worked on by the Uno Platform partners.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants