Repository navigation
Back-port seals inside layers, gradient repetition and WebGPU scratch bounds to 3.1.x - #429
Open
JimBobSquarePants wants to merge 8 commits into
Open
JimBobSquarePants wants to merge 8 commits into
JimBobSquarePants wants to merge 8 commits into
Conversation
compose_source evaluates the blend overlap once per call instead of inside five switch cases. The fine pipeline compiles in 0.5 s instead of 1.7 s with identical arithmetic per mode. The scheduling pipelines compile in parallel when the device is probed. The fine pipeline compiles once per target format, started when the target is created, instead of four fixed variants started at the first render. Stroke scratch estimates are bounded from the outline geometry (offset edges, caps, joins) instead of the bounding-box diagonal. The PTCL seed is a per-crossing bound plus one chunk per target tile. (cherry picked from commit 8dd5241)
CMD_FILL and CMD_SOLID reference their raster interest rectangle by its info-stream offset instead of copying four words into every tile. CMD_COLOR references the packed colour in the scene stream and the draw flags in the info stream. Fill goes from 9 words to 6, solid from 5 to 2, colour from 4 to 3. The PTCL seed bound drops from 14 to 11 words per crossing. The fine shader stores each paint command's per-pixel colour and coverage and composes them at one site after the command switch. One compose site keeps the blend-mode switch from being inlined into every paint case, which cuts the cold fine compile from 1.8 s to 1.1 s. (cherry picked from commit 1536258)
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. (cherry picked from commit 620eae3)
Gradient brushes with Repeat and Reflect now repeat before the start point. Repeat subtracts the floor of the position, and Reflect uses the magnitude of the position. The WebGPU shaders use the same rules. Flush, RenderScene, CreateScene and CopyPixelsFrom inside an open layer keep the layer whole. A retained scene renders inside a layer on both backends. The WebGPU encoder reads it in place through a scene segment table. CopyPixelsFrom inside a layer reads the source rectangle with ReadRegion and draws the image into the layer with Src. The WebGPU encoder computes upper bounds for the scratch buffers, with row bounds for tile-row chunks and blend depth regions for the blend spill. fine adds the coverage of each pixel in fixed point, so the output does not depend on the GPU scheduling order, and it equals the CPU output. An offscreen WebGPU render checks its scratch status before it returns, and it renders again with larger buffers after an overflow. The deferred corrective re-render is removed, so a scene releases its resources when it is disposed. After an overflow, fine writes the backdrop, so a deferred presentation frame keeps the previous pixels. Each backend finds the retained scenes with ordered work through DrawingCommandBatch.FindOrderedScenes. The public API does not change. Tests cover each seal inside a layer on both backends, the gradient repetition, the scratch bounds, and a 100k-line offscreen render that overflows and chunks. The WebGPU reference images that held the old output are updated: the new WebGPU output equals the CPU output.
A plain WebGPU render now submits its work and returns. It reads no scratch status when every capacity is an upper bound of the GPU use. Ordered ranges, a binning bound above the binding limit, and chunked scenes without row bounds still read the status. At 100k lines the flush call takes about 45 ms against 97 ms on the baseline, and the time per frame is the same. The bounds are now true upper bounds: - The row bounds keep one entry for each tile row, so a chunk shorter than one bin gets the bound of its own rows. - The stroke style flags hold the CPU arc count, and the shader limits each round arc to it. - A long inner join adds its own crossing bound, and the inner miter uses the shader limit. - The PTCL bound comes from the chunk allocation in coarse. - Each clip estimate grows by one pixel on each side. - The outline radius of a Miter join is sqrt(m^2 + 1) half widths, which is the clipped bevel point of both strokers. - path_count makes the y clip exact, so each line adds at most its tile count and the row index stays in the bbox. A test renders 100k lines in chunks shorter than one bin and compares them with an unchunked render. The layer tests compare their pixels with the CPU backend.
…tation The documentation said that the pen expands in local geometry space and that the outline is transformed after. Both backends stroke the transformed path in device space, with the pen width multiplied by the square root of the absolute determinant of the transform. The documentation now describes this behavior.
The documentation gives only the observable contract of the property: the transform that applies to vector output before rasterization.
The CopyPixelsFromSelf case composites green 128 at 50% over white. The exact green value is 191.5, which is a rounding tie. The WebGPU backend on macOS gives 191, and the reference image has 192. The difference is 0.0184% in 96 pixels. The reference comparison of this case now uses 0.0185%, which is the measured difference plus one unit. The other cases keep 0.0003%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This PR back-ports the changes of #428 to
release/3.1.x. It corrects three faults inDrawingCanvas. It also changes how the WebGPU backend sets the size of its scratch buffers.Calls inside a layer
A
Flush,RenderScene,CreateSceneorCopyPixelsFromcall betweenSaveLayerandRestorebroke the layer:Applycall lost its earlier content.Now these calls keep the layer whole on the two backends:
Flushdoes nothing while a layer is open.RenderScenedraws the scene into the open layer.CreateScenecloses the open layer at the end of the scene. Then the canvas opens the layer again.CopyPixelsFromreads the source rectangle and draws it into the open layer.Scenes in
CreateSceneCreateScenelost the scenes thatRenderScenerecorded before it. Now the new scene contains these scenes, in their recorded order.Gradient repetition
With
RepeatorReflect, a position before the start point got the color of the first stop. Now the two modes repeat the gradient in the two directions. The CPU backend and the WebGPU shaders use the same rule.WebGPU scratch buffers
The encoder calculates an upper bound for each scratch buffer. If all the bounds hold, a render submits its work and returns. It does not read back the scratch status.
A scene with ordered work, for example
Apply, still reads the status. If an offscreen render overflows a buffer, the backend renders the scene again with larger buffers.The fine stage adds pixel coverage as fixed-point values. Thus, the order of the GPU work does not change the output.
WebGPU commits from
mainThis PR also contains three earlier WebGPU commits from
main:Other changes
LineJoin.Miterstroke now include the clipped bevel point.DrawingOptions.Transformdocumentation no longer says that strokes expand in local space.The public API does not change. Some WebGPU reference images change. The new images match the CPU reference images.
Tests on Windows: net8.0 and net10.0 have 2802 passed, 0 failed and 9 skipped each.