Skip to content

RenderSurface in bands through recorders (ADR 0011, step 2) - #242

Open
timzifer wants to merge 1 commit into
mainfrom
claude/gpu-bands
Open

timzifer wants to merge 1 commit into
mainfrom
claude/gpu-bands

Conversation

@timzifer

Copy link
Copy Markdown
Owner

Step 2 of ADR 0011 (#157), after #241.

  • cera.BandSurface is a Surface that several goroutines draw onto at once. Bands(n) hands out one compositor per worker.

  • When bands are used: RenderSurface draws a list in bands, by up to Workers goroutines as Render does, only if the list needs nothing but drawing:

    • no transparency groups or soft masks: their layers would be read, written or flushed mid-band, which recorders forbid;
    • no blending with the background.

    Other lists are drawn in one pass, as in step 1.

  • Filling and isolation: the region is filled once before the bands start. A worker's part of the surface refuses the surface's other operations.

  • gpu.Surface.Bands: uses gpu.Recorders of the target, kept across renders and closed with the surface.

Tests

  • Core module: scenes in four bands onto an image surface, whole and onto a region, against Render, also under -race.
  • GPU module: four bands, twice onto one surface, within 2/255 of the CPU, race-free on Metal and on the software adapter.

Benchmark — BenchmarkRenderSurface: A3 at 150 dpi, readback included, Apple M4 with 10 cores. CPU is Render with all workers.

scene CPU GPU 1 band GPU 4 bands GPU 8 bands
contours-3000 8.5 ms 33.2 ms 15.1 ms 12.4 ms
short-20000-0.35mm 5.1 ms 17.9 ms 10.0 ms 8.2 ms
hatch-2000-0.35mm 7.1 ms 31.7 ms 13.4 ms 10.6 ms
fills-subpixel 0.8 ms 3.8 ms 2.6 ms 2.9 ms

Bands make the GPU path two to three times faster than one pass. It is still slower than the CPU on all cores, partly because of reading back 17 MB per page. A viewer presents the target without readback; the 4K benchmark from the ADR still has to measure that case.

🤖 Generated with Claude Code

cera.BandSurface is a Surface that several goroutines draw onto at
once: Bands(n) hands out one compositor per worker. RenderSurface
draws a list onto one in bands, by up to Workers goroutines as Render
does, when the list needs nothing but drawing: no transparency groups
or soft masks, whose layers are read, written or flushed mid-band, and
no blending with the background. Other lists are drawn in one pass as
before. The region is filled once before the bands start; a worker's
part of the surface refuses the surface's other operations.

gpu.Surface implements Bands with gpu.Recorders of its target, kept
across renders and closed with the surface.

Tests: the core module draws scenes in four bands onto an image
surface, whole and onto a region, against Render, also under the race
detector; the GPU module draws them in four bands, twice onto one
surface, within 2/255 of the CPU, race-free. BenchmarkRenderSurface
(A3, 150 dpi, readback, Apple M4): bands are two to three times faster
than one pass.

Refs #157

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant