OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrVkResourceProvider.h" | 8 #include "GrVkResourceProvider.h" |
9 | 9 |
10 #include "GrTextureParams.h" | 10 #include "GrTextureParams.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 dsAllocateInfo.pNext = nullptr; | 214 dsAllocateInfo.pNext = nullptr; |
215 dsAllocateInfo.descriptorPool = fUniformDescPool->descPool(); | 215 dsAllocateInfo.descriptorPool = fUniformDescPool->descPool(); |
216 dsAllocateInfo.descriptorSetCount = 1; | 216 dsAllocateInfo.descriptorSetCount = 1; |
217 dsAllocateInfo.pSetLayouts = &fUniformDescLayout; | 217 dsAllocateInfo.pSetLayouts = &fUniformDescLayout; |
218 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), AllocateDescriptorSets(fGpu->device (), | 218 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), AllocateDescriptorSets(fGpu->device (), |
219 &dsAllocateI nfo, | 219 &dsAllocateI nfo, |
220 ds)); | 220 ds)); |
221 *outPool = fUniformDescPool; | 221 *outPool = fUniformDescPool; |
222 } | 222 } |
223 | 223 |
224 GrVkPrimaryCommandBuffer* GrVkResourceProvider::createPrimaryCommandBuffer() { | 224 GrVkPrimaryCommandBuffer* GrVkResourceProvider::findOrCreatePrimaryCommandBuffer () { |
225 GrVkPrimaryCommandBuffer* cmdBuffer = GrVkPrimaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); | 225 GrVkPrimaryCommandBuffer* cmdBuffer = nullptr; |
226 int count = fAvailableCommandBuffers.count(); | |
227 if (count > 0) { | |
228 cmdBuffer = fAvailableCommandBuffers[count -1]; | |
229 SkASSERT(cmdBuffer->finished(fGpu)); | |
230 fAvailableCommandBuffers.removeShuffle(count - 1); | |
231 } else { | |
232 cmdBuffer = GrVkPrimaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); | |
233 } | |
226 fActiveCommandBuffers.push_back(cmdBuffer); | 234 fActiveCommandBuffers.push_back(cmdBuffer); |
227 cmdBuffer->ref(); | 235 cmdBuffer->ref(); |
228 return cmdBuffer; | 236 return cmdBuffer; |
229 } | 237 } |
230 | 238 |
231 void GrVkResourceProvider::checkCommandBuffers() { | 239 void GrVkResourceProvider::checkCommandBuffers() { |
232 for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) { | 240 for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) { |
233 if (fActiveCommandBuffers[i]->finished(fGpu)) { | 241 if (fActiveCommandBuffers[i]->finished(fGpu)) { |
234 fActiveCommandBuffers[i]->unref(fGpu); | 242 GrVkPrimaryCommandBuffer* cmdBuffer = fActiveCommandBuffers[i]; |
243 cmdBuffer->reset(fGpu); | |
244 fAvailableCommandBuffers.push_back(cmdBuffer); | |
235 fActiveCommandBuffers.removeShuffle(i); | 245 fActiveCommandBuffers.removeShuffle(i); |
236 } | 246 } |
237 } | 247 } |
238 } | 248 } |
239 | 249 |
250 GrVkSecondaryCommandBuffer* GrVkResourceProvider::findOrCreateSecondaryCommandBu ffer() { | |
251 GrVkSecondaryCommandBuffer* cmdBuffer = nullptr; | |
252 int count = fAvailableSecondaryCommandBuffers.count(); | |
253 if (count > 0) { | |
254 cmdBuffer = fAvailableSecondaryCommandBuffers[count-1]; | |
255 fAvailableSecondaryCommandBuffers.removeShuffle(count - 1); | |
256 } else { | |
257 cmdBuffer = GrVkSecondaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); | |
258 } | |
259 return cmdBuffer; | |
260 } | |
261 | |
262 void GrVkResourceProvider::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuf fer* cb) { | |
263 cb->reset(fGpu); | |
264 fAvailableSecondaryCommandBuffers.push_back(cb); | |
265 } | |
266 | |
240 void GrVkResourceProvider::destroyResources() { | 267 void GrVkResourceProvider::destroyResources() { |
241 // release our current command buffers | 268 // release our active command buffers |
242 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 269 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
243 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 270 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
244 SkASSERT(fActiveCommandBuffers[i]->unique()); | 271 SkASSERT(fActiveCommandBuffers[i]->unique()); |
245 fActiveCommandBuffers[i]->unref(fGpu); | 272 fActiveCommandBuffers[i]->unref(fGpu); |
246 } | 273 } |
247 fActiveCommandBuffers.reset(); | 274 fActiveCommandBuffers.reset(); |
275 // release our available command buffers | |
276 for (int i = 0; i < fAvailableCommandBuffers.count(); ++i) { | |
277 SkASSERT(fAvailableCommandBuffers[i]->finished(fGpu)); | |
278 SkASSERT(fAvailableCommandBuffers[i]->unique()); | |
279 fAvailableCommandBuffers[i]->unref(fGpu); | |
280 } | |
281 fAvailableCommandBuffers.reset(); | |
282 | |
283 // release our available secondary command buffers | |
284 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) { | |
285 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique()); | |
286 fAvailableSecondaryCommandBuffers[i]->unref(fGpu); | |
287 } | |
288 fAvailableSecondaryCommandBuffers.reset(); | |
248 | 289 |
249 // loop over all render pass sets to make sure we destroy all the internal V kRenderPasses | 290 // loop over all render pass sets to make sure we destroy all the internal V kRenderPasses |
250 for (int i = 0; i < fRenderPassArray.count(); ++i) { | 291 for (int i = 0; i < fRenderPassArray.count(); ++i) { |
251 fRenderPassArray[i].releaseResources(fGpu); | 292 fRenderPassArray[i].releaseResources(fGpu); |
252 } | 293 } |
253 fRenderPassArray.reset(); | 294 fRenderPassArray.reset(); |
254 | 295 |
255 // Iterate through all store GrVkSamplers and unref them before resetting th e hash. | 296 // Iterate through all store GrVkSamplers and unref them before resetting th e hash. |
256 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); | 297 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); |
257 for (; !iter.done(); ++iter) { | 298 for (; !iter.done(); ++iter) { |
258 (*iter).unref(fGpu); | 299 (*iter).unref(fGpu); |
259 } | 300 } |
260 fSamplers.reset(); | 301 fSamplers.reset(); |
261 | 302 |
262 fPipelineStateCache->release(); | 303 fPipelineStateCache->release(); |
263 | 304 |
264 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli neCache, nullptr)); | 305 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli neCache, nullptr)); |
265 fPipelineCache = VK_NULL_HANDLE; | 306 fPipelineCache = VK_NULL_HANDLE; |
266 | 307 |
267 if (fUniformDescLayout) { | 308 if (fUniformDescLayout) { |
268 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), | 309 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), |
269 fUniformDescL ayout, | 310 fUniformDescL ayout, |
270 nullptr)); | 311 nullptr)); |
271 fUniformDescLayout = VK_NULL_HANDLE; | 312 fUniformDescLayout = VK_NULL_HANDLE; |
272 } | 313 } |
273 fUniformDescPool->unref(fGpu); | 314 fUniformDescPool->unref(fGpu); |
274 | 315 |
275 #ifdef SK_TRACE_VK_RESOURCES | 316 #ifdef SK_TRACE_VK_RESOURCES |
276 SkASSERT(0 == GrVkResource::fTrace.count()); | 317 if (GrVkResource::fTrace.count()) { |
318 SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&GrVkResource::fTrace) ; | |
319 for (; !iter.done(); ++iter) { | |
320 (*iter).dumpInfo(); | |
321 } | |
egdaniel
2016/07/05 14:18:37
Do we want an assert in here to make it really obv
jvanverth1
2016/07/06 15:49:23
Done.
| |
322 } | |
277 #endif | 323 #endif |
278 } | 324 } |
279 | 325 |
280 void GrVkResourceProvider::abandonResources() { | 326 void GrVkResourceProvider::abandonResources() { |
281 // release our current command buffers | 327 // release our active command buffers |
282 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 328 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
283 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 329 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
330 SkASSERT(fActiveCommandBuffers[i]->unique()); | |
284 fActiveCommandBuffers[i]->unrefAndAbandon(); | 331 fActiveCommandBuffers[i]->unrefAndAbandon(); |
285 } | 332 } |
286 fActiveCommandBuffers.reset(); | 333 fActiveCommandBuffers.reset(); |
334 // release our available command buffers | |
335 for (int i = 0; i < fAvailableCommandBuffers.count(); ++i) { | |
336 SkASSERT(fAvailableCommandBuffers[i]->finished(fGpu)); | |
337 SkASSERT(fAvailableCommandBuffers[i]->unique()); | |
338 fAvailableCommandBuffers[i]->unrefAndAbandon(); | |
339 } | |
340 fAvailableCommandBuffers.reset(); | |
341 | |
342 // release our available secondary command buffers | |
343 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) { | |
344 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique()); | |
345 fAvailableSecondaryCommandBuffers[i]->unrefAndAbandon(); | |
346 } | |
347 fAvailableSecondaryCommandBuffers.reset(); | |
287 | 348 |
288 // loop over all render pass sets to make sure we destroy all the internal V kRenderPasses | 349 // loop over all render pass sets to make sure we destroy all the internal V kRenderPasses |
289 for (int i = 0; i < fRenderPassArray.count(); ++i) { | 350 for (int i = 0; i < fRenderPassArray.count(); ++i) { |
290 fRenderPassArray[i].abandonResources(); | 351 fRenderPassArray[i].abandonResources(); |
291 } | 352 } |
292 fRenderPassArray.reset(); | 353 fRenderPassArray.reset(); |
293 | 354 |
294 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re setting the hash. | 355 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re setting the hash. |
295 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); | 356 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); |
296 for (; !iter.done(); ++iter) { | 357 for (; !iter.done(); ++iter) { |
297 (*iter).unrefAndAbandon(); | 358 (*iter).unrefAndAbandon(); |
298 } | 359 } |
299 fSamplers.reset(); | 360 fSamplers.reset(); |
300 | 361 |
301 fPipelineStateCache->abandon(); | 362 fPipelineStateCache->abandon(); |
302 | 363 |
303 fPipelineCache = VK_NULL_HANDLE; | 364 fPipelineCache = VK_NULL_HANDLE; |
304 | 365 |
305 fUniformDescLayout = VK_NULL_HANDLE; | 366 fUniformDescLayout = VK_NULL_HANDLE; |
306 fUniformDescPool->unrefAndAbandon(); | 367 fUniformDescPool->unrefAndAbandon(); |
307 | 368 |
308 #ifdef SK_TRACE_VK_RESOURCES | 369 #ifdef SK_TRACE_VK_RESOURCES |
309 SkASSERT(0 == GrVkResource::fTrace.count()); | 370 if (GrVkResource::fTrace.count()) { |
371 SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&GrVkResource::fTrace) ; | |
372 for (; !iter.done(); ++iter) { | |
373 (*iter).dumpInfo(); | |
374 } | |
375 } | |
310 #endif | 376 #endif |
311 } | 377 } |
312 | 378 |
313 //////////////////////////////////////////////////////////////////////////////// | 379 //////////////////////////////////////////////////////////////////////////////// |
314 | 380 |
315 GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet( | 381 GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet( |
316 const GrVkG pu* gpu, | 382 const GrVkG pu* gpu, |
317 const GrVkR enderTarget& target) | 383 const GrVkR enderTarget& target) |
318 : fLastReturnedIndex(0) { | 384 : fLastReturnedIndex(0) { |
319 fRenderPasses.emplace_back(new GrVkRenderPass()); | 385 fRenderPasses.emplace_back(new GrVkRenderPass()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 } | 422 } |
357 | 423 |
358 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { | 424 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
359 for (int i = 0; i < fRenderPasses.count(); ++i) { | 425 for (int i = 0; i < fRenderPasses.count(); ++i) { |
360 if (fRenderPasses[i]) { | 426 if (fRenderPasses[i]) { |
361 fRenderPasses[i]->unrefAndAbandon(); | 427 fRenderPasses[i]->unrefAndAbandon(); |
362 fRenderPasses[i] = nullptr; | 428 fRenderPasses[i] = nullptr; |
363 } | 429 } |
364 } | 430 } |
365 } | 431 } |
OLD | NEW |