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 #ifndef GrVkMemory_DEFINED | 8 #ifndef GrVkMemory_DEFINED |
9 #define GrVkMemory_DEFINED | 9 #define GrVkMemory_DEFINED |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 VkDeviceSize fSize; | 86 VkDeviceSize fSize; |
87 VkDeviceSize fAlignment; | 87 VkDeviceSize fAlignment; |
88 VkDeviceSize fFreeSize; | 88 VkDeviceSize fFreeSize; |
89 VkDeviceSize fLargestBlockSize; | 89 VkDeviceSize fLargestBlockSize; |
90 VkDeviceSize fLargestBlockOffset; | 90 VkDeviceSize fLargestBlockOffset; |
91 FreeList fFreeList; | 91 FreeList fFreeList; |
92 }; | 92 }; |
93 | 93 |
94 class GrVkSubHeap : public GrVkFreeListAlloc { | 94 class GrVkSubHeap : public GrVkFreeListAlloc { |
95 public: | 95 public: |
96 GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex, | 96 GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex, uint32_t heapIndex
, |
97 VkDeviceSize size, VkDeviceSize alignment); | 97 VkDeviceSize size, VkDeviceSize alignment); |
98 ~GrVkSubHeap(); | 98 ~GrVkSubHeap(); |
99 | 99 |
100 uint32_t memoryTypeIndex() const { return fMemoryTypeIndex; } | 100 uint32_t memoryTypeIndex() const { return fMemoryTypeIndex; } |
101 VkDeviceMemory memory() { return fAlloc; } | 101 VkDeviceMemory memory() { return fAlloc; } |
102 | 102 |
103 bool alloc(VkDeviceSize requestedSize, GrVkAlloc* alloc); | 103 bool alloc(VkDeviceSize requestedSize, GrVkAlloc* alloc); |
104 void free(const GrVkAlloc& alloc); | 104 void free(const GrVkAlloc& alloc); |
105 | 105 |
106 private: | 106 private: |
107 const GrVkGpu* fGpu; | 107 const GrVkGpu* fGpu; |
108 uint32_t fMemoryTypeIndex; | 108 uint32_t fMemoryTypeIndex; |
| 109 uint32_t fHeapIndex; |
109 VkDeviceMemory fAlloc; | 110 VkDeviceMemory fAlloc; |
110 | 111 |
111 typedef GrVkFreeListAlloc INHERITED; | 112 typedef GrVkFreeListAlloc INHERITED; |
112 }; | 113 }; |
113 | 114 |
114 class GrVkHeap { | 115 class GrVkHeap { |
115 public: | 116 public: |
116 enum Strategy { | 117 enum Strategy { |
117 kSubAlloc_Strategy, // alloc large subheaps and suballoc within th
em | 118 kSubAlloc_Strategy, // alloc large subheaps and suballoc within th
em |
118 kSingleAlloc_Strategy // alloc/recycle an individual subheap per obj
ect | 119 kSingleAlloc_Strategy // alloc/recycle an individual subheap per obj
ect |
119 }; | 120 }; |
120 | 121 |
121 GrVkHeap(const GrVkGpu* gpu, Strategy strategy, VkDeviceSize subHeapSize) | 122 GrVkHeap(const GrVkGpu* gpu, Strategy strategy, VkDeviceSize subHeapSize) |
122 : fGpu(gpu) | 123 : fGpu(gpu) |
123 , fSubHeapSize(subHeapSize) | 124 , fSubHeapSize(subHeapSize) |
124 , fAllocSize(0) | 125 , fAllocSize(0) |
125 , fUsedSize(0) { | 126 , fUsedSize(0) { |
126 if (strategy == kSubAlloc_Strategy) { | 127 if (strategy == kSubAlloc_Strategy) { |
127 fAllocFunc = &GrVkHeap::subAlloc; | 128 fAllocFunc = &GrVkHeap::subAlloc; |
128 } else { | 129 } else { |
129 fAllocFunc = &GrVkHeap::singleAlloc; | 130 fAllocFunc = &GrVkHeap::singleAlloc; |
130 } | 131 } |
131 } | 132 } |
132 | 133 |
133 ~GrVkHeap() {} | 134 ~GrVkHeap() {} |
134 | 135 |
135 VkDeviceSize allocSize() const { return fAllocSize; } | 136 VkDeviceSize allocSize() const { return fAllocSize; } |
136 VkDeviceSize usedSize() const { return fUsedSize; } | 137 VkDeviceSize usedSize() const { return fUsedSize; } |
137 | 138 |
138 bool alloc(VkDeviceSize size, VkDeviceSize alignment, uint32_t memoryTypeInd
ex, | 139 bool alloc(VkDeviceSize size, VkDeviceSize alignment, uint32_t memoryTypeInd
ex, |
139 GrVkAlloc* alloc) { | 140 uint32_t heapIndex, GrVkAlloc* alloc) { |
140 SkASSERT(size > 0); | 141 SkASSERT(size > 0); |
141 return (*this.*fAllocFunc)(size, alignment, memoryTypeIndex, alloc); | 142 return (*this.*fAllocFunc)(size, alignment, memoryTypeIndex, heapIndex,
alloc); |
142 } | 143 } |
143 bool free(const GrVkAlloc& alloc); | 144 bool free(const GrVkAlloc& alloc); |
144 | 145 |
145 private: | 146 private: |
146 typedef bool (GrVkHeap::*AllocFunc)(VkDeviceSize size, VkDeviceSize alignmen
t, | 147 typedef bool (GrVkHeap::*AllocFunc)(VkDeviceSize size, VkDeviceSize alignmen
t, |
147 uint32_t memoryTypeIndex, GrVkAlloc* all
oc); | 148 uint32_t memoryTypeIndex, uint32_t heapI
ndex, |
| 149 GrVkAlloc* alloc); |
148 | 150 |
149 bool subAlloc(VkDeviceSize size, VkDeviceSize alignment, | 151 bool subAlloc(VkDeviceSize size, VkDeviceSize alignment, |
150 uint32_t memoryTypeIndex, GrVkAlloc* alloc); | 152 uint32_t memoryTypeIndex, uint32_t heapIndex, |
| 153 GrVkAlloc* alloc); |
151 bool singleAlloc(VkDeviceSize size, VkDeviceSize alignment, | 154 bool singleAlloc(VkDeviceSize size, VkDeviceSize alignment, |
152 uint32_t memoryTypeIndex, GrVkAlloc* alloc); | 155 uint32_t memoryTypeIndex, uint32_t heapIndex, |
| 156 GrVkAlloc* alloc); |
153 | 157 |
154 const GrVkGpu* fGpu; | 158 const GrVkGpu* fGpu; |
155 VkDeviceSize fSubHeapSize; | 159 VkDeviceSize fSubHeapSize; |
156 VkDeviceSize fAllocSize; | 160 VkDeviceSize fAllocSize; |
157 VkDeviceSize fUsedSize; | 161 VkDeviceSize fUsedSize; |
158 AllocFunc fAllocFunc; | 162 AllocFunc fAllocFunc; |
159 SkTArray<SkAutoTDelete<GrVkSubHeap>> fSubHeaps; | 163 SkTArray<SkAutoTDelete<GrVkSubHeap>> fSubHeaps; |
160 }; | 164 }; |
161 #endif | 165 #endif |
OLD | NEW |