Commit 360daeef by Jamie Madill Committed by Commit Bot

Add platform hook for program cache updates.

This will need to be matched with a corresponding browser-side CL. It will enable writing out binary shaders to disk. BUG=angleproject:1897 Change-Id: I443281086050b9711b92a034cf37f808dd919007 Reviewed-on: https://chromium-review.googlesource.com/542963Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 56375021
......@@ -10,6 +10,7 @@
#define ANGLE_PLATFORM_H
#include <stdint.h>
#include <array>
#if defined(_WIN32)
# if !defined(LIBANGLE_IMPLEMENTATION)
......@@ -230,6 +231,20 @@ inline void DefaultOverrideWorkaroundsD3D(PlatformMethods *platform,
{
}
// Callback on a successful program link with the program binary. Can be used to store
// shaders to disk. Keys are a 160-bit SHA-1 hash.
using ProgramKeyType = std::array<uint8_t, 20>;
using CacheProgramFunc = void (*)(PlatformMethods *platform,
const ProgramKeyType &key,
size_t programSize,
const uint8_t *programBytes);
inline void DefaultCacheProgram(PlatformMethods *platform,
const ProgramKeyType &key,
size_t programSize,
const uint8_t *programBytes)
{
}
// Platform methods are enumerated here once.
#define ANGLE_PLATFORM_OP(OP) \
OP(currentTime, CurrentTime) \
......@@ -244,7 +259,8 @@ inline void DefaultOverrideWorkaroundsD3D(PlatformMethods *platform,
OP(histogramEnumeration, HistogramEnumeration) \
OP(histogramSparse, HistogramSparse) \
OP(histogramBoolean, HistogramBoolean) \
OP(overrideWorkaroundsD3D, OverrideWorkaroundsD3D)
OP(overrideWorkaroundsD3D, OverrideWorkaroundsD3D) \
OP(cacheProgram, CacheProgram)
#define ANGLE_PLATFORM_METHOD_DEF(Name, CapsName) CapsName##Func Name = Default##CapsName;
......
......@@ -17,6 +17,7 @@
#include "libANGLE/Context.h"
#include "libANGLE/Uniform.h"
#include "libANGLE/renderer/ProgramImpl.h"
#include "platform/Platform.h"
namespace gl
{
......@@ -516,12 +517,21 @@ void MemoryProgramCache::remove(const ProgramHash &programHash)
ASSERT(result);
}
void MemoryProgramCache::put(const ProgramHash &program, angle::MemoryBuffer &&binaryProgram)
void MemoryProgramCache::put(const ProgramHash &program,
const Context *context,
angle::MemoryBuffer &&binaryProgram)
{
if (!mProgramBinaryCache.put(program, std::move(binaryProgram), binaryProgram.size()))
const angle::MemoryBuffer *result =
mProgramBinaryCache.put(program, std::move(binaryProgram), binaryProgram.size());
if (!result)
{
ERR() << "Failed to store binary program in memory cache, program is too large.";
}
else
{
auto *platform = ANGLEPlatformCurrent();
platform->cacheProgram(platform, program, result->size(), result->data());
}
}
void MemoryProgramCache::putProgram(const ProgramHash &programHash,
......@@ -530,7 +540,7 @@ void MemoryProgramCache::putProgram(const ProgramHash &programHash,
{
angle::MemoryBuffer binaryProgram;
Serialize(context, program, &binaryProgram);
put(programHash, std::move(binaryProgram));
put(programHash, context, std::move(binaryProgram));
}
void MemoryProgramCache::putBinary(const Context *context,
......@@ -548,7 +558,7 @@ void MemoryProgramCache::putBinary(const Context *context,
ComputeHash(context, program, &programHash);
// Store the binary.
put(programHash, std::move(binaryProgram));
put(programHash, context, std::move(binaryProgram));
}
void MemoryProgramCache::clear()
......
......@@ -18,7 +18,7 @@
namespace gl
{
// 128-bit program hash key.
// 160-bit SHA-1 hash key.
using ProgramHash = std::array<uint8_t, 20>;
} // namespace gl
......@@ -96,7 +96,9 @@ class MemoryProgramCache final : angle::NonCopyable
private:
// Insert or update a binary program. Program contents are transferred.
void put(const ProgramHash &programHash, angle::MemoryBuffer &&binaryProgram);
void put(const ProgramHash &programHash,
const Context *context,
angle::MemoryBuffer &&binaryProgram);
angle::SizedMRUCache<ProgramHash, angle::MemoryBuffer> mProgramBinaryCache;
unsigned int mIssuedWarnings;
......
......@@ -25,17 +25,18 @@ class SizedMRUCache final : angle::NonCopyable
{
}
bool put(const Key &key, Value &&value, size_t size)
// Returns nullptr on failure.
const Value *put(const Key &key, Value &&value, size_t size)
{
if (size > mMaximumTotalSize)
{
return false;
return nullptr;
}
// Check for existing key.
eraseByKey(key);
mStore.Put(key, ValueAndSize(std::move(value), size));
auto retVal = mStore.Put(key, ValueAndSize(std::move(value), size));
mCurrentSize += size;
while (mCurrentSize > mMaximumTotalSize)
......@@ -46,7 +47,7 @@ class SizedMRUCache final : angle::NonCopyable
mStore.Erase(iter);
}
return true;
return &retVal->second.value;
}
bool get(const Key &key, const Value **valueOut)
......
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