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