| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrVkMemory.h" | 8 #include "GrVkMemory.h" |
| 9 | 9 |
| 10 #include "GrVkGpu.h" | 10 #include "GrVkGpu.h" |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 return false; | 369 return false; |
| 370 } | 370 } |
| 371 | 371 |
| 372 | 372 |
| 373 void GrVkSubHeap::free(const GrVkAlloc& alloc) { | 373 void GrVkSubHeap::free(const GrVkAlloc& alloc) { |
| 374 SkASSERT(alloc.fMemory == fAlloc); | 374 SkASSERT(alloc.fMemory == fAlloc); |
| 375 | 375 |
| 376 // find the block right after this allocation | 376 // find the block right after this allocation |
| 377 FreeList::Iter iter = fFreeList.headIter(); | 377 FreeList::Iter iter = fFreeList.headIter(); |
| 378 FreeList::Iter prev; |
| 378 while (iter.get() && iter.get()->fOffset < alloc.fOffset) { | 379 while (iter.get() && iter.get()->fOffset < alloc.fOffset) { |
| 380 prev = iter; |
| 379 iter.next(); | 381 iter.next(); |
| 380 } | 382 } |
| 381 FreeList::Iter prev = iter; | |
| 382 prev.prev(); | |
| 383 // we have four cases: | 383 // we have four cases: |
| 384 // we exactly follow the previous one | 384 // we exactly follow the previous one |
| 385 Block* block; | 385 Block* block; |
| 386 if (prev.get() && prev.get()->fOffset + prev.get()->fSize == alloc.fOffset)
{ | 386 if (prev.get() && prev.get()->fOffset + prev.get()->fSize == alloc.fOffset)
{ |
| 387 block = prev.get(); | 387 block = prev.get(); |
| 388 block->fSize += alloc.fSize; | 388 block->fSize += alloc.fSize; |
| 389 if (block->fOffset == fLargestBlockOffset) { | 389 if (block->fOffset == fLargestBlockOffset) { |
| 390 fLargestBlockSize = block->fSize; | 390 fLargestBlockSize = block->fSize; |
| 391 } | 391 } |
| 392 // and additionally we may exactly precede the next one | 392 // and additionally we may exactly precede the next one |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment, | 439 bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment, |
| 440 uint32_t memoryTypeIndex, GrVkAlloc* alloc) { | 440 uint32_t memoryTypeIndex, GrVkAlloc* alloc) { |
| 441 VkDeviceSize alignedSize = align_size(size, alignment); | 441 VkDeviceSize alignedSize = align_size(size, alignment); |
| 442 | 442 |
| 443 // first try to find a subheap that fits our allocation request | 443 // first try to find a subheap that fits our allocation request |
| 444 int bestFitIndex = -1; | 444 int bestFitIndex = -1; |
| 445 VkDeviceSize bestFitSize = 0x7FFFFFFF; | 445 VkDeviceSize bestFitSize = 0x7FFFFFFF; |
| 446 for (auto i = 0; i < fSubHeaps.count(); ++i) { | 446 for (auto i = 0; i < fSubHeaps.count(); ++i) { |
| 447 if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex) { | 447 if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex) { |
| 448 VkDeviceSize heapSize = fSubHeaps[i]->largestBlockSize(); | 448 VkDeviceSize heapSize = fSubHeaps[i]->largestBlockSize(); |
| 449 if (heapSize > alignedSize && heapSize < bestFitSize) { | 449 if (heapSize >= alignedSize && heapSize < bestFitSize) { |
| 450 bestFitIndex = i; | 450 bestFitIndex = i; |
| 451 bestFitSize = heapSize; | 451 bestFitSize = heapSize; |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 if (bestFitIndex >= 0) { | 456 if (bestFitIndex >= 0) { |
| 457 SkASSERT(fSubHeaps[bestFitIndex]->alignment() == alignment); | 457 SkASSERT(fSubHeaps[bestFitIndex]->alignment() == alignment); |
| 458 if (fSubHeaps[bestFitIndex]->alloc(size, alloc)) { | 458 if (fSubHeaps[bestFitIndex]->alloc(size, alloc)) { |
| 459 fUsedSize += alloc->fSize; | 459 fUsedSize += alloc->fSize; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 477 bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment, | 477 bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment, |
| 478 uint32_t memoryTypeIndex, GrVkAlloc* alloc) { | 478 uint32_t memoryTypeIndex, GrVkAlloc* alloc) { |
| 479 VkDeviceSize alignedSize = align_size(size, alignment); | 479 VkDeviceSize alignedSize = align_size(size, alignment); |
| 480 | 480 |
| 481 // first try to find an unallocated subheap that fits our allocation request | 481 // first try to find an unallocated subheap that fits our allocation request |
| 482 int bestFitIndex = -1; | 482 int bestFitIndex = -1; |
| 483 VkDeviceSize bestFitSize = 0x7FFFFFFF; | 483 VkDeviceSize bestFitSize = 0x7FFFFFFF; |
| 484 for (auto i = 0; i < fSubHeaps.count(); ++i) { | 484 for (auto i = 0; i < fSubHeaps.count(); ++i) { |
| 485 if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex && fSubHeaps[i]->
unallocated()) { | 485 if (fSubHeaps[i]->memoryTypeIndex() == memoryTypeIndex && fSubHeaps[i]->
unallocated()) { |
| 486 VkDeviceSize heapSize = fSubHeaps[i]->size(); | 486 VkDeviceSize heapSize = fSubHeaps[i]->size(); |
| 487 if (heapSize > alignedSize && heapSize < bestFitSize) { | 487 if (heapSize >= alignedSize && heapSize < bestFitSize) { |
| 488 bestFitIndex = i; | 488 bestFitIndex = i; |
| 489 bestFitSize = heapSize; | 489 bestFitSize = heapSize; |
| 490 } | 490 } |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 if (bestFitIndex >= 0) { | 494 if (bestFitIndex >= 0) { |
| 495 SkASSERT(fSubHeaps[bestFitIndex]->alignment() == alignment); | 495 SkASSERT(fSubHeaps[bestFitIndex]->alignment() == alignment); |
| 496 if (fSubHeaps[bestFitIndex]->alloc(size, alloc)) { | 496 if (fSubHeaps[bestFitIndex]->alloc(size, alloc)) { |
| 497 fUsedSize += alloc->fSize; | 497 fUsedSize += alloc->fSize; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 518 fSubHeaps[i]->free(alloc); | 518 fSubHeaps[i]->free(alloc); |
| 519 fUsedSize -= alloc.fSize; | 519 fUsedSize -= alloc.fSize; |
| 520 return true; | 520 return true; |
| 521 } | 521 } |
| 522 } | 522 } |
| 523 | 523 |
| 524 return false; | 524 return false; |
| 525 } | 525 } |
| 526 | 526 |
| 527 | 527 |
| OLD | NEW |