Skip to content

Commit 2e73d54

Browse files
Remove events code and refactor things that used it to use alternative mechanisms (#971)
1 parent 7c4450d commit 2e73d54

22 files changed

+326
-624
lines changed

cmd/gapit/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (verb *commandsVerb) Run(ctx context.Context, flags flag.FlagSet) error {
6060
return log.Err(ctx, err, "Failed to build the CommandFilter")
6161
}
6262
filter.OnlyExecutedDraws = verb.OnlyExecutedDraws
63+
filter.OnlyEndOfFrames = verb.OnlyEndOfFrames
6364

6465
treePath := capture.CommandTree(filter)
6566
treePath.GroupByApi = verb.GroupByAPI

cmd/gapit/common.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,6 @@ func getADBDevice(ctx context.Context, pattern string) (adb.Device, error) {
359359
return matchingDevices[0], nil
360360
}
361361

362-
func getEvents(ctx context.Context, client service.Service, p *path.Events) ([]*service.Event, error) {
363-
b, err := client.Get(ctx, p.Path(), nil)
364-
if err != nil {
365-
return nil, log.Errf(ctx, err, "Couldn't get events at: %v", p)
366-
}
367-
return b.(*service.Events).List, nil
368-
}
369-
370362
func getCommand(ctx context.Context, client service.Service, p *path.Command) (*api.Command, error) {
371363
boxedCmd, err := client.Get(ctx, p.Path(), nil)
372364
if err != nil {

cmd/gapit/dump_fbo.go

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,42 +78,37 @@ func (verb *dumpFBOVerb) frameSource(ctx context.Context, client client.Client,
7878
if err != nil {
7979
return nil, log.Err(ctx, err, "Couldn't get filter")
8080
}
81+
filter.OnlyFramebufferObservations = true
8182

82-
return func(ch chan<- image.Image) error {
83-
// Get the draw call and end-of-frame events.
84-
events, err := getEvents(ctx, client, &path.Events{
85-
Capture: capture,
86-
LastInFrame: true,
87-
FramebufferObservations: true,
88-
Filter: filter,
89-
})
90-
if err != nil {
91-
return log.Err(ctx, err, "Couldn't get events")
83+
treePath := capture.CommandTree(filter)
84+
85+
boxedTree, err := client.Get(ctx, treePath.Path(), nil)
86+
if err != nil {
87+
return nil, log.Err(ctx, err, "Failed to load the command tree")
88+
}
89+
90+
tree := boxedTree.(*service.CommandTree)
91+
92+
var allFBOCommands []*path.Command
93+
traverseCommandTree(ctx, client, tree.Root, func(n *service.CommandTreeNode, prefix string) error {
94+
if n.Group != "" {
95+
return nil
9296
}
97+
allFBOCommands = append(allFBOCommands, n.Commands.First())
98+
return nil
99+
}, "", true)
93100

94-
var lastFrameEvent *path.Command
95-
for _, e := range events {
96-
switch e.Kind {
97-
case service.EventKind_FramebufferObservation:
98-
// Find FBO for all presents.
99-
if lastFrameEvent == nil {
100-
continue
101-
}
102-
lastFrameEvent = nil
103-
104-
fbo, err := getFBO(ctx, client, e.Command)
105-
if err != nil {
106-
return err
107-
}
108-
109-
ch <- flipImg(&image.NRGBA{
110-
Pix: fbo.Bytes,
111-
Stride: int(fbo.Width) * 4,
112-
Rect: image.Rect(0, 0, int(fbo.Width), int(fbo.Height)),
113-
})
114-
case service.EventKind_LastInFrame:
115-
lastFrameEvent = e.Command
101+
return func(ch chan<- image.Image) error {
102+
for _, cmd := range allFBOCommands {
103+
fbo, err := getFBO(ctx, client, cmd)
104+
if err != nil {
105+
return err
116106
}
107+
ch <- flipImg(&image.NRGBA{
108+
Pix: fbo.Bytes,
109+
Stride: int(fbo.Width) * 4,
110+
Rect: image.Rect(0, 0, int(fbo.Width), int(fbo.Height)),
111+
})
117112
}
118113

119114
return nil

cmd/gapit/export_replay.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,29 @@ func (verb *exportReplayVerb) Run(ctx context.Context, flags flag.FlagSet) error
113113
if err != nil {
114114
return log.Err(ctx, err, "Couldn't get filter")
115115
}
116+
filter.OnlyEndOfFrames = true
116117

117-
requestEvents := gapidPath.Events{
118-
Capture: capturePath,
119-
LastInFrame: true,
120-
Filter: filter,
121-
}
118+
treePath := capturePath.CommandTree(filter)
122119

123-
// Get the end-of-frame events.
124-
eofEvents, err := getEvents(ctx, client, &requestEvents)
120+
boxedTree, err := client.Get(ctx, treePath.Path(), nil)
125121
if err != nil {
126-
return log.Err(ctx, err, "Couldn't get frame events")
122+
return log.Err(ctx, err, "Failed to load the command tree")
127123
}
128124

129-
for _, e := range eofEvents {
125+
tree := boxedTree.(*service.CommandTree)
126+
127+
var allEOFCommands []*gapidPath.Command
128+
traverseCommandTree(ctx, client, tree.Root, func(n *service.CommandTreeNode, prefix string) error {
129+
if n.Group != "" {
130+
return nil
131+
}
132+
allEOFCommands = append(allEOFCommands, n.Commands.First())
133+
return nil
134+
}, "", true)
135+
136+
for _, e := range allEOFCommands {
130137
fbreqs = append(fbreqs, &gapidPath.FramebufferAttachment{
131-
After: e.Command,
138+
After: e,
132139
Index: 0,
133140
RenderSettings: &gapidPath.RenderSettings{DisableReplayOptimization: true},
134141
Hints: nil,

cmd/gapit/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ type (
255255
GroupBySubmission bool `help:"Group commands by submissions"`
256256
AllowIncompleteFrame bool `help:"_Make a group for incomplete frames"`
257257
OnlyExecutedDraws bool `help:"Only show executed draw calls from within command buffers"`
258+
OnlyEndOfFrames bool `help:"Only end of frame commands"`
258259
Observations ObservationFlags
259260
CommandFilterFlags
260261
CaptureFileFlags

cmd/gapit/screenshot.go

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"image"
2222
"image/png"
23+
"math"
2324
"os"
2425
"strconv"
2526
"strings"
@@ -203,62 +204,73 @@ func (verb *screenshotVerb) getSingleFrame(ctx context.Context, cmd *path.Comman
203204
}, nil
204205
}
205206

206-
func (verb *screenshotVerb) frameCommands(ctx context.Context, capture *path.Capture, client service.Service) ([]*path.Command, error) {
207+
func (verb *screenshotVerb) frameCommands(ctx context.Context, capture *path.Capture, client client.Client) ([]*path.Command, error) {
207208
filter, err := verb.CommandFilterFlags.commandFilter(ctx, client, capture)
208209
if err != nil {
209210
return nil, log.Err(ctx, err, "Couldn't get filter")
210211
}
212+
filter.OnlyEndOfFrames = true
211213

212-
requestEvents := path.Events{
213-
Capture: capture,
214-
LastInFrame: true,
215-
DrawCalls: verb.Draws,
216-
Filter: filter,
217-
}
214+
treePath := capture.CommandTree(filter)
218215

219-
// Get the end-of-frame and possibly draw call events.
220-
events, err := getEvents(ctx, client, &requestEvents)
216+
boxedTree, err := client.Get(ctx, treePath.Path(), nil)
221217
if err != nil {
222-
return nil, log.Err(ctx, err, "Couldn't get frame events")
218+
return nil, log.Err(ctx, err, "Failed to load the command tree")
223219
}
224220

225-
// Compute an index of frame to event idx.
226-
frameIdx := map[int]int{}
227-
lastFrame := 0
228-
for i, e := range events {
229-
if e.Kind == service.EventKind_LastInFrame {
230-
lastFrame++
231-
frameIdx[lastFrame] = i
221+
tree := boxedTree.(*service.CommandTree)
222+
223+
var allEOFCommands []*path.Command
224+
traverseCommandTree(ctx, client, tree.Root, func(n *service.CommandTreeNode, prefix string) error {
225+
if n.Group != "" {
226+
return nil
232227
}
233-
}
228+
allEOFCommands = append(allEOFCommands, n.Commands.First())
229+
return nil
230+
}, "", true)
234231

235232
if len(verb.Frame) == 0 {
236-
verb.Frame = []int{lastFrame}
233+
verb.Frame = []int{len(allEOFCommands) - 1}
237234
}
238235

239-
var commands []*path.Command
236+
var retCommands []*path.Command
240237
for _, frame := range verb.Frame {
241-
last, ok := frameIdx[frame]
242-
if !ok {
243-
return nil, fmt.Errorf("Invalid frame number %d (last frame is %d)", frame, lastFrame)
238+
239+
if frame < 0 || frame >= len(allEOFCommands) {
240+
return nil, fmt.Errorf("Invalid frame number %d (last frame is %d)", frame, len(allEOFCommands))
244241
}
245242

246-
first := last
247243
if verb.Draws {
248-
if frame == 1 {
249-
first = 0
250-
} else {
251-
first = frameIdx[frame-1]
244+
245+
firstFrameCommand := uint64(0)
246+
if frame > 0 {
247+
firstFrameCommand = allEOFCommands[frame-1].Indices[0]
252248
}
253-
}
254-
for idx := first; idx <= last; idx++ {
255-
commands = append(commands, events[idx].Command)
249+
250+
lastFrameCommand := uint64(math.MaxUint64)
251+
if frame < len(allEOFCommands) {
252+
lastFrameCommand = allEOFCommands[frame].Indices[0]
253+
}
254+
255+
drawCommands, err := verb.doExecutedDrawCommands(ctx, capture, client, math.MaxInt, firstFrameCommand, lastFrameCommand)
256+
if err != nil {
257+
return nil, fmt.Errorf("Error getting draw calls for frame")
258+
}
259+
260+
retCommands = append(retCommands, drawCommands...)
261+
} else {
262+
retCommands = append(retCommands, allEOFCommands[frame])
256263
}
257264
}
258-
return commands, nil
265+
266+
return retCommands, nil
259267
}
260268

261269
func (verb *screenshotVerb) executedDrawCommands(ctx context.Context, capture *path.Capture, client client.Client, maxAmount int) ([]*path.Command, error) {
270+
return verb.doExecutedDrawCommands(ctx, capture, client, maxAmount, 0, math.MaxUint64)
271+
}
272+
273+
func (verb *screenshotVerb) doExecutedDrawCommands(ctx context.Context, capture *path.Capture, client client.Client, maxAmount int, after uint64, before uint64) ([]*path.Command, error) {
262274
filter, err := verb.CommandFilterFlags.commandFilter(ctx, client, capture)
263275
if err != nil {
264276
return nil, log.Err(ctx, err, "Couldn't get filter")
@@ -280,7 +292,9 @@ func (verb *screenshotVerb) executedDrawCommands(ctx context.Context, capture *p
280292
if n.Group != "" || n.NumChildren > 0 || len(n.Commands.First().Indices) == 1 {
281293
return nil
282294
}
283-
allDrawCommands = append(allDrawCommands, n.Commands.First())
295+
if n.Commands.First().Indices[0] >= after && n.Commands.First().Indices[0] < before {
296+
allDrawCommands = append(allDrawCommands, n.Commands.First())
297+
}
284298
return nil
285299
}, "", true)
286300

0 commit comments

Comments
 (0)