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

Side by Side Diff: cc/CCTextureUpdateController.cpp

Issue 10916292: Adaptively throttle texture uploads (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cc_unittests passing again Created 8 years, 3 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 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 6
7 #include "CCTextureUpdateController.h" 7 #include "CCTextureUpdateController.h"
8 8
9 #include "GraphicsContext3D.h" 9 #include "GraphicsContext3D.h"
10 #include "TextureCopier.h" 10 #include "TextureCopier.h"
11 #include "TextureUploader.h" 11 #include "TextureUploader.h"
12 #include "TraceEvent.h"
13 #include <limits>
12 #include <wtf/CurrentTime.h> 14 #include <wtf/CurrentTime.h>
13 15
14 namespace { 16 namespace {
15 17
16 // Number of textures to update with each call to updateMoreTexturesIfEnoughTime Remaining(). 18 static const size_t pixelsPerTexture = 256 * 256;
17 static const size_t textureUpdatesPerTick = 12; 19
20 // Minimum number of textures to update with each call to updateMoreTexturesIfEn oughTimeRemaining().
21 static const size_t textureUpdatesPerFullTickMin = 12;
18 22
19 // Measured in seconds. 23 // Measured in seconds.
20 static const double textureUpdateTickRate = 0.004; 24 static const double textureUpdateTickRate = 0.004;
21 25
22 // Measured in seconds. 26 // Measured in seconds.
23 static const double uploaderBusyTickRate = 0.001; 27 static const double uploaderBusyTickRate = 0.001;
24 28
25 // Flush interval when performing texture uploads. 29 // Flush interval when performing texture uploads.
26 static const int textureUploadFlushPeriod = 4; 30 static const int textureUploadFlushPeriod = 4;
27 31
28 } // anonymous namespace 32 } // anonymous namespace
29 33
30 namespace cc { 34 namespace cc {
31 35
32 size_t CCTextureUpdateController::maxPartialTextureUpdates() 36 size_t CCTextureUpdateController::maxPartialUpdatesDefault()
33 { 37 {
34 return textureUpdatesPerTick; 38 return textureUpdatesPerFullTickMin;
39 }
40
41 size_t CCTextureUpdateController::maxPartialUpdates(TextureUploader* uploader)
42 {
43 return maxFullUpdatesPerTick(uploader);
44 }
45
46 size_t CCTextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploade r)
47 {
48 double texturesPerSecond = uploader->estimatedPixelsPerSecond() / pixelsPerT exture;
49
50 return std::max(textureUpdatesPerFullTickMin,
51 (size_t) floor(textureUpdateTickRate * texturesPerSecond));
35 } 52 }
36 53
37 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* que ue, size_t count) 54 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* que ue, size_t count)
brianderson 2012/09/18 00:45:52 The previous patch set had a few bugs that caused
38 { 55 {
56 TRACE_EVENT0("cc", "CCTextureUpdateController::updateTextures");
39 if (queue->fullUploadSize() || queue->partialUploadSize()) { 57 if (queue->fullUploadSize() || queue->partialUploadSize()) {
40 if (uploader->isBusy()) 58 if (uploader->isBusy())
41 return; 59 return;
42 60
43 uploader->beginUploads(); 61 uploader->beginUploads();
44 62
45 size_t fullUploadCount = 0; 63 size_t fullUploadCount = 0;
46 while (queue->fullUploadSize() && fullUploadCount < count) { 64 if (queue->fullUploadSize()) {
47 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload ()); 65 while (queue->fullUploadSize() && fullUploadCount < count) {
48 fullUploadCount++; 66 if (!(fullUploadCount % textureUploadFlushPeriod) && fullUploadC ount)
49 if (!(fullUploadCount % textureUploadFlushPeriod)) 67 resourceProvider->shallowFlushIfSupported();
68 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUp load());
69 fullUploadCount++;
70 }
71
72 bool cantUpdloadAllPartials = (count - fullUploadCount) < queue->par tialUploadSize();
73 if (cantUpdloadAllPartials) {
74 uploader->endUploads();
50 resourceProvider->shallowFlushIfSupported(); 75 resourceProvider->shallowFlushIfSupported();
76 return;
77 }
51 } 78 }
52 79
53 // Make sure there are no dangling uploads without a flush. 80 ASSERT(queue->partialUploadSize() <= (count - fullUploadCount));
54 if (fullUploadCount % textureUploadFlushPeriod)
55 resourceProvider->shallowFlushIfSupported();
56 81
57 bool moreUploads = queue->fullUploadSize(); 82 size_t partialUploadCount = 0;
58 83 if (queue->partialUploadSize()) {
59 ASSERT(queue->partialUploadSize() <= count); 84 if (fullUploadCount)
60 // We need another update batch if the number of updates remaining 85 resourceProvider->shallowFlushIfSupported();
61 // in |count| is greater than the remaining partial entries. 86 while (queue->partialUploadSize()) {
62 if ((count - fullUploadCount) < queue->partialUploadSize()) 87 if (!(partialUploadCount % textureUploadFlushPeriod) && partialU ploadCount)
63 moreUploads = true; 88 resourceProvider->shallowFlushIfSupported();
64 89 uploader->uploadTexture(resourceProvider, queue->takeFirstPartia lUpload());
65 if (moreUploads) { 90 partialUploadCount++;
66 uploader->endUploads(); 91 }
67 return;
68 } 92 }
69 93
70 size_t partialUploadCount = 0;
71 while (queue->partialUploadSize()) {
72 uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpl oad());
73 partialUploadCount++;
74 if (!(partialUploadCount % textureUploadFlushPeriod))
75 resourceProvider->shallowFlushIfSupported();
76 }
77
78 // Make sure there are no dangling partial uploads without a flush.
79 if (partialUploadCount % textureUploadFlushPeriod)
80 resourceProvider->shallowFlushIfSupported();
81
82 uploader->endUploads(); 94 uploader->endUploads();
95 resourceProvider->shallowFlushIfSupported();
83 } 96 }
84 97
85 size_t copyCount = 0; 98 size_t copyCount = 0;
86 while (queue->copySize()) { 99 while (queue->copySize()) {
87 copier->copyTexture(queue->takeFirstCopy()); 100 copier->copyTexture(queue->takeFirstCopy());
88 copyCount++; 101 copyCount++;
89 } 102 }
90 103
91 // If we've performed any texture copies, we need to insert a flush here int o the compositor context 104 // If we've performed any texture copies, we need to insert a flush here int o the compositor context
92 // before letting the main thread proceed as it may make draw calls to the s ource texture of one of 105 // before letting the main thread proceed as it may make draw calls to the s ource texture of one of
93 // our copy operations. 106 // our copy operations.
94 if (copyCount) 107 if (copyCount)
95 copier->flush(); 108 copier->flush();
96 } 109 }
97 110
98 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader) 111 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader, size_t maxPartialTextureUpdates)
99 : m_client(client) 112 : m_client(client)
100 , m_timer(adoptPtr(new CCTimer(thread, this))) 113 , m_timer(adoptPtr(new CCTimer(thread, this)))
101 , m_queue(queue) 114 , m_queue(queue)
102 , m_resourceProvider(resourceProvider) 115 , m_resourceProvider(resourceProvider)
103 , m_copier(copier) 116 , m_copier(copier)
104 , m_uploader(uploader) 117 , m_uploader(uploader)
105 , m_monotonicTimeLimit(0) 118 , m_monotonicTimeLimit(0)
119 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader))
120 , m_maxPartialTextureUpdates(maxPartialTextureUpdates)
106 , m_firstUpdateAttempt(true) 121 , m_firstUpdateAttempt(true)
107 { 122 {
108 } 123 }
109 124
110 CCTextureUpdateController::~CCTextureUpdateController() 125 CCTextureUpdateController::~CCTextureUpdateController()
111 { 126 {
112 } 127 }
113 128
114 void CCTextureUpdateController::performMoreUpdates( 129 void CCTextureUpdateController::performMoreUpdates(
115 double monotonicTimeLimit) 130 double monotonicTimeLimit)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return monotonicallyIncreasingTime(); 168 return monotonicallyIncreasingTime();
154 } 169 }
155 170
156 double CCTextureUpdateController::updateMoreTexturesTime() const 171 double CCTextureUpdateController::updateMoreTexturesTime() const
157 { 172 {
158 return textureUpdateTickRate; 173 return textureUpdateTickRate;
159 } 174 }
160 175
161 size_t CCTextureUpdateController::updateMoreTexturesSize() const 176 size_t CCTextureUpdateController::updateMoreTexturesSize() const
162 { 177 {
163 return textureUpdatesPerTick; 178 if (m_queue->fullUploadSize() && !m_queue->partialUploadSize())
179 return m_maxPartialTextureUpdates;
180 return m_textureUpdatesPerTick;
164 } 181 }
165 182
166 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() 183 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
167 { 184 {
168 // Uploader might be busy when we're too aggressive in our upload time 185 // Uploader might be busy when we're too aggressive in our upload time
169 // estimate. We use a different timeout here to prevent unnecessary 186 // estimate. We use a different timeout here to prevent unnecessary
170 // amounts of idle time. 187 // amounts of idle time.
171 if (m_uploader->isBusy()) { 188 if (m_uploader->isBusy()) {
172 m_timer->startOneShot(uploaderBusyTickRate); 189 m_timer->startOneShot(uploaderBusyTickRate);
173 return true; 190 return true;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 222 }
206 223
207 // Make sure there are no dangling partial uploads without a flush. 224 // Make sure there are no dangling partial uploads without a flush.
208 if (uploadCount % textureUploadFlushPeriod) 225 if (uploadCount % textureUploadFlushPeriod)
209 m_resourceProvider->shallowFlushIfSupported(); 226 m_resourceProvider->shallowFlushIfSupported();
210 227
211 m_uploader->endUploads(); 228 m_uploader->endUploads();
212 } 229 }
213 230
214 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698