Expose Skia's Vulkan device-lost callback (#4601) - #338
Open
ramezgerges wants to merge 1 commit into
Open
Conversation
14 tasks
Skia's skgpu::VulkanBackendContext gained fDeviceLostContext / fDeviceLostProc after the milestone we last mapped this struct against. On VK_ERROR_DEVICE_LOST Skia invokes the callback with driver-provided fault text (from VK_EXT_device_fault when the extension is enabled) — the intended channel for apps to react to TDRs / driver resets. Until now the C shim didn't expose it, so managed callers had no way to see device-loss events. * new gr_vk_device_lost.h / .cpp — opaque handle, gr_vk_device_lost_handler_new(proc, userData) / gr_vk_device_lost_handler_delete(handle). Bridge adapts Skia's beefy callback signature (std::string + VkDeviceFaultAddressInfoEXT / VendorInfo vectors) down to a plain C proc that takes only the description. v1 drops the fault-detail arrays; a fault-details overload can land later if a customer needs them. * gr_vk_backendcontext_t and sk_graphite_vk_backend_context_init_t gain fDeviceLostHandler. Nullable, caller-owned; the C shim installs the bridge on skgpu::VulkanBackendContext non-owning so the handle must outlive the Context. * AsGrVkBackendContext + sk_graphite_context_make_vulkan wire the handle through to Skia's fDeviceLostContext / fDeviceLostProc. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
ramezgerges
force-pushed
the
dev/issue-4601-vulkan-device-lost-callback
branch
from
August 4, 2026 17:42
61a61ac to
482d44c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Exposes Skia's Vulkan device-lost callback (
skgpu::VulkanBackendContext.fDeviceLostContext/fDeviceLostProc) on the C API so managed callers can react toVK_ERROR_DEVICE_LOST— the intended channel for detecting TDRs / driver resets.Skia's own callback signature is
(std::string description, std::vector<VkDeviceFaultAddressInfoEXT>, std::vector<VkDeviceFaultVendorInfoEXT>, std::vector<std::byte>). Not C-ABI-friendly. The shim adapts it into agr_vk_device_lost_info_tPOD struct that mirrors the full payload — description string + address-info array + vendor-info array + vendor binary blob. The Vk struct layouts are stable ABI, so the shim'sgr_vk_device_fault_*_info_tmirror them field-for-field andreinterpret_castthe vector storage (no per-element copy). Static_assert guards the layout equivalence.Same caller-owned bridge pattern as
sk_graphite_shader_error_handler(_newreturns an opaque handle; caller passes to backend context; caller deletes after Context destruction). No leaks.SkiaSharp issue
Related to mono/SkiaSharp#4601
Required SkiaSharp PR
Requires mono/SkiaSharp#4655
Areas affected
include/c,src/c)DEPSChanges
C API
Behavior
fDeviceLostHandlernow receive Skia's full device-lost payload on the driver-owned thread — description + address-info array + vendor-info array + vendor binary blob (the last three empty whenVK_EXT_device_faultisn't enabled).fDeviceLostHandlernull get today's behavior (no callback).Testing
Verified in the companion SkiaSharp PR: 5 proxy-level marshalling tests + 5 Vulkan integration tests. All pass locally on Linux/Lavapipe alongside the full Vulkan regression suite (28 pass / 2 skip / 0 fail).
Actually forcing
VK_ERROR_DEVICE_LOSTin CI isn't realistic (needs hardware TDR); the proxy tests cover the marshalling, the integration tests cover the wiring.Checklist
skiasharpbranchChangesabove lists every added/changed C API export (or "None.")mono/SkiaSharpPR linked above (submodule bump at minimum; regenerates bindings + adds tests for C API changes)