 Chromium Code Reviews
 Chromium Code Reviews Issue 116863003:
  gpu: Reuse transfer buffers more aggresively  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master
    
  
    Issue 116863003:
  gpu: Reuse transfer buffers more aggresively  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains unit tests for gles2 commmands | 5 // This file contains unit tests for gles2 commmands | 
| 6 | 6 | 
| 7 #include <limits> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/synchronization/waitable_event.h" | |
| 11 #include "base/threading/thread.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" | 
| 8 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 
| 9 | 14 | 
| 10 namespace gpu { | 15 namespace gpu { | 
| 11 namespace gles2 { | 16 namespace gles2 { | 
| 12 | 17 | 
| 13 class GLES2FormatTest : public testing::Test { | 18 class GLES2FormatTest : public testing::Test { | 
| 14 protected: | 19 protected: | 
| 15 static const unsigned char kInitialValue = 0xBD; | 20 static const unsigned char kInitialValue = 0xBD; | 
| 16 | 21 | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 39 | 44 | 
| 40 void CheckBytesWrittenMatchesExpectedSize( | 45 void CheckBytesWrittenMatchesExpectedSize( | 
| 41 const void* end, size_t expected_size) { | 46 const void* end, size_t expected_size) { | 
| 42 CheckBytesWritten(end, expected_size, expected_size); | 47 CheckBytesWritten(end, expected_size, expected_size); | 
| 43 } | 48 } | 
| 44 | 49 | 
| 45 private: | 50 private: | 
| 46 unsigned char buffer_[1024]; | 51 unsigned char buffer_[1024]; | 
| 47 }; | 52 }; | 
| 48 | 53 | 
| 54 void SignalCompletion(uint32* assigned_async_token_ptr, | |
| 55 uint32 async_token, | |
| 56 AsyncUploadSync* sync) { | |
| 57 EXPECT_EQ(async_token, *assigned_async_token_ptr); | |
| 58 sync->SetAsyncUploadToken(async_token); | |
| 59 } | |
| 60 | |
| 61 TEST(GLES2FormatAsyncUploadSyncTest, AsyncUploadSync) { | |
| 62 const size_t kSize = 10; | |
| 63 const size_t kCount = 1000; | |
| 64 | |
| 65 base::Thread thread("GLES2FormatUploadSyncTest - Fake Upload Thread"); | |
| 66 thread.Start(); | |
| 67 | |
| 68 // Run the same test 50 times so we retest the wrap as well. | |
| 69 for (size_t test_run = 0; test_run < 50; ++test_run) { | |
| 70 AsyncUploadSync sync; | |
| 71 sync.Reset(); | |
| 72 | |
| 73 uint32 buffer_tokens[kSize]; | |
| 74 memset(buffer_tokens, 0, sizeof(buffer_tokens)); | |
| 75 | |
| 76 // Start with a token large enough so that we'll wrap. | |
| 77 uint32 async_token = std::numeric_limits<uint32>::max() - kCount / 2; | |
| 78 | |
| 79 // Set initial async token. | |
| 80 sync.SetAsyncUploadToken(async_token); | |
| 81 | |
| 82 for (size_t i = 0; i < kCount; ++i) { | |
| 83 size_t buffer = i % kSize; | |
| 84 | |
| 85 // Loop until previous async token has passed if any was set. | |
| 86 while (buffer_tokens[buffer] && | |
| 87 !sync.HasAsyncUploadTokenPassed(buffer_tokens[buffer])) | |
| 88 base::PlatformThread::YieldCurrentThread(); | |
| 89 | |
| 90 // Next token, skip 0. | |
| 91 async_token++; | |
| 92 if (async_token == 0) | |
| 93 async_token++; | |
| 94 | |
| 95 // Set the buffer's associated token. | |
| 96 buffer_tokens[buffer] = async_token; | |
| 97 | |
| 98 base::subtle::MemoryBarrier(); | |
| 
piman
2014/03/20 21:18:26
Why the barrier? On the contrary, we want to make
 
jadahl
2014/03/21 08:30:53
I added it to ensure the buffer_tokens[buffer] sto
 | |
| 99 | |
| 100 // Set the async upload token on the fake upload thread and assert that | |
| 101 // the associated buffer still has the given token. | |
| 102 thread.message_loop()->PostTask(FROM_HERE, | |
| 103 base::Bind(&SignalCompletion, | |
| 104 &buffer_tokens[buffer], | |
| 105 async_token, | |
| 106 &sync)); | |
| 107 } | |
| 108 | |
| 109 // Flush the thread message loop before starting again. | |
| 110 base::WaitableEvent waitable(false, false); | |
| 111 thread.message_loop()->PostTask(FROM_HERE, | |
| 112 base::Bind(&base::WaitableEvent::Signal, | |
| 113 base::Unretained(&waitable))); | |
| 114 waitable.Wait(); | |
| 115 } | |
| 116 } | |
| 117 | |
| 49 // GCC requires these declarations, but MSVC requires they not be present | 118 // GCC requires these declarations, but MSVC requires they not be present | 
| 50 #ifndef _MSC_VER | 119 #ifndef _MSC_VER | 
| 51 const unsigned char GLES2FormatTest::kInitialValue; | 120 const unsigned char GLES2FormatTest::kInitialValue; | 
| 52 #endif | 121 #endif | 
| 53 | 122 | 
| 54 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h" | 123 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h" | 
| 55 | 124 | 
| 56 } // namespace gles2 | 125 } // namespace gles2 | 
| 57 } // namespace gpu | 126 } // namespace gpu | 
| 58 | 127 | 
| OLD | NEW |