Repository navigation
feat(gpu): stilus CPU renderer, CPU surfaces, shader effects and cera surfaces - #172
Merged
Merged
Conversation
|
All Contributors have signed the CLA. Thanks! |
Add StilusRenderer, a pure-Go CPU backend built on github.com/timzifer/stilus (RFC-001 §6.1 "Software (CI, Headless)"). It draws rects, shadows, gradients, paths, bitmap/MSDF/emoji text, images, blur, shader effects, CPU surfaces and overlays in the wgpu draw order, in horizontal bands on all cores (byte-identical to a single band). - app.WithSoftwareRenderer(present): use the CPU renderer; frames go to present, or to the window via GDI on Windows. - uitest.RenderImage: pixel tests of element trees with real text. - draw.SurfaceRasterizer: surface providers that rasterize on the CPU are drawn in place by the CPU renderer and via scratch image + upload by the wgpu renderer, so one provider works on both backends. - Built-in shader effects (noise, plasma, voronoi) ported to Go; ShaderDesc.CPU supplies a CPU form of custom WGSL. - WGPURenderer: offscreen target (Config.Offscreen), ReadPixels and WaitIdle via an optional TextureReader on the gogpu backend. - Fix: multiple surfaces in one frame all drew at the last surface's rect (shared 16-byte instance buffer overwritten during the pass). - Fix: ensureGPUBuffer dereferenced a nil buffer on first growth. - BenchmarkCompare: CPU vs GPU on dashboard, blur, rect and shadow scenes; results in docs/cpu-renderer-benchmark.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cerasurface.Page shows a page rendered by github.com/timzifer/cera in a ui.Surface. It implements draw.SurfaceRasterizer: cera draws straight into the CPU renderer's framebuffer (aliased to page coordinates, no copy), in bands on all cores. Separate module because cera needs Go 1.27.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
timzifer
force-pushed
the
feat/stilus-cpu-renderer
branch
from
November 16, 2026 20:47
4560989 to
88aa065
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Adds a pure-Go CPU renderer built on stilus (RFC-001 §6.1, "Software (CI, Headless)"), CPU surfaces that work on both backends, Go ports of the built-in shader effects, and a cera adapter that shows PDF pages as lux surfaces.
CPU renderer (
internal/gpu/stilus_renderer.go)WGPURenderer.stilus.Canvasper band. The output is byte-identical to a single band (tested).app.WithSoftwareRenderer(present): frames go topresent. Withnil, frames go to the window via GDI on Windows; elsewhere they are only rendered, which is what headless/CI needs.uitest.RenderImage(root, w, h): pixel tests of element trees with real text shaping.CPU surfaces (
draw.SurfaceRasterizer)ui.SurfaceProviderthat also implementsRasterizeSurface(dst, rect, clip)is drawn by the renderer:Shader effects
ShaderDesc.CPU(draw.ShaderFunc) supplies a CPU form of custom WGSL. Without it the CPU renderer skips the rect.contrib/cerasurface(separate module, Go 1.27.1)&cerasurface.Page{Page: p}draws a cera page straight into lux's framebuffer: the framebuffer is aliased to page coordinates, no copy, rendered in bands on all cores.go.modpoints at this checkout viareplace; switch to a released lux version before tagging it.wgpu renderer
Config.Offscreen,ReadPixels,WaitIdle: render without a window and read the frame back. This uses an optionalwgpu.TextureReader, implemented in the gogpu backend.ensureGPUBufferdereferenced a nil buffer on its first growth.Benchmark
Apple M4 (10 cores), macOS, Metal via gogpu, median of 6 runs, ms per frame. Full table and method in
docs/cpu-renderer-benchmark.md.Type of change
draw.ShaderDesc(and with itdraw.Paint) now holds a func field, soPaintvalues can no longer be compared with==. Nothing in the repo compares them.Testing
go build -tags nogui ./...passesgo vet -tags nogui ./...passes-tags nogui, all packages); renderer tests also pass with-race-tags noguithey are skipped in CI.CGO_ENABLED=0): windows/amd64 (GUI + nogui), linux/amd64 nogui, darwin/arm64 cocoa, js/wasm. The Windows GDI presentation is build-checked only, not run.Note: GPU tests and benchmarks lock the OS thread, because Metal autorelease pools are per thread (the app's render loop already does this).
Not in this PR
WGPURenderernever drawsShaderRects:ShaderCacheis built but unused, andDrawShaderRect.Timeis never set. Built-in effects and custom shaders therefore render only on the CPU backend for now. Tracked in #173.Checklist
CONTRIBUTING.mddocs/platform-backends.md,docs/testing.md,docs/cpu-renderer-benchmark.md🤖 Generated with Claude Code