Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group the reprojection commands #1098

Merged
merged 5 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gapis/api/cmd_id_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ func (g *CmdIDGroup) AddGroup(start, end CmdID, name string) (*CmdIDGroup, error
// New group fits entirely within an existing group. Add as subgroup.
out, err = first.AddGroup(start, end, name)
case sIn && start != first.Range.Start:
return nil, fmt.Errorf("New group '%s' overlaps with existing group '%s'", name, first)
return nil, fmt.Errorf("New group '%v' %v overlaps with existing group '%v'", name, r, first)
case eIn && end != last.Range.End:
return nil, fmt.Errorf("New group '%s' overlaps with existing group '%s'", name, last)
return nil, fmt.Errorf("New group '%v' %v overlaps with existing group '%v'", name, r, last)
default:
// New group completely wraps one or more existing groups. Add the
// existing group(s) as subgroups to the new group, and add to the list.
Expand Down
23 changes: 19 additions & 4 deletions gapis/api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

package api

import "github.com/google/gapid/core/data/id"
import (
"reflect"

"github.com/google/gapid/core/data/id"
"github.com/google/gapid/gapis/service/path"
)

// ContextID is the unique identifier for a context.
type ContextID id.ID
Expand All @@ -23,9 +28,19 @@ type ContextID id.ID
type Context interface {
APIObject

// Name returns the display-name of the context.
Name() string

// ID returns the context's unique identifier
ID() ContextID
}

// ContextInfo is describes a Context.
// Unlike Context, ContextInfo describes the context at no particular point in
// the trace.
type ContextInfo struct {
Path *path.Context
ID ContextID
API ID
NumCommandsByType map[reflect.Type]int
Name string
Priority int
UserData map[interface{}]interface{}
}
4 changes: 2 additions & 2 deletions gapis/api/gles/gles.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (s *State) Root(ctx context.Context, p *path.State) (path.Node, error) {
if p.Context == nil || !p.Context.IsValid() {
return p, nil
}
c, err := resolve.Context(ctx, p.After.Capture.Context(p.Context))
c, err := resolve.Context(ctx, p.After.Capture.Context(p.Context.ID()))
if err != nil {
return nil, err
}
for thread, context := range s.Contexts {
if c.ID() == context.ID() {
if c.ID == context.ID() {
return s.contextRoot(p.After, thread), nil
}
}
Expand Down
1 change: 1 addition & 0 deletions gapis/api/gvr/CMakeFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(files
constant_sets.go
convert.go
enum.go
extension.go
framebindings.go
gvr.api
gvr.go
Expand Down
200 changes: 200 additions & 0 deletions gapis/api/gvr/extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gvr

import (
"context"
"reflect"

"github.com/google/gapid/gapis/api"
"github.com/google/gapid/gapis/api/gles"
"github.com/google/gapid/gapis/extensions"
"github.com/google/gapid/gapis/resolve"
"github.com/google/gapid/gapis/resolve/cmdgrouper"
"github.com/google/gapid/gapis/service"
"github.com/google/gapid/gapis/service/path"
)

func init() {
extensions.Register(extensions.Extension{
Name: "GVR",
AdjustContexts: adjustContexts,
CmdGroupers: newReprojectionGroupers,
Events: newReprojectionEvents,
})
}

type contextUsage int

const (
rendererCtx = contextUsage(iota)
reprojectionCtx
)

func adjustContexts(ctx context.Context, ctxs []*api.ContextInfo) {
// Look for the renderer context.
tyGvrFrameSubmit := reflect.TypeOf(&Gvr_frame_submit{})
if c := findContextByCommand(ctxs, tyGvrFrameSubmit); c != nil {
c.UserData[rendererCtx] = true
c.Name = "Main context (" + c.Name + ")"
}

// Look for the reprojection context.
tyGlFlush := reflect.TypeOf(&gles.GlFlush{})
if c := findContextByCommand(ctxs, tyGlFlush); c != nil {
c.UserData[reprojectionCtx] = true
c.Name = "Reprojection context"
}
}

func findContextByCommand(ctxs []*api.ContextInfo, ty reflect.Type) *api.ContextInfo {
highest, best := 0, (*api.ContextInfo)(nil)
for _, c := range ctxs {
if count := c.NumCommandsByType[ty]; count > highest {
highest, best = count, c
}
}
return best
}

func isReprojectionContext(ctx context.Context, p *path.Context) bool {
// Only group if we're looking at the reprojection thread.
if p == nil {
return false
}
c, err := resolve.Context(ctx, p)
if c == nil || err != nil {
return false
}
_, ok := c.UserData[reprojectionCtx]
return ok
}

func newReprojectionGroupers(ctx context.Context, p *path.CommandTree) []cmdgrouper.Grouper {
if !isReprojectionContext(ctx, p.Capture.Context(p.GetFilter().GetContext().ID())) {
return nil
}
glFenceSync := func(cond gles.GLenum) func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
c, ok := cmd.(*gles.GlFenceSync)
return ok && c.Condition == cond
}
}
glEndTilingQCOM := func(cond gles.GLbitfield) func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
c, ok := cmd.(*gles.GlEndTilingQCOM)
return ok && c.PreserveMask == cond
}
}
eglDestroySyncKHR := func() func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
_, ok := cmd.(*gles.EglDestroySyncKHR)
return ok
}
}
glClientWaitSync := func() func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
_, ok := cmd.(*gles.GlClientWaitSync)
return ok
}
}
glDeleteSync := func() func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
_, ok := cmd.(*gles.GlDeleteSync)
return ok
}
}
glDrawElements := func() func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
_, ok := cmd.(*gles.GlDrawElements)
return ok
}
}
notGlDrawElements := func() func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
_, ok := cmd.(*gles.GlDrawElements)
return !ok
}
}
notGlFlush := func() func(cmd, prev api.Cmd) bool {
return func(cmd, prev api.Cmd) bool {
_, ok := cmd.(*gles.GlFlush)
return !ok
}
}
return []cmdgrouper.Grouper{
noSubFrameEventGrouper{cmdgrouper.Sequence("Left eye",
cmdgrouper.Rule{Pred: eglDestroySyncKHR()},
cmdgrouper.Rule{Pred: glClientWaitSync()},
cmdgrouper.Rule{Pred: glDeleteSync()},
cmdgrouper.Rule{Pred: notGlDrawElements(), Repeats: true},
cmdgrouper.Rule{Pred: glDrawElements()},
)},
noSubFrameEventGrouper{cmdgrouper.Sequence("Right eye",
cmdgrouper.Rule{Pred: glFenceSync(gles.GLenum_GL_SYNC_GPU_COMMANDS_COMPLETE)},
cmdgrouper.Rule{Pred: glEndTilingQCOM(1), Optional: true},
cmdgrouper.Rule{Pred: glClientWaitSync()},
cmdgrouper.Rule{Pred: glDeleteSync()},
cmdgrouper.Rule{Pred: notGlDrawElements(), Repeats: true},
cmdgrouper.Rule{Pred: glDrawElements()},
cmdgrouper.Rule{Pred: notGlFlush(), Repeats: true},
)},
}
}

