Skip to content

Commit acca457

Browse files
Update WebGPU docs.
1 parent 185f7d6 commit acca457

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

src/ImageSharp.Drawing.WebGPU/WebGPUDeviceContext{TPixel}.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
77

88
/// <summary>
9-
/// A WebGPU drawing context for a specific <typeparamref name="TPixel"/> that owns the drawing backend and device handles used to create frames, canvases, and render targets.
10-
/// Use this type when you already own the device and queue, or when you want direct control over how ImageSharp.Drawing wraps external WebGPU textures.
9+
/// Binds ImageSharp.Drawing's WebGPU backend to an externally-owned device and queue.
10+
/// Use <see cref="CreateCanvas(nint, nint, WebGPUTextureFormatId, int, int, DrawingOptions)"/> to render into a
11+
/// host-supplied texture (typically a swap-chain back buffer for UI-framework embedding), or
12+
/// <see cref="CreateRenderTarget(int, int)"/> to allocate an offscreen target on the same device.
1113
/// </summary>
1214
/// <typeparam name="TPixel">The canvas pixel format.</typeparam>
1315
public sealed class WebGPUDeviceContext<TPixel> : IDisposable
@@ -129,6 +131,10 @@ internal WebGPUDeviceContext(Configuration configuration, WebGPUDeviceHandle dev
129131

130132
/// <summary>
131133
/// Gets the WebGPU drawing backend owned by this context.
134+
/// Use this to inspect per-flush diagnostics
135+
/// (<see cref="WebGPUDrawingBackend.DiagnosticLastFlushUsedGPU"/>,
136+
/// <see cref="WebGPUDrawingBackend.DiagnosticLastSceneFailure"/>) when you need to confirm whether the staged
137+
/// GPU path executed or fell back to the CPU backend.
132138
/// </summary>
133139
public WebGPUDrawingBackend Backend { get; }
134140

@@ -158,14 +164,21 @@ public WebGPURenderTarget<TPixel> CreateRenderTarget(int width, int height)
158164
}
159165

