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 #ifdef SK_DEBUG |
| 109 uint32_t fHeapIndex; |
| 110 #endif |
108 uint32_t fMemoryTypeIndex; | 111 uint32_t fMemoryTypeIndex; |
109 VkDeviceMemory fAlloc; | 112 VkDeviceMemory fAlloc; |
110 | 113 |
111 typedef GrVkFreeListAlloc INHERITED; | 114 typedef GrVkFreeListAlloc INHERITED; |
112 }; | 115 }; |
113 | 116 |
114 class GrVkHeap { | 117 class GrVkHeap { |
115 public: | 118 public: |
116 enum Strategy { | 119 enum Strategy { |
117 kSubAlloc_Strategy, // alloc large subheaps and suballoc within th
em | 120 kSubAlloc_Strategy, // alloc large subheaps and suballoc within th
em |
(...skipping 10 matching lines...) Expand all Loading... |
128 } else { | 131 } else { |
129 fAllocFunc = &GrVkHeap::singleAlloc; | 132 fAllocFunc = &GrVkHeap::singleAlloc; |
130 } | 133 } |
131 } | 134 } |
132 | 135 |
133 ~GrVkHeap() {} | 136 ~GrVkHeap() {} |
134 | 137 |
135 VkDeviceSize allocSize() const { return fAllocSize; } | 138 VkDeviceSize allocSize() const { return fAllocSize; } |
136 VkDeviceSize usedSize() const { return fUsedSize; } | 139 VkDeviceSize usedSize() const { return fUsedSize; } |
137 | 140 |
138 bool alloc(VkDeviceSize size, VkDeviceSize alignment, uint32_t memoryTypeInd
ex, | 141 bool alloc(VkDeviceSize size, VkDeviceSize alignment, uint32_t memoryTypeInd
ex, |
139 GrVkAlloc* alloc) { | 142 uint32_t heapIndex, GrVkAlloc* alloc) { |
140 SkASSERT(size > 0); | 143 SkASSERT(size > 0); |
141 return (*this.*fAllocFunc)(size, alignment, memoryTypeIndex, alloc); | 144 return (*this.*fAllocFunc)(size, alignment, memoryTypeIndex, heapIndex,
alloc); |
142 } | 145 } |
143 bool free(const GrVkAlloc& alloc); | 146 bool free(const GrVkAlloc& alloc); |
144 | 147 |
145 private: | 148 private: |
146 typedef bool (GrVkHeap::*AllocFunc)(VkDeviceSize size, VkDeviceSize alignmen
t, | 149 typedef bool (GrVkHeap::*AllocFunc)(VkDeviceSize size, VkDeviceSize alignmen
t, |
147 uint32_t memoryTypeIndex, GrVkAlloc* all
oc); | 150 uint32_t memoryTypeIndex, uint32_t heapI
ndex, |
| 151 GrVkAlloc* alloc); |
148 | 152 |
149 bool subAlloc(VkDeviceSize size, VkDeviceSize alignment, | 153 bool subAlloc(VkDeviceSize size, VkDeviceSize alignment, |
150 uint32_t memoryTypeIndex, GrVkAlloc* alloc); | 154 uint32_t memoryTypeIndex, uint32_t heapIndex, |
| 155 GrVkAlloc* alloc); |
151 bool singleAlloc(VkDeviceSize size, VkDeviceSize alignment, | 156 bool singleAlloc(VkDeviceSize size, VkDeviceSize alignment, |
152 uint32_t memoryTypeIndex, GrVkAlloc* alloc); | 157 uint32_t memoryTypeIndex, uint32_t heapIndex, |
| 158 GrVkAlloc* alloc); |
153 | 159 |
154 const GrVkGpu* fGpu; | 160 const GrVkGpu* fGpu; |
155 VkDeviceSize fSubHeapSize; | 161 VkDeviceSize fSubHeapSize; |
156 VkDeviceSize fAllocSize; | 162 VkDeviceSize fAllocSize; |
157 VkDeviceSize fUsedSize; | 163 VkDeviceSize fUsedSize; |
158 AllocFunc fAllocFunc; | 164 AllocFunc fAllocFunc; |
159 SkTArray<SkAutoTDelete<GrVkSubHeap>> fSubHeaps; | 165 SkTArray<SkAutoTDelete<GrVkSubHeap>> fSubHeaps; |
160 }; | 166 }; |
161 #endif | 167 #endif |
OLD | NEW |