Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(801)

Side by Side Diff: gpu/command_buffer/service/memory_program_cache.cc

Issue 2629633003: Refactor GL bindings so there is no global GLApi or DriverGL. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/memory_program_cache.h" 5 #include "gpu/command_buffer/service/memory_program_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 GpuProgramProto* proto, 193 GpuProgramProto* proto,
194 std::string sha_string) { 194 std::string sha_string) {
195 std::string shader; 195 std::string shader;
196 proto->SerializeToString(&shader); 196 proto->SerializeToString(&shader);
197 197
198 std::string key; 198 std::string key;
199 base::Base64Encode(sha_string, &key); 199 base::Base64Encode(sha_string, &key);
200 callback.Run(key, shader); 200 callback.Run(key, shader);
201 } 201 }
202 202
203 bool ProgramBinaryExtensionsAvailable() {
204 return gl::g_current_gl_driver &&
205 (gl::g_current_gl_driver->ext.b_GL_ARB_get_program_binary ||
206 gl::g_current_gl_driver->ext.b_GL_OES_get_program_binary);
207 }
208
203 } // namespace 209 } // namespace
204 210
205 MemoryProgramCache::MemoryProgramCache( 211 MemoryProgramCache::MemoryProgramCache(
206 size_t max_cache_size_bytes, 212 size_t max_cache_size_bytes,
207 bool disable_gpu_shader_disk_cache, 213 bool disable_gpu_shader_disk_cache,
208 bool disable_program_caching_for_transform_feedback) 214 bool disable_program_caching_for_transform_feedback)
209 : max_size_bytes_(max_cache_size_bytes), 215 : max_size_bytes_(max_cache_size_bytes),
210 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache), 216 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache),
211 disable_program_caching_for_transform_feedback_( 217 disable_program_caching_for_transform_feedback_(
212 disable_program_caching_for_transform_feedback), 218 disable_program_caching_for_transform_feedback),
213 curr_size_bytes_(0), 219 curr_size_bytes_(0),
214 store_(ProgramMRUCache::NO_AUTO_EVICT) { 220 store_(ProgramMRUCache::NO_AUTO_EVICT) {
215 } 221 }
216 222
217 MemoryProgramCache::~MemoryProgramCache() {} 223 MemoryProgramCache::~MemoryProgramCache() {}
218 224
219 void MemoryProgramCache::ClearBackend() { 225 void MemoryProgramCache::ClearBackend() {
220 store_.Clear(); 226 store_.Clear();
221 DCHECK_EQ(0U, curr_size_bytes_); 227 DCHECK_EQ(0U, curr_size_bytes_);
222 } 228 }
223 229
224 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( 230 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram(
225 GLuint program, 231 GLuint program,
226 Shader* shader_a, 232 Shader* shader_a,
227 Shader* shader_b, 233 Shader* shader_b,
228 const LocationMap* bind_attrib_location_map, 234 const LocationMap* bind_attrib_location_map,
229 const std::vector<std::string>& transform_feedback_varyings, 235 const std::vector<std::string>& transform_feedback_varyings,
230 GLenum transform_feedback_buffer_mode, 236 GLenum transform_feedback_buffer_mode,
231 const ShaderCacheCallback& shader_callback) { 237 const ShaderCacheCallback& shader_callback) {
238 if (!ProgramBinaryExtensionsAvailable()) {
239 // Early exit if this context can't support program binaries
240 return PROGRAM_LOAD_FAILURE;
241 }
242
232 char a_sha[kHashLength]; 243 char a_sha[kHashLength];
233 char b_sha[kHashLength]; 244 char b_sha[kHashLength];
234 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && 245 DCHECK(shader_a && !shader_a->last_compiled_source().empty() &&
235 shader_b && !shader_b->last_compiled_source().empty()); 246 shader_b && !shader_b->last_compiled_source().empty());
236 ComputeShaderHash( 247 ComputeShaderHash(
237 shader_a->last_compiled_signature(), a_sha); 248 shader_a->last_compiled_signature(), a_sha);
238 ComputeShaderHash( 249 ComputeShaderHash(
239 shader_b->last_compiled_signature(), b_sha); 250 shader_b->last_compiled_signature(), b_sha);
240 251
241 char sha[kHashLength]; 252 char sha[kHashLength];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 299 }
289 300
290 void MemoryProgramCache::SaveLinkedProgram( 301 void MemoryProgramCache::SaveLinkedProgram(
291 GLuint program, 302 GLuint program,
292 const Shader* shader_a, 303 const Shader* shader_a,
293 const Shader* shader_b, 304 const Shader* shader_b,
294 const LocationMap* bind_attrib_location_map, 305 const LocationMap* bind_attrib_location_map,
295 const std::vector<std::string>& transform_feedback_varyings, 306 const std::vector<std::string>& transform_feedback_varyings,
296 GLenum transform_feedback_buffer_mode, 307 GLenum transform_feedback_buffer_mode,
297 const ShaderCacheCallback& shader_callback) { 308 const ShaderCacheCallback& shader_callback) {
309 if (!ProgramBinaryExtensionsAvailable()) {
310 // Early exit if this context can't support program binaries
311 return;
312 }
298 if (disable_program_caching_for_transform_feedback_ && 313 if (disable_program_caching_for_transform_feedback_ &&
299 !transform_feedback_varyings.empty()) { 314 !transform_feedback_varyings.empty()) {
300 return; 315 return;
301 } 316 }
302 GLenum format; 317 GLenum format;
303 GLsizei length = 0; 318 GLsizei length = 0;
304 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); 319 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length);
305 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { 320 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) {
306 return; 321 return;
307 } 322 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 program_cache_->LinkedProgramCacheSuccess(program_hash); 504 program_cache_->LinkedProgramCacheSuccess(program_hash);
490 } 505 }
491 506
492 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { 507 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {
493 program_cache_->curr_size_bytes_ -= length_; 508 program_cache_->curr_size_bytes_ -= length_;
494 program_cache_->Evict(program_hash_); 509 program_cache_->Evict(program_hash_);
495 } 510 }
496 511
497 } // namespace gles2 512 } // namespace gles2
498 } // namespace gpu 513 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/mailbox_manager_sync.cc ('k') | gpu/command_buffer/service/program_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698