Skip to content

Commit ce482dc

Browse files
Add docs and helpers for WebGPU shaders & backend
1 parent 0937ae3 commit ce482dc

36 files changed

Lines changed: 1153 additions & 134 deletions

src/ImageSharp.Drawing.WebGPU/RemoteExecutor/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
1010
/// </summary>
1111
internal static class Program
1212
{
13+
/// <summary>
14+
/// Dispatches the requested probe method inside the child process.
15+
/// </summary>
1316
private static int Main(string[] args)
1417
{
1518
if (args.Length < 1)

src/ImageSharp.Drawing.WebGPU/Shaders/BackdropComputeShader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
1111
/// </summary>
1212
internal static unsafe class BackdropComputeShader
1313
{
14+
/// <summary>
15+
/// Gets the generated WGSL source bytes for the dynamic backdrop stage.
16+
/// </summary>
1417
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.BackdropDynCode;
1518

19+
/// <summary>
20+
/// Gets the WGSL entry point used by this shader.
21+
/// </summary>
1622
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1723

24+
/// <summary>
25+
/// Gets the X workgroup count required to process every draw object in the scene.
26+
/// </summary>
1827
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1928
public static uint GetDispatchX(uint drawObjectCount)
2029
=> drawObjectCount;
2130

31+
/// <summary>
32+
/// Creates the bind-group layout required by the dynamic backdrop stage.
33+
/// </summary>
2234
public static bool TryCreateBindGroupLayout(
2335
WebGPU api,
2436
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/BboxClearComputeShader.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66

77
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
88

9+
/// <summary>
10+
/// GPU stage that clears path bounding boxes before flatten repopulates them.
11+
/// </summary>
912
internal static unsafe class BboxClearComputeShader
1013
{
14+
/// <summary>
15+
/// Gets the generated WGSL source bytes for the bbox-clear stage.
16+
/// </summary>
1117
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.BboxClearCode;
1218

19+
/// <summary>
20+
/// Gets the WGSL entry point used by this shader.
21+
/// </summary>
1322
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1423

24+
/// <summary>
25+
/// Gets the X workgroup count required to clear every path bounding box.
26+
/// </summary>
1527
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1628
public static uint GetDispatchX(uint pathCount)
1729
=> (pathCount + 255U) / 256U;
1830

31+
/// <summary>
32+
/// Creates the bind-group layout required by the bbox-clear stage.
33+
/// </summary>
1934
public static bool TryCreateBindGroupLayout(
2035
WebGPU api,
2136
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/BinningComputeShader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
1111
/// </summary>
1212
internal static unsafe class BinningComputeShader
1313
{
14+
/// <summary>
15+
/// Gets the generated WGSL source bytes for the binning stage.
16+
/// </summary>
1417
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.BinningCode;
1518

19+
/// <summary>
20+
/// Gets the WGSL entry point used by this shader.
21+
/// </summary>
1622
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1723

24+
/// <summary>
25+
/// Gets the X workgroup count required to bin every draw object in the scene.
26+
/// </summary>
1827
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1928
public static uint GetDispatchX(uint drawObjectCount)
2029
=> (drawObjectCount + 255U) / 256U;
2130

31+
/// <summary>
32+
/// Creates the bind-group layout required by the binning stage.
33+
/// </summary>
2234
public static bool TryCreateBindGroupLayout(
2335
WebGPU api,
2436
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/ClipLeafComputeShader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55

66
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
77

8+
/// <summary>
9+
/// GPU stage that resolves clip leaves into concrete clip bounding boxes.
10+
/// </summary>
811
internal static unsafe class ClipLeafComputeShader
912
{
13+
/// <summary>
14+
/// Gets the generated WGSL source bytes for the clip-leaf stage.
15+
/// </summary>
1016
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.ClipLeafCode;
1117

18+
/// <summary>
19+
/// Gets the WGSL entry point used by this shader.
20+
/// </summary>
1221
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1322

23+
/// <summary>
24+
/// Creates the bind-group layout required by the clip-leaf stage.
25+
/// </summary>
1426
public static bool TryCreateBindGroupLayout(
1527
WebGPU api,
1628
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/ClipReduceComputeShader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55

66
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
77

8+
/// <summary>
9+
/// GPU stage that reduces clip inputs into the binary-interval-combination structure consumed by clip leaf expansion.
10+
/// </summary>
811
internal static unsafe class ClipReduceComputeShader
912
{
13+
/// <summary>
14+
/// Gets the generated WGSL source bytes for the clip-reduce stage.
15+
/// </summary>
1016
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.ClipReduceCode;
1117

18+
/// <summary>
19+
/// Gets the WGSL entry point used by this shader.
20+
/// </summary>
1221
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1322

23+
/// <summary>
24+
/// Creates the bind-group layout required by the clip-reduce stage.
25+
/// </summary>
1426
public static bool TryCreateBindGroupLayout(
1527
WebGPU api,
1628
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/CoarseComputeShader.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,31 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
1111
/// </summary>
1212
internal static unsafe class CoarseComputeShader
1313
{
14+
/// <summary>
15+
/// Gets the generated WGSL source bytes for the coarse stage.
16+
/// </summary>
1417
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.CoarseCode;
1518

19+
/// <summary>
20+
/// Gets the WGSL entry point used by this shader.
21+
/// </summary>
1622
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1723

24+
/// <summary>
25+
/// Gets the X workgroup count required to cover the bin grid width.
26+
/// </summary>
1827
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1928
public static uint GetDispatchX(uint widthInBins) => widthInBins;
2029

30+
/// <summary>
31+
/// Gets the Y workgroup count required to cover the bin grid height.
32+
/// </summary>
2133
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2234
public static uint GetDispatchY(uint heightInBins) => heightInBins;
2335

36+
/// <summary>
37+
/// Creates the bind-group layout required by the coarse stage.
38+
/// </summary>
2439
public static bool TryCreateBindGroupLayout(
2540
WebGPU api,
2641
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/DrawLeafComputeShader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55

66
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
77

8+
/// <summary>
9+
/// GPU stage that expands reduced draw metadata into concrete draw and clip inputs.
10+
/// </summary>
811
internal static unsafe class DrawLeafComputeShader
912
{
13+
/// <summary>
14+
/// Gets the generated WGSL source bytes for the draw-leaf stage.
15+
/// </summary>
1016
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.DrawLeafCode;
1117

18+
/// <summary>
19+
/// Gets the WGSL entry point used by this shader.
20+
/// </summary>
1221
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1322

23+
/// <summary>
24+
/// Creates the bind-group layout required by the draw-leaf stage.
25+
/// </summary>
1426
public static bool TryCreateBindGroupLayout(
1527
WebGPU api,
1628
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/DrawReduceComputeShader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55

66
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
77

8+
/// <summary>
9+
/// GPU stage that scans draw tags into draw-object offsets and counts.
10+
/// </summary>
811
internal static unsafe class DrawReduceComputeShader
912
{
13+
/// <summary>
14+
/// Gets the generated WGSL source bytes for the draw-reduce stage.
15+
/// </summary>
1016
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.DrawReduceCode;
1117

18+
/// <summary>
19+
/// Gets the WGSL entry point used by this shader.
20+
/// </summary>
1221
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
1322

23+
/// <summary>
24+
/// Creates the bind-group layout required by the draw-reduce stage.
25+
/// </summary>
1426
public static bool TryCreateBindGroupLayout(
1527
WebGPU api,
1628
Device* device,

src/ImageSharp.Drawing.WebGPU/Shaders/FineAreaComputeShader.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ internal static class FineAreaComputeShader
1919
private static readonly object CacheSync = new();
2020
private static readonly Dictionary<TextureFormat, byte[]> ShaderCache = [];
2121

22+
/// <summary>
23+
/// Gets the WGSL entry point used by this shader.
24+
/// </summary>
2225
public static ReadOnlySpan<byte> EntryPoint => "main\0"u8;
2326

27+
/// <summary>
28+
/// Gets or generates the fine-pass shader specialized for the requested output texture format.
29+
/// </summary>
2430
public static bool TryGetCode(TextureFormat textureFormat, out byte[] code, out string? error)
2531
{
2632
if (!TryGetTraits(textureFormat, out ShaderTraits traits))
@@ -55,6 +61,9 @@ public static bool TryGetCode(TextureFormat textureFormat, out byte[] code, out
5561
return true;
5662
}
5763

64+
/// <summary>
65+
/// Creates the bind-group layout required by the fine area shader.
66+
/// </summary>
5867
public static unsafe bool TryCreateBindGroupLayout(
5968
WebGPU api,
6069
Device* device,

0 commit comments

Comments
 (0)