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

Unified Diff: src/gpu/vk/GrVkMemory.h

Issue 2128673002: Pull out freelist allocation from GrVkSubHeap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up and fixes Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/gpu/vk/GrVkMemory.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkMemory.h
diff --git a/src/gpu/vk/GrVkMemory.h b/src/gpu/vk/GrVkMemory.h
index 2b9feda7b517b592ee25a1fd3cd2641fa088116c..4b746a3dc1dd15271eef0804a08a0f487a73f566 100644
--- a/src/gpu/vk/GrVkMemory.h
+++ b/src/gpu/vk/GrVkMemory.h
@@ -39,42 +39,75 @@ namespace GrVkMemory {
VkAccessFlags LayoutToSrcAccessMask(const VkImageLayout layout);
}
-class GrVkSubHeap {
+class GrVkFreeListAlloc {
public:
- GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex,
- VkDeviceSize size, VkDeviceSize alignment);
- ~GrVkSubHeap();
+ GrVkFreeListAlloc(VkDeviceSize size, VkDeviceSize alignment)
+ : fSize(size)
+ , fAlignment(alignment)
+ , fFreeSize(size)
+ , fLargestBlockSize(size)
+ , fLargestBlockOffset(0) {
+ Block* block = fFreeList.addToTail();
+ block->fOffset = 0;
+ block->fSize = fSize;
+ }
+ ~GrVkFreeListAlloc() {
+ this->reset();
+ }
- uint32_t memoryTypeIndex() const { return fMemoryTypeIndex; }
VkDeviceSize size() const { return fSize; }
VkDeviceSize alignment() const { return fAlignment; }
VkDeviceSize freeSize() const { return fFreeSize; }
VkDeviceSize largestBlockSize() const { return fLargestBlockSize; }
- VkDeviceMemory memory() { return fAlloc; }
bool unallocated() const { return fSize == fFreeSize; }
- bool alloc(VkDeviceSize size, GrVkAlloc* alloc);
- void free(const GrVkAlloc& alloc);
+protected:
+ bool alloc(VkDeviceSize requestedSize, VkDeviceSize* allocOffset, VkDeviceSize* allocSize);
+ void free(VkDeviceSize allocOffset, VkDeviceSize allocSize);
+
+ void reset() {
+ fSize = 0;
+ fAlignment = 0;
+ fFreeSize = 0;
+ fLargestBlockSize = 0;
+ fFreeList.reset();
+ }
-private:
struct Block {
VkDeviceSize fOffset;
VkDeviceSize fSize;
};
typedef SkTLList<Block, 16> FreeList;
- const GrVkGpu* fGpu;
- uint32_t fMemoryTypeIndex;
VkDeviceSize fSize;
VkDeviceSize fAlignment;
VkDeviceSize fFreeSize;
VkDeviceSize fLargestBlockSize;
VkDeviceSize fLargestBlockOffset;
- VkDeviceMemory fAlloc;
FreeList fFreeList;
};
+class GrVkSubHeap : public GrVkFreeListAlloc {
+public:
+ GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex,
+ VkDeviceSize size, VkDeviceSize alignment);
+ ~GrVkSubHeap();
+
+ uint32_t memoryTypeIndex() const { return fMemoryTypeIndex; }
+ VkDeviceMemory memory() { return fAlloc; }
+
+ bool alloc(VkDeviceSize requestedSize, GrVkAlloc* alloc);
+ void free(const GrVkAlloc& alloc);
+
+private:
+ const GrVkGpu* fGpu;
+ uint32_t fMemoryTypeIndex;
+ VkDeviceMemory fAlloc;
+
+ typedef GrVkFreeListAlloc INHERITED;
+};
+
class GrVkHeap {
public:
enum Strategy {
@@ -94,7 +127,7 @@ public:
}
}
- ~GrVkHeap();
+ ~GrVkHeap() {}
VkDeviceSize allocSize() const { return fAllocSize; }
VkDeviceSize usedSize() const { return fUsedSize; }
« no previous file with comments | « no previous file | src/gpu/vk/GrVkMemory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698