Commit 6c58b062 by Jamie Madill Committed by Commit Bot

Add histograms for the program cache.

Also includes some tracking of if a cache hit comes from a binary inserted after a Link call, or sourced from the external disk cache. Chromium-side CL: https://chromium-review.googlesource.com/c/592151/ BUG=angleproject:2118 Change-Id: I80eefd203d8ce31d1ac03dd1a36459d3581128f5 Reviewed-on: https://chromium-review.googlesource.com/590689 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent c2493e38
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "libANGLE/BinaryStream.h" #include "libANGLE/BinaryStream.h"
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "libANGLE/Uniform.h" #include "libANGLE/Uniform.h"
#include "libANGLE/histogram_macros.h"
#include "libANGLE/renderer/ProgramImpl.h" #include "libANGLE/renderer/ProgramImpl.h"
#include "platform/Platform.h" #include "platform/Platform.h"
...@@ -24,6 +25,14 @@ namespace gl ...@@ -24,6 +25,14 @@ namespace gl
namespace namespace
{ {
enum CacheResult
{
kCacheMiss,
kCacheHitMemory,
kCacheHitDisk,
kCacheResultMax,
};
constexpr unsigned int kWarningLimit = 3; constexpr unsigned int kWarningLimit = 3;
void WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var) void WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var)
...@@ -534,6 +543,7 @@ LinkResult MemoryProgramCache::getProgram(const Context *context, ...@@ -534,6 +543,7 @@ LinkResult MemoryProgramCache::getProgram(const Context *context,
ANGLE_TRY_RESULT(Deserialize(context, program, state, binaryProgram->data(), ANGLE_TRY_RESULT(Deserialize(context, program, state, binaryProgram->data(),
binaryProgram->size(), infoLog), binaryProgram->size(), infoLog),
result); result);
ANGLE_HISTOGRAM_BOOLEAN("GPU.ANGLE.ProgramCache.LoadBinarySuccess", result.getResult());
if (!result.getResult()) if (!result.getResult())
{ {
// Cache load failed, evict. // Cache load failed, evict.
...@@ -555,14 +565,41 @@ LinkResult MemoryProgramCache::getProgram(const Context *context, ...@@ -555,14 +565,41 @@ LinkResult MemoryProgramCache::getProgram(const Context *context,
bool MemoryProgramCache::get(const ProgramHash &programHash, const angle::MemoryBuffer **programOut) bool MemoryProgramCache::get(const ProgramHash &programHash, const angle::MemoryBuffer **programOut)
{ {
return mProgramBinaryCache.get(programHash, programOut); const CacheEntry *entry = nullptr;
if (!mProgramBinaryCache.get(programHash, &entry))
{
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.ProgramCache.CacheResult", kCacheMiss,
kCacheResultMax);
return false;
}
if (entry->second == CacheSource::PutProgram)
{
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.ProgramCache.CacheResult", kCacheHitMemory,
kCacheResultMax);
}
else
{
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.ProgramCache.CacheResult", kCacheHitDisk,
kCacheResultMax);
}
*programOut = &entry->first;
return true;
} }
bool MemoryProgramCache::getAt(size_t index, bool MemoryProgramCache::getAt(size_t index,
ProgramHash *hashOut, ProgramHash *hashOut,
const angle::MemoryBuffer **programOut) const angle::MemoryBuffer **programOut)
{ {
return mProgramBinaryCache.getAt(index, hashOut, programOut); const CacheEntry *entry = nullptr;
if (!mProgramBinaryCache.getAt(index, hashOut, &entry))
{
return false;
}
*programOut = &entry->first;
return true;
} }
void MemoryProgramCache::remove(const ProgramHash &programHash) void MemoryProgramCache::remove(const ProgramHash &programHash)
...@@ -571,11 +608,19 @@ void MemoryProgramCache::remove(const ProgramHash &programHash) ...@@ -571,11 +608,19 @@ void MemoryProgramCache::remove(const ProgramHash &programHash)
ASSERT(result); ASSERT(result);
} }
void MemoryProgramCache::put(const ProgramHash &program, void MemoryProgramCache::putProgram(const ProgramHash &programHash,
angle::MemoryBuffer &&binaryProgram) const Context *context,
const Program *program)
{ {
const angle::MemoryBuffer *result = CacheEntry newEntry;
mProgramBinaryCache.put(program, std::move(binaryProgram), binaryProgram.size()); Serialize(context, program, &newEntry.first);
newEntry.second = CacheSource::PutProgram;
ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramBinarySizeBytes",
static_cast<int>(newEntry.first.size()));
const CacheEntry *result =
mProgramBinaryCache.put(programHash, std::move(newEntry), newEntry.first.size());
if (!result) if (!result)
{ {
ERR() << "Failed to store binary program in memory cache, program is too large."; ERR() << "Failed to store binary program in memory cache, program is too large.";
...@@ -583,19 +628,10 @@ void MemoryProgramCache::put(const ProgramHash &program, ...@@ -583,19 +628,10 @@ void MemoryProgramCache::put(const ProgramHash &program,
else else
{ {
auto *platform = ANGLEPlatformCurrent(); auto *platform = ANGLEPlatformCurrent();
platform->cacheProgram(platform, program, result->size(), result->data()); platform->cacheProgram(platform, programHash, result->first.size(), result->first.data());
} }
} }
void MemoryProgramCache::putProgram(const ProgramHash &programHash,
const Context *context,
const Program *program)
{
angle::MemoryBuffer binaryProgram;
Serialize(context, program, &binaryProgram);
put(programHash, std::move(binaryProgram));
}
void MemoryProgramCache::updateProgram(const Context *context, const Program *program) void MemoryProgramCache::updateProgram(const Context *context, const Program *program)
{ {
gl::ProgramHash programHash; gl::ProgramHash programHash;
...@@ -608,13 +644,13 @@ void MemoryProgramCache::putBinary(const ProgramHash &programHash, ...@@ -608,13 +644,13 @@ void MemoryProgramCache::putBinary(const ProgramHash &programHash,
size_t length) size_t length)
{ {
// Copy the binary. // Copy the binary.
angle::MemoryBuffer binaryProgram; CacheEntry newEntry;
binaryProgram.resize(length); newEntry.first.resize(length);
memcpy(binaryProgram.data(), binary, length); memcpy(newEntry.first.data(), binary, length);
newEntry.second = CacheSource::PutBinary;
// Store the binary. // Store the binary.
const angle::MemoryBuffer *result = const CacheEntry *result = mProgramBinaryCache.put(programHash, std::move(newEntry), length);
mProgramBinaryCache.put(programHash, std::move(binaryProgram), binaryProgram.size());
if (!result) if (!result)
{ {
ERR() << "Failed to store binary program in memory cache, program is too large."; ERR() << "Failed to store binary program in memory cache, program is too large.";
......
...@@ -114,11 +114,14 @@ class MemoryProgramCache final : angle::NonCopyable ...@@ -114,11 +114,14 @@ class MemoryProgramCache final : angle::NonCopyable
size_t maxSize() const; size_t maxSize() const;
private: private:
// Insert or update a binary program. Program contents are transferred. enum class CacheSource
void put(const ProgramHash &programHash, {
angle::MemoryBuffer &&binaryProgram); PutProgram,
PutBinary,
};
angle::SizedMRUCache<ProgramHash, angle::MemoryBuffer> mProgramBinaryCache; using CacheEntry = std::pair<angle::MemoryBuffer, CacheSource>;
angle::SizedMRUCache<ProgramHash, CacheEntry> mProgramBinaryCache;
unsigned int mIssuedWarnings; unsigned int mIssuedWarnings;
}; };
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
#include "libANGLE/UniformLinker.h" #include "libANGLE/UniformLinker.h"
#include "libANGLE/VaryingPacking.h" #include "libANGLE/VaryingPacking.h"
#include "libANGLE/features.h" #include "libANGLE/features.h"
#include "libANGLE/histogram_macros.h"
#include "libANGLE/queryconversions.h" #include "libANGLE/queryconversions.h"
#include "libANGLE/renderer/GLImplFactory.h" #include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/ProgramImpl.h" #include "libANGLE/renderer/ProgramImpl.h"
#include "platform/Platform.h"
namespace gl namespace gl
{ {
...@@ -624,6 +626,9 @@ Error Program::link(const gl::Context *context) ...@@ -624,6 +626,9 @@ Error Program::link(const gl::Context *context)
{ {
const auto &data = context->getContextState(); const auto &data = context->getContextState();
auto *platform = ANGLEPlatformCurrent();
double startTime = platform->currentTime(platform);
unlink(); unlink();
ProgramHash programHash; ProgramHash programHash;
...@@ -631,10 +636,14 @@ Error Program::link(const gl::Context *context) ...@@ -631,10 +636,14 @@ Error Program::link(const gl::Context *context)
if (cache) if (cache)
{ {
ANGLE_TRY_RESULT(cache->getProgram(context, this, &mState, &programHash), mLinked); ANGLE_TRY_RESULT(cache->getProgram(context, this, &mState, &programHash), mLinked);
ANGLE_HISTOGRAM_BOOLEAN("GPU.ANGLE.ProgramCache.LoadBinarySuccess", mLinked);
} }
if (mLinked) if (mLinked)
{ {
double delta = platform->currentTime(platform) - startTime;
int us = static_cast<int>(delta * 1000000.0);
ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramCacheHitTimeUS", us);
return NoError(); return NoError();
} }
...@@ -786,6 +795,10 @@ Error Program::link(const gl::Context *context) ...@@ -786,6 +795,10 @@ Error Program::link(const gl::Context *context)
cache->putProgram(programHash, context, this); cache->putProgram(programHash, context, this);
} }
double delta = platform->currentTime(platform) - startTime;
int us = static_cast<int>(delta * 1000000.0);
ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramCacheMissTimeUS", us);
return NoError(); return NoError();
} }
......
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