diff --git a/gapis/api/cmd_observations.go b/gapis/api/cmd_observations.go index 6a50571576..3f1c5e3821 100644 --- a/gapis/api/cmd_observations.go +++ b/gapis/api/cmd_observations.go @@ -26,6 +26,20 @@ import ( "github.com/google/gapid/gapis/memory/memory_pb" ) +// ResourceReference is the interface implemented by types that hold references +// to Resource identifiers which require remapping. Resources are stored in +// the capture files using an identifier that is generated by the interceptor. +// When resources are stored into the server database, the database returns a +// different identifier for this data. To simplify things, we use +// RemapResourceIDs to transform the capture resource identifier to the database +// resource identifier as the capture is loaded. +type ResourceReference interface { + // RemapResourceIDs returns this object with the serialized resource + // identifier replaced with the identifier used to store the resource in the + // database. + RemapResourceIDs(map[id.ID]id.ID) ResourceReference +} + // CmdObservations is a collection of reads and write observations performed by an // command. type CmdObservations struct { @@ -57,7 +71,7 @@ func (o *CmdObservations) ApplyReads(p *memory.Pool) { } } -// ApplyReads applies all the observed writes to the memory pool p. +// ApplyWrites applies all the observed writes to the memory pool p. // This is a no-op when called when o is nil. func (o *CmdObservations) ApplyWrites(p *memory.Pool) { if o != nil { @@ -100,6 +114,17 @@ func (o CmdObservation) String() string { return fmt.Sprintf("{Range: %v, ID: %v}", o.Range, o.ID) } +var _ ResourceReference = (*CmdObservation)(nil) + +// RemapResourceIDs remaps the serialized resource identifier with the +// identifier used to store the resource in the database. +func (o CmdObservation) RemapResourceIDs(ids map[id.ID]id.ID) ResourceReference { + if id, found := ids[o.ID]; found { + o.ID = id + } + return o +} + func init() { protoconv.Register( func(ctx context.Context, a CmdObservation) (*memory_pb.Observation, error) { diff --git a/gapis/capture/capture.go b/gapis/capture/capture.go index 217e81062f..1daf568510 100644 --- a/gapis/capture/capture.go +++ b/gapis/capture/capture.go @@ -264,9 +264,6 @@ func (b *builder) addAPI(ctx context.Context, api api.API) { func (b *builder) addObservation(ctx context.Context, o *api.CmdObservation) { interval.Merge(&b.observed, o.Range.Span(), true) - if id, found := b.idmap[o.ID]; found { - o.ID = id - } } func (b *builder) addRes(ctx context.Context, id id.ID, data []byte) error { diff --git a/gapis/capture/decoder.go b/gapis/capture/decoder.go index 374bd51d74..d9078154b7 100644 --- a/gapis/capture/decoder.go +++ b/gapis/capture/decoder.go @@ -132,6 +132,10 @@ func (d *decoder) decode(ctx context.Context, in proto.Message) (interface{}, er return nil, err } + if r, ok := obj.(api.ResourceReference); ok { + obj = r.RemapResourceIDs(d.builder.idmap) + } + switch obj := obj.(type) { case *Header: d.header = obj