Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // MemoryProgramCache: Stores compiled and linked programs in memory so they don't |
| 7 | // always have to be re-compiled. Can be used in conjunction with the platform |
| 8 | // layer to warm up the cache from disk. |
| 9 | |
| 10 | #include "libANGLE/MemoryProgramCache.h" |
| 11 | |
| 12 | #include <GLSLANG/ShaderVars.h> |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 13 | #include <anglebase/sha1.h> |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 14 | |
Jamie Madill | f00f7ff | 2017-08-31 14:39:15 -0400 | [diff] [blame] | 15 | #include "common/utilities.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 16 | #include "common/version.h" |
| 17 | #include "libANGLE/BinaryStream.h" |
| 18 | #include "libANGLE/Context.h" |
| 19 | #include "libANGLE/Uniform.h" |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 20 | #include "libANGLE/histogram_macros.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 21 | #include "libANGLE/renderer/ProgramImpl.h" |
Jamie Madill | 360daee | 2017-06-29 10:36:19 -0400 | [diff] [blame] | 22 | #include "platform/Platform.h" |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 23 | |
| 24 | namespace gl |
| 25 | { |
| 26 | |
| 27 | namespace |
| 28 | { |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 29 | enum CacheResult |
| 30 | { |
| 31 | kCacheMiss, |
| 32 | kCacheHitMemory, |
| 33 | kCacheHitDisk, |
| 34 | kCacheResultMax, |
| 35 | }; |
| 36 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 37 | constexpr unsigned int kWarningLimit = 3; |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 38 | |
| 39 | void WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var) |
| 40 | { |
| 41 | stream->writeInt(var.type); |
| 42 | stream->writeInt(var.precision); |
| 43 | stream->writeString(var.name); |
| 44 | stream->writeString(var.mappedName); |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame^] | 45 | stream->writeIntVector(var.arraySizes); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 46 | stream->writeInt(var.staticUse); |
| 47 | stream->writeString(var.structName); |
| 48 | ASSERT(var.fields.empty()); |
| 49 | } |
| 50 | |
| 51 | void LoadShaderVar(BinaryInputStream *stream, sh::ShaderVariable *var) |
| 52 | { |
| 53 | var->type = stream->readInt<GLenum>(); |
| 54 | var->precision = stream->readInt<GLenum>(); |
| 55 | var->name = stream->readString(); |
| 56 | var->mappedName = stream->readString(); |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame^] | 57 | stream->readIntVector<unsigned int>(&var->arraySizes); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 58 | var->staticUse = stream->readBool(); |
| 59 | var->structName = stream->readString(); |
| 60 | } |
| 61 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 62 | void WriteShaderVariableBuffer(BinaryOutputStream *stream, const ShaderVariableBuffer &var) |
| 63 | { |
| 64 | stream->writeInt(var.binding); |
| 65 | stream->writeInt(var.dataSize); |
| 66 | |
| 67 | stream->writeInt(var.vertexStaticUse); |
| 68 | stream->writeInt(var.fragmentStaticUse); |
| 69 | stream->writeInt(var.computeStaticUse); |
| 70 | |
| 71 | stream->writeInt(var.memberIndexes.size()); |
| 72 | for (unsigned int memberCounterIndex : var.memberIndexes) |
| 73 | { |
| 74 | stream->writeInt(memberCounterIndex); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void LoadShaderVariableBuffer(BinaryInputStream *stream, ShaderVariableBuffer *var) |
| 79 | { |
| 80 | var->binding = stream->readInt<int>(); |
| 81 | var->dataSize = stream->readInt<unsigned int>(); |
| 82 | var->vertexStaticUse = stream->readBool(); |
| 83 | var->fragmentStaticUse = stream->readBool(); |
| 84 | var->computeStaticUse = stream->readBool(); |
| 85 | |
| 86 | unsigned int numMembers = stream->readInt<unsigned int>(); |
| 87 | for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++) |
| 88 | { |
| 89 | var->memberIndexes.push_back(stream->readInt<unsigned int>()); |
| 90 | } |
| 91 | } |
| 92 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 93 | void WriteBufferVariable(BinaryOutputStream *stream, const BufferVariable &var) |
| 94 | { |
| 95 | WriteShaderVar(stream, var); |
| 96 | |
| 97 | stream->writeInt(var.bufferIndex); |
| 98 | stream->writeInt(var.blockInfo.offset); |
| 99 | stream->writeInt(var.blockInfo.arrayStride); |
| 100 | stream->writeInt(var.blockInfo.matrixStride); |
| 101 | stream->writeInt(var.blockInfo.isRowMajorMatrix); |
| 102 | stream->writeInt(var.blockInfo.topLevelArrayStride); |
| 103 | stream->writeInt(var.topLevelArraySize); |
| 104 | stream->writeInt(var.vertexStaticUse); |
| 105 | stream->writeInt(var.fragmentStaticUse); |
| 106 | stream->writeInt(var.computeStaticUse); |
| 107 | } |
| 108 | |
| 109 | void LoadBufferVariable(BinaryInputStream *stream, BufferVariable *var) |
| 110 | { |
| 111 | LoadShaderVar(stream, var); |
| 112 | |
| 113 | var->bufferIndex = stream->readInt<int>(); |
| 114 | var->blockInfo.offset = stream->readInt<int>(); |
| 115 | var->blockInfo.arrayStride = stream->readInt<int>(); |
| 116 | var->blockInfo.matrixStride = stream->readInt<int>(); |
| 117 | var->blockInfo.isRowMajorMatrix = stream->readBool(); |
| 118 | var->blockInfo.topLevelArrayStride = stream->readInt<int>(); |
| 119 | var->topLevelArraySize = stream->readInt<int>(); |
| 120 | var->vertexStaticUse = stream->readBool(); |
| 121 | var->fragmentStaticUse = stream->readBool(); |
| 122 | var->computeStaticUse = stream->readBool(); |
| 123 | } |
| 124 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 125 | void WriteInterfaceBlock(BinaryOutputStream *stream, const InterfaceBlock &block) |
| 126 | { |
| 127 | stream->writeString(block.name); |
| 128 | stream->writeString(block.mappedName); |
| 129 | stream->writeInt(block.isArray); |
| 130 | stream->writeInt(block.arrayElement); |
| 131 | |
| 132 | WriteShaderVariableBuffer(stream, block); |
| 133 | } |
| 134 | |
| 135 | void LoadInterfaceBlock(BinaryInputStream *stream, InterfaceBlock *block) |
| 136 | { |
| 137 | block->name = stream->readString(); |
| 138 | block->mappedName = stream->readString(); |
| 139 | block->isArray = stream->readBool(); |
| 140 | block->arrayElement = stream->readInt<unsigned int>(); |
| 141 | |
| 142 | LoadShaderVariableBuffer(stream, block); |
| 143 | } |
| 144 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 145 | class HashStream final : angle::NonCopyable |
| 146 | { |
| 147 | public: |
| 148 | std::string str() { return mStringStream.str(); } |
| 149 | |
| 150 | template <typename T> |
| 151 | HashStream &operator<<(T value) |
| 152 | { |
| 153 | mStringStream << value << kSeparator; |
| 154 | return *this; |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | static constexpr char kSeparator = ':'; |
| 159 | std::ostringstream mStringStream; |
| 160 | }; |
| 161 | |
| 162 | HashStream &operator<<(HashStream &stream, const Shader *shader) |
| 163 | { |
| 164 | if (shader) |
| 165 | { |
| 166 | stream << shader->getSourceString().c_str() << shader->getSourceString().length() |
| 167 | << shader->getCompilerResourcesString().c_str(); |
| 168 | } |
| 169 | return stream; |
| 170 | } |
| 171 | |
| 172 | HashStream &operator<<(HashStream &stream, const Program::Bindings &bindings) |
| 173 | { |
| 174 | for (const auto &binding : bindings) |
| 175 | { |
| 176 | stream << binding.first << binding.second; |
| 177 | } |
| 178 | return stream; |
| 179 | } |
| 180 | |
| 181 | HashStream &operator<<(HashStream &stream, const std::vector<std::string> &strings) |
| 182 | { |
| 183 | for (const auto &str : strings) |
| 184 | { |
| 185 | stream << str; |
| 186 | } |
| 187 | return stream; |
| 188 | } |
| 189 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 190 | } // anonymous namespace |
| 191 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 192 | MemoryProgramCache::MemoryProgramCache(size_t maxCacheSizeBytes) |
| 193 | : mProgramBinaryCache(maxCacheSizeBytes), mIssuedWarnings(0) |
| 194 | { |
| 195 | } |
| 196 | |
| 197 | MemoryProgramCache::~MemoryProgramCache() |
| 198 | { |
| 199 | } |
| 200 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 201 | // static |
| 202 | LinkResult MemoryProgramCache::Deserialize(const Context *context, |
| 203 | const Program *program, |
| 204 | ProgramState *state, |
| 205 | const uint8_t *binary, |
| 206 | size_t length, |
| 207 | InfoLog &infoLog) |
| 208 | { |
| 209 | BinaryInputStream stream(binary, length); |
| 210 | |
| 211 | unsigned char commitString[ANGLE_COMMIT_HASH_SIZE]; |
| 212 | stream.readBytes(commitString, ANGLE_COMMIT_HASH_SIZE); |
| 213 | if (memcmp(commitString, ANGLE_COMMIT_HASH, sizeof(unsigned char) * ANGLE_COMMIT_HASH_SIZE) != |
| 214 | 0) |
| 215 | { |
| 216 | infoLog << "Invalid program binary version."; |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | int majorVersion = stream.readInt<int>(); |
| 221 | int minorVersion = stream.readInt<int>(); |
| 222 | if (majorVersion != context->getClientMajorVersion() || |
| 223 | minorVersion != context->getClientMinorVersion()) |
| 224 | { |
| 225 | infoLog << "Cannot load program binaries across different ES context versions."; |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | state->mComputeShaderLocalSize[0] = stream.readInt<int>(); |
| 230 | state->mComputeShaderLocalSize[1] = stream.readInt<int>(); |
| 231 | state->mComputeShaderLocalSize[2] = stream.readInt<int>(); |
| 232 | |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 233 | state->mNumViews = stream.readInt<int>(); |
| 234 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 235 | static_assert(MAX_VERTEX_ATTRIBS <= sizeof(unsigned long) * 8, |
| 236 | "Too many vertex attribs for mask"); |
| 237 | state->mActiveAttribLocationsMask = stream.readInt<unsigned long>(); |
| 238 | |
| 239 | unsigned int attribCount = stream.readInt<unsigned int>(); |
| 240 | ASSERT(state->mAttributes.empty()); |
| 241 | for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex) |
| 242 | { |
| 243 | sh::Attribute attrib; |
| 244 | LoadShaderVar(&stream, &attrib); |
| 245 | attrib.location = stream.readInt<int>(); |
| 246 | state->mAttributes.push_back(attrib); |
| 247 | } |
| 248 | |
| 249 | unsigned int uniformCount = stream.readInt<unsigned int>(); |
| 250 | ASSERT(state->mUniforms.empty()); |
| 251 | for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; ++uniformIndex) |
| 252 | { |
| 253 | LinkedUniform uniform; |
| 254 | LoadShaderVar(&stream, &uniform); |
| 255 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 256 | uniform.bufferIndex = stream.readInt<int>(); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 257 | uniform.blockInfo.offset = stream.readInt<int>(); |
| 258 | uniform.blockInfo.arrayStride = stream.readInt<int>(); |
| 259 | uniform.blockInfo.matrixStride = stream.readInt<int>(); |
| 260 | uniform.blockInfo.isRowMajorMatrix = stream.readBool(); |
| 261 | |
Jamie Madill | f00f7ff | 2017-08-31 14:39:15 -0400 | [diff] [blame] | 262 | uniform.typeInfo = &GetUniformTypeInfo(uniform.type); |
| 263 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 264 | state->mUniforms.push_back(uniform); |
| 265 | } |
| 266 | |
| 267 | const unsigned int uniformIndexCount = stream.readInt<unsigned int>(); |
| 268 | ASSERT(state->mUniformLocations.empty()); |
| 269 | for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; |
| 270 | uniformIndexIndex++) |
| 271 | { |
| 272 | VariableLocation variable; |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 273 | stream.readInt(&variable.arrayIndex); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 274 | stream.readInt(&variable.index); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 275 | stream.readBool(&variable.ignored); |
| 276 | |
| 277 | state->mUniformLocations.push_back(variable); |
| 278 | } |
| 279 | |
| 280 | unsigned int uniformBlockCount = stream.readInt<unsigned int>(); |
| 281 | ASSERT(state->mUniformBlocks.empty()); |
| 282 | for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; |
| 283 | ++uniformBlockIndex) |
| 284 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 285 | InterfaceBlock uniformBlock; |
| 286 | LoadInterfaceBlock(&stream, &uniformBlock); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 287 | state->mUniformBlocks.push_back(uniformBlock); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 288 | |
jchen10 | 7a20b97 | 2017-06-13 14:25:26 +0800 | [diff] [blame] | 289 | state->mActiveUniformBlockBindings.set(uniformBlockIndex, uniformBlock.binding != 0); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 290 | } |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 291 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 292 | unsigned int bufferVariableCount = stream.readInt<unsigned int>(); |
| 293 | ASSERT(state->mBufferVariables.empty()); |
| 294 | for (unsigned int index = 0; index < bufferVariableCount; ++index) |
| 295 | { |
| 296 | BufferVariable bufferVariable; |
| 297 | LoadBufferVariable(&stream, &bufferVariable); |
| 298 | state->mBufferVariables.push_back(bufferVariable); |
| 299 | } |
| 300 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 301 | unsigned int shaderStorageBlockCount = stream.readInt<unsigned int>(); |
| 302 | ASSERT(state->mShaderStorageBlocks.empty()); |
| 303 | for (unsigned int shaderStorageBlockIndex = 0; |
| 304 | shaderStorageBlockIndex < shaderStorageBlockCount; ++shaderStorageBlockIndex) |
| 305 | { |
| 306 | InterfaceBlock shaderStorageBlock; |
| 307 | LoadInterfaceBlock(&stream, &shaderStorageBlock); |
| 308 | state->mShaderStorageBlocks.push_back(shaderStorageBlock); |
| 309 | } |
| 310 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 311 | unsigned int atomicCounterBufferCount = stream.readInt<unsigned int>(); |
| 312 | ASSERT(state->mAtomicCounterBuffers.empty()); |
| 313 | for (unsigned int bufferIndex = 0; bufferIndex < atomicCounterBufferCount; ++bufferIndex) |
| 314 | { |
| 315 | AtomicCounterBuffer atomicCounterBuffer; |
| 316 | LoadShaderVariableBuffer(&stream, &atomicCounterBuffer); |
| 317 | |
| 318 | state->mAtomicCounterBuffers.push_back(atomicCounterBuffer); |
| 319 | } |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 320 | |
| 321 | unsigned int transformFeedbackVaryingCount = stream.readInt<unsigned int>(); |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 322 | |
| 323 | // Reject programs that use transform feedback varyings if the hardware cannot support them. |
| 324 | if (transformFeedbackVaryingCount > 0 && |
| 325 | context->getWorkarounds().disableProgramCachingForTransformFeedback) |
| 326 | { |
| 327 | infoLog << "Current driver does not support transform feedback in binary programs."; |
| 328 | return false; |
| 329 | } |
| 330 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 331 | ASSERT(state->mLinkedTransformFeedbackVaryings.empty()); |
| 332 | for (unsigned int transformFeedbackVaryingIndex = 0; |
| 333 | transformFeedbackVaryingIndex < transformFeedbackVaryingCount; |
| 334 | ++transformFeedbackVaryingIndex) |
| 335 | { |
| 336 | sh::Varying varying; |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame^] | 337 | stream.readIntVector<unsigned int>(&varying.arraySizes); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 338 | stream.readInt(&varying.type); |
| 339 | stream.readString(&varying.name); |
| 340 | |
| 341 | GLuint arrayIndex = stream.readInt<GLuint>(); |
| 342 | |
| 343 | state->mLinkedTransformFeedbackVaryings.emplace_back(varying, arrayIndex); |
| 344 | } |
| 345 | |
| 346 | stream.readInt(&state->mTransformFeedbackBufferMode); |
| 347 | |
| 348 | unsigned int outputCount = stream.readInt<unsigned int>(); |
| 349 | ASSERT(state->mOutputVariables.empty()); |
| 350 | for (unsigned int outputIndex = 0; outputIndex < outputCount; ++outputIndex) |
| 351 | { |
| 352 | sh::OutputVariable output; |
| 353 | LoadShaderVar(&stream, &output); |
| 354 | output.location = stream.readInt<int>(); |
| 355 | state->mOutputVariables.push_back(output); |
| 356 | } |
| 357 | |
| 358 | unsigned int outputVarCount = stream.readInt<unsigned int>(); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 359 | ASSERT(state->mOutputLocations.empty()); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 360 | for (unsigned int outputIndex = 0; outputIndex < outputVarCount; ++outputIndex) |
| 361 | { |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 362 | VariableLocation locationData; |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 363 | stream.readInt(&locationData.arrayIndex); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 364 | stream.readInt(&locationData.index); |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 365 | stream.readBool(&locationData.ignored); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 366 | state->mOutputLocations.push_back(locationData); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | unsigned int outputTypeCount = stream.readInt<unsigned int>(); |
| 370 | for (unsigned int outputIndex = 0; outputIndex < outputTypeCount; ++outputIndex) |
| 371 | { |
| 372 | state->mOutputVariableTypes.push_back(stream.readInt<GLenum>()); |
| 373 | } |
| 374 | static_assert(IMPLEMENTATION_MAX_DRAW_BUFFERS < 8 * sizeof(uint32_t), |
| 375 | "All bits of DrawBufferMask can be contained in an uint32_t"); |
| 376 | state->mActiveOutputVariables = stream.readInt<uint32_t>(); |
| 377 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 378 | unsigned int samplerRangeLow = stream.readInt<unsigned int>(); |
| 379 | unsigned int samplerRangeHigh = stream.readInt<unsigned int>(); |
| 380 | state->mSamplerUniformRange = RangeUI(samplerRangeLow, samplerRangeHigh); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 381 | unsigned int samplerCount = stream.readInt<unsigned int>(); |
| 382 | for (unsigned int samplerIndex = 0; samplerIndex < samplerCount; ++samplerIndex) |
| 383 | { |
| 384 | GLenum textureType = stream.readInt<GLenum>(); |
| 385 | size_t bindingCount = stream.readInt<size_t>(); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 386 | bool unreferenced = stream.readBool(); |
| 387 | state->mSamplerBindings.emplace_back( |
| 388 | SamplerBinding(textureType, bindingCount, unreferenced)); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 389 | } |
| 390 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 391 | unsigned int imageRangeLow = stream.readInt<unsigned int>(); |
| 392 | unsigned int imageRangeHigh = stream.readInt<unsigned int>(); |
| 393 | state->mImageUniformRange = RangeUI(imageRangeLow, imageRangeHigh); |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 394 | unsigned int imageBindingCount = stream.readInt<unsigned int>(); |
| 395 | for (unsigned int imageIndex = 0; imageIndex < imageBindingCount; ++imageIndex) |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 396 | { |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 397 | unsigned int elementCount = stream.readInt<unsigned int>(); |
| 398 | ImageBinding imageBinding(elementCount); |
| 399 | for (unsigned int i = 0; i < elementCount; ++i) |
| 400 | { |
| 401 | imageBinding.boundImageUnits[i] = stream.readInt<unsigned int>(); |
| 402 | } |
| 403 | state->mImageBindings.emplace_back(imageBinding); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 404 | } |
| 405 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 406 | unsigned int atomicCounterRangeLow = stream.readInt<unsigned int>(); |
| 407 | unsigned int atomicCounterRangeHigh = stream.readInt<unsigned int>(); |
| 408 | state->mAtomicCounterUniformRange = RangeUI(atomicCounterRangeLow, atomicCounterRangeHigh); |
| 409 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 410 | return program->getImplementation()->load(context, infoLog, &stream); |
| 411 | } |
| 412 | |
| 413 | // static |
| 414 | void MemoryProgramCache::Serialize(const Context *context, |
| 415 | const gl::Program *program, |
| 416 | angle::MemoryBuffer *binaryOut) |
| 417 | { |
| 418 | BinaryOutputStream stream; |
| 419 | |
| 420 | stream.writeBytes(reinterpret_cast<const unsigned char *>(ANGLE_COMMIT_HASH), |
| 421 | ANGLE_COMMIT_HASH_SIZE); |
| 422 | |
| 423 | // nullptr context is supported when computing binary length. |
| 424 | if (context) |
| 425 | { |
| 426 | stream.writeInt(context->getClientVersion().major); |
| 427 | stream.writeInt(context->getClientVersion().minor); |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | stream.writeInt(2); |
| 432 | stream.writeInt(0); |
| 433 | } |
| 434 | |
| 435 | const auto &state = program->getState(); |
| 436 | |
| 437 | const auto &computeLocalSize = state.getComputeShaderLocalSize(); |
| 438 | |
| 439 | stream.writeInt(computeLocalSize[0]); |
| 440 | stream.writeInt(computeLocalSize[1]); |
| 441 | stream.writeInt(computeLocalSize[2]); |
| 442 | |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 443 | stream.writeInt(state.mNumViews); |
| 444 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 445 | stream.writeInt(state.getActiveAttribLocationsMask().to_ulong()); |
| 446 | |
| 447 | stream.writeInt(state.getAttributes().size()); |
| 448 | for (const sh::Attribute &attrib : state.getAttributes()) |
| 449 | { |
| 450 | WriteShaderVar(&stream, attrib); |
| 451 | stream.writeInt(attrib.location); |
| 452 | } |
| 453 | |
| 454 | stream.writeInt(state.getUniforms().size()); |
| 455 | for (const LinkedUniform &uniform : state.getUniforms()) |
| 456 | { |
| 457 | WriteShaderVar(&stream, uniform); |
| 458 | |
| 459 | // FIXME: referenced |
| 460 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 461 | stream.writeInt(uniform.bufferIndex); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 462 | stream.writeInt(uniform.blockInfo.offset); |
| 463 | stream.writeInt(uniform.blockInfo.arrayStride); |
| 464 | stream.writeInt(uniform.blockInfo.matrixStride); |
| 465 | stream.writeInt(uniform.blockInfo.isRowMajorMatrix); |
| 466 | } |
| 467 | |
| 468 | stream.writeInt(state.getUniformLocations().size()); |
| 469 | for (const auto &variable : state.getUniformLocations()) |
| 470 | { |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 471 | stream.writeInt(variable.arrayIndex); |
Jamie Madill | fb997ec | 2017-09-20 15:44:27 -0400 | [diff] [blame] | 472 | stream.writeIntOrNegOne(variable.index); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 473 | stream.writeInt(variable.ignored); |
| 474 | } |
| 475 | |
| 476 | stream.writeInt(state.getUniformBlocks().size()); |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 477 | for (const InterfaceBlock &uniformBlock : state.getUniformBlocks()) |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 478 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 479 | WriteInterfaceBlock(&stream, uniformBlock); |
| 480 | } |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 481 | |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 482 | stream.writeInt(state.getBufferVariables().size()); |
| 483 | for (const BufferVariable &bufferVariable : state.getBufferVariables()) |
| 484 | { |
| 485 | WriteBufferVariable(&stream, bufferVariable); |
| 486 | } |
| 487 | |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 488 | stream.writeInt(state.getShaderStorageBlocks().size()); |
| 489 | for (const InterfaceBlock &shaderStorageBlock : state.getShaderStorageBlocks()) |
| 490 | { |
| 491 | WriteInterfaceBlock(&stream, shaderStorageBlock); |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 492 | } |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 493 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 494 | stream.writeInt(state.mAtomicCounterBuffers.size()); |
| 495 | for (const auto &atomicCounterBuffer : state.mAtomicCounterBuffers) |
| 496 | { |
| 497 | WriteShaderVariableBuffer(&stream, atomicCounterBuffer); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 500 | // Warn the app layer if saving a binary with unsupported transform feedback. |
| 501 | if (!state.getLinkedTransformFeedbackVaryings().empty() && |
| 502 | context->getWorkarounds().disableProgramCachingForTransformFeedback) |
| 503 | { |
| 504 | WARN() << "Saving program binary with transform feedback, which is not supported on this " |
| 505 | "driver."; |
| 506 | } |
| 507 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 508 | stream.writeInt(state.getLinkedTransformFeedbackVaryings().size()); |
| 509 | for (const auto &var : state.getLinkedTransformFeedbackVaryings()) |
| 510 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame^] | 511 | stream.writeIntVector(var.arraySizes); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 512 | stream.writeInt(var.type); |
| 513 | stream.writeString(var.name); |
| 514 | |
| 515 | stream.writeIntOrNegOne(var.arrayIndex); |
| 516 | } |
| 517 | |
| 518 | stream.writeInt(state.getTransformFeedbackBufferMode()); |
| 519 | |
| 520 | stream.writeInt(state.getOutputVariables().size()); |
| 521 | for (const sh::OutputVariable &output : state.getOutputVariables()) |
| 522 | { |
| 523 | WriteShaderVar(&stream, output); |
| 524 | stream.writeInt(output.location); |
| 525 | } |
| 526 | |
| 527 | stream.writeInt(state.getOutputLocations().size()); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 528 | for (const auto &outputVar : state.getOutputLocations()) |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 529 | { |
Olli Etuaho | 1734e17 | 2017-10-27 15:30:27 +0300 | [diff] [blame] | 530 | stream.writeInt(outputVar.arrayIndex); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 531 | stream.writeIntOrNegOne(outputVar.index); |
Olli Etuaho | d255123 | 2017-10-26 20:03:33 +0300 | [diff] [blame] | 532 | stream.writeInt(outputVar.ignored); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | stream.writeInt(state.mOutputVariableTypes.size()); |
| 536 | for (const auto &outputVariableType : state.mOutputVariableTypes) |
| 537 | { |
| 538 | stream.writeInt(outputVariableType); |
| 539 | } |
| 540 | |
| 541 | static_assert(IMPLEMENTATION_MAX_DRAW_BUFFERS < 8 * sizeof(uint32_t), |
| 542 | "All bits of DrawBufferMask can be contained in an uint32_t"); |
| 543 | stream.writeInt(static_cast<uint32_t>(state.mActiveOutputVariables.to_ulong())); |
| 544 | |
| 545 | stream.writeInt(state.getSamplerUniformRange().low()); |
| 546 | stream.writeInt(state.getSamplerUniformRange().high()); |
| 547 | |
| 548 | stream.writeInt(state.getSamplerBindings().size()); |
| 549 | for (const auto &samplerBinding : state.getSamplerBindings()) |
| 550 | { |
| 551 | stream.writeInt(samplerBinding.textureType); |
| 552 | stream.writeInt(samplerBinding.boundTextureUnits.size()); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 553 | stream.writeInt(samplerBinding.unreferenced); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 556 | stream.writeInt(state.getImageUniformRange().low()); |
| 557 | stream.writeInt(state.getImageUniformRange().high()); |
| 558 | |
| 559 | stream.writeInt(state.getImageBindings().size()); |
| 560 | for (const auto &imageBinding : state.getImageBindings()) |
| 561 | { |
Xinghua Cao | 0328b57 | 2017-06-26 15:51:36 +0800 | [diff] [blame] | 562 | stream.writeInt(imageBinding.boundImageUnits.size()); |
| 563 | for (size_t i = 0; i < imageBinding.boundImageUnits.size(); ++i) |
| 564 | { |
| 565 | stream.writeInt(imageBinding.boundImageUnits[i]); |
| 566 | } |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 567 | } |
| 568 | |
jchen10 | eaef1e5 | 2017-06-13 10:44:11 +0800 | [diff] [blame] | 569 | stream.writeInt(state.getAtomicCounterUniformRange().low()); |
| 570 | stream.writeInt(state.getAtomicCounterUniformRange().high()); |
| 571 | |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 572 | program->getImplementation()->save(context, &stream); |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 573 | |
| 574 | ASSERT(binaryOut); |
| 575 | binaryOut->resize(stream.length()); |
| 576 | memcpy(binaryOut->data(), stream.data(), stream.length()); |
| 577 | } |
| 578 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 579 | // static |
| 580 | void MemoryProgramCache::ComputeHash(const Context *context, |
| 581 | const Program *program, |
| 582 | ProgramHash *hashOut) |
| 583 | { |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 584 | const Shader *vertexShader = program->getAttachedVertexShader(); |
| 585 | const Shader *fragmentShader = program->getAttachedFragmentShader(); |
| 586 | const Shader *computeShader = program->getAttachedComputeShader(); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 587 | |
| 588 | // Compute the program hash. Start with the shader hashes and resource strings. |
| 589 | HashStream hashStream; |
| 590 | hashStream << vertexShader << fragmentShader << computeShader; |
| 591 | |
| 592 | // Add some ANGLE metadata and Context properties, such as version and back-end. |
| 593 | hashStream << ANGLE_COMMIT_HASH << context->getClientMajorVersion() |
| 594 | << context->getClientMinorVersion() << context->getString(GL_RENDERER); |
| 595 | |
| 596 | // Hash pre-link program properties. |
| 597 | hashStream << program->getAttributeBindings() << program->getUniformLocationBindings() |
| 598 | << program->getFragmentInputBindings() |
| 599 | << program->getState().getTransformFeedbackVaryingNames() |
| 600 | << program->getState().getTransformFeedbackBufferMode(); |
| 601 | |
| 602 | // Call the secure SHA hashing function. |
| 603 | const std::string &programKey = hashStream.str(); |
| 604 | angle::base::SHA1HashBytes(reinterpret_cast<const unsigned char *>(programKey.c_str()), |
| 605 | programKey.length(), hashOut->data()); |
| 606 | } |
| 607 | |
| 608 | LinkResult MemoryProgramCache::getProgram(const Context *context, |
| 609 | const Program *program, |
| 610 | ProgramState *state, |
| 611 | ProgramHash *hashOut) |
| 612 | { |
| 613 | ComputeHash(context, program, hashOut); |
| 614 | const angle::MemoryBuffer *binaryProgram = nullptr; |
| 615 | LinkResult result(false); |
| 616 | if (get(*hashOut, &binaryProgram)) |
| 617 | { |
| 618 | InfoLog infoLog; |
| 619 | ANGLE_TRY_RESULT(Deserialize(context, program, state, binaryProgram->data(), |
| 620 | binaryProgram->size(), infoLog), |
| 621 | result); |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 622 | ANGLE_HISTOGRAM_BOOLEAN("GPU.ANGLE.ProgramCache.LoadBinarySuccess", result.getResult()); |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 623 | if (!result.getResult()) |
| 624 | { |
| 625 | // Cache load failed, evict. |
| 626 | if (mIssuedWarnings++ < kWarningLimit) |
| 627 | { |
| 628 | WARN() << "Failed to load binary from cache: " << infoLog.str(); |
| 629 | |
| 630 | if (mIssuedWarnings == kWarningLimit) |
| 631 | { |
| 632 | WARN() << "Reaching warning limit for cache load failures, silencing " |
| 633 | "subsequent warnings."; |
| 634 | } |
| 635 | } |
| 636 | remove(*hashOut); |
| 637 | } |
| 638 | } |
| 639 | return result; |
| 640 | } |
| 641 | |
| 642 | bool MemoryProgramCache::get(const ProgramHash &programHash, const angle::MemoryBuffer **programOut) |
| 643 | { |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 644 | const CacheEntry *entry = nullptr; |
| 645 | if (!mProgramBinaryCache.get(programHash, &entry)) |
| 646 | { |
| 647 | ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.ProgramCache.CacheResult", kCacheMiss, |
| 648 | kCacheResultMax); |
| 649 | return false; |
| 650 | } |
| 651 | |
| 652 | if (entry->second == CacheSource::PutProgram) |
| 653 | { |
| 654 | ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.ProgramCache.CacheResult", kCacheHitMemory, |
| 655 | kCacheResultMax); |
| 656 | } |
| 657 | else |
| 658 | { |
| 659 | ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.ProgramCache.CacheResult", kCacheHitDisk, |
| 660 | kCacheResultMax); |
| 661 | } |
| 662 | |
| 663 | *programOut = &entry->first; |
| 664 | return true; |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 665 | } |
| 666 | |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 667 | bool MemoryProgramCache::getAt(size_t index, |
| 668 | ProgramHash *hashOut, |
| 669 | const angle::MemoryBuffer **programOut) |
| 670 | { |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 671 | const CacheEntry *entry = nullptr; |
| 672 | if (!mProgramBinaryCache.getAt(index, hashOut, &entry)) |
| 673 | { |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | *programOut = &entry->first; |
| 678 | return true; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 679 | } |
| 680 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 681 | void MemoryProgramCache::remove(const ProgramHash &programHash) |
| 682 | { |
| 683 | bool result = mProgramBinaryCache.eraseByKey(programHash); |
| 684 | ASSERT(result); |
| 685 | } |
| 686 | |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 687 | void MemoryProgramCache::putProgram(const ProgramHash &programHash, |
| 688 | const Context *context, |
| 689 | const Program *program) |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 690 | { |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 691 | CacheEntry newEntry; |
| 692 | Serialize(context, program, &newEntry.first); |
| 693 | newEntry.second = CacheSource::PutProgram; |
| 694 | |
| 695 | ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.ProgramCache.ProgramBinarySizeBytes", |
| 696 | static_cast<int>(newEntry.first.size())); |
| 697 | |
| 698 | const CacheEntry *result = |
| 699 | mProgramBinaryCache.put(programHash, std::move(newEntry), newEntry.first.size()); |
Jamie Madill | 360daee | 2017-06-29 10:36:19 -0400 | [diff] [blame] | 700 | if (!result) |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 701 | { |
| 702 | ERR() << "Failed to store binary program in memory cache, program is too large."; |
| 703 | } |
Jamie Madill | 360daee | 2017-06-29 10:36:19 -0400 | [diff] [blame] | 704 | else |
| 705 | { |
| 706 | auto *platform = ANGLEPlatformCurrent(); |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 707 | platform->cacheProgram(platform, programHash, result->first.size(), result->first.data()); |
Jamie Madill | 360daee | 2017-06-29 10:36:19 -0400 | [diff] [blame] | 708 | } |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 709 | } |
| 710 | |
Jamie Madill | 4c19a8a | 2017-07-24 11:46:06 -0400 | [diff] [blame] | 711 | void MemoryProgramCache::updateProgram(const Context *context, const Program *program) |
| 712 | { |
| 713 | gl::ProgramHash programHash; |
| 714 | ComputeHash(context, program, &programHash); |
| 715 | putProgram(programHash, context, program); |
| 716 | } |
| 717 | |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 718 | void MemoryProgramCache::putBinary(const ProgramHash &programHash, |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 719 | const uint8_t *binary, |
| 720 | size_t length) |
| 721 | { |
| 722 | // Copy the binary. |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 723 | CacheEntry newEntry; |
| 724 | newEntry.first.resize(length); |
| 725 | memcpy(newEntry.first.data(), binary, length); |
| 726 | newEntry.second = CacheSource::PutBinary; |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 727 | |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 728 | // Store the binary. |
Jamie Madill | 6c58b06 | 2017-08-01 13:44:25 -0400 | [diff] [blame] | 729 | const CacheEntry *result = mProgramBinaryCache.put(programHash, std::move(newEntry), length); |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 730 | if (!result) |
| 731 | { |
| 732 | ERR() << "Failed to store binary program in memory cache, program is too large."; |
| 733 | } |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | void MemoryProgramCache::clear() |
| 737 | { |
| 738 | mProgramBinaryCache.clear(); |
| 739 | mIssuedWarnings = 0; |
| 740 | } |
| 741 | |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 742 | void MemoryProgramCache::resize(size_t maxCacheSizeBytes) |
| 743 | { |
| 744 | mProgramBinaryCache.resize(maxCacheSizeBytes); |
| 745 | } |
| 746 | |
| 747 | size_t MemoryProgramCache::entryCount() const |
| 748 | { |
| 749 | return mProgramBinaryCache.entryCount(); |
| 750 | } |
| 751 | |
| 752 | size_t MemoryProgramCache::trim(size_t limit) |
| 753 | { |
| 754 | return mProgramBinaryCache.shrinkToSize(limit); |
| 755 | } |
| 756 | |
| 757 | size_t MemoryProgramCache::size() const |
| 758 | { |
| 759 | return mProgramBinaryCache.size(); |
| 760 | } |
| 761 | |
| 762 | size_t MemoryProgramCache::maxSize() const |
| 763 | { |
| 764 | return mProgramBinaryCache.maxSize(); |
| 765 | } |
| 766 | |
Jamie Madill | 4f86d05 | 2017-06-05 12:59:26 -0400 | [diff] [blame] | 767 | } // namespace gl |