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

Side by Side Diff: src/gpu/GrResourceCache2.cpp

Issue 721353002: Allow GPU resources to not be counted against the cache budget. (Closed) Base URL: https://skia.googlesource.com/skia.git@wrap
Patch Set: update Created 6 years, 1 month 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 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrResourceCache2.h" 10 #include "GrResourceCache2.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 SkASSERT(!this->isInCache(resource)); 97 SkASSERT(!this->isInCache(resource));
98 SkASSERT(!fPurging); 98 SkASSERT(!fPurging);
99 fResources.addToHead(resource); 99 fResources.addToHead(resource);
100 resource->ref(); 100 resource->ref();
101 101
102 size_t size = resource->gpuMemorySize(); 102 size_t size = resource->gpuMemorySize();
103 ++fCount; 103 ++fCount;
104 SkDEBUGCODE(fHighWaterCount = SkTMax(fCount, fHighWaterCount)); 104 SkDEBUGCODE(fHighWaterCount = SkTMax(fCount, fHighWaterCount));
105 fBytes += size; 105 fBytes += size;
106 SkDEBUGCODE(fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes)); 106 SkDEBUGCODE(fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes));
107 if (!resource->cacheAccess().isWrapped()) { 107 if (resource->cacheAccess().isBudgeted()) {
bsalomon 2014/11/13 19:20:54 Previously isWrapped() controlled whether a resour
108 ++fBudgetedCount; 108 ++fBudgetedCount;
109 SkDEBUGCODE(fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHi ghWaterCount)); 109 SkDEBUGCODE(fBudgetedHighWaterCount = SkTMax(fBudgetedCount, fBudgetedHi ghWaterCount));
110 fBudgetedBytes += size; 110 fBudgetedBytes += size;
111 SkDEBUGCODE(fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHi ghWaterBytes)); 111 SkDEBUGCODE(fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHi ghWaterBytes));
112 } 112 }
113 if (!resource->cacheAccess().getScratchKey().isNullScratch()) { 113 if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
114 // TODO(bsalomon): Make this assertion possible. 114 SkASSERT(!resource->cacheAccess().isWrapped());
115 // SkASSERT(!resource->isWrapped());
116 fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource); 115 fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource);
117 } 116 }
118 117
119 this->purgeAsNeeded(); 118 this->purgeAsNeeded();
120 } 119 }
121 120
122 void GrResourceCache2::removeResource(GrGpuResource* resource) { 121 void GrResourceCache2::removeResource(GrGpuResource* resource) {
123 AutoValidate av(this); 122 AutoValidate av(this);
124 123
125 SkASSERT(this->isInCache(resource)); 124 SkASSERT(this->isInCache(resource));
126 125
127 size_t size = resource->gpuMemorySize(); 126 size_t size = resource->gpuMemorySize();
128 --fCount; 127 --fCount;
129 fBytes -= size; 128 fBytes -= size;
130 if (!resource->cacheAccess().isWrapped()) { 129 if (resource->cacheAccess().isBudgeted()) {
131 --fBudgetedCount; 130 --fBudgetedCount;
132 fBudgetedBytes -= size; 131 fBudgetedBytes -= size;
133 } 132 }
134 133
135 fResources.remove(resource); 134 fResources.remove(resource);
136 if (!resource->cacheAccess().getScratchKey().isNullScratch()) { 135 if (!resource->cacheAccess().getScratchKey().isNullScratch()) {
137 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); 136 fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource);
138 } 137 }
139 if (const GrResourceKey* contentKey = resource->cacheAccess().getContentKey( )) { 138 if (const GrResourceKey* contentKey = resource->cacheAccess().getContentKey( )) {
140 fContentHash.remove(*contentKey); 139 fContentHash.remove(*contentKey);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 178 }
180 179
181 class GrResourceCache2::AvailableForScratchUse { 180 class GrResourceCache2::AvailableForScratchUse {
182 public: 181 public:
183 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin gIO) { } 182 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin gIO) { }
184 183
185 bool operator()(const GrGpuResource* resource) const { 184 bool operator()(const GrGpuResource* resource) const {
186 if (!resource->reffedOnlyByCache() || !resource->cacheAccess().isScratch ()) { 185 if (!resource->reffedOnlyByCache() || !resource->cacheAccess().isScratch ()) {
187 return false; 186 return false;
188 } 187 }
189
190 return !fRejectPendingIO || !resource->internalHasPendingIO(); 188 return !fRejectPendingIO || !resource->internalHasPendingIO();
191 } 189 }
192 190
193 private: 191 private:
194 bool fRejectPendingIO; 192 bool fRejectPendingIO;
195 }; 193 };
196 194
197 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey, 195 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey,
198 uint32_t flags) { 196 uint32_t flags) {
199 AutoValidate av(this); 197 AutoValidate av(this);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 291
294 void GrResourceCache2::didChangeGpuMemorySize(const GrGpuResource* resource, siz e_t oldSize) { 292 void GrResourceCache2::didChangeGpuMemorySize(const GrGpuResource* resource, siz e_t oldSize) {
295 // SkASSERT(!fPurging); GrPathRange increases size during flush. :( 293 // SkASSERT(!fPurging); GrPathRange increases size during flush. :(
296 SkASSERT(resource); 294 SkASSERT(resource);
297 SkASSERT(this->isInCache(resource)); 295 SkASSERT(this->isInCache(resource));
298 296
299 ptrdiff_t delta = resource->gpuMemorySize() - oldSize; 297 ptrdiff_t delta = resource->gpuMemorySize() - oldSize;
300 298
301 fBytes += delta; 299 fBytes += delta;
302 SkDEBUGCODE(fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes)); 300 SkDEBUGCODE(fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes));
303 if (!resource->cacheAccess().isWrapped()) { 301 if (resource->cacheAccess().isBudgeted()) {
304 fBudgetedBytes += delta; 302 fBudgetedBytes += delta;
305 SkDEBUGCODE(fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHi ghWaterBytes)); 303 SkDEBUGCODE(fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHi ghWaterBytes));
306 } 304 }
307 305
308 this->purgeAsNeeded(); 306 this->purgeAsNeeded();
309 this->validate(); 307 this->validate();
310 } 308 }
311 309
310 void GrResourceCache2::didChangeBudgetStatus(GrGpuResource* resource) {
311 SkASSERT(!fPurging);
312 SkASSERT(resource);
313 SkASSERT(this->isInCache(resource));
314
315 size_t size = resource->gpuMemorySize();
316
317 if (resource->cacheAccess().isBudgeted()) {
318 ++fBudgetedCount;
319 fBudgetedBytes += size;
320 this->purgeAsNeeded();
321 } else {
322 --fBudgetedCount;
323 fBudgetedBytes -= size;
324 }
325
326 this->validate();
327 }
328
329
312 void GrResourceCache2::internalPurgeAsNeeded() { 330 void GrResourceCache2::internalPurgeAsNeeded() {
313 SkASSERT(!fPurging); 331 SkASSERT(!fPurging);
314 SkASSERT(!fNewlyPurgableResourceWhilePurging); 332 SkASSERT(!fNewlyPurgableResourceWhilePurging);
315 SkASSERT(fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxBytes); 333 SkASSERT(fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxBytes);
316 334
317 fPurging = true; 335 fPurging = true;
318 336
319 AutoValidate av(this); // Put this after setting fPurging so we're allowed t o be over budget. 337 AutoValidate av(this); // Put this after setting fPurging so we're allowed t o be over budget.
320 338
321 bool overBudget = true; 339 bool overBudget = true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK ey())); 426 SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchK ey()));
409 SkASSERT(!resource->cacheAccess().isWrapped()); 427 SkASSERT(!resource->cacheAccess().isWrapped());
410 } 428 }
411 429
412 if (const GrResourceKey* contentKey = resource->cacheAccess().getContent Key()) { 430 if (const GrResourceKey* contentKey = resource->cacheAccess().getContent Key()) {
413 ++content; 431 ++content;
414 SkASSERT(fContentHash.find(*contentKey) == resource); 432 SkASSERT(fContentHash.find(*contentKey) == resource);
415 SkASSERT(!resource->cacheAccess().isWrapped()); 433 SkASSERT(!resource->cacheAccess().isWrapped());
416 } 434 }
417 435
418 if (!resource->cacheAccess().isWrapped()) { 436 if (resource->cacheAccess().isBudgeted()) {
419 ++budgetedCount; 437 ++budgetedCount;
420 budgetedBytes += resource->gpuMemorySize(); 438 budgetedBytes += resource->gpuMemorySize();
421 } 439 }
422 } 440 }
423 441
424 SkASSERT(fBudgetedCount <= fCount); 442 SkASSERT(fBudgetedCount <= fCount);
425 SkASSERT(fBudgetedBytes <= fBudgetedBytes); 443 SkASSERT(fBudgetedBytes <= fBudgetedBytes);
426 SkASSERT(bytes == fBytes); 444 SkASSERT(bytes == fBytes);
427 SkASSERT(count == fCount); 445 SkASSERT(count == fCount);
428 SkASSERT(budgetedBytes == fBudgetedBytes); 446 SkASSERT(budgetedBytes == fBudgetedBytes);
(...skipping 13 matching lines...) Expand all
442 SkASSERT(!overBudget || locked == count || fPurging); 460 SkASSERT(!overBudget || locked == count || fPurging);
443 } 461 }
444 #endif 462 #endif
445 463
446 #if GR_CACHE_STATS 464 #if GR_CACHE_STATS
447 void GrResourceCache2::printStats() const { 465 void GrResourceCache2::printStats() const {
448 this->validate(); 466 this->validate();
449 467
450 int locked = 0; 468 int locked = 0;
451 int scratch = 0; 469 int scratch = 0;
470 int wrapped = 0;
452 471
453 ResourceList::Iter iter; 472 ResourceList::Iter iter;
454 GrGpuResource* resource = iter.init(fResources, ResourceList::Iter::kHead_It erStart); 473 GrGpuResource* resource = iter.init(fResources, ResourceList::Iter::kHead_It erStart);
455 474
456 for ( ; resource; resource = iter.next()) { 475 for ( ; resource; resource = iter.next()) {
457 if (!resource->isPurgable()) { 476 if (!resource->isPurgable()) {
458 ++locked; 477 ++locked;
459 } 478 }
460 if (resource->cacheAccess().isScratch()) { 479 if (resource->cacheAccess().isScratch()) {
461 ++scratch; 480 ++scratch;
462 } 481 }
482 if (resource->cacheAccess().isWrapped()) {
483 ++wrapped;
484 }
463 } 485 }
464 486
465 float countUtilization = (100.f * fBudgetedCount) / fMaxCount; 487 float countUtilization = (100.f * fBudgetedCount) / fMaxCount;
466 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes; 488 float byteUtilization = (100.f * fBudgetedBytes) / fMaxBytes;
467 489
468 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); 490 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
469 SkDebugf( 491 SkDebugf(
470 "\t\tEntry Count: current %d (%d budgeted, %d locked, %d scratch %.2g%% full), high %d\n", 492 "\t\tEntry Count: current %d (%d budgeted, %d wrapped, %d locked, %d scr atch %.2g%% full), high %d\n",
egdaniel 2014/11/13 20:47:32 over 100, but not the easiest to make look nice...
bsalomon 2014/11/13 20:53:34 wrapped
471 fCount, fBudgetedCount, locked, scratch, countUtilization, fHighWaterCou nt); 493 fCount, fBudgetedCount, wrapped, locked, scratch, countUtilization, fHig hWaterCount);
472 SkDebugf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full) high %d\n", 494 SkDebugf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full) high %d\n",
473 fBytes, fBudgetedBytes, byteUtilization, fHighWaterBytes); 495 fBytes, fBudgetedBytes, byteUtilization, fHighWaterBytes);
474 } 496 }
475 497
476 #endif 498 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698