From 81f958fc709ac9cdff2d5a100d522fc03f40b34e Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 7 Feb 2020 19:59:36 +0100 Subject: [PATCH] app/internal/gpu: remove profile flag Automatically determine whether to profile GPU operations from the existence of a profiling op. Signed-off-by: Elias Naur --- app/headless/headless.go | 6 +++--- app/internal/gpu/gpu.go | 16 ++++++++++------ app/loop.go | 15 +++++++-------- app/window.go | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/headless/headless.go b/app/headless/headless.go index 313eb1eb..e17360e6 100644 --- a/app/headless/headless.go +++ b/app/headless/headless.go @@ -90,9 +90,9 @@ func (w *Window) Release() { // operation list. func (w *Window) Frame(frame *op.Ops) { contextDo(w.ctx, func() error { - w.gpu.Collect(false, w.size, frame) - w.gpu.Frame(false, w.size) - w.gpu.EndFrame(false) + w.gpu.Collect(w.size, frame) + w.gpu.Frame(w.size) + w.gpu.EndFrame() return nil }) } diff --git a/app/internal/gpu/gpu.go b/app/internal/gpu/gpu.go index 44196731..d18c29e7 100644 --- a/app/internal/gpu/gpu.go +++ b/app/internal/gpu/gpu.go @@ -42,6 +42,7 @@ type renderer struct { } type drawOps struct { + profile bool reader ops.Reader cache *resourceCache viewport image.Point @@ -252,11 +253,11 @@ func (g *GPU) Release() { } } -func (g *GPU) Collect(profile bool, viewport image.Point, frameOps *op.Ops) { +func (g *GPU) Collect(viewport image.Point, frameOps *op.Ops) { g.drawOps.reset(g.cache, viewport) g.drawOps.collect(g.cache, frameOps, viewport) g.frameStart = time.Now() - if profile && g.timers == nil && g.ctx.caps.EXT_disjoint_timer_query { + if g.drawOps.profile && g.timers == nil && g.ctx.caps.EXT_disjoint_timer_query { g.timers = newTimers(g.ctx) g.zopsTimer = g.timers.newTimer() g.stencilTimer = g.timers.newTimer() @@ -272,13 +273,13 @@ func (g *GPU) Collect(profile bool, viewport image.Point, frameOps *op.Ops) { } } -func (g *GPU) Frame(profile bool, viewport image.Point) { +func (g *GPU) Frame(viewport image.Point) { g.renderer.blitter.viewport = viewport g.renderer.pather.viewport = viewport for _, img := range g.drawOps.imageOps { expandPathOp(img.path, img.clip) } - if profile { + if g.drawOps.profile { g.zopsTimer.begin() } g.ctx.DepthFunc(gl.GREATER) @@ -303,13 +304,13 @@ func (g *GPU) Frame(profile bool, viewport image.Point) { g.coverTimer.end() } -func (g *GPU) EndFrame(profile bool) string { +func (g *GPU) EndFrame() string { g.cleanupTimer.begin() g.cache.frame(g.ctx) g.pathCache.frame(g.ctx) g.cleanupTimer.end() var summary string - if profile && g.timers.ready() { + if g.drawOps.profile && g.timers.ready() { zt, st, covt, cleant := g.zopsTimer.Elapsed, g.stencilTimer.Elapsed, g.coverTimer.Elapsed, g.cleanupTimer.Elapsed ft := zt + st + covt + cleant q := 100 * time.Microsecond @@ -587,6 +588,7 @@ func floor(v float32) int { } func (d *drawOps) reset(cache *resourceCache, viewport image.Point) { + d.profile = false d.clearColor = [3]float32{1.0, 1.0, 1.0} d.cache = cache d.viewport = viewport @@ -621,6 +623,8 @@ func (d *drawOps) collectOps(r *ops.Reader, state drawState) int { loop: for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() { switch opconst.OpType(encOp.Data[0]) { + case opconst.TypeProfile: + d.profile = true case opconst.TypeTransform: dop := ops.DecodeTransformOp(encOp.Data) state.t = state.t.Multiply(op.TransformOp(dop)) diff --git a/app/loop.go b/app/loop.go index 175675a7..9216a325 100644 --- a/app/loop.go +++ b/app/loop.go @@ -26,9 +26,8 @@ type renderLoop struct { } type frame struct { - collectStats bool - viewport image.Point - ops *op.Ops + viewport image.Point + ops *op.Ops } type frameResult struct { @@ -81,13 +80,13 @@ func (l *renderLoop) renderLoop(glctx window.Context) error { l.refreshErr <- glctx.MakeCurrent() case frame := <-l.frames: glctx.Lock() - g.Collect(frame.collectStats, frame.viewport, frame.ops) + g.Collect(frame.viewport, frame.ops) // Signal that we're done with the frame ops. l.ack <- struct{}{} - g.Frame(frame.collectStats, frame.viewport) + g.Frame(frame.viewport) var res frameResult res.err = glctx.Present() - res.summary = g.EndFrame(frame.collectStats) + res.summary = g.EndFrame() glctx.Unlock() l.results <- res case <-l.stop: @@ -134,13 +133,13 @@ func (l *renderLoop) Refresh() { // Draw initiates a draw of a frame. It returns a channel // than signals when the frame is no longer being accessed. -func (l *renderLoop) Draw(profile bool, viewport image.Point, frameOps *op.Ops) <-chan struct{} { +func (l *renderLoop) Draw(viewport image.Point, frameOps *op.Ops) <-chan struct{} { if l.err != nil { l.ack <- struct{}{} return l.ack } l.Flush() - l.frames <- frame{profile, viewport, frameOps} + l.frames <- frame{viewport, frameOps} l.drawing = true return l.ack } diff --git a/app/window.go b/app/window.go index 02a2ccf7..120c7e7f 100644 --- a/app/window.go +++ b/app/window.go @@ -125,7 +125,7 @@ func (w *Window) update(frame *op.Ops) { } func (w *Window) draw(frameStart time.Time, size image.Point, frame *op.Ops) { - sync := w.loop.Draw(w.queue.q.Profiling(), size, frame) + sync := w.loop.Draw(size, frame) w.queue.q.Frame(frame) switch w.queue.q.TextInputState() { case input.TextInputOpen: