Hash :
c0d806b4
Author :
Date :
2025-02-10T23:01:33
CL: OpenCL support for ANGLE Capture/Replay Implementation of OpenCL Capture/Replay tool in ANGLE. Brief notes about the change: - Most meaningful changes for the capture process are made in src/libANGLE/capture/ - Most meaningful changes for replay are made in util/capture/ and src/tests/perf_tests/ - Many autogenerated files are changed/added to allow the capture of OpenCL objects & calls - The following applications were captured/replayed: benchmark_model, GeekBench Compute, GeekBench ML, AI-Benchmark, various OCL CTS tests - End2end test added to capture_tests. CapturedTestCL.MultiFrameCL/ES3_Vulkan Bug: angleproject:383841335 Change-Id: I55fdaa6cd6c7ba740aaa2351e4d29050059d6d1d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6102105 Commit-Queue: Cody Northrop <cnorthrop@google.com> Reviewed-by: 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 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 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
//
// 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.cpp:
// Parser and interpreter for the C-based replays.
//
#include "trace_interpreter.h"
#include "anglebase/no_destructor.h"
#include "common/gl_enum_utils.h"
#include "common/string_utils.h"
#include "trace_fixture.h"
#define USE_SYSTEM_ZLIB
#include "compression_utils_portable.h"
namespace angle
{
namespace
{
bool ShouldParseFile(const std::string &file)
{
return EndsWith(file, ".c") || EndsWith(file, ".cpp");
}
void ReplayTraceFunction(const TraceFunction &func, const TraceFunctionMap &customFunctions)
{
for (const CallCapture &call : func)
{
ReplayTraceFunctionCall(call, customFunctions);
}
}
class Parser : angle::NonCopyable
{
public:
Parser(const std::string &stream,
TraceFunctionMap &functionsIn,
TraceStringMap &stringsIn,
bool verboseLogging)
: mStream(stream),
mFunctions(functionsIn),
mStrings(stringsIn),
mIndex(0),
mVerboseLogging(verboseLogging)
{}
void parse()
{
while (mIndex < mStream.size())
{
if (peek() == '#' || peek() == '/')
{
skipLine();
}
else if (peek() == 'v')
{
ASSERT(check("void "));
readFunction();
}
else if (peek() == 'c')
{
ASSERT(check("const "));
readMultilineString();
}
else
{
printf("Unexpected character: '%c'\n", peek());
UNREACHABLE();
}
}
}
private:
ANGLE_INLINE char peek() const { return mStream[mIndex]; }
ANGLE_INLINE char look(size_t ahead) const { return mStream[mIndex + ahead]; }
ANGLE_INLINE void advance() { mIndex++; }
ANGLE_INLINE void advanceTo(char delim)
{
while (peek() != delim)
{
advance();
}
}
bool check(const char *forString) const
{
return mStream.substr(mIndex, strlen(forString)) == forString;
}
void skipLine()
{
advanceTo('\n');
skipWhitespace();
}
void skipWhitespace()
{
while (isspace(peek()))
{
advance();
}
}
void skipNonWhitespace()
{
while (!isspace(peek()))
{
advance();
}
}
// In our simplified trace C, every line that begins with a } either ends a function or a
// string. All lines inside the function begin with whitespace. So to find the end of the
// function we just need to scan for a line beginning with }.
void skipFunction()
{
while (peek() != '}')
{
advanceTo('\n');
advance();
}
advance();
skipWhitespace();
}
void readStringAppend(std::string *stringOut, char delim)
{
while (peek() != delim)
{
if (peek() == '\\')
{
advance();
switch (peek())
{
case 'n':
*stringOut += '\n';
break;
case '\"':
*stringOut += '\"';
break;
case '\\':
*stringOut += '\\';
break;
default:
printf("Unrecognized escape character: \\%c\n", peek());
UNREACHABLE();
break;
}
}
else
{
*stringOut += peek();
}
advance();
}
}
void readToken(Token &token, char delim)
{
size_t startIndex = mIndex;
advanceTo(delim);
size_t tokenSize = mIndex - startIndex;
ASSERT(tokenSize < kMaxTokenSize);
memcpy(token, &mStream[startIndex], tokenSize);
token[mIndex - startIndex] = 0;
}
void skipCast()
{
if (peek() == '(')
{
advanceTo(')');
advance();
}
}
void skipComments()
{
while (peek() == '/')
{
skipLine();
}
}
void readFunction()
{
std::string funcName;
TraceFunction func;
// Skip past the "void" return value.
skipNonWhitespace();
advance();
readStringAppend(&funcName, '(');
if (mVerboseLogging)
{
printf("function: %s\n", funcName.c_str());
}
// Skip this function because of the switch statements.
if (funcName == "ReplayFrame")
{
skipFunction();
return;
}
skipLine();
ASSERT(peek() == '{');
skipLine();
while (peek() != '}')
{
skipComments();
Token nameToken;
readToken(nameToken, '(');
advance();
ParamBuffer params;
Token paramTokens[kMaxParameters];
size_t numParams = 0;
skipCast();
size_t tokenStart = mIndex;
while (peek() != ';')
{
// Skip casts.
if (peek() == ',' || (peek() == ')' && mIndex != tokenStart))
{
ASSERT(numParams < kMaxParameters);
size_t tokenSize = mIndex - tokenStart;
ASSERT(tokenSize < kMaxTokenSize);
Token &token = paramTokens[numParams++];
memcpy(token, &mStream[tokenStart], tokenSize);
token[tokenSize] = 0;
advance();
skipWhitespace();
skipCast();
tokenStart = mIndex;
}
else
{
advance();
}
}
// Turn on if you want more spam.
// if (mVerboseLogging)
//{
// printf("call: %s(", nameToken);
// for (size_t paramIndex = 0; paramIndex < numParams; ++paramIndex)
// {
// if (paramIndex > 0)
// {
// printf(", ");
// }
// printf("%s", paramTokens[paramIndex]);
// }
// printf(")\n");
//}
// We pass in the strings for specific use with C string array parameters.
CallCapture call = ParseCallCapture(nameToken, numParams, paramTokens, mStrings);
func.push_back(std::move(call));
skipLine();
}
skipLine();
addFunction(funcName, func);
}
void readMultilineString()
{
std::string name;
TraceString traceStr;
while (peek() != 'g')
{
advance();
}
ASSERT(check("glShaderSource") || check("glTransformFeedbackVaryings"));
readStringAppend(&name, '[');
if (mVerboseLogging)
{
printf("string: %s\n", name.c_str());
}
skipLine();
std::string str;
while (peek() != '}')
{
advance();
readStringAppend(&str, '\"');
advance();
if (peek() == ',')
{
traceStr.strings.push_back(std::move(str));
}
skipLine();
}
skipLine();
for (const std::string &cppstr : traceStr.strings)
{
traceStr.pointers.push_back(cppstr.c_str());
}
mStrings[name] = std::move(traceStr);
}
void addFunction(const std::string &funcName, TraceFunction &func)
{
// Run initialize immediately so we can load the binary data.
if (funcName == "InitReplay")
{
ReplayTraceFunction(func, {});
func.clear();
}
mFunctions[funcName] = std::move(func);
}
const std::string &mStream;
TraceFunctionMap &mFunctions;
TraceStringMap &mStrings;
size_t mIndex;
bool mVerboseLogging = false;
};
void PackResourceID(ParamBuffer ¶ms, const Token &token)
{
ASSERT(token[0] == 'g');
const char *start = strrchr(token, '[');
ASSERT(start != nullptr && EndsWith(token, "]"));
uint32_t value = static_cast<uint32_t>(atoi(start + 1));
if (BeginsWith(token, "gShaderProgramMap"))
{
gl::ShaderProgramID id = {value};
params.addUnnamedParam(ParamType::TShaderProgramID, id);
}
else if (BeginsWith(token, "gBufferMap"))
{
gl::BufferID id = {value};
params.addUnnamedParam(ParamType::TBufferID, id);
}
else if (BeginsWith(token, "gTextureMap"))
{
gl::TextureID id = {value};
params.addUnnamedParam(ParamType::TTextureID, id);
}
else if (BeginsWith(token, "gRenderbufferMap"))
{
gl::RenderbufferID id = {value};
params.addUnnamedParam(ParamType::TRenderbufferID, id);
}
else if (BeginsWith(token, "gFramebufferMap"))
{
gl::FramebufferID id = {value};
params.addUnnamedParam(ParamType::TFramebufferID, id);
}
else if (BeginsWith(token, "gSyncMap"))
{
gl::SyncID id = {value};
params.addUnnamedParam(ParamType::TSyncID, id);
}
else if (BeginsWith(token, "gTransformFeedbackMap"))
{
gl::TransformFeedbackID id = {value};
params.addUnnamedParam(ParamType::TTransformFeedbackID, id);
}
else if (BeginsWith(token, "gVertexArrayMap"))
{
gl::VertexArrayID id = {value};
params.addUnnamedParam(ParamType::TVertexArrayID, id);
}
else if (BeginsWith(token, "gQueryMap"))
{
gl::QueryID id = {value};
params.addUnnamedParam(ParamType::TQueryID, id);
}
else if (BeginsWith(token, "gSamplerMap"))
{
gl::SamplerID id = {value};
params.addUnnamedParam(ParamType::TSamplerID, id);
}
else
{
printf("Unknown resource map: %s\n", token);
UNREACHABLE();
}
}
template <typename IntT>
void PackIntParameter(ParamBuffer ¶ms, ParamType paramType, const Token &token)
{
IntT value;
if (token[0] == 'G')
{
ASSERT(BeginsWith(token, "GL_"));
if (strchr(token, '|') == 0)
{
value = static_cast<IntT>(gl::StringToGLenum(token));
}
else
{
value = static_cast<IntT>(gl::StringToGLbitfield(token));
}
}
else
{
if (!isdigit(token[0]) && !(token[0] == '-' && isdigit(token[1])))
{
printf("Expected number, got %s\n", token);
UNREACHABLE();
}
if (token[0] == '0' && token[1] == 'x')
{
value = static_cast<IntT>(strtol(token, nullptr, 16));
}
else
{
value = static_cast<IntT>(atoi(token));
}
}
params.addUnnamedParam(paramType, value);
}
uint32_t GetStringArrayOffset(const Token &token, const char *prefixString)
{
const char *offsetString = &token[strlen(prefixString)];
return atoi(offsetString);
}
template <typename PointerT>
void PackMemPointer(ParamBuffer ¶ms, ParamType paramType, uint32_t offset, uint8_t *mem)
{
ASSERT(gBinaryData);
params.addUnnamedParam(paramType, reinterpret_cast<PointerT>(&mem[offset]));
}
template <typename T>
void PackMutablePointerParameter(ParamBuffer ¶ms, ParamType paramType, const Token &token)
{
if (token[0] == '0' && token[1] == 0)
{
params.addUnnamedParam(paramType, reinterpret_cast<T *>(0));
}
else if (token[0] == '&')
{
ASSERT(BeginsWith(token, "&gReadBuffer[") && EndsWith(token, "]"));
uint32_t offset = GetStringArrayOffset(token, "&gReadBuffer[");
PackMemPointer<T *>(params, paramType, offset, gReadBuffer);
}
else if (token[0] == 'g')
{
ASSERT(strcmp(token, "gReadBuffer") == 0);
params.addUnnamedParam(paramType, reinterpret_cast<T *>(gReadBuffer));
}
else
{
UNREACHABLE();
}
}
template <typename T>
void PackConstPointerParameter(ParamBuffer ¶ms, ParamType paramType, const Token &token)
{
// Handle nullptr, the literal "0".
if (token[0] == '0' && token[1] == 0)
{
params.addUnnamedParam(paramType, reinterpret_cast<const T *>(0));
}
else if (token[0] == '&')
{
ASSERT(BeginsWith(token, "&gBinaryData[") && EndsWith(token, "]"));
uint32_t offset = GetStringArrayOffset(token, "&gReadBuffer[");
PackMemPointer<const T *>(params, paramType, offset, gBinaryData);
}
else if (token[0] == 'g')
{
if (strcmp(token, "gResourceIDBuffer") == 0)
{
params.addUnnamedParam(paramType, reinterpret_cast<const T *>(gResourceIDBuffer));
}
else if (BeginsWith(token, "gClientArrays"))
{
uint32_t offset = GetStringArrayOffset(token, "gClientArrays[");
params.addUnnamedParam(paramType, reinterpret_cast<const T *>(gClientArrays[offset]));
}
else
{
printf("Unexpected token: %s\n", token);
UNREACHABLE();
}
}
else
{
ASSERT(isdigit(token[0]));
uint32_t offset = atoi(token);
params.addUnnamedParam(paramType,
reinterpret_cast<const T *>(static_cast<uintptr_t>(offset)));
}
}
class TraceInterpreter : angle::NonCopyable
{
public:
TraceInterpreter() = default;
~TraceInterpreter() = default;
void replayFrame(uint32_t frameIndex);
void setupReplay();
void resetReplay();
void setupFirstFrame();
const char *getSerializedContextState(uint32_t frameIndex);
private:
void runTraceFunction(const char *name) const;
void parseTraceUncompressed();
void parseTraceGz();
TraceFunctionMap mTraceFunctions;
TraceStringMap mTraceStrings;
bool mVerboseLogging = true;
};
void TraceInterpreter::replayFrame(uint32_t frameIndex)
{
char funcName[kMaxTokenSize];
snprintf(funcName, kMaxTokenSize, "ReplayFrame%u", frameIndex);
runTraceFunction(funcName);
}
void TraceInterpreter::parseTraceUncompressed()
{
for (const std::string &file : gTraceInfo.traceFiles)
{
if (!ShouldParseFile(file))
{
if (mVerboseLogging)
{
printf("Skipping function parsing for %s.\n", file.c_str());
}
continue;
}
if (mVerboseLogging)
{
printf("Parsing functions from %s\n", file.c_str());
}
std::stringstream pathStream;
pathStream << gBinaryDataDir << GetPathSeparator() << file;
std::string path = pathStream.str();
std::string fileData;
if (!ReadFileToString(path, &fileData))
{
UNREACHABLE();
}
Parser parser(fileData, mTraceFunctions, mTraceStrings, mVerboseLogging);
parser.parse();
}
}
void TraceInterpreter::parseTraceGz()
{
if (mVerboseLogging)
{
printf("Parsing functions from %s\n", gTraceGzPath.c_str());
}
FILE *fp = fopen(gTraceGzPath.c_str(), "rb");
if (fp == 0)
{
printf("Error loading trace (gz) from: %s\n", gTraceGzPath.c_str());
exit(1);
}
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
fseek(fp, 0, SEEK_SET);
std::vector<uint8_t> compressedData(size);
(void)fread(compressedData.data(), 1, size, fp);
uint32_t uncompressedSize =
zlib_internal::GetGzipUncompressedSize(compressedData.data(), compressedData.size());
std::string uncompressedData(uncompressedSize, 0);
uLong destLen = uncompressedSize;
int zResult = zlib_internal::GzipUncompressHelper((uint8_t *)uncompressedData.data(), &destLen,
compressedData.data(),
static_cast<uLong>(compressedData.size()));
if (zResult != Z_OK)
{
printf("Failure to decompress gz trace: %s\n", gTraceGzPath.c_str());
exit(1);
}
Parser parser(uncompressedData, mTraceFunctions, mTraceStrings, mVerboseLogging);
parser.parse();
}
void TraceInterpreter::setupReplay()
{
if (!gTraceGzPath.empty())
{
parseTraceGz();
}
else
{
parseTraceUncompressed();
}
if (mTraceFunctions.count("SetupReplay") == 0)
{
printf("Did not find a SetupReplay function to run among %zu parsed functions.\n",
mTraceFunctions.size());
exit(1);
}
runTraceFunction("SetupReplay");
}
void TraceInterpreter::resetReplay()
{
runTraceFunction("ResetReplay");
}
void TraceInterpreter::setupFirstFrame()
{
runTraceFunction("SetupFirstFrame");
}
const char *TraceInterpreter::getSerializedContextState(uint32_t frameIndex)
{
// TODO: Necessary for complete self-testing. http://anglebug.com/42266250
UNREACHABLE();
return nullptr;
}
void TraceInterpreter::runTraceFunction(const char *name) const
{
auto iter = mTraceFunctions.find(name);
if (iter == mTraceFunctions.end())
{
printf("Cannot find function: %s\n", name);
UNREACHABLE();
}
const TraceFunction &func = iter->second;
ReplayTraceFunction(func, mTraceFunctions);
}
TraceInterpreter &GetInterpreter()
{
static angle::base::NoDestructor<std::unique_ptr<TraceInterpreter>> sTraceInterpreter(
new TraceInterpreter());
return *sTraceInterpreter.get()->get();
}
} // anonymous namespace
template <>
void PackParameter<uint32_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
if (token[0] == 'g')
{
PackResourceID(params, token);
}
else
{
PackIntParameter<uint32_t>(params, ParamType::TGLuint, token);
}
}
template <>
void PackParameter<int32_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
if (BeginsWith(token, "gUniformLocations"))
{
const char *start = strrchr(token, '[');
ASSERT(start != nullptr && EndsWith(token, "]"));
int32_t value = atoi(start + 1);
gl::UniformLocation loc = {value};
params.addUnnamedParam(ParamType::TUniformLocation, loc);
}
else
{
PackIntParameter<int32_t>(params, ParamType::TGLint, token);
}
}
template <>
void PackParameter<void *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
void *value = 0;
params.addUnnamedParam(ParamType::TvoidPointer, value);
}
template <>
void PackParameter<const int32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackConstPointerParameter<int32_t>(params, ParamType::TGLintConstPointer, token);
}
template <>
void PackParameter<void **>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<int32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackMutablePointerParameter<int32_t>(params, ParamType::TGLintPointer, token);
}
template <>
void PackParameter<uint64_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
params.addUnnamedParam(ParamType::TGLuint64,
static_cast<GLuint64>(std::strtoull(token, nullptr, 10)));
}
template <>
void PackParameter<int64_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
params.addUnnamedParam(ParamType::TGLint64,
static_cast<GLint64>(std::strtoll(token, nullptr, 10)));
}
template <>
void PackParameter<const int64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<int64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<uint64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<const char *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
if (token[0] == '"')
{
ASSERT(EndsWith(token, "\""));
ParamCapture param(params.getNextParamName(), ParamType::TGLcharConstPointer);
std::vector<uint8_t> data(&token[1], &token[strlen(token) - 1]);
data.push_back(0);
param.data.push_back(std::move(data));
param.value.GLcharConstPointerVal = reinterpret_cast<const char *>(param.data[0].data());
params.addParam(std::move(param));
}
else
{
PackConstPointerParameter<char>(params, ParamType::TGLcharConstPointer, token);
}
}
template <>
void PackParameter<const void *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackConstPointerParameter<void>(params, ParamType::TvoidConstPointer, token);
}
template <>
void PackParameter<uint32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackMutablePointerParameter<uint32_t>(params, ParamType::TGLuintPointer, token);
}
template <>
void PackParameter<const uint32_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackConstPointerParameter<uint32_t>(params, ParamType::TGLuintConstPointer, token);
}
template <>
void PackParameter<float>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
params.addUnnamedParam(ParamType::TGLfloat, std::stof(token));
}
template <>
void PackParameter<uint8_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
PackIntParameter<uint8_t>(params, ParamType::TGLubyte, token);
}
template <>
void PackParameter<float *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
PackMutablePointerParameter<float>(params, ParamType::TGLfloatPointer, token);
}
template <>
void PackParameter<const float *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackConstPointerParameter<float>(params, ParamType::TGLfloatConstPointer, token);
}
template <>
void PackParameter<GLsync>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
PackResourceID(params, token);
}
template <>
void PackParameter<const char *const *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
// Find the string that corresponds to "token". Currently we only support string arrays.
auto iter = strings.find(token);
if (iter == strings.end())
{
printf("Could not find string: %s\n", token);
UNREACHABLE();
}
const TraceString &traceStr = iter->second;
params.addUnnamedParam(ParamType::TGLcharConstPointerPointer, traceStr.pointers.data());
}
template <>
void PackParameter<const char **>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<GLDEBUGPROCKHR>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<EGLDEBUGPROCKHR>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<const struct AHardwareBuffer *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<EGLSetBlobFuncANDROID>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<EGLGetBlobFuncANDROID>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<int16_t>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
PackIntParameter<int16_t>(params, ParamType::TGLshort, token);
}
template <>
void PackParameter<const int16_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackConstPointerParameter<int16_t>(params, ParamType::TGLshortConstPointer, token);
}
template <>
void PackParameter<char *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<unsigned char *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackMutablePointerParameter<GLubyte>(params, ParamType::TGLubytePointer, token);
}
template <>
void PackParameter<const void *const *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<const uint64_t *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<GLGETBLOBPROCANGLE>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
template <>
void PackParameter<GLSETBLOBPROCANGLE>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
#if defined(ANGLE_PLATFORM_WINDOWS)
template <>
void PackParameter<EGLNativeDisplayType>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
#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)
{
UNREACHABLE();
}
template <>
void PackParameter<EGLNativePixmapType>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
UNREACHABLE();
}
#endif // defined(ANGLE_PLATFORM_WINDOWS) || defined(ANGLE_PLATFORM_ANDROID)
#if defined(ANGLE_PLATFORM_APPLE) || !defined(ANGLE_IS_64_BIT_CPU)
template <>
void PackParameter<const long *>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackConstPointerParameter<int64_t>(params, ParamType::TGLuint64ConstPointer, token);
}
template <>
void PackParameter<long *>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
PackMutablePointerParameter<int64_t>(params, ParamType::TGLint64Pointer, token);
}
template <>
void PackParameter<long>(ParamBuffer ¶ms, const Token &token, const TraceStringMap &strings)
{
PackIntParameter<int64_t>(params, ParamType::TGLint64, token);
}
template <>
void PackParameter<unsigned long>(ParamBuffer ¶ms,
const Token &token,
const TraceStringMap &strings)
{
PackIntParameter<uint64_t>(params, ParamType::TGLuint64, token);
}
#endif // defined(ANGLE_PLATFORM_APPLE) || !defined(ANGLE_IS_64_BIT_CPU)
GLuint GetResourceIDMapValue(ResourceIDType resourceIDType, GLuint key)
{
switch (resourceIDType)
{
case ResourceIDType::Buffer:
return gBufferMap[key];
case ResourceIDType::FenceNV:
return gFenceNVMap[key];
case ResourceIDType::Framebuffer:
return gFramebufferMap[key];
case ResourceIDType::ProgramPipeline:
return gProgramPipelineMap[key];
case ResourceIDType::Query:
return gQueryMap[key];
case ResourceIDType::Renderbuffer:
return gRenderbufferMap[key];
case ResourceIDType::Sampler:
return gSamplerMap[key];
case ResourceIDType::Semaphore:
return gSemaphoreMap[key];
case ResourceIDType::ShaderProgram:
return gShaderProgramMap[key];
case ResourceIDType::Texture:
return gTextureMap[key];
case ResourceIDType::TransformFeedback:
return gTransformFeedbackMap[key];
case ResourceIDType::VertexArray:
return gVertexArrayMap[key];
default:
printf("Incompatible resource ID type: %d\n", static_cast<int>(resourceIDType));
UNREACHABLE();
return 0;
}
}
} // namespace angle
extern "C" {
void SetupReplay()
{
angle::GetInterpreter().setupReplay();
}
void ReplayFrame(uint32_t frameIndex)
{
angle::GetInterpreter().replayFrame(frameIndex);
}
void ResetReplay()
{
angle::GetInterpreter().resetReplay();
}
const char *GetSerializedContextState(uint32_t frameIndex)
{
return angle::GetInterpreter().getSerializedContextState(frameIndex);
}
} // extern "C"