// // Copyright 2022 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // frame_capture_utils.h: // ANGLE Frame capture common classes. // #ifndef COMMON_FRAME_CAPTURE_UTILS_H_ #define COMMON_FRAME_CAPTURE_UTILS_H_ #include "common/frame_capture_utils_autogen.h" #include "common/gl_enum_utils_autogen.h" namespace angle { namespace { template struct ParamValueTrait { static_assert(sizeof(ParamValueType) == 0, "invalid ParamValueType"); }; template <> struct ParamValueTrait { static constexpr const char *name = "framebufferPacked"; static const ParamType typeID = ParamType::TFramebufferID; }; template <> struct ParamValueTrait { static constexpr const char *name = "bufferPacked"; static const ParamType typeID = ParamType::TBufferID; }; template <> struct ParamValueTrait { static constexpr const char *name = "renderbufferPacked"; static const ParamType typeID = ParamType::TRenderbufferID; }; template <> struct ParamValueTrait { static constexpr const char *name = "texturePacked"; static const ParamType typeID = ParamType::TTextureID; }; template <> struct ParamValueTrait { static constexpr const char *name = "programPacked"; static const ParamType typeID = ParamType::TShaderProgramID; }; } // namespace using ParamData = std::vector>; struct ParamCapture : angle::NonCopyable { ParamCapture(); ParamCapture(const char *nameIn, ParamType typeIn); ~ParamCapture(); ParamCapture(ParamCapture &&other); ParamCapture &operator=(ParamCapture &&other); std::string name; ParamType type; ParamValue value; gl::GLESEnum enumGroup; // only used for param type GLenum, GLboolean and GLbitfield gl::BigGLEnum bigGLEnum; // only used for param type GLenum, GLboolean and GLbitfield ParamData data; int dataNElements = 0; int arrayClientPointerIndex = -1; size_t readBufferSizeBytes = 0; }; using Captures = std::vector; class ParamBuffer final : angle::NonCopyable { public: ParamBuffer(); ~ParamBuffer(); ParamBuffer(ParamBuffer &&other); ParamBuffer &operator=(ParamBuffer &&other); template void addValueParam(const char *paramName, ParamType paramType, T paramValue); template void setValueParamAtIndex(const char *paramName, ParamType paramType, T paramValue, int index); template void addEnumParam(const char *paramName, gl::GLESEnum enumGroup, ParamType paramType, T paramValue); template void addEnumParam(const char *paramName, gl::BigGLEnum enumGroup, ParamType paramType, T paramValue); template void addUnnamedParam(ParamType paramType, T paramValue); ParamCapture &getParam(const char *paramName, ParamType paramType, int index); const ParamCapture &getParam(const char *paramName, ParamType paramType, int index) const; ParamCapture &getParamFlexName(const char *paramName1, const char *paramName2, ParamType paramType, int index); const ParamCapture &getParamFlexName(const char *paramName1, const char *paramName2, ParamType paramType, int index) const; const ParamCapture &getReturnValue() const { return mReturnValueCapture; } void addParam(ParamCapture &¶m); void addReturnValue(ParamCapture &&returnValue); bool hasClientArrayData() const { return mClientArrayDataParam != -1; } ParamCapture &getClientArrayPointerParameter(); size_t getReadBufferSize() const { return mReadBufferSize; } bool empty() const { return mParamCaptures.empty(); } const std::vector &getParamCaptures() const { return mParamCaptures; } const char *getNextParamName(); private: std::vector mParamCaptures; ParamCapture mReturnValueCapture; int mClientArrayDataParam = -1; size_t mReadBufferSize = 0; }; struct CallCapture { CallCapture(EntryPoint entryPointIn, ParamBuffer &¶msIn); CallCapture(const std::string &customFunctionNameIn, ParamBuffer &¶msIn); ~CallCapture(); CallCapture(CallCapture &&other); CallCapture &operator=(CallCapture &&other); const char *name() const; EntryPoint entryPoint; std::string customFunctionName; ParamBuffer params; bool isActive = true; gl::ContextID contextID; bool isSyncPoint = false; }; template void ParamBuffer::addValueParam(const char *paramName, ParamType paramType, T paramValue) { ParamCapture capture(paramName, paramType); InitParamValue(paramType, paramValue, &capture.value); mParamCaptures.emplace_back(std::move(capture)); } template void ParamBuffer::setValueParamAtIndex(const char *paramName, ParamType paramType, T paramValue, int index) { ASSERT(mParamCaptures.size() > static_cast(index)); ParamCapture capture(paramName, paramType); InitParamValue(paramType, paramValue, &capture.value); mParamCaptures[index] = std::move(capture); } template void ParamBuffer::addEnumParam(const char *paramName, gl::GLESEnum enumGroup, ParamType paramType, T paramValue) { ParamCapture capture(paramName, paramType); InitParamValue(paramType, paramValue, &capture.value); capture.enumGroup = enumGroup; mParamCaptures.emplace_back(std::move(capture)); } template void ParamBuffer::addEnumParam(const char *paramName, gl::BigGLEnum enumGroup, ParamType paramType, T paramValue) { ParamCapture capture(paramName, paramType); InitParamValue(paramType, paramValue, &capture.value); capture.bigGLEnum = enumGroup; mParamCaptures.emplace_back(std::move(capture)); } template void ParamBuffer::addUnnamedParam(ParamType paramType, T paramValue) { addValueParam(getNextParamName(), paramType, paramValue); } template void WriteParamValueReplay(std::ostream &os, const CallCapture &call, T value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLboolean value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLboolean *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, const void *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, void *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, const GLfloat *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, const GLint *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLsizei *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLuint *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, const GLuint *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLDEBUGPROCKHR value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLDEBUGPROC value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::BufferID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::FenceNVID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::FramebufferID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::MemoryObjectID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::ProgramPipelineID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::QueryID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::RenderbufferID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::SamplerID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::SemaphoreID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::ShaderProgramID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::TextureID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::TransformFeedbackID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::VertexArrayID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::UniformLocation value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::UniformBlockIndex value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::SyncID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLubyte value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, gl::ContextID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, egl::Display *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, egl::ImageID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, egl::SurfaceID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLDEBUGPROCKHR value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLGetBlobFuncANDROID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLSetBlobFuncANDROID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLClientBuffer value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLAttrib *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, const EGLAttrib *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLint *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, const EGLint *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, egl::Config *value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, egl::SyncID value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLTime value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, EGLTimeKHR value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLGETBLOBPROCANGLE value); template <> void WriteParamValueReplay(std::ostream &os, const CallCapture &call, GLSETBLOBPROCANGLE value); // General fallback for any unspecific type. template void WriteParamValueReplay(std::ostream &os, const CallCapture &call, T value) { os << value; } struct FmtPointerIndex { FmtPointerIndex(const void *ptrIn) : ptr(ptrIn) {} const void *ptr; }; inline std::ostream &operator<<(std::ostream &os, const FmtPointerIndex &fmt) { os << reinterpret_cast(fmt.ptr) << "ul"; return os; } template bool FindResourceIDsInCall(const CallCapture &call, std::vector &idsOut); } // namespace angle #endif // COMMON_FRAME_CAPTURE_UTILS_H_