1 //
2 // Copyright 2022 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // frame_capture_utils.h:
7 // ANGLE Frame capture common classes.
8 //
9
10 #ifndef COMMON_FRAME_CAPTURE_UTILS_H_
11 #define COMMON_FRAME_CAPTURE_UTILS_H_
12
13 #include "common/frame_capture_utils_autogen.h"
14 #include "common/gl_enum_utils_autogen.h"
15
16 namespace angle
17 {
18 using ParamData = std::vector<std::vector<uint8_t>>;
19 struct ParamCapture : angle::NonCopyable
20 {
21 ParamCapture();
22 ParamCapture(const char *nameIn, ParamType typeIn);
23 ~ParamCapture();
24
25 ParamCapture(ParamCapture &&other);
26 ParamCapture &operator=(ParamCapture &&other);
27
28 std::string name;
29 ParamType type;
30 ParamValue value;
31 gl::GLESEnum enumGroup; // only used for param type GLenum, GLboolean and GLbitfield
32 gl::BigGLEnum bigGLEnum; // only used for param type GLenum, GLboolean and GLbitfield
33 ParamData data;
34 int dataNElements = 0;
35 int arrayClientPointerIndex = -1;
36 size_t readBufferSizeBytes = 0;
37 };
38
39 using Captures = std::vector<ParamCapture>;
40
41 class ParamBuffer final : angle::NonCopyable
42 {
43 public:
44 ParamBuffer();
45 ~ParamBuffer();
46
47 ParamBuffer(ParamBuffer &&other);
48 ParamBuffer &operator=(ParamBuffer &&other);
49
50 template <typename T>
51 void addValueParam(const char *paramName, ParamType paramType, T paramValue);
52 template <typename T>
53 void setValueParamAtIndex(const char *paramName, ParamType paramType, T paramValue, int index);
54 template <typename T>
55 void addEnumParam(const char *paramName,
56 gl::GLESEnum enumGroup,
57 ParamType paramType,
58 T paramValue);
59 template <typename T>
60 void addEnumParam(const char *paramName,
61 gl::BigGLEnum enumGroup,
62 ParamType paramType,
63 T paramValue);
64
65 template <typename T>
66 void addUnnamedParam(ParamType paramType, T paramValue);
67
68 ParamCapture &getParam(const char *paramName, ParamType paramType, int index);
69 const ParamCapture &getParam(const char *paramName, ParamType paramType, int index) const;
70 ParamCapture &getParamFlexName(const char *paramName1,
71 const char *paramName2,
72 ParamType paramType,
73 int index);
74 const ParamCapture &getParamFlexName(const char *paramName1,
75 const char *paramName2,
76 ParamType paramType,
77 int index) const;
getReturnValue()78 const ParamCapture &getReturnValue() const { return mReturnValueCapture; }
79
80 void addParam(ParamCapture &¶m);
81 void addReturnValue(ParamCapture &&returnValue);
hasClientArrayData()82 bool hasClientArrayData() const { return mClientArrayDataParam != -1; }
83 ParamCapture &getClientArrayPointerParameter();
getReadBufferSize()84 size_t getReadBufferSize() const { return mReadBufferSize; }
85
empty()86 bool empty() const { return mParamCaptures.empty(); }
getParamCaptures()87 const std::vector<ParamCapture> &getParamCaptures() const { return mParamCaptures; }
88
89 const char *getNextParamName();
90
91 private:
92 std::vector<ParamCapture> mParamCaptures;
93 ParamCapture mReturnValueCapture;
94 int mClientArrayDataParam = -1;
95 size_t mReadBufferSize = 0;
96 };
97
98 struct CallCapture
99 {
100 CallCapture(EntryPoint entryPointIn, ParamBuffer &¶msIn);
101 CallCapture(const std::string &customFunctionNameIn, ParamBuffer &¶msIn);
102 ~CallCapture();
103
104 CallCapture(CallCapture &&other);
105 CallCapture &operator=(CallCapture &&other);
106
107 const char *name() const;
108
109 EntryPoint entryPoint;
110 std::string customFunctionName;
111 ParamBuffer params;
112 bool isActive = true;
113 };
114
115 template <typename T>
addValueParam(const char * paramName,ParamType paramType,T paramValue)116 void ParamBuffer::addValueParam(const char *paramName, ParamType paramType, T paramValue)
117 {
118 ParamCapture capture(paramName, paramType);
119 InitParamValue(paramType, paramValue, &capture.value);
120 mParamCaptures.emplace_back(std::move(capture));
121 }
122
123 template <typename T>
setValueParamAtIndex(const char * paramName,ParamType paramType,T paramValue,int index)124 void ParamBuffer::setValueParamAtIndex(const char *paramName,
125 ParamType paramType,
126 T paramValue,
127 int index)
128 {
129 ASSERT(mParamCaptures.size() > static_cast<size_t>(index));
130
131 ParamCapture capture(paramName, paramType);
132 InitParamValue(paramType, paramValue, &capture.value);
133 mParamCaptures[index] = std::move(capture);
134 }
135
136 template <typename T>
addEnumParam(const char * paramName,gl::GLESEnum enumGroup,ParamType paramType,T paramValue)137 void ParamBuffer::addEnumParam(const char *paramName,
138 gl::GLESEnum enumGroup,
139 ParamType paramType,
140 T paramValue)
141 {
142 ParamCapture capture(paramName, paramType);
143 InitParamValue(paramType, paramValue, &capture.value);
144 capture.enumGroup = enumGroup;
145 mParamCaptures.emplace_back(std::move(capture));
146 }
147
148 template <typename T>
addEnumParam(const char * paramName,gl::BigGLEnum enumGroup,ParamType paramType,T paramValue)149 void ParamBuffer::addEnumParam(const char *paramName,
150 gl::BigGLEnum enumGroup,
151 ParamType paramType,
152 T paramValue)
153 {
154 ParamCapture capture(paramName, paramType);
155 InitParamValue(paramType, paramValue, &capture.value);
156 capture.bigGLEnum = enumGroup;
157 mParamCaptures.emplace_back(std::move(capture));
158 }
159
160 template <typename T>
addUnnamedParam(ParamType paramType,T paramValue)161 void ParamBuffer::addUnnamedParam(ParamType paramType, T paramValue)
162 {
163 addValueParam(getNextParamName(), paramType, paramValue);
164 }
165
166 template <ParamType ParamT, typename T>
167 void WriteParamValueReplay(std::ostream &os, const CallCapture &call, T value);
168
169 template <>
170 void WriteParamValueReplay<ParamType::TGLboolean>(std::ostream &os,
171 const CallCapture &call,
172 GLboolean value);
173
174 template <>
175 void WriteParamValueReplay<ParamType::TGLbooleanPointer>(std::ostream &os,
176 const CallCapture &call,
177 GLboolean *value);
178
179 template <>
180 void WriteParamValueReplay<ParamType::TvoidConstPointer>(std::ostream &os,
181 const CallCapture &call,
182 const void *value);
183
184 template <>
185 void WriteParamValueReplay<ParamType::TvoidPointer>(std::ostream &os,
186 const CallCapture &call,
187 void *value);
188
189 template <>
190 void WriteParamValueReplay<ParamType::TGLfloatConstPointer>(std::ostream &os,
191 const CallCapture &call,
192 const GLfloat *value);
193
194 template <>
195 void WriteParamValueReplay<ParamType::TGLintConstPointer>(std::ostream &os,
196 const CallCapture &call,
197 const GLint *value);
198
199 template <>
200 void WriteParamValueReplay<ParamType::TGLsizeiPointer>(std::ostream &os,
201 const CallCapture &call,
202 GLsizei *value);
203
204 template <>
205 void WriteParamValueReplay<ParamType::TGLuintConstPointer>(std::ostream &os,
206 const CallCapture &call,
207 const GLuint *value);
208
209 template <>
210 void WriteParamValueReplay<ParamType::TGLDEBUGPROCKHR>(std::ostream &os,
211 const CallCapture &call,
212 GLDEBUGPROCKHR value);
213
214 template <>
215 void WriteParamValueReplay<ParamType::TGLDEBUGPROC>(std::ostream &os,
216 const CallCapture &call,
217 GLDEBUGPROC value);
218
219 template <>
220 void WriteParamValueReplay<ParamType::TBufferID>(std::ostream &os,
221 const CallCapture &call,
222 gl::BufferID value);
223
224 template <>
225 void WriteParamValueReplay<ParamType::TFenceNVID>(std::ostream &os,
226 const CallCapture &call,
227 gl::FenceNVID value);
228
229 template <>
230 void WriteParamValueReplay<ParamType::TFramebufferID>(std::ostream &os,
231 const CallCapture &call,
232 gl::FramebufferID value);
233
234 template <>
235 void WriteParamValueReplay<ParamType::TMemoryObjectID>(std::ostream &os,
236 const CallCapture &call,
237 gl::MemoryObjectID value);
238
239 template <>
240 void WriteParamValueReplay<ParamType::TProgramPipelineID>(std::ostream &os,
241 const CallCapture &call,
242 gl::ProgramPipelineID value);
243
244 template <>
245 void WriteParamValueReplay<ParamType::TQueryID>(std::ostream &os,
246 const CallCapture &call,
247 gl::QueryID value);
248
249 template <>
250 void WriteParamValueReplay<ParamType::TRenderbufferID>(std::ostream &os,
251 const CallCapture &call,
252 gl::RenderbufferID value);
253
254 template <>
255 void WriteParamValueReplay<ParamType::TSamplerID>(std::ostream &os,
256 const CallCapture &call,
257 gl::SamplerID value);
258
259 template <>
260 void WriteParamValueReplay<ParamType::TSemaphoreID>(std::ostream &os,
261 const CallCapture &call,
262 gl::SemaphoreID value);
263
264 template <>
265 void WriteParamValueReplay<ParamType::TShaderProgramID>(std::ostream &os,
266 const CallCapture &call,
267 gl::ShaderProgramID value);
268
269 template <>
270 void WriteParamValueReplay<ParamType::TTextureID>(std::ostream &os,
271 const CallCapture &call,
272 gl::TextureID value);
273
274 template <>
275 void WriteParamValueReplay<ParamType::TTransformFeedbackID>(std::ostream &os,
276 const CallCapture &call,
277 gl::TransformFeedbackID value);
278
279 template <>
280 void WriteParamValueReplay<ParamType::TVertexArrayID>(std::ostream &os,
281 const CallCapture &call,
282 gl::VertexArrayID value);
283
284 template <>
285 void WriteParamValueReplay<ParamType::TUniformLocation>(std::ostream &os,
286 const CallCapture &call,
287 gl::UniformLocation value);
288
289 template <>
290 void WriteParamValueReplay<ParamType::TUniformBlockIndex>(std::ostream &os,
291 const CallCapture &call,
292 gl::UniformBlockIndex value);
293
294 template <>
295 void WriteParamValueReplay<ParamType::TSyncID>(std::ostream &os,
296 const CallCapture &call,
297 gl::SyncID value);
298
299 template <>
300 void WriteParamValueReplay<ParamType::TGLubyte>(std::ostream &os,
301 const CallCapture &call,
302 GLubyte value);
303
304 template <>
305 void WriteParamValueReplay<ParamType::TContextID>(std::ostream &os,
306 const CallCapture &call,
307 gl::ContextID value);
308
309 template <>
310 void WriteParamValueReplay<ParamType::Tegl_DisplayPointer>(std::ostream &os,
311 const CallCapture &call,
312 egl::Display *value);
313
314 template <>
315 void WriteParamValueReplay<ParamType::TImageID>(std::ostream &os,
316 const CallCapture &call,
317 egl::ImageID value);
318
319 template <>
320 void WriteParamValueReplay<ParamType::TSurfaceID>(std::ostream &os,
321 const CallCapture &call,
322 egl::SurfaceID value);
323
324 template <>
325 void WriteParamValueReplay<ParamType::TEGLDEBUGPROCKHR>(std::ostream &os,
326 const CallCapture &call,
327 EGLDEBUGPROCKHR value);
328
329 template <>
330 void WriteParamValueReplay<ParamType::TEGLGetBlobFuncANDROID>(std::ostream &os,
331 const CallCapture &call,
332 EGLGetBlobFuncANDROID value);
333
334 template <>
335 void WriteParamValueReplay<ParamType::TEGLSetBlobFuncANDROID>(std::ostream &os,
336 const CallCapture &call,
337 EGLSetBlobFuncANDROID value);
338 template <>
339 void WriteParamValueReplay<ParamType::TEGLClientBuffer>(std::ostream &os,
340 const CallCapture &call,
341 EGLClientBuffer value);
342
343 template <>
344 void WriteParamValueReplay<ParamType::TEGLAttribPointer>(std::ostream &os,
345 const CallCapture &call,
346 const EGLAttrib *value);
347
348 template <>
349 void WriteParamValueReplay<ParamType::TEGLintPointer>(std::ostream &os,
350 const CallCapture &call,
351 EGLint *value);
352
353 template <>
354 void WriteParamValueReplay<ParamType::TEGLintConstPointer>(std::ostream &os,
355 const CallCapture &call,
356 const EGLint *value);
357
358 template <>
359 void WriteParamValueReplay<ParamType::Tegl_ConfigPointer>(std::ostream &os,
360 const CallCapture &call,
361 egl::Config *value);
362
363 template <>
364 void WriteParamValueReplay<ParamType::Tegl_SyncID>(std::ostream &os,
365 const CallCapture &call,
366 egl::SyncID value);
367
368 template <>
369 void WriteParamValueReplay<ParamType::TEGLTime>(std::ostream &os,
370 const CallCapture &call,
371 EGLTime value);
372
373 template <>
374 void WriteParamValueReplay<ParamType::TEGLTimeKHR>(std::ostream &os,
375 const CallCapture &call,
376 EGLTimeKHR value);
377
378 // General fallback for any unspecific type.
379 template <ParamType ParamT, typename T>
WriteParamValueReplay(std::ostream & os,const CallCapture & call,T value)380 void WriteParamValueReplay(std::ostream &os, const CallCapture &call, T value)
381 {
382 os << value;
383 }
384
385 struct FmtPointerIndex
386 {
FmtPointerIndexFmtPointerIndex387 FmtPointerIndex(const void *ptrIn) : ptr(ptrIn) {}
388 const void *ptr;
389 };
390
391 inline std::ostream &operator<<(std::ostream &os, const FmtPointerIndex &fmt)
392 {
393 os << reinterpret_cast<uintptr_t>(fmt.ptr) << "ul";
394 return os;
395 }
396
397 bool FindShaderProgramIDsInCall(const CallCapture &call, std::vector<gl::ShaderProgramID> &idsOut);
398 } // namespace angle
399
400 #endif // COMMON_FRAME_CAPTURE_UTILS_H_
401