From 0f81bf02c14d12c363b91d4abb08fd8f4bbaa87c Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 23 Aug 2021 17:47:14 +0200 Subject: [PATCH] gpu: don't invoke GPU backend outside BeginFrame/EndFrame The Metal backend is particularly sensitive because its staging buffers are synchronized to BeginFrame. Signed-off-by: Elias Naur --- gpu/gpu.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gpu/gpu.go b/gpu/gpu.go index 768559a2..826aebd9 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -403,7 +403,7 @@ func (g *gpu) Collect(viewport image.Point, frameOps *op.Ops) { g.renderer.blitter.viewport = viewport g.renderer.pather.viewport = viewport g.drawOps.reset(g.cache, viewport) - g.drawOps.collect(g.ctx, g.cache, frameOps, viewport) + g.drawOps.collect(frameOps, viewport) g.frameStart = time.Now() if g.drawOps.profile && g.timers == nil && g.ctx.Caps().Features.Has(driver.FeatureTimers) { g.timers = newTimers(g.ctx) @@ -417,6 +417,7 @@ func (g *gpu) Frame(target RenderTarget) error { viewport := g.renderer.blitter.viewport defFBO := g.ctx.BeginFrame(target, g.drawOps.clear, viewport) defer g.ctx.EndFrame() + g.drawOps.buildPaths(g.ctx) for _, img := range g.drawOps.imageOps { expandPathOp(img.path, img.clip) } @@ -810,7 +811,7 @@ func (d *drawOps) reset(cache *resourceCache, viewport image.Point) { d.vertCache = d.vertCache[:0] } -func (d *drawOps) collect(ctx driver.Device, cache *resourceCache, root *op.Ops, viewport image.Point) { +func (d *drawOps) collect(root *op.Ops, viewport image.Point) { clip := f32.Rectangle{ Max: f32.Point{X: float32(viewport.X), Y: float32(viewport.Y)}, } @@ -821,6 +822,9 @@ func (d *drawOps) collect(ctx driver.Device, cache *resourceCache, root *op.Ops, color: color.NRGBA{A: 0xff}, } d.collectOps(&d.reader, state) +} + +func (d *drawOps) buildPaths(ctx driver.Device) { for _, p := range d.pathOps { if v, exists := d.pathCache.get(p.pathKey); !exists || v.data.data == nil { data := buildPath(ctx, p.pathVerts)