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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-07 19:59:36 +01:00
parent 320535a978
commit 81f958fc70
4 changed files with 21 additions and 18 deletions
+3 -3
View File
@@ -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
})
}
+10 -6
View File
@@ -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))
+7 -8
View File
@@ -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
}
+1 -1
View File
@@ -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: