# Choose Canvas or GPU rendering

Start with Canvas for text, controls, paths, charts, and diagrams. Choose a GPU surface when you need shader-driven geometry, a depth buffer, or large batches of textured triangles. Both paths can appear in the same view tree.

Xui's GPU API is experimental. A GPU interface tells you what to request; it does not guarantee that a window can supply it.

## Two different jobs

`RenderCore(IContext)` draws into the current Canvas context. It can also place a GPU surface using `context.GpuSurface(...)`. The surface's stable key implements `IGpuSurfaceContent`; the runtime calls its `Render(IGpuRenderTarget)` to submit GPU commands.

The runtime owns that presentation target. Use it during the callback, then let it go. Do not retain or dispose it. Your view owns the shaders, command lists, and any offscreen targets it creates. Release those when the view deactivates. The window owns the device returned by `GetService`.

## Check the capability you need

| Requirement | Contract to check |
| --- | --- |
| Present a GPU node in a Canvas tree | The boolean result and failure from `IContext.GpuSurface` |
| Compile and submit a basic mesh | Window service `IGpuDevice` and `IShaderBackend` |
| Upload immutable geometry or sampled textures | `IGpuResourceDevice` and `IGpuResourceCommandList` |
| Export a vector figure | Software `SvgDrawingContext`; a GPU frame is not vector geometry |

Windows uses Direct3D, Apple runtimes use Metal, and the browser uses WebGL 2. Android's current Vulkan path supports the cube-style position/color layout, one draw per pass, and a uniform buffer. It does not provide general sampled textures or offscreen readback. A disabled WebGL context, unsupported clip, or missing service needs an explicit fallback; a platform name alone is insufficient.

## Make failure understandable

For a decorative effect, draw a simpler Canvas version. For a required 3D editor, show a clear unavailable state and preserve the user's data. Do not silently call a CPU picture “hardware rendering.”

The [triangle example](../triangle/index.md) shows a real GPU submission and a readable Canvas fallback. Its static SVG displays the fallback because the SVG renderer does not execute GPU surfaces. Starting the demo attempts the actual browser GPU path.
