| 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 // This is a GPU-backend specific test. It relies on static intializers to work | 8 // This is a GPU-backend specific test. It relies on static intializers to work |
| 9 | 9 |
| 10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
| 11 | 11 |
| 12 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_VULKAN) | 12 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_VULKAN) |
| 13 | 13 |
| 14 #include "GrContextFactory.h" | 14 #include "GrContextFactory.h" |
| 15 #include "GrTest.h" | 15 #include "GrTest.h" |
| 16 #include "Test.h" | 16 #include "Test.h" |
| 17 #include "vk/GrVkGpu.h" | 17 #include "vk/GrVkGpu.h" |
| 18 | 18 |
| 19 using sk_gpu_test::GrContextFactory; | 19 using sk_gpu_test::GrContextFactory; |
| 20 | 20 |
| 21 void subheap_test(skiatest::Reporter* reporter, GrContext* context) { | 21 void subheap_test(skiatest::Reporter* reporter, GrContext* context) { |
| 22 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | 22 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 23 | 23 |
| 24 // memtype doesn't matter, we're just testing the suballocation algorithm so
we'll use 0 | 24 // heap index doesn't matter, we're just testing the suballocation algorithm
so we'll use 0 |
| 25 GrVkSubHeap heap(gpu, 0, 0, 64 * 1024, 32); | 25 GrVkSubHeap heap(gpu, 0, 64 * 1024, 32); |
| 26 GrVkAlloc alloc0, alloc1, alloc2, alloc3; | 26 GrVkAlloc alloc0, alloc1, alloc2, alloc3; |
| 27 // test full allocation and free | 27 // test full allocation and free |
| 28 REPORTER_ASSERT(reporter, heap.alloc(64 * 1024, &alloc0)); | 28 REPORTER_ASSERT(reporter, heap.alloc(64 * 1024, &alloc0)); |
| 29 REPORTER_ASSERT(reporter, alloc0.fOffset == 0); | 29 REPORTER_ASSERT(reporter, alloc0.fOffset == 0); |
| 30 REPORTER_ASSERT(reporter, alloc0.fSize == 64 * 1024); | 30 REPORTER_ASSERT(reporter, alloc0.fSize == 64 * 1024); |
| 31 REPORTER_ASSERT(reporter, heap.freeSize() == 0 && heap.largestBlockSize() ==
0); | 31 REPORTER_ASSERT(reporter, heap.freeSize() == 0 && heap.largestBlockSize() ==
0); |
| 32 heap.free(alloc0); | 32 heap.free(alloc0); |
| 33 REPORTER_ASSERT(reporter, heap.freeSize() == 64*1024 && heap.largestBlockSiz
e() == 64 * 1024); | 33 REPORTER_ASSERT(reporter, heap.freeSize() == 64*1024 && heap.largestBlockSiz
e() == 64 * 1024); |
| 34 | 34 |
| 35 // now let's suballoc some memory | 35 // now let's suballoc some memory |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 REPORTER_ASSERT(reporter, heap.freeSize() == 19 * 1024 && heap.largestBlockS
ize() == 19 * 1024); | 111 REPORTER_ASSERT(reporter, heap.freeSize() == 19 * 1024 && heap.largestBlockS
ize() == 19 * 1024); |
| 112 heap.free(alloc1); | 112 heap.free(alloc1); |
| 113 REPORTER_ASSERT(reporter, heap.freeSize() == 24 * 1024 && heap.largestBlockS
ize() == 24 * 1024); | 113 REPORTER_ASSERT(reporter, heap.freeSize() == 24 * 1024 && heap.largestBlockS
ize() == 24 * 1024); |
| 114 heap.free(alloc0); | 114 heap.free(alloc0); |
| 115 REPORTER_ASSERT(reporter, heap.freeSize() == 64 * 1024 && heap.largestBlockS
ize() == 64 * 1024); | 115 REPORTER_ASSERT(reporter, heap.freeSize() == 64 * 1024 && heap.largestBlockS
ize() == 64 * 1024); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void suballoc_test(skiatest::Reporter* reporter, GrContext* context) { | 118 void suballoc_test(skiatest::Reporter* reporter, GrContext* context) { |
| 119 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | 119 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 120 | 120 |
| 121 // memtype/heap index don't matter, we're just testing the allocation algori
thm so we'll use 0 | 121 // heap index doesn't matter, we're just testing the allocation algorithm so
we'll use 0 |
| 122 GrVkHeap heap(gpu, GrVkHeap::kSubAlloc_Strategy, 64 * 1024); | 122 GrVkHeap heap(gpu, GrVkHeap::kSubAlloc_Strategy, 64 * 1024); |
| 123 GrVkAlloc alloc0, alloc1, alloc2, alloc3; | 123 GrVkAlloc alloc0, alloc1, alloc2, alloc3; |
| 124 const VkDeviceSize kAlignment = 16; | 124 const VkDeviceSize kAlignment = 16; |
| 125 const uint32_t kMemType = 0; | |
| 126 const uint32_t kHeapIndex = 0; | 125 const uint32_t kHeapIndex = 0; |
| 127 | 126 |
| 128 REPORTER_ASSERT(reporter, heap.allocSize() == 0 && heap.usedSize() == 0); | 127 REPORTER_ASSERT(reporter, heap.allocSize() == 0 && heap.usedSize() == 0); |
| 129 | 128 |
| 130 // fragment allocations so we need to grow heap | 129 // fragment allocations so we need to grow heap |
| 131 REPORTER_ASSERT(reporter, heap.alloc(19 * 1024 - 3, kAlignment, kMemType, kH
eapIndex, &alloc0)); | 130 REPORTER_ASSERT(reporter, heap.alloc(19 * 1024 - 3, kAlignment, kHeapIndex,
&alloc0)); |
| 132 REPORTER_ASSERT(reporter, heap.alloc(5 * 1024 - 9, kAlignment, kMemType, kHe
apIndex, &alloc1)); | 131 REPORTER_ASSERT(reporter, heap.alloc(5 * 1024 - 9, kAlignment, kHeapIndex, &
alloc1)); |
| 133 REPORTER_ASSERT(reporter, heap.alloc(15 * 1024 - 15, kAlignment, kMemType, k
HeapIndex, &alloc2)); | 132 REPORTER_ASSERT(reporter, heap.alloc(15 * 1024 - 15, kAlignment, kHeapIndex,
&alloc2)); |
| 134 REPORTER_ASSERT(reporter, heap.alloc(3 * 1024 - 6, kAlignment, kMemType, kHe
apIndex, &alloc3)); | 133 REPORTER_ASSERT(reporter, heap.alloc(3 * 1024 - 6, kAlignment, kHeapIndex, &
alloc3)); |
| 135 REPORTER_ASSERT(reporter, heap.allocSize() == 64 * 1024 && heap.usedSize() =
= 42 * 1024); | 134 REPORTER_ASSERT(reporter, heap.allocSize() == 64 * 1024 && heap.usedSize() =
= 42 * 1024); |
| 136 heap.free(alloc0); | 135 heap.free(alloc0); |
| 137 REPORTER_ASSERT(reporter, heap.allocSize() == 64 * 1024 && heap.usedSize() =
= 23 * 1024); | 136 REPORTER_ASSERT(reporter, heap.allocSize() == 64 * 1024 && heap.usedSize() =
= 23 * 1024); |
| 138 heap.free(alloc2); | 137 heap.free(alloc2); |
| 139 REPORTER_ASSERT(reporter, heap.allocSize() == 64 * 1024 && heap.usedSize() =
= 8 * 1024); | 138 REPORTER_ASSERT(reporter, heap.allocSize() == 64 * 1024 && heap.usedSize() =
= 8 * 1024); |
| 140 // we expect the heap to grow here | 139 // we expect the heap to grow here |
| 141 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc0)); | 140 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kHeapIndex, &all
oc0)); |
| 142 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 48 * 1024); | 141 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 48 * 1024); |
| 143 heap.free(alloc3); | 142 heap.free(alloc3); |
| 144 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 45 * 1024); | 143 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 45 * 1024); |
| 145 // heap should not grow here (first subheap has exactly enough room) | 144 // heap should not grow here (first subheap has exactly enough room) |
| 146 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc3)); | 145 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kHeapIndex, &all
oc3)); |
| 147 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 85 * 1024); | 146 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 85 * 1024); |
| 148 // heap should not grow here (second subheap has room) | 147 // heap should not grow here (second subheap has room) |
| 149 REPORTER_ASSERT(reporter, heap.alloc(22 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc2)); | 148 REPORTER_ASSERT(reporter, heap.alloc(22 * 1024, kAlignment, kHeapIndex, &all
oc2)); |
| 150 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 107 * 1024); | 149 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 107 * 1024); |
| 151 heap.free(alloc1); | 150 heap.free(alloc1); |
| 152 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 102 * 1024); | 151 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 102 * 1024); |
| 153 heap.free(alloc0); | 152 heap.free(alloc0); |
| 154 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 62 * 1024); | 153 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 62 * 1024); |
| 155 heap.free(alloc2); | 154 heap.free(alloc2); |
| 156 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 40 * 1024); | 155 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 40 * 1024); |
| 157 heap.free(alloc3); | 156 heap.free(alloc3); |
| 158 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 0 * 1024); | 157 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 0 * 1024); |
| 159 // heap should not grow here (allocating more than subheap size) | 158 // heap should not grow here (allocating more than subheap size) |
| 160 REPORTER_ASSERT(reporter, heap.alloc(128 * 1024, kAlignment, kMemType, kHeap
Index, &alloc0)); | 159 REPORTER_ASSERT(reporter, heap.alloc(128 * 1024, kAlignment, kHeapIndex, &al
loc0)); |
| 161 REPORTER_ASSERT(reporter, 0 == alloc0.fSize); | 160 REPORTER_ASSERT(reporter, 0 == alloc0.fSize); |
| 162 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 0 * 1024); | 161 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 0 * 1024); |
| 163 heap.free(alloc0); | 162 heap.free(alloc0); |
| 164 REPORTER_ASSERT(reporter, heap.alloc(24 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc0)); | |
| 165 REPORTER_ASSERT(reporter, heap.allocSize() == 128 * 1024 && heap.usedSize()
== 24 * 1024); | |
| 166 // heap should alloc a new subheap because the memory type is different | |
| 167 REPORTER_ASSERT(reporter, heap.alloc(24 * 1024, kAlignment, kMemType+1, kHea
pIndex, &alloc1)); | |
| 168 REPORTER_ASSERT(reporter, heap.allocSize() == 192 * 1024 && heap.usedSize()
== 48 * 1024); | |
| 169 // heap should alloc a new subheap because the alignment is different | |
| 170 REPORTER_ASSERT(reporter, heap.alloc(24 * 1024, 128, kMemType, kHeapIndex, &
alloc2)); | |
| 171 REPORTER_ASSERT(reporter, heap.allocSize() == 256 * 1024 && heap.usedSize()
== 72 * 1024); | |
| 172 heap.free(alloc2); | |
| 173 heap.free(alloc0); | |
| 174 heap.free(alloc1); | |
| 175 REPORTER_ASSERT(reporter, heap.allocSize() == 256 * 1024 && heap.usedSize()
== 0 * 1024); | |
| 176 } | 163 } |
| 177 | 164 |
| 178 void singlealloc_test(skiatest::Reporter* reporter, GrContext* context) { | 165 void singlealloc_test(skiatest::Reporter* reporter, GrContext* context) { |
| 179 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | 166 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 180 | 167 |
| 181 // memtype/heap index don't matter, we're just testing the allocation algori
thm so we'll use 0 | 168 // heap index doesn't matter, we're just testing the allocation algorithm so
we'll use 0 |
| 182 GrVkHeap heap(gpu, GrVkHeap::kSingleAlloc_Strategy, 64 * 1024); | 169 GrVkHeap heap(gpu, GrVkHeap::kSingleAlloc_Strategy, 64 * 1024); |
| 183 GrVkAlloc alloc0, alloc1, alloc2, alloc3; | 170 GrVkAlloc alloc0, alloc1, alloc2, alloc3; |
| 184 const VkDeviceSize kAlignment = 64; | 171 const VkDeviceSize kAlignment = 64; |
| 185 const uint32_t kMemType = 0; | |
| 186 const uint32_t kHeapIndex = 0; | 172 const uint32_t kHeapIndex = 0; |
| 187 | 173 |
| 188 REPORTER_ASSERT(reporter, heap.allocSize() == 0 && heap.usedSize() == 0); | 174 REPORTER_ASSERT(reporter, heap.allocSize() == 0 && heap.usedSize() == 0); |
| 189 | 175 |
| 190 // make a few allocations | 176 // make a few allocations |
| 191 REPORTER_ASSERT(reporter, heap.alloc(49 * 1024 - 3, kAlignment, kMemType, kH
eapIndex, &alloc0)); | 177 REPORTER_ASSERT(reporter, heap.alloc(49 * 1024 - 3, kAlignment, kHeapIndex,
&alloc0)); |
| 192 REPORTER_ASSERT(reporter, heap.alloc(5 * 1024 - 37, kAlignment, kMemType, kH
eapIndex, &alloc1)); | 178 REPORTER_ASSERT(reporter, heap.alloc(5 * 1024 - 37, kAlignment, kHeapIndex,
&alloc1)); |
| 193 REPORTER_ASSERT(reporter, heap.alloc(15 * 1024 - 11, kAlignment, kMemType, k
HeapIndex, &alloc2)); | 179 REPORTER_ASSERT(reporter, heap.alloc(15 * 1024 - 11, kAlignment, kHeapIndex,
&alloc2)); |
| 194 REPORTER_ASSERT(reporter, heap.alloc(3 * 1024 - 29, kAlignment, kMemType, kH
eapIndex, &alloc3)); | 180 REPORTER_ASSERT(reporter, heap.alloc(3 * 1024 - 29, kAlignment, kHeapIndex,
&alloc3)); |
| 195 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 72 * 1024); | 181 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 72 * 1024); |
| 196 heap.free(alloc0); | 182 heap.free(alloc0); |
| 197 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 23 * 1024); | 183 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 23 * 1024); |
| 198 heap.free(alloc2); | 184 heap.free(alloc2); |
| 199 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 8 * 1024); | 185 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 8 * 1024); |
| 200 // heap should not grow here (first subheap has room) | 186 // heap should not grow here (first subheap has room) |
| 201 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc0)); | 187 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kHeapIndex, &all
oc0)); |
| 202 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 48 * 1024); | 188 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 48 * 1024); |
| 203 heap.free(alloc3); | 189 heap.free(alloc3); |
| 204 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 45 * 1024); | 190 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 45 * 1024); |
| 205 // check for exact fit -- heap should not grow here (third subheap has room) | 191 // check for exact fit -- heap should not grow here (third subheap has room) |
| 206 REPORTER_ASSERT(reporter, heap.alloc(15 * 1024 - 63, kAlignment, kMemType, k
HeapIndex, &alloc2)); | 192 REPORTER_ASSERT(reporter, heap.alloc(15 * 1024 - 63, kAlignment, kHeapIndex,
&alloc2)); |
| 207 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 60 * 1024); | 193 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 60 * 1024); |
| 208 heap.free(alloc2); | 194 heap.free(alloc2); |
| 209 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 45 * 1024); | 195 REPORTER_ASSERT(reporter, heap.allocSize() == 72 * 1024 && heap.usedSize() =
= 45 * 1024); |
| 210 // heap should grow here (no subheap has room) | 196 // heap should grow here (no subheap has room) |
| 211 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc3)); | 197 REPORTER_ASSERT(reporter, heap.alloc(40 * 1024, kAlignment, kHeapIndex, &all
oc3)); |
| 212 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 85 * 1024); | 198 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 85 * 1024); |
| 213 heap.free(alloc1); | 199 heap.free(alloc1); |
| 214 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 80 * 1024); | 200 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 80 * 1024); |
| 215 heap.free(alloc0); | 201 heap.free(alloc0); |
| 216 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 40 * 1024); | 202 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 40 * 1024); |
| 217 heap.free(alloc3); | 203 heap.free(alloc3); |
| 218 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 0 * 1024); | 204 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 0 * 1024); |
| 219 REPORTER_ASSERT(reporter, heap.alloc(24 * 1024, kAlignment, kMemType, kHeapI
ndex, &alloc0)); | |
| 220 REPORTER_ASSERT(reporter, heap.allocSize() == 112 * 1024 && heap.usedSize()
== 24 * 1024); | |
| 221 // heap should alloc a new subheap because the memory type is different | |
| 222 REPORTER_ASSERT(reporter, heap.alloc(24 * 1024, kAlignment, kMemType + 1, kH
eapIndex, &alloc1)); | |
| 223 REPORTER_ASSERT(reporter, heap.allocSize() == 136 * 1024 && heap.usedSize()
== 48 * 1024); | |
| 224 // heap should alloc a new subheap because the alignment is different | |
| 225 REPORTER_ASSERT(reporter, heap.alloc(24 * 1024, 128, kMemType, kHeapIndex, &
alloc2)); | |
| 226 REPORTER_ASSERT(reporter, heap.allocSize() == 160 * 1024 && heap.usedSize()
== 72 * 1024); | |
| 227 heap.free(alloc1); | |
| 228 heap.free(alloc2); | |
| 229 heap.free(alloc0); | |
| 230 REPORTER_ASSERT(reporter, heap.allocSize() == 160 * 1024 && heap.usedSize()
== 0 * 1024); | |
| 231 } | 205 } |
| 232 | 206 |
| 233 DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkHeapTests, reporter, ctxInfo) { | 207 DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkHeapTests, reporter, ctxInfo) { |
| 234 subheap_test(reporter, ctxInfo.grContext()); | 208 subheap_test(reporter, ctxInfo.grContext()); |
| 235 suballoc_test(reporter, ctxInfo.grContext()); | 209 suballoc_test(reporter, ctxInfo.grContext()); |
| 236 singlealloc_test(reporter, ctxInfo.grContext()); | 210 singlealloc_test(reporter, ctxInfo.grContext()); |
| 237 } | 211 } |
| 238 | 212 |
| 239 #endif | 213 #endif |
| OLD | NEW |