Repository navigation
Fix Graphite/Metal GradientBlend on the iOS simulator + shader-error diagnostic API (#4555) - #4586
ramezgerges wants to merge 8 commits into
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 -- 4586PowerShell / Windows: iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 4586"Step 2 — Add the local NuGet source dotnet nuget add source ~/.skiasharp/hives/pr-4586/packages --name skiasharp-pr-4586More options
Or download manually from Azure Pipelines — look for the Remove the source when you're done: dotnet nuget remove source skiasharp-pr-4586 |
#4555 was broadened to cover all three Metal failures because they share a root cause: no CI host has a real Metal device. That was wrong for tracking. #4586 carries 'Fixes #4555' and addresses only the iOS simulator's gradient pipeline, so merging it would have silently closed the macOS shutdown hang and the Mac Catalyst GPU-family gap along with it. #4555 is back to its original scope. The other two are now #4598 (macOS virtualized Metal hangs the test host on shutdown, killing the whole leg) and #4599 (Mac Catalyst reports no MTLGPUFamily that Ganesh or Graphite accepts). Each has its own cause and its own likely fix -- an Apple Silicon pool for the first, possibly a probe change for the second -- so each closes on its own. Repointed the opt-out comments and the policy doc at whichever issue explains that leg, and updated the #4591 umbrella table. The iOS leg cites both #4598 and #4555, because the simulator has the shutdown hang *and* the gradient bug.
|
/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. |
1 similar comment
|
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. |
0b92317 to
9ab7523
Compare
|
Rebased onto the current |
9ab7523 to
a12b2b3
Compare
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Graphite/Metal iOS-simulator rendering failure (null Recorder.Snap() in the GradientBlend scene) and introduces a managed shader-error diagnostic hook by wiring a new native fShaderErrorHandler option through to SKGraphiteContext creation.
Changes:
- Adds
SKGraphiteShaderErrorHandlerDelegateand newCreateDawn/CreateMetal/CreateVulkanoverloads that accept a shader-error handler, with lifetime management via pinned delegates and a native bridge handle. - Removes the simulator-specific null-
Snap()special-casing in the Graphite/Metal visual renderer so regressions fail consistently across hosts. - Adds a Vulkan smoke test ensuring installing a shader-error handler does not break context teardown and basic submission.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/VulkanTests/GraphiteVkBackendContextTest.cs | Adds a Vulkan smoke test for the new shader-error handler overload and lifetime/teardown behavior. |
| tests/Tests/SkiaSharp/Visual/Renderers/GraphiteMetalRenderer.cs | Makes Recorder.Snap() null a hard failure on all hosts (including simulator) now that the underlying issue is fixed. |
| binding/SkiaSharp/SkiaApi.generated.cs | Adds new P/Invoke surface and struct field for sk_graphite_shader_error_handler_t and SKGraphiteContextOptions.fShaderErrorHandler. |
| binding/SkiaSharp/Gpu/Graphite/SKGraphiteContext.cs | Adds handler-overload factories and pins/tears down managed + native handler bridge resources. |
| binding/SkiaSharp/DelegateProxies.cs | Adds the managed callback proxy implementation for shader-error handler invocations. |
| binding/SkiaSharp.Skottie/SkottieApi.generated.cs | Regenerates typedefs to include the new Graphite shader-error handler type alias. |
| binding/SkiaSharp.SceneGraph/SceneGraphApi.generated.cs | Regenerates typedefs to include the new Graphite shader-error handler type alias. |
| binding/SkiaSharp.Resources/ResourcesApi.generated.cs | Regenerates typedefs to include the new Graphite shader-error handler type alias. |
mattleibow
left a comment
There was a problem hiding this comment.
Requesting changes: the shader-handler test does not verify callback delivery, and the new backend-specific test setup should be consolidated with the existing Graphite backend harness so future Graphite scenarios can run consistently across Vulkan, Metal, and Dawn.
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
5 similar comments
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
📦 Artifact size reportPackages from this PR (build Total Packages
+38 package(s) unchanged (< 50.0 KB). Per-file changes
|
| File | Size |
|---|---|
🧬 wasm 5.0.6/mt · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/5.0.6/mt/libSkiaSharp.a) |
17.9 MB → 17.9 MB (🔴 +1.5 KB) |
🧬 wasm 5.0.6/st,simd · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/5.0.6/st,simd/libSkiaSharp.a) |
18.2 MB → 18.2 MB (🔴 +1.5 KB) |
🧬 wasm 5.0.6/mt,simd · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/5.0.6/mt,simd/libSkiaSharp.a) |
18.2 MB → 18.2 MB (🔴 +1.5 KB) |
🧬 wasm 5.0.6/st · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/5.0.6/st/libSkiaSharp.a) |
17.9 MB → 17.9 MB (🔴 +1.5 KB) |
🧬 wasm 3.1.56/mt · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/3.1.56/mt/libSkiaSharp.a) |
17.7 MB → 17.7 MB (🔴 +1.5 KB) |
🧬 wasm 3.1.56/st · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/3.1.56/st/libSkiaSharp.a) |
17.8 MB → 17.8 MB (🔴 +1.5 KB) |
🧬 wasm 3.1.56/mt,simd · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/3.1.56/mt,simd/libSkiaSharp.a) |
18.0 MB → 18.0 MB (🔴 +1.5 KB) |
🧬 wasm 3.1.56/st,simd · libSkiaSharp.a (buildTransitive/netstandard1.0/libSkiaSharp.a/3.1.56/st,simd/libSkiaSharp.a) |
18.0 MB → 18.0 MB (🔴 +1.5 KB) |
SkiaSharp.NativeAssets.WinUI
| File | Size |
|---|---|
runtimes/win-x64/native/libGLESv2.pdb |
66.6 MB → 66.5 MB (🟢 −144.0 KB) |
runtimes/win-arm64/native/libGLESv2.pdb |
64.5 MB → 64.4 MB (🟢 −80.0 KB) |
runtimes/win-x86/native/libGLESv2.pdb |
67.3 MB → 67.2 MB (🟢 −80.0 KB) |
Informational only — this never blocks the PR. Native binaries are labelled by os/arch.
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
5 similar comments
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
a12b2b3 to
077354b
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. |
1 similar comment
|
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. |
3c4749f to
a073aec
Compare
a073aec to
fbec948
Compare
|
Thanks for the iOS-simulator Callback API In GPU budget
fGpuBudgetInBytes = gpuBudgetInBytes == 0 ? -1 : gpuBudgetInBytes;This also changes an explicit private long? gpuBudgetInBytes;
public long GpuBudgetInBytes {
readonly get => gpuBudgetInBytes.GetValueOrDefault();
set => gpuBudgetInBytes = value;
}
// In ToNative:
fGpuBudgetInBytes = gpuBudgetInBytes ?? -1;The public property stays Exception-safe ownership In Metal failure diagnostics On pipeline-state failure, sharedContext->caps()->shaderErrorHandler()->compileError(
label.c_str(), diag.c_str(), /*shaderWasCached=*/false);But Failure-path coverage
|
fbec948 to
91c4759
Compare
91c4759 to
5ec253f
Compare
5f843a8 to
9cffbc8
Compare
mattleibow
left a comment
There was a problem hiding this comment.
One additional follow-up not covered by my earlier review: the callback decodes shader and errors with Marshal.PtrToStringAnsi. On Windows that uses the active ANSI code page rather than UTF-8, so non-ASCII shader source or diagnostics can be corrupted. Please decode these native UTF-8 strings explicitly (for example, with Marshal.PtrToStringUTF8) and add a non-ASCII forwarding test.
|
@mattleibow requesting a re-review: all five threads from your August review were addressed and resolved on 2026-08-04 (callback-delivery coverage via |
Wraps the new sk_graphite_context_options.fShaderErrorHandler C API so managed callers can capture Graphite shader compile failures. The motivating case is the Metal iOS simulator gradient scene where Recorder.Snap() silently returns null with no diagnostic — Skia's default handler prints via SkDebugf + asserts, which is invisible in shipping apps on Apple platforms. * new CreateDawn/CreateMetal/CreateVulkan overloads taking SKGraphiteShaderErrorHandlerDelegate (backwards-compatible additions, no signature changes) * SKGraphiteShaderErrorHandlerDelegate proxy in DelegateProxies never throws across the FFI boundary — a bad handler cannot crash Skia's shader-compile path * GCHandle pinned for the Context's lifetime, freed in DisposeNative after the native context tears down its internal handler pointer Includes GraphiteVkContextAcceptsShaderErrorHandler smoke test that proves the wiring survives Context create + trivial draw + dispose on Vulkan (Lavapipe compiles cleanly so the callback does not fire — the important assertion is no double-free / no EntryPointNotFound on teardown). The Metal simulator failure path requires an iOS host to reproduce and is out of scope for CI. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Root cause (diagnosed with the fShaderErrorHandler hook from this branch, plus PSO-failure forwarding added to it): Graphite's MtlCaps enabled framebuffer fetch for every Apple-family GPU and Caps::getDstReadStrategy() then always used it for dst reads. The iOS simulator advertises an Apple GPU family but cannot read a render target from a fragment shader — the MSL compiles, but newRenderPipelineStateWithDescriptor fails with CompilerError Code=2 "reading from a rendertarget is not supported" — so the Multiply-blend draw in GradientBlend (the only matrix scene needing a dst read) nulled its pipeline and Recorder.Snap() returned null. Ganesh/Metal never uses framebuffer fetch and real devices/macOS support it, which is why only this one cell failed. Submodule changes (mono/skia dev/issue-4555-graphite-shader-error-handler): * Metal PSO-creation failures are now reported through the ShaderErrorHandler (previously SkDebugf-only, invisible on iOS) * framebuffer fetch is disabled under TARGET_OS_SIMULATOR; dst reads fall back to DstReadStrategy::kTextureCopy there Test harness: * remove the simulator-only null-Snap() skip seam from GraphiteMetalRenderer — a null Snap() is a hard failure everywhere again, so regressions can no longer hide behind the skip * seed the graphite-metal.ios/GradientBlend golden (rendered on an iPhone 16 / iOS 26.1 simulator; pixel-identical to the graphite-metal.macos golden) Verified on the iOS simulator: full SkiaSharp.Tests.Devices run is green (1219 total, 0 failed, 1138 succeeded, 81 skipped), with the GradientBlend cell rendering and matching its golden. Fixes mono#4555. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-authored-by: Copilot App <[email protected]> Copilot-Session: bf9e0803-2d6c-49eb-b83a-ed4d81ebbc31
Pass explicit zero-byte GPU budgets through unchanged and cover the managed options conversion with exact-value regression cases. Use one stable diagnostic handler for the shared Dawn harness so shader coverage follows GpuPolicy without a separate capability skip. Assert diagnostics after scenario cleanup and fail when shared-context options differ. Co-authored-by: Copilot App <[email protected]> Copilot-Session: bf9e0803-2d6c-49eb-b83a-ed4d81ebbc31
SKGraphiteContext.Create{Dawn,Metal,Vulkan} called options.ToNative(),
which allocates a GCHandle and native bridge for the shader-error
handler, before backendContext.ToNative(), which throws on incomplete
backend handles. A throwing backend left the handler rooted forever.
Convert the backend first so nothing is allocated before validation.
Adds FailedCreateDoesNotRootShaderErrorHandler (Metal/Vulkan/Dawn),
which failed 3/3 before the reorder and passes after.
Also adapts the shader-error proxy to the generator's byte-marshalled
bool after rebasing onto main.
Co-authored-by: Copilot App <[email protected]>
Exercise non-ASCII callback strings and both cache flags. Require successful Snap and Submit in the shared backend harness. Co-authored-by: Copilot App <[email protected]>
9cffbc8 to
574d678
Compare
Inject a pipeline-state creation failure via an ObjC swizzle and assert the handler receives MSL source rather than the pipeline label. Repin externals/skia to the native fix. Co-authored-by: Copilot App <[email protected]>
…no (mono#4555) Skia reports shader source and compiler errors as UTF-8, but the proxy decoded them with PtrToStringAnsi, which uses the system code page on Windows and mangled every non-ASCII character. Decode explicitly with Encoding.UTF8, which works on every target including netstandard2.0 and .NET Framework where Marshal.PtrToStringUTF8 is unavailable. FailedCreateDoesNotRootShaderErrorHandler relies on a WeakReference being cleared, which Mono's conservative stack scanning does not guarantee, so it failed on Android even though no handler is pinned on that path. Use the existing SkipOnMono policy like the other collection tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Description
Fixes the Graphite/Metal
GradientBlendfailure on the iOS simulator by selecting texture-copy destination reads instead of unsupported framebuffer fetch. Exposes shader and Metal pipeline-creation diagnostics throughSKGraphiteContextOptions.ShaderErrorHandler; the managed callback stays rooted until the native context and its caller-owned handler bridge are destroyed.The review follow-up preserves explicitly requested zero-byte GPU budgets and removes the independent Dawn shader-test capability skip. All Graphite backend scenarios use the same diagnostic handler, the process-shared Dawn context verifies matching options, and shader errors are asserted after scenario cleanup. Skips are controlled only by the existing
GpuPolicy.Current verification is structural only. The follow-up regression tests and rebuilt-native GPU/device behavior have not been executed at the current head. Native builds, device runs, and heavy restores remain paused; historical device/Vulkan results are not current-head proof.
Related issues
Fixes #4555
Required skia PR
Requires mono/skia#308. The submodule remains pinned to
2e210c699456831d90d413775646d9d44116b569; the companion PR is still open.Areas affected
binding/)externals/skia/src/c,include/c)Changes
Public API
Added delegate and members on
SKGraphiteContextOptions:Existing
SKGraphiteContext.CreateDawn,CreateMetal, andCreateVulkansignatures are retained. The handler is supplied through the options property, not through new three-parameter factory overloads. The review follow-up changes no public declarations or constructor defaults.Behavior
Recorder.Snap()remains a hard failure.default(SKGraphiteContextOptions), passes through as zero. Negative values retain their default-budget sentinel meaning. The parameterless constructor and no-options factories retain this PR's existing-1initialization.Testing
git --no-pager diff --check 085a3a619c1af059a022a41f0718c195bdac753d..HEAD— passed.git --no-pager diff --exit-code 085a3a619c1af059a022a41f0718c195bdac753d..HEAD -- scripts tests/SkiaSharp.Tests.Samples tests/SkiaSharp.Tests.Samples.Analyzers tests/SkiaSharp.Tests.Samples.slnx tests/Tests/SkiaSharp/Gpu/GpuPolicy.cs documentation/dev/building-samples.md— passed; canonical CI/Samples contracts and GPU policy are unchanged.git --no-pager diff --exit-code 5ec253f7ffa82a9d999469f730de97af7c74f2d7..HEAD -- externals/skia binding/SkiaSharp/Generated binding/SkiaSharp/Gpu/Graphite/SKGraphiteContext.cs— passed; the scoped follow-up leaves the native pin, generated interop, factory signatures, and native ownership code unchanged.SKGraphiteContextOptionsTestcoverage for-2,-1,0,1,268435456, andlong.MaxValue, plus default-initialized and parameterless-constructor options. These native-call-free conversion cases have not been executed.dotnet cake --target=externals-macos --arch=arm64— not run, under the native-build pause. The submodule is uninitialized andoutput/nativeis absent.externals-downloadis not a valid substitute for this native pin.dotnet test tests/SkiaSharp.Tests.Console.slnx -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0— not run; native binaries and managed restore assets are absent, with heavy restores paused.tests/Content/Goldens/graphite-metal.ios/GradientBlend.pngis retained unchanged; fresh rendering comparison and before/after screenshots remain outstanding. Earlier author-reported device/Vulkan runs are historical and are not reused as verification of this revision.Checklist
Changesabove lists all public API and behavioral changes (or "None.")///documentation and regenerated bindings when applicablemono/skiaPR linked above and bindings regenerated