Table of Contents

Use Graphite with Dawn

Graphite Dawn is the WebGPU backend used by SkiaSharp in browser/WebAssembly hosts. SKGraphiteContext.IsBackendAvailable(SKGraphiteBackend.Dawn) reports whether the Dawn factory was compiled into the current native library.

Create the Graphite context

Supply the WebGPU instance, device, and queue handles:

using var backendContext = new SKGraphiteDawnBackendContext
{
    WgpuInstance = instanceHandle,
    WgpuDevice = deviceHandle,
    WgpuQueue = queueHandle,
};

using var context = SKGraphiteContext.CreateDawn(backendContext);

With the emdawnwebgpu port, create a real WGPUInstance through wgpuCreateInstance. Register the device and queue under that instance as their event-source parent. A placeholder or mismatched instance can cause SKGraphiteContext.CreateDawn to wait indefinitely.

Submit from the browser loop

The browser event loop cannot be pumped from inside a managed call, so synchronous submission is not allowed. Calling Submit with Sync = true throws InvalidOperationException.

Submit without blocking, then drive completion from the host render or event loop:

context.InsertRecording(recording);
context.Submit(new SKGraphiteSubmitInfo { Sync = false });

// Later, from the host loop:
context.CheckAsyncWorkCompletion();

The same rule applies to readback: request the pixels, submit asynchronously, and keep pumping CheckAsyncWorkCompletion until the callback runs.

Wrap Dawn textures

Use SKGraphiteBackendTexture.CreateDawn(wgpuTexture) to describe an existing WebGPU texture, then pass it to the shared SKSurface.Create(recorder, backendTexture, colorType) overload. The native WebGPU texture remains owned by the code that created it; release it only after any supplied Graphite release callback fires.

Next steps

Continue with the shared Graphite recording, submission, readback, texture, and resource flow.