Skip to content

Commit

Permalink
Allow requests for grouped commands.
Browse files Browse the repository at this point in the history
This allows us to do state/memory/resource requests for commands
that are grouped under other commands.
Fixes google#1027
  • Loading branch information
AWoloszyn committed Aug 30, 2017
1 parent 1fdb0c1 commit ab47ab2
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
3 changes: 3 additions & 0 deletions gapis/api/sync/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type ExecutionRanges struct {
type SubcommandReference struct {
Index api.SubCmdIdx
GeneratingCmd api.CmdID
// IsCalledGroup defines whether or not this generating command is
// from a grouping, or if it is from a command-list.
IsCallerGroup bool
}

// Data contains a map of synchronization pairs.
Expand Down
28 changes: 27 additions & 1 deletion gapis/api/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,43 @@ func (s *writer) MutateAndWrite(ctx context.Context, id api.CmdID, cmd api.Cmd)
s.cmds = append(s.cmds, cmd)
}

func translateIDForMutate(idx api.SubCmdIdx, data *Data) api.CmdID {
atomIdx := api.CmdID(0)
sg, ok := data.SubcommandReferences[api.CmdID(idx[0])]
if !ok {
return 0
}
for _, v := range sg {
if v.Index.Equals(idx[1:]) {
if v.IsCallerGroup {
atomIdx = v.GeneratingCmd
}
break
}
}
return atomIdx
}

// MutationCmdsFor returns a list of command that represent the correct
// mutations to have the state for all commands before and including the given
// index.
func MutationCmdsFor(ctx context.Context, c *path.Capture, cmds []api.Cmd, id api.CmdID, subindex []uint64) ([]api.Cmd, error) {
func MutationCmdsFor(ctx context.Context, c *path.Capture, data *Data, cmds []api.Cmd, id api.CmdID, subindex []uint64) ([]api.Cmd, error) {
// This is where we want to handle sub-states
// This involves transforming the tree for the given Indices, and
// then mutating that.
rc, err := capture.ResolveFromPath(ctx, c)
if err != nil {
return nil, err
}

fullCommand := api.SubCmdIdx{uint64(id)}
fullCommand = append(fullCommand, subindex...)

if newIdx := translateIDForMutate(fullCommand, data); newIdx != 0 {
id = newIdx
subindex = []uint64{}
}

terminators := make([]transform.Terminator, 0)
transforms := transform.Transforms{}

Expand Down
4 changes: 2 additions & 2 deletions gapis/api/vulkan/vulkan.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ func (API) ResolveSynchronization(ctx context.Context, d *sync.Data, c *path.Cap
k := submissionMap[s.CurrentSubmission]
if v, ok := d.SubcommandReferences[k]; ok {
v = append(v,
sync.SubcommandReference{append(api.SubCmdIdx(nil), s.SubCmdIdx...), commandMap[data.initialCall]})
sync.SubcommandReference{append(api.SubCmdIdx(nil), s.SubCmdIdx...), commandMap[data.initialCall], false})
d.SubcommandReferences[k] = v
} else {
d.SubcommandReferences[k] = []sync.SubcommandReference{
sync.SubcommandReference{append(api.SubCmdIdx(nil), s.SubCmdIdx...), commandMap[data.initialCall]}}
sync.SubcommandReference{append(api.SubCmdIdx(nil), s.SubCmdIdx...), commandMap[data.initialCall], false}}
}

previousIndex := append(api.SubCmdIdx(nil), s.SubCmdIdx...)
Expand Down
6 changes: 3 additions & 3 deletions gapis/resolve/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
stop = fault.Const("stop")
)

func translateId(idx api.SubCmdIdx, data *sync.Data) (api.CmdID, bool) {
func translateIDForDisplay(idx api.SubCmdIdx, data *sync.Data) (api.CmdID, bool) {
atomIdx := api.CmdID(0)
sg, ok := data.SubcommandReferences[api.CmdID(idx[0])]
if !ok {
Expand Down Expand Up @@ -105,15 +105,15 @@ func Find(ctx context.Context, req *service.FindRequest, h service.FindHandler)
return pred(item.Name)
case api.SubCmdIdx:
if len(item) > 1 {
if idx, found := translateId(item, snc); found {
if idx, found := translateIDForDisplay(item, snc); found {
return pred(fmt.Sprint(c.Commands[idx]))
}
return false
}
return pred(fmt.Sprint(c.Commands[item[0]]))
case api.SubCmdRoot:
if len(item.Id) > 1 {
if idx, found := translateId(item.Id, snc); found {
if idx, found := translateIDForDisplay(item.Id, snc); found {
return pred(fmt.Sprint(c.Commands[idx]))
}
return false
Expand Down
8 changes: 7 additions & 1 deletion gapis/resolve/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ func Memory(ctx context.Context, p *path.Memory) (*service.Memory, error) {
if err != nil {
return nil, err
}
cmds, err := sync.MutationCmdsFor(ctx, path.FindCapture(p), allCmds, api.CmdID(cmdIdx), fullCmdIdx[1:])

sd, err := SyncData(ctx, path.FindCapture(p))
if err != nil {
return nil, err
}

cmds, err := sync.MutationCmdsFor(ctx, path.FindCapture(p), sd, allCmds, api.CmdID(cmdIdx), fullCmdIdx[1:])
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion gapis/resolve/resource_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func buildResources(ctx context.Context, p *path.Command) (*ResolvedResources, e
return nil, err
}

cmds, err := sync.MutationCmdsFor(ctx, p.Capture, allCmds, api.CmdID(atomIdx), p.Indices[1:])
s, err := SyncData(ctx, p.Capture)
if err != nil {
return nil, err
}
cmds, err := sync.MutationCmdsFor(ctx, p.Capture, s, allCmds, api.CmdID(atomIdx), p.Indices[1:])
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion gapis/resolve/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func (r *GlobalStateResolvable) Resolve(ctx context.Context) (interface{}, error
if err != nil {
return nil, err
}
cmds, err := sync.MutationCmdsFor(ctx, r.Path.After.Capture, allCmds, api.CmdID(cmdIdx), r.Path.After.Indices[1:])

sd, err := SyncData(ctx, r.Path.After.Capture)
if err != nil {
return nil, err
}
cmds, err := sync.MutationCmdsFor(ctx, r.Path.After.Capture, sd, allCmds, api.CmdID(cmdIdx), r.Path.After.Indices[1:])
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions gapis/resolve/synchronization_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func addCallerGroups(ctx context.Context, d *sync.Data, c *path.Capture) error {
l = append(l, sync.SubcommandReference{
Index: idx,
GeneratingCmd: id,
IsCallerGroup: true,
})
d.SubcommandReferences[caller] = l
d.SubcommandGroups[caller] = []api.SubCmdIdx{idx}
Expand Down

0 comments on commit ab47ab2

Please sign in to comment.