OLD | NEW |
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 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 private: | 63 private: |
64 GLsizei length_; | 64 GLsizei length_; |
65 GLenum format_; | 65 GLenum format_; |
66 const char* binary_; | 66 const char* binary_; |
67 }; | 67 }; |
68 | 68 |
69 class MemoryProgramCacheTest : public GpuServiceTest { | 69 class MemoryProgramCacheTest : public GpuServiceTest { |
70 public: | 70 public: |
71 static const size_t kCacheSizeBytes = 1024; | 71 static const size_t kCacheSizeBytes = 1024; |
72 static const bool kDisableGpuDiskCache = false; | 72 static const bool kDisableGpuDiskCache = false; |
| 73 static const bool kDisableCachingForTransformFeedback = false; |
73 static const GLuint kVertexShaderClientId = 90; | 74 static const GLuint kVertexShaderClientId = 90; |
74 static const GLuint kVertexShaderServiceId = 100; | 75 static const GLuint kVertexShaderServiceId = 100; |
75 static const GLuint kFragmentShaderClientId = 91; | 76 static const GLuint kFragmentShaderClientId = 91; |
76 static const GLuint kFragmentShaderServiceId = 100; | 77 static const GLuint kFragmentShaderServiceId = 100; |
77 | 78 |
78 MemoryProgramCacheTest() | 79 MemoryProgramCacheTest() |
79 : cache_(new MemoryProgramCache(kCacheSizeBytes, kDisableGpuDiskCache)), | 80 : cache_(new MemoryProgramCache(kCacheSizeBytes, kDisableGpuDiskCache, |
| 81 kDisableCachingForTransformFeedback)), |
80 shader_manager_(nullptr), | 82 shader_manager_(nullptr), |
81 vertex_shader_(nullptr), | 83 vertex_shader_(nullptr), |
82 fragment_shader_(nullptr), | 84 fragment_shader_(nullptr), |
83 shader_cache_count_(0) {} | 85 shader_cache_count_(0) {} |
84 ~MemoryProgramCacheTest() override { shader_manager_.Destroy(false); } | 86 ~MemoryProgramCacheTest() override { shader_manager_.Destroy(false); } |
85 | 87 |
86 void ShaderCacheCb(const std::string& key, const std::string& shader) { | 88 void ShaderCacheCb(const std::string& key, const std::string& shader) { |
87 shader_cache_count_++; | 89 shader_cache_count_++; |
88 shader_cache_shader_ = shader; | 90 shader_cache_shader_ = shader; |
89 } | 91 } |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 kProgramId, | 532 kProgramId, |
531 vertex_shader_, | 533 vertex_shader_, |
532 fragment_shader_, | 534 fragment_shader_, |
533 NULL, | 535 NULL, |
534 varyings_, | 536 varyings_, |
535 GL_INTERLEAVED_ATTRIBS, | 537 GL_INTERLEAVED_ATTRIBS, |
536 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, | 538 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, |
537 base::Unretained(this)))); | 539 base::Unretained(this)))); |
538 } | 540 } |
539 | 541 |
| 542 TEST_F(MemoryProgramCacheTest, LoadFailIfTransformFeedbackCachingDisabled) { |
| 543 const GLenum kFormat = 1; |
| 544 const int kProgramId = 10; |
| 545 const int kBinaryLength = 20; |
| 546 char test_binary[kBinaryLength]; |
| 547 for (int i = 0; i < kBinaryLength; ++i) { |
| 548 test_binary[i] = i; |
| 549 } |
| 550 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary); |
| 551 |
| 552 // Forcibly reset the program cache so we can disable caching of |
| 553 // programs which include transform feedback varyings. |
| 554 cache_.reset(new MemoryProgramCache( |
| 555 kCacheSizeBytes, kDisableGpuDiskCache, true)); |
| 556 varyings_.push_back("test"); |
| 557 cache_->SaveLinkedProgram(kProgramId, |
| 558 vertex_shader_, |
| 559 fragment_shader_, |
| 560 NULL, |
| 561 varyings_, |
| 562 GL_INTERLEAVED_ATTRIBS, |
| 563 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, |
| 564 base::Unretained(this))); |
| 565 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram( |
| 566 kProgramId, |
| 567 vertex_shader_, |
| 568 fragment_shader_, |
| 569 NULL, |
| 570 varyings_, |
| 571 GL_INTERLEAVED_ATTRIBS, |
| 572 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, |
| 573 base::Unretained(this)))); |
| 574 } |
| 575 |
540 TEST_F(MemoryProgramCacheTest, MemoryProgramCacheEviction) { | 576 TEST_F(MemoryProgramCacheTest, MemoryProgramCacheEviction) { |
541 const GLenum kFormat = 1; | 577 const GLenum kFormat = 1; |
542 const int kProgramId = 10; | 578 const int kProgramId = 10; |
543 const int kBinaryLength = 20; | 579 const int kBinaryLength = 20; |
544 char test_binary[kBinaryLength]; | 580 char test_binary[kBinaryLength]; |
545 for (int i = 0; i < kBinaryLength; ++i) { | 581 for (int i = 0; i < kBinaryLength; ++i) { |
546 test_binary[i] = i; | 582 test_binary[i] = i; |
547 } | 583 } |
548 ProgramBinaryEmulator emulator1(kBinaryLength, kFormat, test_binary); | 584 ProgramBinaryEmulator emulator1(kBinaryLength, kFormat, test_binary); |
549 | 585 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 fragment_shader_, | 720 fragment_shader_, |
685 NULL, | 721 NULL, |
686 varyings_, | 722 varyings_, |
687 GL_NONE, | 723 GL_NONE, |
688 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, | 724 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, |
689 base::Unretained(this)))); | 725 base::Unretained(this)))); |
690 } | 726 } |
691 | 727 |
692 } // namespace gles2 | 728 } // namespace gles2 |
693 } // namespace gpu | 729 } // namespace gpu |
OLD | NEW |