-
Notifications
You must be signed in to change notification settings - Fork 0
/
replay_types.go
213 lines (187 loc) · 5.83 KB
/
replay_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (C) 2020 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package vulkan
import (
"bytes"
"context"
"fmt"
"github.com/google/gapid/core/image"
"github.com/google/gapid/core/log"
"github.com/google/gapid/gapis/api"
"github.com/google/gapid/gapis/replay"
"github.com/google/gapid/gapis/resolve"
"github.com/google/gapid/gapis/service"
"github.com/google/gapid/gapis/service/path"
"github.com/google/gapid/gapis/trace"
)
var (
// Interface compliance tests
_ = replay.QueryIssues(API{})
_ = replay.QueryFramebufferAttachment(API{})
_ = replay.Support(API{})
_ = replay.QueryTimestamps(API{})
_ = replay.Profiler(API{})
)
// drawConfig is a replay.Config used by colorBufferRequest and
// depthBufferRequests.
type drawConfig struct {
startScope api.CmdID
endScope api.CmdID
subindices string // drawConfig needs to be comparable, so we cannot use a slice
drawMode path.DrawMode
disableReplayOptimization bool
}
type imgRes struct {
img *image.Data // The image data.
err error // The error that occurred generating the image.
}
// framebufferRequest requests a postback of a framebuffer's attachment.
type framebufferRequest struct {
after []uint64
width, height uint32
attachment api.FramebufferAttachmentType
framebufferIndex uint32
out chan imgRes
wireframeOverlay bool
displayToSurface bool
}
// issuesConfig is a replay.Config used by issuesRequests.
type issuesConfig struct {
}
// issuesRequest requests all issues found during replay to be reported to out.
type issuesRequest struct {
out chan<- replay.Issue
displayToSurface bool
}
type timestampsConfig struct {
}
type timestampsRequest struct {
handler service.TimeStampsHandler
}
// uniqueConfig returns a replay.Config that is guaranteed to be unique.
// Any requests made with a Config returned from uniqueConfig will not be
// batched with any other request.
func uniqueConfig() replay.Config {
return &struct{}{}
}
type profileRequest struct {
traceOptions *service.TraceOptions
handler *replay.SignalHandler
buffer *bytes.Buffer
handleMappings map[uint64][]service.VulkanHandleMappingItem
experiments replay.ProfileExperiments
loopCount int32
}
func (a API) QueryFramebufferAttachment(
ctx context.Context,
intent replay.Intent,
mgr replay.Manager,
after []uint64,
width, height uint32,
attachment api.FramebufferAttachmentType,
framebufferIndex uint32,
drawMode path.DrawMode,
disableReplayOptimization bool,
displayToSurface bool,
hints *path.UsageHints) (*image.Data, error) {
beginIndex := api.CmdID(0)
endIndex := api.CmdID(0)
subcommand := ""
// We cant break up overdraw right now, but we can break up
// everything else.
if drawMode == path.DrawMode_OVERDRAW {
if len(after) > 1 { // If we are replaying subcommands, then we can't batch at all
beginIndex = api.CmdID(after[0])
endIndex = api.CmdID(after[0])
for i, j := range after[1:] {
if i != 0 {
subcommand += ":"
}
subcommand += fmt.Sprintf("%d", j)
}
}
}
c := drawConfig{beginIndex, endIndex, subcommand, drawMode, disableReplayOptimization}
out := make(chan imgRes, 1)
r := framebufferRequest{after: after, width: width, height: height, framebufferIndex: framebufferIndex, attachment: attachment, out: out, displayToSurface: displayToSurface}
res, err := mgr.Replay(ctx, intent, c, r, a, hints, false)
if err != nil {
return nil, err
}
if _, ok := mgr.(replay.Exporter); ok {
return nil, nil
}
return res.(*image.Data), nil
}
func (a API) QueryIssues(
ctx context.Context,
intent replay.Intent,
mgr replay.Manager,
displayToSurface bool,
hints *path.UsageHints) ([]replay.Issue, error) {
c, r := issuesConfig{}, issuesRequest{displayToSurface: displayToSurface}
res, err := mgr.Replay(ctx, intent, c, r, a, hints, true)
if err != nil {
return nil, err
}
if _, ok := mgr.(replay.Exporter); ok {
return nil, nil
}
return res.([]replay.Issue), nil
}
func (a API) QueryTimestamps(
ctx context.Context,
intent replay.Intent,
mgr replay.Manager,
handler service.TimeStampsHandler,
hints *path.UsageHints) error {
c, r := timestampsConfig{}, timestampsRequest{
handler: handler}
_, err := mgr.Replay(ctx, intent, c, r, a, hints, false)
if err != nil {
return err
}
if _, ok := mgr.(replay.Exporter); ok {
return nil
}
return nil
}
func (a API) QueryProfile(
ctx context.Context,
intent replay.Intent,
mgr replay.Manager,
staticAnalysisResult chan *api.StaticAnalysisProfileData,
hints *path.UsageHints,
traceOptions *service.TraceOptions,
experiments replay.ProfileExperiments,
loopCount int32) (*service.ProfilingData, error) {
log.W(ctx, "QueryProfile !!!")
c := uniqueConfig()
handler := replay.NewSignalHandler()
var buffer bytes.Buffer
handleMappings := map[uint64][]service.VulkanHandleMappingItem{}
r := profileRequest{traceOptions, handler, &buffer, handleMappings, experiments, loopCount}
_, err := mgr.Replay(ctx, intent, c, r, a, hints, true)
if err != nil {
return nil, err
}
handler.DoneSignal.Wait(ctx)
s, err := resolve.SyncData(ctx, intent.Capture)
if err != nil {
return nil, err
}
log.W(ctx, "trace.ProcessProfilingData!!!")
d, err := trace.ProcessProfilingData(ctx, intent.Device, intent.Capture, &buffer, staticAnalysisResult, handleMappings, s)
return d, err
}