Skip to content

Commit 620eae3

Browse files
Seed the PTCL scratch from each draw's paint command size
The encoder accumulates a PTCL word bound per draw: one CMD_FILL (6 words) plus the paint command coarse writes for that draw tag, times the draw's tile-crossing bound. The bound flows through partitions, checkpoints, ranges, and the scene, and replaces the fixed 11 words per crossing in the scratch seed. A solid-colour scene now seeds 9 words per crossing.
1 parent 1536258 commit 620eae3

3 files changed

Lines changed: 91 additions & 16 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ internal static class WebGPUSceneDispatch
6767
// validation rejects deeper nesting before anything is dispatched.
6868
private const int MaxClipStackDepth = 256;
6969

70-
// The PTCL word budget attributed to each estimated tile crossing when seeding the PTCL
71-
// scratch capacity. Every crossing belongs to one (draw, tile) pair with segments, and such a
72-
// pair writes one CMD_FILL (6 words) plus one paint command of at most 5 words.
73-
private const long PtclWordsPerCrossing = 11;
74-
7570
// Coarse allocates the dynamic PTCL tail in PTCL_INCREMENT-word chunks (Shared/ptcl.wgsl); a
7671
// command that does not fit the remaining chunk starts a new one, so each tile can leave one
7772
// partial chunk and each chunk can waste up to one command of headroom.
@@ -2450,6 +2445,7 @@ private static WebGPUSceneBumpSizes SeedSceneBumpSizes(WebGPUSceneBumpSizes curr
24502445
scene.TotalPathRowCount,
24512446
scene.PathCount,
24522447
scene.EstimatedTileCrossings,
2448+
scene.EstimatedPtclWords,
24532449
scene.EstimatedBinFootprint,
24542450
(long)scene.TileCountX * scene.TileCountY,
24552451
maxStorageBufferBindingSize);
@@ -2468,6 +2464,7 @@ private static WebGPUSceneBumpSizes SeedSceneBumpSizes(WebGPUSceneBumpSizes curr
24682464
range.TotalPathRowCount,
24692465
range.PathCount,
24702466
range.EstimatedTileCrossings,
2467+
range.EstimatedPtclWords,
24712468
range.EstimatedBinFootprint,
24722469
(long)((range.TargetBounds.Width + 15) / 16) * ((range.TargetBounds.Height + 15) / 16),
24732470
maxStorageBufferBindingSize);
@@ -2484,6 +2481,7 @@ private static WebGPUSceneBumpSizes SeedSceneBumpSizes(WebGPUSceneBumpSizes curr
24842481
/// <param name="totalPathRowCount">The estimated sparse path-row count.</param>
24852482
/// <param name="pathCount">The encoded path count.</param>
24862483
/// <param name="estimatedTileCrossings">The CPU-side upper bound for tile-boundary crossings.</param>
2484+
/// <param name="estimatedPtclWords">The CPU-side upper bound for the dynamic PTCL words those crossings write.</param>
24872485
/// <param name="estimatedBinFootprint">The CPU-side upper bound for per-(draw, bin) records.</param>
24882486
/// <param name="targetTileCount">The number of tiles in the target, each of which can leave one partial PTCL chunk.</param>
24892487
/// <param name="maxStorageBufferBindingSize">The device-reported maximum size of one storage-buffer binding.</param>
@@ -2494,6 +2492,7 @@ private static WebGPUSceneBumpSizes SeedSceneBumpSizes(
24942492
int totalPathRowCount,
24952493
int pathCount,
24962494
long estimatedTileCrossings,
2495+
long estimatedPtclWords,
24972496
long estimatedBinFootprint,
24982497
long targetTileCount,
24992498
ulong maxStorageBufferBindingSize)
@@ -2511,7 +2510,7 @@ private static WebGPUSceneBumpSizes SeedSceneBumpSizes(
25112510
ClampEstimate(estimatedTileCrossings, maxStorageBufferBindingSize, (uint)Unsafe.SizeOf<GpuPathTile>()),
25122511
pathRowFloor);
25132512
uint binningFloor = ClampEstimate(estimatedBinFootprint, maxStorageBufferBindingSize, sizeof(uint));
2514-
long ptclWords = ((estimatedTileCrossings * PtclWordsPerCrossing * 105L) / 100L) + (targetTileCount * PtclChunkWords);
2513+
long ptclWords = ((estimatedPtclWords * 105L) / 100L) + (targetTileCount * PtclChunkWords);
25152514
uint ptclFloor = ClampEstimate(ptclWords, maxStorageBufferBindingSize, sizeof(uint));
25162515

25172516
return new WebGPUSceneBumpSizes(

0 commit comments

Comments
 (0)