AvaloniaUI/Avalonia · error · NotSupportedException
Need skia to dump textures, sorry
Error message
Need skia to dump textures, sorry
What it means
In SaveTexture, when there is no Skia GPU context (_vk.GrContext == null) and no IOSurface path available, the sample throws NotSupportedException. It means the texture-dump fallback requires Skia (GrContext) to read GPU pixels, and on non-macOS without Skia it cannot proceed.
Source
Thrown at samples/GpuInterop/VulkanDemo/VulkanImage.cs:365
{
var surf = ExportIOSurface();
if (NativeMethods.IOSurfaceLock(surf, 0, IntPtr.Zero) != 0)
throw new Exception("IOSurfaceLock failed");
var w = (int)NativeMethods.IOSurfaceGetWidth(surf);
var h = (int)NativeMethods.IOSurfaceGetHeight(surf);
var sstride = NativeMethods.IOSurfaceGetBytesPerRow(surf);
var pSurface = NativeMethods.IOSurfaceGetBaseAddress(surf);
using var b = new Avalonia.Media.Imaging.Bitmap(PixelFormat.Bgra8888,
AlphaFormat.Premul, pSurface, new PixelSize(w, h),
new Vector(96, 96), (int)sstride);
b.Save(path, PngBitmapEncoderOptions.Default);
NativeMethods.IOSurfaceUnlock(surf, 0, IntPtr.Zero);
return;
}
else
throw new NotSupportedException("Need skia to dump textures, sorry");
}
_vk.GrContext.ResetContext();
var _image = this;
var imageInfo = new GRVkImageInfo()
{
CurrentQueueFamily = _vk.QueueFamilyIndex,
Format = (uint)_image.Format,
Image = _image.Handle,
ImageLayout = (uint)_image.CurrentLayout,
ImageTiling = (uint)_image.Tiling,
ImageUsageFlags = (uint)_image.UsageFlags,
LevelCount = _image.MipLevels,
SampleCount = 1,
Protected = false,
Alloc = new GRVkAlloc()
{
Memory = _image.MemoryHandle, Flags = 0, Offset = 0, Size = _image.MemorySizeView on GitHub (pinned to 11c5427268)
Solutions
- Initialize and keep a valid Skia GrContext bound to the Vulkan device so SaveTexture can use it.
- On macOS, ensure _hasIOSurface is true so the IOSurface dump path is taken instead.
- Avoid calling SaveTexture when no GPU readback backend (Skia or IOSurface) is available.
- Implement a plain vkCmdCopyImageToBuffer readback fallback if Skia is undesirable.
Example fix
// before
else
throw new NotSupportedException("Need skia to dump textures, sorry");
// after (explicit, actionable)
else
throw new NotSupportedException(
"Texture dump requires a Skia GrContext (or an IOSurface on macOS). Initialize _vk.GrContext before calling SaveTexture."); Defensive patterns
Strategy: validation
Validate before calling
// only attempt a dump if a readback backend exists var canDump = _vk.GrContext is not null || (OperatingSystem.IsOSPlatform(OSPlatform.OSX) && _hasIOSurface); if (!canDump) return;
Type guard
static bool HasReadbackBackend(VulkanImage img) => img._vk.GrContext is not null || img._hasIOSurface;
Try / catch
try { SaveTexture(path); }
catch (NotSupportedException ex) when (ex.Message.Contains("skia"))
{ _logger.LogWarning("No Skia GPU context; cannot dump texture."); } Prevention
- Initialize a Skia GrContext on Linux/Windows if you need texture dumps.
- On macOS, ensure _hasIOSurface so the IOSurface path is used.
- Gate SaveTexture behind a readback-backend check.
When it happens
Trigger: Calling SaveTexture when the demo has no GrContext (SkiaSharp GPU context) wired up and the platform is not macOS-with-IOSurface. The code only handles IOSurface on macOS; everything else routes through Skia, which is absent here.
Common situations: Running the Vulkan demo on Linux/Windows where the Skia GPU bridge was not initialized; GrContext disposed before dump; trimming/AOT removing Skia.
Related errors
- IOSurfaceLock failed
- Unable to export IOSurfaceRef
- Unable to export IOSurfaceRef
- Device with the corresponding LUID not found
- Not supported format
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/70c165d439782061.
Report an issue: GitHub.