160166
/// <summary>
161-
/// Creates a native-only frame over an externally-owned WebGPU texture and view.
167+
/// Creates a native-only frame over an externally-owned WebGPU texture and view — typically the per-frame
168+
/// swap-chain back buffer obtained from <c>wgpuSurfaceGetCurrentTexture</c> on a host-owned surface.
162169
/// </summary>
163170
/// <param name="textureHandle">The external WebGPU texture handle.</param>
164171
/// <param name="textureViewHandle">The external WebGPU texture-view handle.</param>
165-
/// <param name="format">The texture format identifier.</param>
172+
/// <param name="format">The texture format identifier. Must match the format expected for <typeparamref name="TPixel"/>.</param>
166173
/// <param name="width">The frame width in pixels.</param>
167174
/// <param name="height">The frame height in pixels.</param>
168175
/// <returns>A native-only canvas frame.</returns>
176+
/// <remarks>
177+
/// The caller retains ownership of the texture and view; this context does not release them.
178+
/// The texture must have been created with <c>RenderAttachment | TextureBinding</c> usage.
179+
/// Both handles are typically valid only for the current frame: dispose any consumer of the returned frame
180+
/// before the host calls <c>wgpuSurfacePresent</c>, then re-acquire on the next frame.
181+
/// </remarks>
169182
public NativeCanvasFrame<TPixel> CreateFrame(
170183
nint textureHandle,
171184
nint textureViewHandle,
@@ -175,14 +188,20 @@ public NativeCanvasFrame<TPixel> CreateFrame(
175188
=> this.CreateFrame(CreateExternalTextureHandle(textureHandle), CreateExternalTextureViewHandle(textureViewHandle), format, width, height);
176189

177190
/// <summary>
178-
/// Creates a drawing canvas over an externally-owned WebGPU texture.
191+
/// Creates a drawing canvas that renders directly into an externally-owned WebGPU texture — typically the per-frame
192+
/// swap-chain back buffer obtained from <c>wgpuSurfaceGetCurrentTexture</c> on a host-owned surface.
179193
/// </summary>
180194
/// <param name="textureHandle">The external WebGPU texture handle.</param>
181195
/// <param name="textureViewHandle">The external WebGPU texture-view handle.</param>
182-
/// <param name="format">The texture format identifier.</param>
196+
/// <param name="format">The texture format identifier. Must match the format expected for <typeparamref name="TPixel"/>.</param>
183197
/// <param name="width">The frame width in pixels.</param>
184198
/// <param name="height">The frame height in pixels.</param>
185199
/// <returns>A drawing canvas targeting the external texture.</returns>
200+
/// <remarks>
201+
/// The caller retains ownership of the texture and view; this context does not release them.
202+
/// The texture must have been created with <c>RenderAttachment | TextureBinding</c> usage.
203+
/// Dispose the returned canvas before the host calls <c>wgpuSurfacePresent</c>, then create a new canvas on the next frame.
204+
/// </remarks>
186205
public DrawingCanvas<TPixel> CreateCanvas(
187206
nint textureHandle,
188207
nint textureViewHandle,
@@ -192,15 +211,21 @@ public DrawingCanvas<TPixel> CreateCanvas(
192211
=> this.CreateCanvas(CreateExternalTextureHandle(textureHandle), CreateExternalTextureViewHandle(textureViewHandle), format, width, height, new DrawingOptions());
193212

194213
/// <summary>
195-
/// Creates a drawing canvas over an externally-owned WebGPU texture.
214+
/// Creates a drawing canvas that renders directly into an externally-owned WebGPU texture — typically the per-frame
215+
/// swap-chain back buffer obtained from <c>wgpuSurfaceGetCurrentTexture</c> on a host-owned surface.
196216
/// </summary>
197217
/// <param name="textureHandle">The external WebGPU texture handle.</param>
198218
/// <param name="textureViewHandle">The external WebGPU texture-view handle.</param>
199-
/// <param name="format">The texture format identifier.</param>
219+
/// <param name="format">The texture format identifier. Must match the format expected for <typeparamref name="TPixel"/>.</param>
200220
/// <param name="width">The frame width in pixels.</param>
201221
/// <param name="height">The frame height in pixels.</param>
202222
/// <param name="options">The initial drawing options.</param>
203223
/// <returns>A drawing canvas targeting the external texture.</returns>
224+
/// <remarks>
225+
/// The caller retains ownership of the texture and view; this context does not release them.
226+
/// The texture must have been created with <c>RenderAttachment | TextureBinding</c> usage.
227+
/// Dispose the returned canvas before the host calls <c>wgpuSurfacePresent</c>, then create a new canvas on the next frame.
228+
/// </remarks>
204229
public DrawingCanvas<TPixel> CreateCanvas(
205230
nint textureHandle,
206231
nint textureViewHandle,

src/ImageSharp.Drawing.WebGPU/WebGPUNativeSurfaceFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
77

88
/// <summary>
9-
/// Creates <see cref="NativeSurface"/> instances for WebGPU targets.
9+
/// Low-level escape hatch for constructing a <see cref="NativeSurface"/> directly from raw WebGPU handles.
1010
/// </summary>
11+
/// <remarks>
12+
/// Most callers should use <see cref="WebGPUDeviceContext{TPixel}.CreateCanvas(nint, nint, WebGPUTextureFormatId, int, int, DrawingOptions)"/>
13+
/// or <see cref="WebGPUDeviceContext{TPixel}.CreateFrame(nint, nint, WebGPUTextureFormatId, int, int)"/> instead, which wrap this factory
14+
/// and validate handle/format compatibility against the canvas pixel type. Use this factory only when you need a
15+
/// <see cref="NativeSurface"/> independent of <see cref="WebGPUDeviceContext{TPixel}"/>.
16+
/// </remarks>
1117
public static class WebGPUNativeSurfaceFactory
1218
{
1319
/// <summary>

src/ImageSharp.Drawing.WebGPU/WebGPURenderTarget{TPixel}.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
1313
/// <see cref="Readback"/> or <see cref="ReadbackInto(Image{TPixel})"/>.
1414
/// </summary>
1515
/// <typeparam name="TPixel">The canvas pixel format.</typeparam>
16+
/// <remarks>
17+
/// The constructors on this type allocate a target on the shared process WebGPU device. To allocate offscreen
18+
/// targets against an externally-owned device (for example, a host UI framework's WebGPU device), call
19+
/// <see cref="WebGPUDeviceContext{TPixel}.CreateRenderTarget(int, int)"/> instead.
20+
/// </remarks>
1621
public sealed class WebGPURenderTarget<TPixel> : IDisposable
1722
where TPixel : unmanaged, IPixel<TPixel>
1823
{
@@ -94,12 +99,16 @@ private WebGPURenderTarget(WebGPUDeviceContext<TPixel> graphics, bool ownsGraphi
9499
public WebGPUDeviceContext<TPixel> Graphics { get; }
95100

96101
/// <summary>
97-
/// Gets the wrapped native surface.
102+
/// Gets the wrapped native surface backing this render target.
103+
/// Exposed for advanced interop with <see cref="WebGPUDrawingBackend"/> APIs that consume a native surface;
104+
/// most callers do not need to touch this directly.
98105
/// </summary>
99106
public NativeSurface Surface { get; }
100107

101108
/// <summary>
102109
/// Gets the native-only frame over this render target.
110+
/// Pass this to <see cref="WebGPUDrawingBackend.TryReadRegion{TPixel}(Configuration, ICanvasFrame{TPixel}, Rectangle, Buffer2DRegion{TPixel})"/>
111+
/// when you need to read back into a caller-owned region instead of using <see cref="Readback"/>.
103112
/// </summary>
104113
public NativeCanvasFrame<TPixel> NativeFrame { get; }
105114

src/ImageSharp.Drawing.WebGPU/WebGPUWindow{TPixel}.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@
1313
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
1414

1515
/// <summary>
16-
/// A WebGPU-backed window that provides a <see cref="DrawingCanvas{TPixel}"/> for each frame.
17-
/// Use <see cref="Run(Action{DrawingCanvas{TPixel}})"/> when you want the window to drive rendering for you, or <see cref="TryAcquireFrame(TimeSpan, out WebGPUWindowFrame{TPixel}?)"/> when you need to drive the frame loop yourself.
16+
/// A self-contained WebGPU-backed window that owns the platform window, the WebGPU device and queue, the surface
17+
/// and swap chain, and the per-frame texture acquire/present cycle, exposing a <see cref="DrawingCanvas{TPixel}"/>
18+
/// for each frame. Use <see cref="Run(Action{DrawingCanvas{TPixel}})"/> to let the window drive rendering, or
19+
/// <see cref="TryAcquireFrame(TimeSpan, out WebGPUWindowFrame{TPixel}?)"/> to drive the frame loop yourself.
1820
/// </summary>
1921
/// <typeparam name="TPixel">The canvas pixel format.</typeparam>
22+
/// <remarks>
23+
/// Use this type when ImageSharp.Drawing owns the application's window. To render into a window owned by a host
24+
/// application or UI framework, wrap the host's device and queue with <see cref="WebGPUDeviceContext{TPixel}"/>
25+
/// and pass the host's per-frame swap-chain texture to
26+
/// <see cref="WebGPUDeviceContext{TPixel}.CreateCanvas(nint, nint, WebGPUTextureFormatId, int, int, DrawingOptions)"/> instead.
27+
/// </remarks>
2028
public sealed unsafe class WebGPUWindow<TPixel> : IDisposable
2129
where TPixel : unmanaged, IPixel<TPixel>
2230
{

0 commit comments

Comments
 (0)