Commit 218a6835 by Manh Nguyen Committed by Commit Bot

Store non-string, non-enum data in binary file.

Before, non-string, non-enum data smaller than a size threshold will be inlined in the cpp files. Now, they will be stored in binary file regardless of size. Bug: angleproject:4661 Change-Id: Id71cd22c97d26c9b9afaf5b26f7a327b998cb858 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2216306Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Manh Nguyen <nguyenmh@google.com>
parent ca092f01
...@@ -280,26 +280,6 @@ void WriteInlineData(const std::vector<uint8_t> &vec, std::ostream &out) ...@@ -280,26 +280,6 @@ void WriteInlineData(const std::vector<uint8_t> &vec, std::ostream &out)
} }
template <> template <>
void WriteInlineData<GLfloat>(const std::vector<uint8_t> &vec, std::ostream &out)
{
const float *data = reinterpret_cast<const GLfloat *>(vec.data());
size_t count = vec.size() / sizeof(GLfloat);
if (data == nullptr)
{
return;
}
WriteGLFloatValue(out, data[0]);
for (size_t dataIndex = 1; dataIndex < count; ++dataIndex)
{
out << ", ";
WriteGLFloatValue(out, data[dataIndex]);
}
}
template <>
void WriteInlineData<GLchar>(const std::vector<uint8_t> &vec, std::ostream &out) void WriteInlineData<GLchar>(const std::vector<uint8_t> &vec, std::ostream &out)
{ {
const GLchar *data = reinterpret_cast<const GLchar *>(vec.data()); const GLchar *data = reinterpret_cast<const GLchar *>(vec.data());
...@@ -323,8 +303,6 @@ void WriteInlineData<GLchar>(const std::vector<uint8_t> &vec, std::ostream &out) ...@@ -323,8 +303,6 @@ void WriteInlineData<GLchar>(const std::vector<uint8_t> &vec, std::ostream &out)
out << "\""; out << "\"";
} }
constexpr size_t kInlineDataThreshold = 128;
void WriteStringParamReplay(std::ostream &out, const ParamCapture &param) void WriteStringParamReplay(std::ostream &out, const ParamCapture &param)
{ {
const std::vector<uint8_t> &data = param.data[0]; const std::vector<uint8_t> &data = param.data[0];
...@@ -405,68 +383,39 @@ void WriteBinaryParamReplay(DataCounters *counters, ...@@ -405,68 +383,39 @@ void WriteBinaryParamReplay(DataCounters *counters,
ASSERT(param.data.size() == 1); ASSERT(param.data.size() == 1);
const std::vector<uint8_t> &data = param.data[0]; const std::vector<uint8_t> &data = param.data[0];
if (data.size() > kInlineDataThreshold)
{
size_t offset = binaryData->size();
binaryData->resize(offset + data.size());
memcpy(binaryData->data() + offset, data.data(), data.size());
if (param.type == ParamType::TvoidConstPointer || param.type == ParamType::TvoidPointer)
{
out << "&gBinaryData[" << offset << "]";
}
else
{
out << "reinterpret_cast<" << ParamTypeToString(param.type) << ">(&gBinaryData["
<< offset << "])";
}
}
else
{
ParamType overrideType = param.type; ParamType overrideType = param.type;
if (param.type == ParamType::TGLvoidConstPointer || if (param.type == ParamType::TGLvoidConstPointer || param.type == ParamType::TvoidConstPointer)
param.type == ParamType::TvoidConstPointer)
{ {
overrideType = ParamType::TGLubyteConstPointer; overrideType = ParamType::TGLubyteConstPointer;
} }
if (overrideType == ParamType::TGLenumConstPointer || overrideType == ParamType::TGLcharPointer)
std::string paramTypeString = ParamTypeToString(overrideType); {
// Inline if data are of type string or enum
std::string paramTypeString = ParamTypeToString(param.type);
header << paramTypeString.substr(0, paramTypeString.length() - 1); header << paramTypeString.substr(0, paramTypeString.length() - 1);
WriteParamStaticVarName(call, param, counter, header); WriteParamStaticVarName(call, param, counter, header);
header << "[] = { "; header << "[] = { ";
if (overrideType == ParamType::TGLenumConstPointer)
switch (overrideType)
{ {
case ParamType::TGLintConstPointer:
WriteInlineData<GLint>(data, header);
break;
case ParamType::TGLshortConstPointer:
WriteInlineData<GLshort>(data, header);
break;
case ParamType::TGLfloatConstPointer:
WriteInlineData<GLfloat>(data, header);
break;
case ParamType::TGLubyteConstPointer:
WriteInlineData<GLubyte, int>(data, header);
break;
case ParamType::TGLuintConstPointer:
case ParamType::TGLenumConstPointer:
WriteInlineData<GLuint>(data, header); WriteInlineData<GLuint>(data, header);
break; }
case ParamType::TGLcharPointer: else
{
ASSERT(overrideType == ParamType::TGLcharPointer);
WriteInlineData<GLchar>(data, header); WriteInlineData<GLchar>(data, header);
break;
default:
INFO() << "Unhandled ParamType: " << angle::ParamTypeToString(overrideType)
<< " in " << call.name();
UNIMPLEMENTED();
break;
} }
header << " };\n"; header << " };\n";
WriteParamStaticVarName(call, param, counter, out); WriteParamStaticVarName(call, param, counter, out);
} }
else
{
// Store in binary file if data are not of type string or enum
size_t offset = binaryData->size();
binaryData->resize(offset + data.size());
memcpy(binaryData->data() + offset, data.data(), data.size());
out << "reinterpret_cast<" << ParamTypeToString(overrideType) << ">(&gBinaryData[" << offset
<< "])";
}
} }
uintptr_t SyncIndexValue(GLsync sync) uintptr_t SyncIndexValue(GLsync sync)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment