Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "config.h" | 5 #include "config.h" |
| 6 #include "ThrottledTextureUploader.h" | 6 #include "ThrottledTextureUploader.h" |
| 7 | 7 |
| 8 #include "Extensions3DChromium.h" | 8 #include "Extensions3DChromium.h" |
| 9 #include "TraceEvent.h" | 9 #include "TraceEvent.h" |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <iterator> | |
| 11 #include <public/Platform.h> | 12 #include <public/Platform.h> |
| 12 #include <public/WebGraphicsContext3D.h> | 13 #include <public/WebGraphicsContext3D.h> |
| 13 #include <vector> | |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // How many previous uploads to use when predicting future throughput. | 17 // How many previous uploads to use when predicting future throughput. |
| 18 static const size_t uploadHistorySize = 100; | 18 static const size_t uploadHistorySizeMax = 1000; |
| 19 static const size_t uploadHistorySizeInitial = 100; | |
| 19 | 20 |
| 20 // Global estimated number of textures per second to maintain estimates across | 21 // Global estimated number of textures per second to maintain estimates across |
| 21 // subsequent instances of ThrottledTextureUploader. | 22 // subsequent instances of ThrottledTextureUploader. |
| 22 // More than one thread will not access this variable, so we do not need to sync hronize access. | 23 // More than one thread will not access this variable, so we do not need to sync hronize access. |
| 23 static double estimatedTexturesPerSecondGlobal = 48.0 * 60.0; | 24 static double estimatedTexturesPerSecondGlobal = 48.0 * 60.0; |
| 24 | 25 |
| 25 } // anonymous namespace | 26 } // anonymous namespace |
| 26 | 27 |
| 27 namespace cc { | 28 namespace cc { |
| 28 | 29 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 m_isNonBlocking = true; | 81 m_isNonBlocking = true; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool ThrottledTextureUploader::Query::isNonBlocking() | 84 bool ThrottledTextureUploader::Query::isNonBlocking() |
| 84 { | 85 { |
| 85 return m_isNonBlocking; | 86 return m_isNonBlocking; |
| 86 } | 87 } |
| 87 | 88 |
| 88 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D* context) | 89 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D* context) |
| 89 : m_context(context) | 90 : m_context(context) |
| 90 , m_texturesPerSecondHistory(uploadHistorySize, estimatedTexturesPerSecondGl obal) | |
| 91 , m_numBlockingTextureUploads(0) | 91 , m_numBlockingTextureUploads(0) |
| 92 , m_historyRemovalCount(0) | |
| 92 { | 93 { |
| 94 for (size_t i = uploadHistorySizeInitial; i > 0; i--) | |
| 95 m_texturesPerSecondHistory.insert(estimatedTexturesPerSecondGlobal); | |
| 93 } | 96 } |
| 94 | 97 |
| 95 ThrottledTextureUploader::~ThrottledTextureUploader() | 98 ThrottledTextureUploader::~ThrottledTextureUploader() |
| 96 { | 99 { |
| 97 } | 100 } |
| 98 | 101 |
| 99 size_t ThrottledTextureUploader::numBlockingUploads() | 102 size_t ThrottledTextureUploader::numBlockingUploads() |
| 100 { | 103 { |
| 101 processQueries(); | 104 processQueries(); |
| 102 return m_numBlockingTextureUploads; | 105 return m_numBlockingTextureUploads; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 113 it->get()->markAsNonBlocking(); | 116 it->get()->markAsNonBlocking(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 ASSERT(!m_numBlockingTextureUploads); | 119 ASSERT(!m_numBlockingTextureUploads); |
| 117 } | 120 } |
| 118 | 121 |
| 119 double ThrottledTextureUploader::estimatedTexturesPerSecond() | 122 double ThrottledTextureUploader::estimatedTexturesPerSecond() |
| 120 { | 123 { |
| 121 processQueries(); | 124 processQueries(); |
| 122 | 125 |
| 123 // The history should never be empty because we initialize all elements with an estimate. | 126 // Use the 3/4 median as our optimistic estimate. |
|
reveman
2012/10/12 01:41:00
I'm not convinced that 3/4 median magic number we
| |
| 124 ASSERT(m_texturesPerSecondHistory.size() == uploadHistorySize); | 127 std::set<double>::iterator median = m_texturesPerSecondHistory.end(); |
| 125 | 128 std::advance(median, -(int)m_texturesPerSecondHistory.size() / 4); |
|
reveman
2012/10/12 01:41:00
nit: use static_cast<> here
| |
| 126 // Sort the history and use the median as our estimate. | 129 estimatedTexturesPerSecondGlobal = *median; |
| 127 std::vector<double> sortedHistory(m_texturesPerSecondHistory.begin(), | |
| 128 m_texturesPerSecondHistory.end()); | |
| 129 std::sort(sortedHistory.begin(), sortedHistory.end()); | |
| 130 | |
| 131 estimatedTexturesPerSecondGlobal = sortedHistory[sortedHistory.size() * 2 / 3]; | |
| 132 TRACE_COUNTER1("cc", "estimatedTexturesPerSecond", estimatedTexturesPerSecon dGlobal); | 130 TRACE_COUNTER1("cc", "estimatedTexturesPerSecond", estimatedTexturesPerSecon dGlobal); |
| 133 return estimatedTexturesPerSecondGlobal; | 131 return estimatedTexturesPerSecondGlobal; |
| 134 } | 132 } |
| 135 | 133 |
| 136 void ThrottledTextureUploader::beginQuery() | 134 void ThrottledTextureUploader::beginQuery() |
| 137 { | 135 { |
| 138 processQueries(); | 136 processQueries(); |
| 139 | 137 |
| 140 if (m_availableQueries.isEmpty()) | 138 if (m_availableQueries.isEmpty()) |
| 141 m_availableQueries.append(Query::create(m_context)); | 139 m_availableQueries.append(Query::create(m_context)); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 169 while (!m_pendingQueries.isEmpty()) { | 167 while (!m_pendingQueries.isEmpty()) { |
| 170 if (m_pendingQueries.first()->isPending()) | 168 if (m_pendingQueries.first()->isPending()) |
| 171 break; | 169 break; |
| 172 | 170 |
| 173 unsigned usElapsed = m_pendingQueries.first()->value(); | 171 unsigned usElapsed = m_pendingQueries.first()->value(); |
| 174 WebKit::Platform::current()->histogramCustomCounts("Renderer4.TextureGpu UploadTimeUS", usElapsed, 0, 100000, 50); | 172 WebKit::Platform::current()->histogramCustomCounts("Renderer4.TextureGpu UploadTimeUS", usElapsed, 0, 100000, 50); |
| 175 | 173 |
| 176 if (!m_pendingQueries.first()->isNonBlocking()) | 174 if (!m_pendingQueries.first()->isNonBlocking()) |
| 177 m_numBlockingTextureUploads--; | 175 m_numBlockingTextureUploads--; |
| 178 | 176 |
| 179 // Remove the oldest values from our history and insert the new one | 177 // Alternately remove the min or max value from our history and insert t he new one. |
| 178 // We remove the min 3/4 of the time and the max 1/4 of the time to keep an optimistic history. | |
| 180 double texturesPerSecond = 1.0 / (usElapsed * 1e-6); | 179 double texturesPerSecond = 1.0 / (usElapsed * 1e-6); |
| 181 m_texturesPerSecondHistory.pop_back(); | 180 m_texturesPerSecondHistory.insert(texturesPerSecond); |
|
reveman
2012/10/12 01:41:00
maybe do the remove before adding the new value?
| |
| 182 m_texturesPerSecondHistory.push_front(texturesPerSecond); | 181 if (m_texturesPerSecondHistory.size() >= uploadHistorySizeMax) { |
| 182 if (m_historyRemovalCount & 0x3) | |
|
reveman
2012/10/12 01:41:00
how about we save the 3/4 and 1/4 details for late
| |
| 183 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begi n()); | |
| 184 else | |
| 185 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.en d()); | |
| 186 m_historyRemovalCount++; | |
| 187 } | |
| 183 | 188 |
| 184 m_availableQueries.append(m_pendingQueries.takeFirst()); | 189 m_availableQueries.append(m_pendingQueries.takeFirst()); |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 | 192 |
| 188 } | 193 } |
| OLD | NEW |