type noSubFrameEventGrouper struct {
cmdgrouper.Grouper
}

func (n noSubFrameEventGrouper) Build(end api.CmdID) []cmdgrouper.Group {
out := n.Grouper.Build(end)
for i := range out {
out[i].UserData = &resolve.CmdGroupData{
Thumbnail: api.CmdNoID,
NoFrameEventGroups: true,
}
}
return out
}

func newReprojectionEvents(ctx context.Context, p *path.Events) extensions.EventProvider {
if !isReprojectionContext(ctx, p.Capture.Context(p.GetFilter().GetContext().ID())) {
return nil
}

var pending []service.EventKind
return func(ctx context.Context, id api.CmdID, cmd api.Cmd, s *api.GlobalState) []*service.Event {
events := []*service.Event{}
for _, kind := range pending {
events = append(events, &service.Event{
Kind: kind,
Command: p.Capture.Command(uint64(id)),
})
}
pending = nil
if _, ok := cmd.(*gles.GlFlush); ok {
if p.LastInFrame {
events = append(events, &service.Event{
Kind: service.EventKind_LastInFrame,
Command: p.Capture.Command(uint64(id)),
})
}
if p.FirstInFrame {
pending = append(pending, service.EventKind_FirstInFrame)
}
}
return events
}
}
15 changes: 14 additions & 1 deletion gapis/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,36 @@
package extensions

import (
"context"
"sync"

"github.com/google/gapid/gapis/api"
"github.com/google/gapid/gapis/resolve/cmdgrouper"
"github.com/google/gapid/gapis/service"
"github.com/google/gapid/gapis/service/path"
)

var (
extensions []Extension
mutex sync.Mutex
)

// EventProvider is a function that produces events for the given command and
// state.
type EventProvider func(ctx context.Context, id api.CmdID, cmd api.Cmd, s *api.GlobalState) []*service.Event

// Extension is a GAPIS extension.
// It should be registered at application initialization with Register.
type Extension struct {
// Name of the extension.
Name string
// AdjustContexts lets the extension rename or reprioritize the list of
// contexts.
AdjustContexts func(context.Context, []*api.ContextInfo)
// Custom command groupers.
CmdGroupers func() []cmdgrouper.Grouper
CmdGroupers func(ctx context.Context, p *path.CommandTree) []cmdgrouper.Grouper
// Custom events provider.
Events func(ctx context.Context, p *path.Events) EventProvider
}

// Register registers the extension e.
Expand Down
Loading