Hash :
52152933
Author :
Date :
2023-06-06T15:36:36
Add trace_interface: functions and callbacks for traces Defines the interface between the test suite (or an other TraceLibrary class user) and trace libraries. TraceFunctions defines entry points for calls suite->trace, such as SetupReplay() or SetBinaryDataDir(). TraceCallbacks defines entry points for calls trace->suite, for example for loading .angledata.gz files. These are set up via the exported SetupEntryPoints() call. Functions like SetupReplay etc no longer need to be exported from the trace library. TraceInfo (parsed representation of the trace json) is moved to trace_interface as is. This is convenient for further changes to the fixture that will allow to easily move some of the captured parameters to json. This also moves Decompress functionality (and memory ownership) to test suite entirely, which avoids Decompress/Delete callbacks - the trace just calls LoadBinaryData via TraceCallbacks and TraceLibrary releases the memory either on FinishReplay or in its destructor. This should also take care of the memory leak described in https://crrev.com/c/3858185 Bug: b/286072760 Change-Id: Ibc6f6f64156ad805b1917c8fc41a3b0d2c0d6375 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4594445 Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Roman Lavrov <romanl@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com>
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
//
// 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.
//
// trace_interpreter.h:
// Parser and interpreter for the C-based replays.
//
#ifndef ANGLE_TRACE_INTERPRETER_H_
#define ANGLE_TRACE_INTERPRETER_H_
#include "common/frame_capture_utils.h"
#include "frame_capture_test_utils.h"
#include "traces_export.h"
namespace angle
{
struct TraceString
{
std::vector<std::string> strings;
std::vector<const char *> pointers;
};
using TraceStringMap = std::map<std::string, TraceString>;
constexpr size_t kMaxTokenSize = 200;
constexpr size_t kMaxParameters = 32;
using Token = char[kMaxTokenSize];
CallCapture ParseCallCapture(const Token &nameToken,
size_t numParamTokens,
const Token *paramTokens,
const TraceStringMap &strings);
template <typename T>
void PackParameter(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<uint32_t>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<int32_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<void *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<const int32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<void **>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<int32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<uint64_t>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<int64_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<const int64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<int64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<uint64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const char *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const void *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<uint32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const uint32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<float>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<uint8_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<float *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<const float *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<GLsync>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<const char *const *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const char **>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<GLDEBUGPROCKHR>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<EGLDEBUGPROCKHR>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const struct AHardwareBuffer *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<EGLSetBlobFuncANDROID>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<EGLGetBlobFuncANDROID>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<int16_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<const int16_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<char *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<unsigned char *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const void *const *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<const uint64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
#if defined(ANGLE_PLATFORM_WINDOWS)
template <>
void PackParameter<EGLNativeDisplayType>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
#endif // defined(ANGLE_PLATFORM_WINDOWS)
#if defined(ANGLE_PLATFORM_WINDOWS) || defined(ANGLE_PLATFORM_ANDROID)
template <>
void PackParameter<EGLNativeWindowType>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<EGLNativePixmapType>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
#endif // defined(ANGLE_PLATFORM_WINDOWS) || defined(ANGLE_PLATFORM_ANDROID)
// On Apple platforms, std::is_same<uint64_t, long> is false despite being both 8 bits.
#if defined(ANGLE_PLATFORM_APPLE) || !defined(ANGLE_IS_64_BIT_CPU)
template <>
void PackParameter<const long *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
template <>
void PackParameter<long *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<long>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings);
template <>
void PackParameter<unsigned long>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings);
#endif // defined(ANGLE_PLATFORM_APPLE) || !defined(ANGLE_IS_64_BIT_CPU)
template <typename T>
void PackParameter(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
static_assert(AssertFalse<T>::value, "No specialization for type.");
}
template <typename T>
struct ParameterPacker;
template <typename Ret>
struct ParameterPacker<Ret()>
{
static void Pack(ParamBuffer ¶ms, const Token *tokens, const TraceStringMap &strings) {}
};
template <typename Ret, typename Arg>
struct ParameterPacker<Ret(Arg)>
{
static void Pack(ParamBuffer ¶ms, const Token *tokens, const TraceStringMap &strings)
{
PackParameter<Arg>(params, tokens[0], strings);
}
};
template <typename Ret, typename Arg, typename... Args>
struct ParameterPacker<Ret(Arg, Args...)>
{
static void Pack(ParamBuffer ¶ms, const Token *tokens, const TraceStringMap &strings)
{
PackParameter<Arg>(params, tokens[0], strings);
ParameterPacker<Ret(Args...)>::Pack(params, &tokens[1], strings);
}
};
template <typename Ret, typename Arg, typename... Args>
struct ParameterPacker<Ret (*)(Arg, Args...)>
{
static void Pack(ParamBuffer ¶ms, const Token *tokens, const TraceStringMap &strings)
{
PackParameter<Arg>(params, tokens[0], strings);
ParameterPacker<Ret(Args...)>::Pack(params, &tokens[1], strings);
}
};
template <typename Func>
struct RemoveStdCall;
template <typename Ret, typename... Args>
struct RemoveStdCall<Ret KHRONOS_APIENTRY(Args...)>
{
using Type = Ret(Args...);
};
template <typename Func>
struct RemoveStdCall
{
using Type = Func;
};
template <typename Func>
ParamBuffer ParseParameters(const Token *paramTokens, const TraceStringMap &strings)
{
ParamBuffer params;
ParameterPacker<typename RemoveStdCall<Func>::Type>::Pack(params, paramTokens, strings);
return params;
}
} // namespace angle
extern "C" {
void SetupReplay();
void ReplayFrame(uint32_t frameIndex);
void ResetReplay();
ANGLE_REPLAY_EXPORT const char *GetSerializedContextState(uint32_t frameIndex);
} // extern "C"
#endif // ANGLE_TRACE_INTERPRETER_H_