Skip to content

Commit

Permalink
gapis/api/gvr: Exclude all eglSwapBuffer commands when generating eve…
Browse files Browse the repository at this point in the history
…nts for the render conext.

For some unknown reason the GVR samples call eglSwapBuffers. This is pointless as the context does not use a displayed framebuffer. Worse still, these were being considered as frames - displaying nothing but the undefined framebuffer pattern.
  • Loading branch information
ben-clayton committed Oct 27, 2017
1 parent 3c6b0f2 commit cafdbd4
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
39 changes: 38 additions & 1 deletion gapis/api/gvr/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func init() {
AdjustContexts: adjustContexts,
CmdGroupers: newReprojectionGroupers,
Events: newReprojectionEvents,
EventFilter: eventFilter,
})
}

Expand Down Expand Up @@ -70,7 +71,6 @@ func findContextByCommand(ctxs []*api.ContextInfo, ty reflect.Type) *api.Context
}

func isReprojectionContext(ctx context.Context, p *path.Context) bool {
// Only group if we're looking at the reprojection thread.
if p == nil {
return false
}
Expand All @@ -82,6 +82,22 @@ func isReprojectionContext(ctx context.Context, p *path.Context) bool {
return ok
}

func getRenderContextID(ctx context.Context, p *path.Contexts) *api.ContextID {
if p == nil {
return nil
}
ctxs, err := resolve.Contexts(ctx, p)
if err != nil {
return nil
}
for _, c := range ctxs {
if _, ok := c.UserData[rendererCtx]; ok {
return &c.ID
}
}
return nil
}

func newReprojectionGroupers(ctx context.Context, p *path.CommandTree) []cmdgrouper.Grouper {
if !isReprojectionContext(ctx, p.Capture.Context(p.GetFilter().GetContext().ID())) {
return nil
Expand Down Expand Up @@ -198,3 +214,24 @@ func newReprojectionEvents(ctx context.Context, p *path.Events) extensions.Event
return events
}
}

func eventFilter(ctx context.Context, p *path.Events) extensions.EventFilter {
renderCtxID := getRenderContextID(ctx, p.Capture.Contexts())
if renderCtxID == nil {
return nil
}
return func(id api.CmdID, cmd api.Cmd, s *api.GlobalState) bool {
_, isSwapBuffers := cmd.(*gles.EglSwapBuffers)
if isSwapBuffers {
if context := gles.GetContext(s, cmd.Thread()); context != nil {
ctxID := context.ID()
if ctxID == *renderCtxID {
// Strip out eglSwapBuffers from the render context.
// We don't want them appearing as frames.
return false
}
}
}
return true
}
}
7 changes: 7 additions & 0 deletions gapis/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ var (
// state.
type EventProvider func(ctx context.Context, id api.CmdID, cmd api.Cmd, s *api.GlobalState) []*service.Event

// EventFilter is a predicate used for filtering event commands.
// If the function returns true then the command is considered for event
// generation, otherwise it is ignored.
type EventFilter func(api.CmdID, api.Cmd, *api.GlobalState) bool

// Extension is a GAPIS extension.
// It should be registered at application initialization with Register.
type Extension struct {
Expand All @@ -49,6 +54,8 @@ type Extension struct {
CmdGroupers func(ctx context.Context, p *path.CommandTree) []cmdgrouper.Grouper
// Custom events provider.
Events func(ctx context.Context, p *path.Events) EventProvider
// Custom events filters.
EventFilter func(ctx context.Context, p *path.Events) EventFilter
}

// Register registers the extension e.
Expand Down
9 changes: 9 additions & 0 deletions gapis/resolve/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func Events(ctx context.Context, p *path.Events) (*service.Events, error) {
return nil, err
}

// Add any extension event filters
filters := CommandFilters{filter}
for _, e := range extensions.Get() {
if f := e.EventFilter; f != nil {
filters = append(filters, CommandFilter(f(ctx, p)))
}
}
filter = filters.All

// Add any extension events
eps := []extensions.EventProvider{}
for _, e := range extensions.Get() {
Expand Down
31 changes: 20 additions & 11 deletions gapis/resolve/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,26 @@ import (
"github.com/google/gapid/gapis/service/path"
)

type filter func(api.CmdID, api.Cmd, *api.GlobalState) bool
// CommandFilter is a predicate used for filtering commands.
// If the function returns true then the command is considered, otherwise it is
// ignored.
type CommandFilter func(api.CmdID, api.Cmd, *api.GlobalState) bool

func buildFilter(ctx context.Context, p *path.Capture, f *path.CommandFilter, sd *sync.Data) (filter, error) {
filters := []filter{
// CommandFilters is a list of CommandFilters.
type CommandFilters []CommandFilter

// All is a CommandFilter that needs all the contained filters to pass.
func (l CommandFilters) All(id api.CmdID, cmd api.Cmd, s *api.GlobalState) bool {
for _, f := range l {
if !f(id, cmd, s) {
return false
}
}
return true
}

func buildFilter(ctx context.Context, p *path.Capture, f *path.CommandFilter, sd *sync.Data) (CommandFilter, error) {
filters := CommandFilters{
func(id api.CmdID, cmd api.Cmd, s *api.GlobalState) bool {
return !sd.Hidden.Contains(id)
},
Expand Down Expand Up @@ -55,12 +71,5 @@ func buildFilter(ctx context.Context, p *path.Capture, f *path.CommandFilter, sd
return false
})
}
return func(id api.CmdID, cmd api.Cmd, s *api.GlobalState) bool {
for _, f := range filters {
if !f(id, cmd, s) {
return false
}
}
return true
}, nil
return filters.All, nil
}

0 comments on commit cafdbd4

Please sign in to comment.