Skip to content

Commit

Permalink
Show command buffer vulkan handle for subcommand node. (#188)
Browse files Browse the repository at this point in the history
 - Bug: http://b/143734139.
  • Loading branch information
stellama0208 authored Apr 3, 2020
1 parent c03ac01 commit 6f98dab
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
34 changes: 20 additions & 14 deletions gapis/api/cmd_id_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ type CmdGroupOrRoot interface {
}

// NewRoot sets up a new root object.
func NewRoot(idx []uint64) *SubCmdRoot {
func NewRoot(idx []uint64, nameLookUp *SubCmdIdxTrie) *SubCmdRoot {
var name = "Subgroup"
if nameVal := nameLookUp.Value(idx); nameVal != nil {
if n, ok := nameVal.(string); ok {
name = n
}
}
return &SubCmdRoot{Id: append(slice.Clone(idx).([]uint64)),
SubGroup: CmdIDGroup{Name: "Subgroup"}}
SubGroup: CmdIDGroup{Name: name}}
}

// Spans is a list of Span elements. Functions in this package expect the
Expand Down Expand Up @@ -356,15 +362,15 @@ func (g *CmdIDGroup) AddGroup(start, end CmdID, name string) (*CmdIDGroup, error

// AddRoot adds a new Subcommand Root for the given index.
// It returns the span for this SubcommandGroup
func (g *CmdIDGroup) AddRoot(rootidx []uint64) *SubCmdRoot {
func (g *CmdIDGroup) AddRoot(rootidx []uint64, nameLookUp *SubCmdIdxTrie) *SubCmdRoot {
r := CmdIDRange{Start: CmdID(rootidx[len(rootidx)-1]), End: CmdID(rootidx[len(rootidx)-1] + 1)}
s, c := interval.Intersect(&g.Spans, r.Span())
if c == 0 {
// No groups to put this in
i := sort.Search(len(g.Spans), func(i int) bool {
return g.Spans[i].Bounds().Start > CmdID(rootidx[0])
})
slice.InsertBefore(&g.Spans, i, NewRoot(rootidx))
slice.InsertBefore(&g.Spans, i, NewRoot(rootidx, nameLookUp))
return g.Spans[i].(*SubCmdRoot)
}
if c != 1 {
Expand All @@ -374,14 +380,14 @@ func (g *CmdIDGroup) AddRoot(rootidx []uint64) *SubCmdRoot {
// At least one overlap
switch first := g.Spans[s].(type) {
case *CmdIDGroup:
return first.AddRoot(rootidx)
return first.AddRoot(rootidx, nameLookUp)
case *CmdIDRange:
firstHalf := &CmdIDRange{first.Start, CmdID(rootidx[len(rootidx)-1])}
if firstHalf.End > firstHalf.Start {
slice.InsertBefore(&g.Spans, s, firstHalf)
s++
}
slice.Replace(&g.Spans, s, 1, NewRoot(rootidx))
slice.Replace(&g.Spans, s, 1, NewRoot(rootidx, nameLookUp))
secondHalf := &CmdIDRange{CmdID(rootidx[len(rootidx)-1] + 1), first.End}
slice.InsertBefore(&g.Spans, s+1, secondHalf)
return g.Spans[s].(*SubCmdRoot)
Expand All @@ -393,7 +399,7 @@ func (g *CmdIDGroup) AddRoot(rootidx []uint64) *SubCmdRoot {

// newChildSubCmdRoots adds child SubCmdRoots to the SubCmdRoot's subgroup. If
// subcomamnds are skipped, create SubCmdRoots for them.
func (c *SubCmdRoot) newChildSubCmdRoots(r []uint64) *SubCmdRoot {
func (c *SubCmdRoot) newChildSubCmdRoots(r []uint64, nameLookUp *SubCmdIdxTrie) *SubCmdRoot {
if len(r) == 0 {
return c
}
Expand All @@ -404,23 +410,23 @@ func (c *SubCmdRoot) newChildSubCmdRoots(r []uint64) *SubCmdRoot {
}
if c.SubGroup.Range.End > oldEnd {
for i := uint64(oldEnd); i < uint64(c.SubGroup.Range.End); i++ {
c.SubGroup.AddRoot(append(c.Id, i))
c.SubGroup.AddRoot(append(c.Id, i), nameLookUp)
}
}
sg := c.SubGroup.FindSubCommandRoot(CmdID(nextRootRelativeIndex))
if sg == nil {
sg = c.SubGroup.AddRoot(append(c.Id, nextRootRelativeIndex))
sg = c.SubGroup.AddRoot(append(c.Id, nextRootRelativeIndex), nameLookUp)
}
return sg.newChildSubCmdRoots(r[1:])
return sg.newChildSubCmdRoots(r[1:], nameLookUp)
}

// Insert adds a new subcommand into the SubCmdRoot. The subcommand is specified
// with its relative hierarchy to the target SubCmdRoot. If the subcommand is
// not an immediate child of the target SubCmdRoot (i.e. len(r) > 1) , new
// child SubCmdRoots will be created under the target SubCmdRoot, until the
// immediate parent of the subcommand is created.
func (c *SubCmdRoot) Insert(r []uint64) {
childRoot := c.newChildSubCmdRoots(r[0 : len(r)-1])
func (c *SubCmdRoot) Insert(r []uint64, nameLookUp *SubCmdIdxTrie) {
childRoot := c.newChildSubCmdRoots(r[0:len(r)-1], nameLookUp)
// Add subcommands one-by-one to the SubCmdRoot and its subgroups/child
// SubCmdRoots
id := r[len(r)-1]
Expand All @@ -437,8 +443,8 @@ func (c *SubCmdRoot) Insert(r []uint64) {
// immediate children of the target SubCmdRoot (r is not empty), child
// SubCmdRoots will be created under the target SubCmdRoot recursively until
// the immediate parent SubCmdRoot is created.
func (c *SubCmdRoot) AddSubCmdMarkerGroups(r []uint64, groups []*CmdIDGroup) error {
childRoot := c.newChildSubCmdRoots(r)
func (c *SubCmdRoot) AddSubCmdMarkerGroups(r []uint64, groups []*CmdIDGroup, nameLookUp *SubCmdIdxTrie) error {
childRoot := c.newChildSubCmdRoots(r, nameLookUp)
for _, g := range groups {
if g.Range.Start < childRoot.SubGroup.Range.Start {
childRoot.SubGroup.Range.Start = g.Range.Start
Expand Down
4 changes: 4 additions & 0 deletions gapis/api/subcmd_idx_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ func (t *SubCmdIdxTrie) PostOrderSortedKeys() []SubCmdIdx {
}
return keys
}

func (t *SubCmdIdxTrie) GetChildren(index uint64) *SubCmdIdxTrie {
return t.children[index]
}
14 changes: 10 additions & 4 deletions gapis/api/sync/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ type Data struct {
SubCommandMarkerGroups *subCommandMarkerGroupTrie
// SyncDependencies contains the commands that must complete
// (according to their fences or semaphores) before they can be executed.
SyncDependencies map[SyncNodeIdx][]SyncNodeIdx
SyncNodes []SyncNode
CmdSyncNodes map[api.CmdID]SyncNodeIdx
SubcommandLookup *api.SubCmdIdxTrie
SyncDependencies map[SyncNodeIdx][]SyncNodeIdx
SyncNodes []SyncNode
CmdSyncNodes map[api.CmdID]SyncNodeIdx
// SubcommandLookup maps a SubCmdIdx to its corresponding SubcommandReference.
SubcommandLookup *api.SubCmdIdxTrie
// SubcommandNames maps a SubCmdIdx to its corresponding string typed name.
// The names are especially useful for the virtual SubCmdRoot nodes, which are
// created to organize psubmits, command buffers, etc.
SubcommandNames *api.SubCmdIdxTrie
SubmissionIndices map[api.CmdSubmissionKey][]api.SubCmdIdx
}

Expand Down Expand Up @@ -125,6 +130,7 @@ func NewData() *Data {
SyncNodes: []SyncNode{},
CmdSyncNodes: map[api.CmdID]SyncNodeIdx{},
SubcommandLookup: new(api.SubCmdIdxTrie),
SubcommandNames: new(api.SubCmdIdxTrie),
SubmissionIndices: map[api.CmdSubmissionKey][]api.SubCmdIdx{},
}
}
Expand Down
4 changes: 4 additions & 0 deletions gapis/api/vulkan/vulkan.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func (API) ResolveSynchronization(ctx context.Context, d *sync.Data, c *path.Cap

switch args := GetCommandArgs(ctx, cb.CommandReferences().Get(uint32(i)), st).(type) {
case VkCmdExecuteCommandsArgsʳ:
d.SubcommandNames.SetValue(nv, "") // Clear the group name so that the original commnd is shown.
for j := uint64(0); j < uint64(args.CommandBuffers().Len()); j++ {
cbo := st.CommandBuffers().Get(args.CommandBuffers().Get(uint32(j)))
subIdx := append(api.SubCmdIdx{}, idx...)
Expand All @@ -212,6 +213,7 @@ func (API) ResolveSynchronization(ctx context.Context, d *sync.Data, c *path.Cap
subgroups = append(subgroups, newSubgroups...)
if cbo.CommandReferences().Len() > 0 {
subgroups = append(subgroups, append(idx, uint64(i), uint64(j), uint64(cbo.CommandReferences().Len()-1)))
d.SubcommandNames.SetValue(append(idx, uint64(i), j), fmt.Sprintf("Command Buffer: %v", cbo.VulkanHandle()))
}
}
case VkCmdBeginRenderPassArgsʳ:
Expand Down Expand Up @@ -317,7 +319,9 @@ func (API) ResolveSynchronization(ctx context.Context, d *sync.Data, c *path.Cap
for submitIdx, submit := range submits {
bufferCount := submit.CommandBufferCount()
buffers := submit.PCommandBuffers().Slice(uint64(0), uint64(bufferCount), l).MustRead(ctx, cmd, s, nil)
d.SubcommandNames.SetValue(api.SubCmdIdx{uint64(id), uint64(submitIdx)}, fmt.Sprintf("pSubmits[%v]: ", submitIdx))
for j, buff := range buffers {
d.SubcommandNames.SetValue(api.SubCmdIdx{uint64(id), uint64(submitIdx), uint64(j)}, fmt.Sprintf("Command Buffer: %v", buff))
cmdBuff := st.CommandBuffers().Get(buff)
// If a submitted command-buffer is empty, we shouldn't show it
if cmdBuff.CommandReferences().Len() > 0 {
Expand Down
8 changes: 4 additions & 4 deletions gapis/resolve/command_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func CommandTreeNode(ctx context.Context, c *path.CommandTreeNode, r *path.Resol
count := uint64(1)
g := ""
if len(item.Id) > 1 {
g = fmt.Sprintf("%v", item.Id)
g = fmt.Sprintf("%v", item.SubGroup.Name)
count = uint64(item.SubGroup.Count())
}
return &service.CommandTreeNode{
Expand Down Expand Up @@ -310,7 +310,7 @@ func (r *CommandTreeResolvable) Resolve(ctx context.Context) (interface{}, error
}

if v, ok := snc.SubcommandGroups[id]; ok {
r := out.root.AddRoot([]uint64{uint64(id)})
r := out.root.AddRoot([]uint64{uint64(id)}, snc.SubcommandNames)
// subcommands are added before nesting SubCmdRoots.
cv := append([]api.SubCmdIdx{}, v...)
sort.SliceStable(cv, func(i, j int) bool { return len(cv[i]) < len(cv[j]) })
Expand All @@ -321,9 +321,9 @@ func (r *CommandTreeResolvable) Resolve(ctx context.Context) (interface{}, error
parentIdx := append([]uint64{uint64(id)}, x[0:len(x)-1]...)
if snc.SubCommandMarkerGroups.Value(parentIdx) != nil {
markers := snc.SubCommandMarkerGroups.Value(parentIdx).([]*api.CmdIDGroup)
r.AddSubCmdMarkerGroups(x[0:len(x)-1], markers)
r.AddSubCmdMarkerGroups(x[0:len(x)-1], markers, snc.SubcommandNames)
}
r.Insert(append([]uint64{}, x...))
r.Insert(append([]uint64{}, x...), snc.SubcommandNames)
}
return nil
}
Expand Down

0 comments on commit 6f98dab

Please sign in to comment.