From ab47ab29879a044abcb8f99f89a4462cf3c01a30 Mon Sep 17 00:00:00 2001 From: Andrew Woloszyn Date: Wed, 30 Aug 2017 10:50:42 -0400 Subject: [PATCH] Allow requests for grouped commands. This allows us to do state/memory/resource requests for commands that are grouped under other commands. Fixes #1027 --- gapis/api/sync/data.go | 3 +++ gapis/api/sync/sync.go | 28 ++++++++++++++++++++++++++- gapis/api/vulkan/vulkan.go | 4 ++-- gapis/resolve/find.go | 6 +++--- gapis/resolve/memory.go | 8 +++++++- gapis/resolve/resource_data.go | 6 +++++- gapis/resolve/state.go | 7 ++++++- gapis/resolve/synchronization_data.go | 1 + 8 files changed, 54 insertions(+), 9 deletions(-) diff --git a/gapis/api/sync/data.go b/gapis/api/sync/data.go index d8fe70f06a..dff3a9412b 100644 --- a/gapis/api/sync/data.go +++ b/gapis/api/sync/data.go @@ -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. diff --git a/gapis/api/sync/sync.go b/gapis/api/sync/sync.go index 1e6dfdf13e..0752790b3d 100644 --- a/gapis/api/sync/sync.go +++ b/gapis/api/sync/sync.go @@ -61,10 +61,27 @@ 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. @@ -72,6 +89,15 @@ func MutationCmdsFor(ctx context.Context, c *path.Capture, cmds []api.Cmd, id ap 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{} diff --git a/gapis/api/vulkan/vulkan.go b/gapis/api/vulkan/vulkan.go index 12df7f40dc..5e9079a10c 100644 --- a/gapis/api/vulkan/vulkan.go +++ b/gapis/api/vulkan/vulkan.go @@ -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...) diff --git a/gapis/resolve/find.go b/gapis/resolve/find.go index afcd0e956c..ee5c9ee314 100644 --- a/gapis/resolve/find.go +++ b/gapis/resolve/find.go @@ -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 { @@ -105,7 +105,7 @@ 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 @@ -113,7 +113,7 @@ func Find(ctx context.Context, req *service.FindRequest, h service.FindHandler) 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 diff --git a/gapis/resolve/memory.go b/gapis/resolve/memory.go index 0bc4f85764..422ab5ce03 100644 --- a/gapis/resolve/memory.go +++ b/gapis/resolve/memory.go @@ -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 } diff --git a/gapis/resolve/resource_data.go b/gapis/resolve/resource_data.go index 6b4014d6c7..a6c31733e9 100644 --- a/gapis/resolve/resource_data.go +++ b/gapis/resolve/resource_data.go @@ -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 } diff --git a/gapis/resolve/state.go b/gapis/resolve/state.go index 988d746c21..9a4150dc5f 100644 --- a/gapis/resolve/state.go +++ b/gapis/resolve/state.go @@ -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 } diff --git a/gapis/resolve/synchronization_data.go b/gapis/resolve/synchronization_data.go index 9570c6818e..ab5d6b9b9f 100644 --- a/gapis/resolve/synchronization_data.go +++ b/gapis/resolve/synchronization_data.go @@ -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}