Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_program_cache_H_ | |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_program_cache_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/hash_tables.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
|
greggman
2012/06/25 18:53:03
is this still needed?
dmurph
2012/06/26 02:32:56
Done.
| |
| 13 #include "base/sha1.h" | |
| 14 #include "gpu/command_buffer/common/gles2_cmd_format.h" | |
| 15 #include "gpu/command_buffer/service/shader_manager.h" | |
| 16 #include "net/disk_cache/hash.h" | |
| 17 | |
| 18 namespace { | |
| 19 typedef std::map<std::string, GLint> BindAttribMap; | |
|
greggman
2012/06/25 18:53:03
I don't think it makes sense to have an anonymous
dmurph
2012/06/26 02:32:56
It's just to shorten arguments for the map, I'll j
| |
| 20 } // anonymous namespace | |
| 21 | |
| 22 namespace gpu { | |
| 23 namespace gles2 { | |
| 24 | |
| 25 // Program cache base class for caching linked gpu programs | |
| 26 class GPU_EXPORT ProgramCache { | |
| 27 public: | |
| 28 enum CompiledShaderStatus { | |
| 29 COMPILATION_UNKNOWN, | |
| 30 COMPILATION_SUCCEEDED | |
| 31 }; | |
| 32 | |
| 33 enum LinkedProgramStatus { | |
| 34 LINK_UNKNOWN, | |
| 35 LINK_SUCCEEDED | |
| 36 }; | |
| 37 | |
| 38 ProgramCache() {} | |
| 39 virtual ~ProgramCache(); | |
| 40 | |
| 41 CompiledShaderStatus GetShaderCompilationStatus( | |
| 42 const std::string& shader_src) const; | |
| 43 void ShaderCompilationSucceeded(const std::string& shader_src); | |
| 44 | |
| 45 LinkedProgramStatus GetLinkedProgramStatus( | |
| 46 const std::string& untranslated_a, | |
| 47 const std::string& untranslated_b, | |
| 48 const BindAttribMap* bind_attrib_location_map) const; | |
| 49 | |
| 50 virtual bool LoadLinkedProgram( | |
| 51 const GLuint program, | |
| 52 ShaderManager::ShaderInfo* shader_a, | |
| 53 ShaderManager::ShaderInfo* shader_b, | |
| 54 const BindAttribMap* bind_attrib_location_map) const = 0; | |
| 55 virtual void SaveLinkedProgram( | |
| 56 const GLuint program, | |
| 57 const ShaderManager::ShaderInfo* shader_a, | |
| 58 const ShaderManager::ShaderInfo* shader_b, | |
| 59 const BindAttribMap* bind_attrib_location_map) = 0; | |
| 60 // clears the cache | |
| 61 void Clear(); | |
| 62 | |
| 63 protected: | |
| 64 static const uint32 kHashLength = base::kSHA1Length; | |
|
greggman
2012/06/25 18:53:03
Is there a reason to use uint32 everywhere? the st
dmurph
2012/06/26 02:32:56
Done.
| |
| 65 | |
| 66 // called by implementing class after a shader was successfully cached | |
| 67 void LinkedProgramCacheSuccess(const std::string& program_hash, | |
| 68 const std::string& shader_a_hash, | |
| 69 const std::string& shader_b_hash); | |
| 70 | |
| 71 // result is not null terminated | |
| 72 void ComputeShaderHash(const std::string& shader, | |
| 73 char* result) const; | |
| 74 | |
| 75 // result is not null terminated. hashed shaders are expected to be | |
| 76 // kHashLength in length | |
| 77 void ComputeProgramHash(const char* hashed_shader_0, | |
| 78 const char* hashed_shader_1, | |
| 79 const BindAttribMap* bind_attrib_location_map, | |
| 80 char* result) const; | |
| 81 | |
| 82 void Evict(const std::string& program_hash, | |
| 83 const std::string& shader_0_hash, | |
| 84 const std::string& shader_1_hash); | |
| 85 | |
| 86 private: | |
| 87 struct FastHash { | |
| 88 const inline uint32 operator()(const std::string& key) const { | |
| 89 if (key.empty()) | |
| 90 return 0; | |
| 91 return disk_cache::SuperFastHash(key.data(), | |
| 92 static_cast<int>(key.size())); | |
| 93 } | |
| 94 }; | |
| 95 struct CompiledShaderInfo { | |
|
greggman
2012/06/25 18:53:03
We don't usually allow structs to have methods tha
dmurph
2012/06/26 02:32:56
I'll remove the method
| |
| 96 CompiledShaderInfo() : status(COMPILATION_UNKNOWN), ref_count(0) { } | |
| 97 CompiledShaderInfo(CompiledShaderStatus status_) | |
| 98 : status(status_), | |
| 99 ref_count(0) { } | |
| 100 | |
| 101 void usedInCachedProgram() { | |
|
greggman
2012/06/25 18:53:03
If you're going to have a function to inc ref coun
dmurph
2012/06/26 02:32:56
Ends up not being needed, that check is included o
| |
| 102 ref_count++; | |
| 103 } | |
| 104 | |
| 105 CompiledShaderStatus status; | |
| 106 uint32 ref_count; | |
| 107 }; | |
| 108 | |
| 109 typedef base::hash_map<std::string, | |
| 110 CompiledShaderInfo, | |
| 111 FastHash> CompileStatusMap; | |
| 112 typedef base::hash_map<std::string, | |
| 113 LinkedProgramStatus, | |
| 114 FastHash> LinkStatusMap; | |
| 115 | |
| 116 // called to clear the backend cache | |
| 117 virtual void ClearBackend() = 0; | |
|
greggman
2012/06/25 18:53:03
There's no such thing as a pure virtual private me
dmurph
2012/06/26 02:32:56
Yeah, it's so the derived class can provide the im
| |
| 118 | |
| 119 CompileStatusMap shader_status_; | |
| 120 LinkStatusMap link_status_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(ProgramCache); | |
| 123 }; | |
| 124 | |
| 125 | |
| 126 | |
| 127 } // namespace gles2 | |
| 128 } // namespace gpu | |
| 129 | |
| 130 #endif // GPU_COMMAND_BUFFER_SERVICE_program_cache_H_ | |
| OLD | NEW |