-
Notifications
You must be signed in to change notification settings - Fork 0
/
links.go
234 lines (208 loc) · 7.46 KB
/
links.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Copyright (C) 2017 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 gles
import (
"context"
"github.com/google/gapid/gapis/resolve"
"github.com/google/gapid/gapis/service/path"
)
// objects returns the path to the Objects field of the currently bound
// context, and the context at p.
func objects(ctx context.Context, p path.Node, r *path.ResolveConfig) (*path.Field, Contextʳ, error) {
if cmdPath := path.FindCommand(p); cmdPath != nil {
cmd, err := resolve.Cmd(ctx, cmdPath, r)
if err != nil {
return nil, NilContextʳ, err
}
thread := cmd.Thread()
stateObj, err := resolve.State(ctx, cmdPath.StateAfter(), r)
if err != nil {
return nil, NilContextʳ, err
}
state := stateObj.(*State)
context, ok := state.Contexts().Lookup(thread)
if !ok {
return nil, NilContextʳ, nil
}
return state.objectsRoot(cmdPath, thread), context, nil
}
return nil, NilContextʳ, nil
}
// Link returns the link to the attribute vertex array in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o AttributeLocation) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil {
return nil, err
}
if !c.Bound().VertexArray().VertexAttributeArrays().Contains(o) {
return nil, nil
}
return i.
Field("VertexArrays").
MapIndex(c.Bound().VertexArray().GetID()).
Field("VertexAttributeArrays").
MapIndex(o), nil
}
// Link returns the link to the buffer object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o BufferId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Buffers().Contains(o) {
return nil, err
}
return i.Field("Buffers").MapIndex(o), nil
}
// Link returns the link to the framebuffer object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o FramebufferId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Framebuffers().Contains(o) {
return nil, err
}
return i.Field("Framebuffers").MapIndex(o), nil
}
// Link returns the link to the program in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o ProgramId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Programs().Contains(o) {
return nil, err
}
return i.Field("Programs").MapIndex(o), nil
}
// Link returns the link to the query object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o QueryId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Queries().Contains(o) {
return nil, err
}
return i.Field("Queries").MapIndex(o), nil
}
// Link returns the link to the renderbuffer object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o RenderbufferId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Renderbuffers().Contains(o) {
return nil, err
}
return i.Field("Renderbuffers").MapIndex(o), nil
}
// Link returns the link to the sampler object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o SamplerId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Samplers().Contains(o) {
return nil, err
}
return i.Field("Samplers").MapIndex(o), nil
}
// Link returns the link to the shader object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o ShaderId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Shaders().Contains(o) {
return nil, err
}
return i.Field("Shaders").MapIndex(o), nil
}
// Link returns the link to the texture object in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o TextureId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().Textures().Contains(o) {
return nil, err
}
return i.Field("Textures").MapIndex(o), nil
}
// Link returns the link to the uniform in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o UniformIndex) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil {
return nil, err
}
cmd, err := resolve.Cmd(ctx, path.FindCommand(p), r)
if err != nil {
return nil, err
}
var program ProgramId
switch cmd := cmd.(type) {
case *GlGetActiveUniform:
program = cmd.Program()
case *GlGetActiveUniformsiv:
program = cmd.Program()
default:
program = c.Bound().Program().GetID()
}
prog, ok := c.Objects().Programs().Lookup(program)
if !ok || prog.ActiveResources().IsNil() || !prog.ActiveResources().Uniforms().Contains(uint32(o)) {
return nil, nil
}
return i.
Field("Programs").
MapIndex(program).
Field("ActiveResources").
Field("Uniforms").
MapIndex(o), nil
}
// Link returns the link to the uniform in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o UniformLocation) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil {
return nil, err
}
cmd, err := resolve.Cmd(ctx, path.FindCommand(p), r)
if err != nil {
return nil, err
}
var program ProgramId
switch cmd := cmd.(type) {
case *GlGetActiveUniform:
program = cmd.Program()
case *GlGetUniformLocation:
program = cmd.Program()
default:
program = c.Bound().Program().GetID()
}
prog, ok := c.Objects().Programs().Lookup(program)
if !ok || !prog.UniformLocations().Contains(o) {
return nil, nil
}
return i.
Field("Programs").
MapIndex(program).
Field("UniformLocations").
MapIndex(o), nil
}
// Link returns the link to the vertex array in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o VertexArrayId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().VertexArrays().Contains(o) {
return nil, err
}
return i.Field("VertexArrays").MapIndex(o), nil
}
// Link returns the link to the transform feedback in the state block.
// If nil, nil is returned then the path cannot be followed.
func (o TransformFeedbackId) Link(ctx context.Context, p path.Node, r *path.ResolveConfig) (path.Node, error) {
i, c, err := objects(ctx, p, r)
if i == nil || !c.Objects().TransformFeedbacks().Contains(o) {
return nil, err
}
return i.Field("TransformFeedbacks").MapIndex(o), nil
}