Commit 23176cea by Jamie Madill Committed by Commit Bot

Fix performance regression in stream init.

Regressed: https://chromium-review.googlesource.com/531798 This was because the std::stringstream constructor was being called every draw call, for the InfoLog of the dynamically recompiled shaders in the D3D back-ends. The constructor was allocating memory and freeing it on destruction. Instead use a lazy init for the std::stringstream in InfoLog like we do for Error. BUG=chromium:750685 Change-Id: I9cd429ae4e1439ae504943a9cad31cbbed17ef32 Reviewed-on: https://chromium-review.googlesource.com/594629 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 878c8b1e
......@@ -205,7 +205,12 @@ InfoLog::~InfoLog()
size_t InfoLog::getLength() const
{
const std::string &logString = mStream.str();
if (!mLazyStream)
{
return 0;
}
const std::string &logString = mLazyStream->str();
return logString.empty() ? 0 : logString.length() + 1;
}
......@@ -215,12 +220,12 @@ void InfoLog::getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
if (bufSize > 0)
{
const std::string str(mStream.str());
const std::string logString(str());
if (!str.empty())
if (!logString.empty())
{
index = std::min(static_cast<size_t>(bufSize) - 1, str.length());
memcpy(infoLog, str.c_str(), index);
index = std::min(static_cast<size_t>(bufSize) - 1, logString.length());
memcpy(infoLog, logString.c_str(), index);
}
infoLog[index] = '\0';
......@@ -237,6 +242,8 @@ void InfoLog::getLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
// messages, so lets remove all occurrences of this fake file path from the log.
void InfoLog::appendSanitized(const char *message)
{
ensureInitialized();
std::string msg(message);
size_t found;
......@@ -250,7 +257,7 @@ void InfoLog::appendSanitized(const char *message)
}
while (found != std::string::npos);
mStream << message << std::endl;
*mLazyStream << message << std::endl;
}
void InfoLog::reset()
......
......@@ -112,15 +112,24 @@ class InfoLog : angle::NonCopyable
template <typename T>
StreamHelper operator<<(const T &value)
{
StreamHelper helper(&mStream);
ensureInitialized();
StreamHelper helper(mLazyStream.get());
helper << value;
return helper;
}
std::string str() const { return mStream.str(); }
std::string str() const { return mLazyStream ? mLazyStream->str() : ""; }
private:
std::stringstream mStream;
void ensureInitialized()
{
if (!mLazyStream)
{
mLazyStream.reset(new std::stringstream());
}
}
std::unique_ptr<std::stringstream> mLazyStream;
};
// Struct used for correlating uniforms/elements of uniform arrays to handles
......
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