Skip to content

Commit 1f6ad7e

Browse files
Merge pull request #411 from SixLabors/js/aliased-scan-conversion
Rework aliased rasterization and path lowering to allow full hinting
2 parents d8c0e28 + f1fa7c7 commit 1f6ad7e

231 files changed

Lines changed: 4557 additions & 2078 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ImageSharp.Drawing.All.sln‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ Global
513513
SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795}
514514
EndGlobalSection
515515
GlobalSection(SharedMSBuildProjectFiles) = preSolution
516-
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{061582c2-658f-40ae-a978-7d74a4eb2c0a}*SharedItemsImports = 5
517516
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{2e33181e-6e28-4662-a801-e2e7dc206029}*SharedItemsImports = 5
518517
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
519518
EndGlobalSection

‎src/ImageSharp.Drawing.WebGPU/GpuSceneDrawTag.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static class GpuSceneDrawTag
1212
{
1313
// These values are not a plain enum because each word also encodes the path-count, clip-count,
1414
// scene-word-count, and info-word-count increments consumed by the scan/reduction stages.
15-
// Visible-fill tags carry five extra info words: coverage threshold plus raster interest. Must match drawtag.wgsl.
15+
// Visible-fill tags carry five extra info words: coverage data plus raster interest. Must match drawtag.wgsl.
1616
public const uint Nop = 0U;
1717
public const uint FillColor = 0x188U;
1818
public const uint FillRecolor = 0x184U;

‎src/ImageSharp.Drawing.WebGPU/ImageSharp.Drawing.WebGPU.csproj‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
<PackageReference Include="Silk.NET.Windowing.Sdl" Version="2.23.0" PrivateAssets="compile;build;analyzers;contentfiles;buildtransitive" />
8080
</ItemGroup>
8181

82-
<Import Project="..\..\shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems" Label="Shared" />
83-
8482
<ItemGroup>
8583
<ProjectReference Include="..\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />
8684
<ProjectReference Include="..\ImageSharp.Drawing.WebGPU.ShaderGen\ImageSharp.Drawing.WebGPU.ShaderGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
88

99
/// <summary>
1010
/// GPU stage that initializes every per-path bounding box to an empty (inverted) box so
11-
/// that flatten can accumulate extents with atomic min/max. Wraps <c>bbox_clear.wgsl</c>.
11+
/// that path lowering can accumulate extents with atomic min/max. Wraps <c>bbox_clear.wgsl</c>.
1212
/// </summary>
1313
internal static unsafe class BboxClearComputeShader
1414
{

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public static unsafe bool TryCreateBindGroupLayout(
103103
// 6 gradients (sampled gradient ramp texture)
104104
// 7 image_atlas (sampled image atlas texture)
105105
// 8 backdrop_texture (sampled existing target contents)
106-
WGPUBindGroupLayoutEntry* entries = stackalloc WGPUBindGroupLayoutEntry[9];
106+
// 9 scene_data (read-only profile ranges and contour links in the packed scene stream)
107+
// 10 path_tiles (read-only neighboring segment-slice indices for aliased row halos)
108+
WGPUBindGroupLayoutEntry* entries = stackalloc WGPUBindGroupLayoutEntry[11];
107109
entries[0] = CreateUniformEntry(0, (nuint)sizeof(GpuSceneConfig));
108110
entries[1] = CreateStorageEntry(1, WGPUBufferBindingType.ReadOnlyStorage, 0);
109111
entries[2] = CreateStorageEntry(2, WGPUBufferBindingType.ReadOnlyStorage, 0);
@@ -113,10 +115,12 @@ public static unsafe bool TryCreateBindGroupLayout(
113115
entries[6] = CreateSampledTextureEntry(6);
114116
entries[7] = CreateSampledTextureEntry(7);
115117
entries[8] = CreateSampledTextureEntry(8);
118+
entries[9] = CreateStorageEntry(9, WGPUBufferBindingType.ReadOnlyStorage, 0);
119+
entries[10] = CreateStorageEntry(10, WGPUBufferBindingType.ReadOnlyStorage, 0);
116120

117121
WGPUBindGroupLayoutDescriptor descriptor = new()
118122
{
119-
entryCount = 9,
123+
entryCount = 11,
120124
entries = entries
121125
};
122126

‎src/ImageSharp.Drawing.WebGPU/Shaders/PathCountComputeShader.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
88

99
/// <summary>
10-
/// GPU stage that counts, per tile, how many flattened line segments cross it: one thread per
10+
/// GPU stage that counts, per tile, how many final line segments cross it: one thread per
1111
/// line walks the line's tile crossings, bumps tile segment counts and backdrops, and emits one
1212
/// SegmentCount record per crossing for path-tiling. Wraps <c>path_count.wgsl</c>.
1313
/// </summary>
@@ -29,7 +29,7 @@ internal static unsafe class PathCountComputeShader
2929
/// ceil(<paramref name="lineCount"/> / 256). At runtime the stage is normally driven by
3030
/// the indirect count written by path-count-setup using the same divisor.
3131
/// </summary>
32-
/// <param name="lineCount">The number of flattened lines.</param>
32+
/// <param name="lineCount">The number of final lines.</param>
3333
/// <returns>The X dispatch dimension in workgroups.</returns>
3434
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3535
public static uint GetDispatchX(uint lineCount)
@@ -52,7 +52,7 @@ public static bool TryCreateBindGroupLayout(
5252
// Bindings match path_count.wgsl:
5353
// 0 config uniform
5454
// 1 bump allocators (read-write; lines read, seg_counts bump-allocated)
55-
// 2 lines (read-only LineSoup from flatten)
55+
// 2 lines (read-only LineSoup from path lowering)
5656
// 3 paths (read-only Path records from path_row_alloc)
5757
// 4 rows (read-only PathRow spans finalized by tile_alloc)
5858
// 5 tile (read-write; backdrop and segment counts updated atomically)

‎src/ImageSharp.Drawing.WebGPU/Shaders/PathCountSetupComputeShader.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
88

99
/// <summary>
1010
/// GPU stage that computes the indirect dispatch size for the per-line stages
11-
/// (path-row-span and path-count) by dividing the flattened line count by the workgroup
11+
/// (path-row-span and path-count) by dividing the final line count by the workgroup
1212
/// size, or zero workgroups after an upstream allocation failure. Wraps
1313
/// <c>path_count_setup.wgsl</c>.
1414
/// </summary>

src/ImageSharp.Drawing.WebGPU/Shaders/FlattenComputeShader.cs renamed to src/ImageSharp.Drawing.WebGPU/Shaders/PathLoweringComputeShader.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
88

99
/// <summary>
10-
/// GPU stage that flattens encoded path segments into a device-space line soup, expands
11-
/// strokes via the CPU PolygonStroker port, and accumulates per-path bounding boxes for the
12-
/// downstream stages. Wraps <c>flatten.wgsl</c>.
10+
/// GPU stage that lowers encoded path segments into device-space lines and expands strokes
11+
/// with the CPU PolygonStroker port. The stage also accumulates per-path bounding boxes for
12+
/// downstream stages. It wraps <c>path_lowering.wgsl</c>.
1313
/// </summary>
14-
internal static unsafe class FlattenComputeShader
14+
internal static unsafe class PathLoweringComputeShader
1515
{
1616
/// <summary>
17-
/// Gets the generated WGSL source bytes for the flatten stage.
17+
/// Gets the generated WGSL source bytes for the path-lowering stage.
1818
/// </summary>
19-
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.FlattenCode;
19+
public static ReadOnlySpan<byte> ShaderCode => GeneratedWgslShaderSources.PathLoweringCode;
2020

2121
/// <summary>
2222
/// Gets the WGSL entry point used by this shader.
@@ -35,7 +35,7 @@ public static uint GetDispatchX(uint pathTagCount)
3535
=> (pathTagCount + 255U) / 256U;
3636

3737
/// <summary>
38-
/// Creates the bind-group layout required by the flatten stage.
38+
/// Creates the bind-group layout required by the path-lowering stage.
3939
/// </summary>
4040
/// <param name="api">The WebGPU API facade.</param>
4141
/// <param name="device">The device that owns the staged-scene pipelines.</param>
@@ -48,7 +48,7 @@ public static bool TryCreateBindGroupLayout(
4848
out WGPUBindGroupLayoutImpl* layout,
4949
out string? error)
5050
{
51-
// Bindings match flatten.wgsl:
51+
// Bindings match path_lowering.wgsl:
5252
// 0 config uniform
5353
// 1 scene (read-only path tags, points, styles and transforms)
5454
// 2 tag_monoids (read-only pathtag prefix sums from the scan stages)
@@ -72,7 +72,7 @@ public static bool TryCreateBindGroupLayout(
7272
layout = api.DeviceCreateBindGroupLayout(device, in descriptor);
7373
if (layout is null)
7474
{
75-
error = "Failed to create the flatten bind-group layout.";
75+
error = "Failed to create the path-lowering bind-group layout.";
7676
return false;
7777
}
7878

‎src/ImageSharp.Drawing.WebGPU/Shaders/PathRowAllocComputeShader.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ public static bool TryCreateBindGroupLayout(
5656
// 3 bump allocators (read-write; path_rows bump-allocated, failure bit set on overflow)
5757
// 4 paths (read-write; Path record written per draw object)
5858
// 5 rows (read-write; PathRow records initialized to empty spans)
59-
WGPUBindGroupLayoutEntry* entries = stackalloc WGPUBindGroupLayoutEntry[6];
59+
// 6 path_bboxes (read-only path bounds before clipping to the drawing bounds)
60+
WGPUBindGroupLayoutEntry* entries = stackalloc WGPUBindGroupLayoutEntry[7];
6061
entries[0] = SceneShaderBindingLayoutHelper.CreateUniformEntry(0, (nuint)sizeof(GpuSceneConfig));
6162
entries[1] = SceneShaderBindingLayoutHelper.CreateStorageEntry(1, WGPUBufferBindingType.ReadOnlyStorage);
6263
entries[2] = SceneShaderBindingLayoutHelper.CreateStorageEntry(2, WGPUBufferBindingType.ReadOnlyStorage);
6364
entries[3] = SceneShaderBindingLayoutHelper.CreateStorageEntry(3, WGPUBufferBindingType.Storage, (nuint)sizeof(GpuSceneBumpAllocators));
6465
entries[4] = SceneShaderBindingLayoutHelper.CreateStorageEntry(4, WGPUBufferBindingType.Storage);
6566
entries[5] = SceneShaderBindingLayoutHelper.CreateStorageEntry(5, WGPUBufferBindingType.Storage);
67+
entries[6] = SceneShaderBindingLayoutHelper.CreateStorageEntry(6, WGPUBufferBindingType.ReadOnlyStorage);
6668

6769
WGPUBindGroupLayoutDescriptor descriptor = new()
6870
{
69-
entryCount = 6,
71+
entryCount = 7,
7072
entries = entries
7173
};
7274

‎src/ImageSharp.Drawing.WebGPU/Shaders/PathRowSpanComputeShader.cs‎

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

88
/// <summary>
9-
/// GPU stage that derives sparse per-row tile column spans from the flattened line stream:
9+
/// GPU stage that derives sparse per-row tile column spans from the final line stream:
1010
/// one thread per line replays the tile-crossing traversal, atomically growing each touched
1111
/// row's span and accumulating per-row winding backdrops for tile-alloc. Wraps
1212
/// <c>path_row_span.wgsl</c>.
@@ -40,7 +40,7 @@ public static bool TryCreateBindGroupLayout(
4040
// Bindings match path_row_span.wgsl:
4141
// 0 config uniform
4242
// 1 bump allocators (read-write because the buffer is atomic; this stage only reads the lines counter)
43-
// 2 lines (read-only LineSoup from flatten)
43+
// 2 lines (read-only LineSoup from path lowering)
4444
// 3 paths (read-only Path records from path_row_alloc)
4545
// 4 rows (read-write; spans, backdrops and flags accumulated atomically)
4646
WGPUBindGroupLayoutEntry* entries = stackalloc WGPUBindGroupLayoutEntry[5];

0 commit comments

Comments
 (0)