Hash :
b0739436
Author :
Date :
2023-02-13T14:28:17
Traces: Add key frame support
Allow specifying a key frame in the trace JSON, i.e:
"KeyFrames": [ 20 ],
This allows our infra to use a frame other than 1 when
taking screenshots for quality comparison.
Adds new flag `--run-to-key-frame`, which will stop the
trace once key frame has been reached. If no key frame in
JSON, frame 1 will be used.
Note the name in JSON is plural, but we only support one
key frame for now. Multiple key frame support can come
in the future.
This CL also updates the code to allow ending traces
early with `--max-steps-performed` which has been broken
since http://crrev/c/4008998
It also removes `--one-frame-only` which is superseded by
`--run-to-key-frame`, and can be replicated using
`--max-steps-performed 1`.
Test: angle_trace_tests --gtest_filter="*tmnt_shredders_revenge*"
Bug: angleproject:8035
Bug: b/270426257
Change-Id: Ib02ef60d887ae5efb0288f5a9b8c2914dafc6efc
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4284637
Commit-Queue: Cody Northrop <cnorthrop@google.com>
Reviewed-by: Yuly Novikov <ynovikov@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
//
// Copyright 2021 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_test_utils:
// Helper functions for capture and replay of traces.
//
#include "frame_capture_test_utils.h"
#include "common/frame_capture_utils.h"
#include "common/string_utils.h"
#include "trace_fixture.h"
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include <fstream>
namespace angle
{
namespace
{
bool LoadJSONFromFile(const std::string &fileName, rapidjson::Document *doc)
{
std::ifstream ifs(fileName);
if (!ifs.is_open())
{
return false;
}
rapidjson::IStreamWrapper inWrapper(ifs);
doc->ParseStream(inWrapper);
return !doc->HasParseError();
}
} // namespace
bool LoadTraceNamesFromJSON(const std::string jsonFilePath, std::vector<std::string> *namesOut)
{
rapidjson::Document doc;
if (!LoadJSONFromFile(jsonFilePath, &doc))
{
return false;
}
if (!doc.IsObject() || !doc.HasMember("traces") || !doc["traces"].IsArray())
{
return false;
}
// Read trace json into a list of trace names.
std::vector<std::string> traces;
rapidjson::Document::Array traceArray = doc["traces"].GetArray();
for (rapidjson::SizeType arrayIndex = 0; arrayIndex < traceArray.Size(); ++arrayIndex)
{
const rapidjson::Document::ValueType &arrayElement = traceArray[arrayIndex];
if (!arrayElement.IsString())
{
return false;
}
std::vector<std::string> traceAndVersion;
angle::SplitStringAlongWhitespace(arrayElement.GetString(), &traceAndVersion);
traces.push_back(traceAndVersion[0]);
}
*namesOut = std::move(traces);
return true;
}
bool LoadTraceInfoFromJSON(const std::string &traceName,
const std::string &traceJsonPath,
TraceInfo *traceInfoOut)
{
rapidjson::Document doc;
if (!LoadJSONFromFile(traceJsonPath, &doc))
{
return false;
}
if (!doc.IsObject() || !doc.HasMember("TraceMetadata"))
{
return false;
}
const rapidjson::Document::Object &meta = doc["TraceMetadata"].GetObj();
strncpy(traceInfoOut->name, traceName.c_str(), kTraceInfoMaxNameLen);
traceInfoOut->contextClientMajorVersion = meta["ContextClientMajorVersion"].GetInt();
traceInfoOut->contextClientMinorVersion = meta["ContextClientMinorVersion"].GetInt();
traceInfoOut->frameEnd = meta["FrameEnd"].GetInt();
traceInfoOut->frameStart = meta["FrameStart"].GetInt();
traceInfoOut->drawSurfaceHeight = meta["DrawSurfaceHeight"].GetInt();
traceInfoOut->drawSurfaceWidth = meta["DrawSurfaceWidth"].GetInt();
angle::HexStringToUInt(meta["DrawSurfaceColorSpace"].GetString(),
&traceInfoOut->drawSurfaceColorSpace);
angle::HexStringToUInt(meta["DisplayPlatformType"].GetString(),
&traceInfoOut->displayPlatformType);
angle::HexStringToUInt(meta["DisplayDeviceType"].GetString(), &traceInfoOut->displayDeviceType);
traceInfoOut->configRedBits = meta["ConfigRedBits"].GetInt();
traceInfoOut->configGreenBits = meta["ConfigGreenBits"].GetInt();
traceInfoOut->configBlueBits = meta["ConfigBlueBits"].GetInt();
traceInfoOut->configAlphaBits = meta["ConfigAlphaBits"].GetInt();
traceInfoOut->configDepthBits = meta["ConfigDepthBits"].GetInt();
traceInfoOut->configStencilBits = meta["ConfigStencilBits"].GetInt();
traceInfoOut->isBinaryDataCompressed = meta["IsBinaryDataCompressed"].GetBool();
traceInfoOut->areClientArraysEnabled = meta["AreClientArraysEnabled"].GetBool();
traceInfoOut->isBindGeneratesResourcesEnabled =
meta["IsBindGeneratesResourcesEnabled"].GetBool();
traceInfoOut->isWebGLCompatibilityEnabled = meta["IsWebGLCompatibilityEnabled"].GetBool();
traceInfoOut->isRobustResourceInitEnabled = meta["IsRobustResourceInitEnabled"].GetBool();
traceInfoOut->windowSurfaceContextId = doc["WindowSurfaceContextID"].GetInt();
if (doc.HasMember("RequiredExtensions"))
{
const rapidjson::Value &requiredExtensions = doc["RequiredExtensions"];
if (!requiredExtensions.IsArray())
{
return false;
}
for (rapidjson::SizeType i = 0; i < requiredExtensions.Size(); i++)
{
std::string ext = std::string(requiredExtensions[i].GetString());
traceInfoOut->requiredExtensions.push_back(ext);
}
}
if (meta.HasMember("KeyFrames"))
{
const rapidjson::Value &keyFrames = meta["KeyFrames"];
if (!keyFrames.IsArray())
{
return false;
}
for (rapidjson::SizeType i = 0; i < keyFrames.Size(); i++)
{
int frame = keyFrames[i].GetInt();
traceInfoOut->keyFrames.push_back(frame);
}
}
const rapidjson::Document::Array &traceFiles = doc["TraceFiles"].GetArray();
for (const rapidjson::Value &value : traceFiles)
{
traceInfoOut->traceFiles.push_back(value.GetString());
}
traceInfoOut->initialized = true;
return true;
}
void ReplayTraceFunction(const TraceFunction &func, const TraceFunctionMap &customFunctions)
{
for (const CallCapture &call : func)
{
ReplayTraceFunctionCall(call, customFunctions);
}
}
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