Hash :
e167f76b
Author :
Date :
2019-11-06T16:51:55
Capture/Replay: Pass gl::State to capture functions. This replaces passing gl::Context. Using a gl::State directly will more easily let the mid-execution replay code pass a mocked gl::State instead of having to modify the real underlying Context state. For example when capturing pixel pack and unpack parameters the states could not be overridden without changing the gl::Context itself. Similarly when capturing client side data. Also moves a query parameter info function into queryutils so it can be accessible to the State-based capture. Refactoring change only. Bug: angleproject:3611 Change-Id: I3c064001cfa83ebbb67a2b8fc8b6180491edd215 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1899728 Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
// Copyright 2019 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.
//
// FrameCapture.h:
// ANGLE Frame capture inteface.
//
#ifndef LIBANGLE_FRAME_CAPTURE_H_
#define LIBANGLE_FRAME_CAPTURE_H_
#include "common/PackedEnums.h"
#include "libANGLE/Context.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/entry_points_utils.h"
#include "libANGLE/frame_capture_utils_autogen.h"
namespace gl
{
enum class GLenumGroup;
}
namespace angle
{
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::GLenumGroup enumGroup; // only used for param type GLenum, GLboolean and GLbitfield
std::vector<std::vector<uint8_t>> data;
int arrayClientPointerIndex = -1;
size_t readBufferSizeBytes = 0;
};
class ParamBuffer final : angle::NonCopyable
{
public:
ParamBuffer();
~ParamBuffer();
ParamBuffer(ParamBuffer &&other);
ParamBuffer &operator=(ParamBuffer &&other);
template <typename T>
void addValueParam(const char *paramName, ParamType paramType, T paramValue);
template <typename T>
void addEnumParam(const char *paramName,
gl::GLenumGroup enumGroup,
ParamType paramType,
T paramValue);
ParamCapture &getParam(const char *paramName, ParamType paramType, int index);
const ParamCapture &getParam(const char *paramName, 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; }
const std::vector<ParamCapture> &getParamCaptures() const { return mParamCaptures; }
private:
std::vector<ParamCapture> mParamCaptures;
ParamCapture mReturnValueCapture;
int mClientArrayDataParam = -1;
size_t mReadBufferSize = 0;
};
struct CallCapture
{
CallCapture(gl::EntryPoint entryPointIn, ParamBuffer &¶msIn);
CallCapture(const std::string &customFunctionNameIn, ParamBuffer &¶msIn);
~CallCapture();
CallCapture(CallCapture &&other);
CallCapture &operator=(CallCapture &&other);
const char *name() const;
gl::EntryPoint entryPoint;
std::string customFunctionName;
ParamBuffer params;
};
class ReplayContext
{
public:
ReplayContext(size_t readBufferSizebytes, const gl::AttribArray<size_t> &clientArraysSizebytes);
~ReplayContext();
template <typename T>
T getReadBufferPointer(const ParamCapture ¶m)
{
ASSERT(param.readBufferSizeBytes > 0);
ASSERT(mReadBuffer.size() >= param.readBufferSizeBytes);
return reinterpret_cast<T>(mReadBuffer.data());
}
template <typename T>
T getAsConstPointer(const ParamCapture ¶m)
{
if (param.arrayClientPointerIndex != -1)
{
return reinterpret_cast<T>(mClientArraysBuffer[param.arrayClientPointerIndex].data());
}
if (!param.data.empty())
{
ASSERT(param.data.size() == 1);
return reinterpret_cast<T>(param.data[0].data());
}
return nullptr;
}
template <typename T>
T getAsPointerConstPointer(const ParamCapture ¶m)
{
static_assert(sizeof(typename std::remove_pointer<T>::type) == sizeof(uint8_t *),
"pointer size not match!");
ASSERT(!param.data.empty());
mPointersBuffer.clear();
mPointersBuffer.reserve(param.data.size());
for (const std::vector<uint8_t> &data : param.data)
{
mPointersBuffer.emplace_back(data.data());
}
return reinterpret_cast<T>(mPointersBuffer.data());
}
gl::AttribArray<std::vector<uint8_t>> &getClientArraysBuffer() { return mClientArraysBuffer; }
private:
std::vector<uint8_t> mReadBuffer;
std::vector<const uint8_t *> mPointersBuffer;
gl::AttribArray<std::vector<uint8_t>> mClientArraysBuffer;
};
// Helper to use unique IDs for each local data variable.
class DataCounters final : angle::NonCopyable
{
public:
DataCounters();
~DataCounters();
int getAndIncrement(gl::EntryPoint entryPoint, const std::string ¶mName);
private:
// <CallName, ParamName>
using Counter = std::pair<gl::EntryPoint, std::string>;
std::map<Counter, int> mData;
};
// Used by the CPP replay to filter out unnecessary code.
using HasResourceTypeMap = angle::PackedEnumBitSet<ResourceIDType>;
// A dictionary of sources indexed by shader type.
using ProgramSources = gl::ShaderMap<std::string>;
// Maps from IDs to sources.
using ShaderSourceMap = std::map<gl::ShaderProgramID, std::string>;
using ProgramSourceMap = std::map<gl::ShaderProgramID, ProgramSources>;
class FrameCapture final : angle::NonCopyable
{
public:
FrameCapture();
~FrameCapture();
void captureCall(const gl::Context *context, CallCapture &&call);
void onEndFrame(const gl::Context *context);
bool enabled() const;
void replay(gl::Context *context);
private:
void captureClientArraySnapshot(const gl::Context *context,
size_t vertexCount,
size_t instanceCount);
void reset();
void maybeCaptureClientData(const gl::Context *context, const CallCapture &call);
static void ReplayCall(gl::Context *context,
ReplayContext *replayContext,
const CallCapture &call);
std::vector<CallCapture> mSetupCalls;
std::vector<CallCapture> mFrameCalls;
std::vector<CallCapture> mTearDownCalls;
bool mEnabled;
std::string mOutDirectory;
gl::AttribArray<int> mClientVertexArrayMap;
uint32_t mFrameIndex;
uint32_t mFrameStart;
uint32_t mFrameEnd;
gl::AttribArray<size_t> mClientArraySizes;
size_t mReadBufferSize;
HasResourceTypeMap mHasResourceType;
// Cache most recently compiled and linked sources.
ShaderSourceMap mCachedShaderSources;
ProgramSourceMap mCachedProgramSources;
};
template <typename CaptureFuncT, typename... ArgsT>
void CaptureCallToFrameCapture(CaptureFuncT captureFunc,
bool isCallValid,
gl::Context *context,
ArgsT... captureParams)
{
FrameCapture *frameCapture = context->getFrameCapture();
if (!frameCapture->enabled())
return;
CallCapture call = captureFunc(context->getState(), isCallValid, captureParams...);
frameCapture->captureCall(context, std::move(call));
}
template <typename T>
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 <typename T>
void ParamBuffer::addEnumParam(const char *paramName,
gl::GLenumGroup enumGroup,
ParamType paramType,
T paramValue)
{
ParamCapture capture(paramName, paramType);
InitParamValue(paramType, paramValue, &capture.value);
capture.enumGroup = enumGroup;
mParamCaptures.emplace_back(std::move(capture));
}
std::ostream &operator<<(std::ostream &os, const ParamCapture &capture);
// Pointer capture helpers.
void CaptureMemory(const void *source, size_t size, ParamCapture *paramCapture);
void CaptureString(const GLchar *str, ParamCapture *paramCapture);
gl::Program *GetLinkedProgramForCapture(const gl::State &glState, gl::ShaderProgramID handle);
// For GetIntegerv, GetFloatv, etc.
void CaptureGetParameter(const gl::State &glState,
GLenum pname,
size_t typeSize,
ParamCapture *paramCapture);
void CaptureGenHandlesImpl(GLsizei n, GLuint *handles, ParamCapture *paramCapture);
template <typename T>
void CaptureGenHandles(GLsizei n, T *handles, ParamCapture *paramCapture)
{
CaptureGenHandlesImpl(n, reinterpret_cast<GLuint *>(handles), paramCapture);
}
template <ParamType ParamT, typename T>
void WriteParamValueToStream(std::ostream &os, T value);
template <>
void WriteParamValueToStream<ParamType::TGLboolean>(std::ostream &os, GLboolean value);
template <>
void WriteParamValueToStream<ParamType::TvoidConstPointer>(std::ostream &os, const void *value);
template <>
void WriteParamValueToStream<ParamType::TGLDEBUGPROCKHR>(std::ostream &os, GLDEBUGPROCKHR value);
template <>
void WriteParamValueToStream<ParamType::TGLDEBUGPROC>(std::ostream &os, GLDEBUGPROC value);
template <>
void WriteParamValueToStream<ParamType::TBufferID>(std::ostream &os, gl::BufferID value);
template <>
void WriteParamValueToStream<ParamType::TFenceNVID>(std::ostream &os, gl::FenceNVID value);
template <>
void WriteParamValueToStream<ParamType::TFramebufferID>(std::ostream &os, gl::FramebufferID value);
template <>
void WriteParamValueToStream<ParamType::TMemoryObjectID>(std::ostream &os,
gl::MemoryObjectID value);
template <>
void WriteParamValueToStream<ParamType::TPathID>(std::ostream &os, gl::PathID value);
template <>
void WriteParamValueToStream<ParamType::TProgramPipelineID>(std::ostream &os,
gl::ProgramPipelineID value);
template <>
void WriteParamValueToStream<ParamType::TQueryID>(std::ostream &os, gl::QueryID value);
template <>
void WriteParamValueToStream<ParamType::TRenderbufferID>(std::ostream &os,
gl::RenderbufferID value);
template <>
void WriteParamValueToStream<ParamType::TSamplerID>(std::ostream &os, gl::SamplerID value);
template <>
void WriteParamValueToStream<ParamType::TSemaphoreID>(std::ostream &os, gl::SemaphoreID value);
template <>
void WriteParamValueToStream<ParamType::TShaderProgramID>(std::ostream &os,
gl::ShaderProgramID value);
template <>
void WriteParamValueToStream<ParamType::TTextureID>(std::ostream &os, gl::TextureID value);
template <>
void WriteParamValueToStream<ParamType::TTransformFeedbackID>(std::ostream &os,
gl::TransformFeedbackID value);
template <>
void WriteParamValueToStream<ParamType::TVertexArrayID>(std::ostream &os, gl::VertexArrayID value);
// General fallback for any unspecific type.
template <ParamType ParamT, typename T>
void WriteParamValueToStream(std::ostream &os, T value)
{
os << value;
}
} // namespace angle
#endif // LIBANGLE_FRAME_CAPTURE_H_