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

Side by Side Diff: src/gpu/vk/GrVkResourceProvider.cpp

Issue 2115993002: Add resource tracking output and command buffer recycling (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments 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 unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkResourceProvider.h ('k') | src/gpu/vk/GrVkSampler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
317 if (GrVkResource::fTrace.count()) {
318 SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&GrVkResource::fTrace) ;
319 for (; !iter.done(); ++iter) {
320 (*iter).dumpInfo();
321 }
322 }
276 SkASSERT(0 == GrVkResource::fTrace.count()); 323 SkASSERT(0 == GrVkResource::fTrace.count());
277 #endif 324 #endif
278 } 325 }
279 326
280 void GrVkResourceProvider::abandonResources() { 327 void GrVkResourceProvider::abandonResources() {
281 // release our current command buffers 328 // release our active command buffers
282 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { 329 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) {
283 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); 330 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu));
331 SkASSERT(fActiveCommandBuffers[i]->unique());
284 fActiveCommandBuffers[i]->unrefAndAbandon(); 332 fActiveCommandBuffers[i]->unrefAndAbandon();
285 } 333 }
286 fActiveCommandBuffers.reset(); 334 fActiveCommandBuffers.reset();
335 // release our available command buffers
336 for (int i = 0; i < fAvailableCommandBuffers.count(); ++i) {
337 SkASSERT(fAvailableCommandBuffers[i]->finished(fGpu));
338 SkASSERT(fAvailableCommandBuffers[i]->unique());
339 fAvailableCommandBuffers[i]->unrefAndAbandon();
340 }
341 fAvailableCommandBuffers.reset();
342
343 // release our available secondary command buffers
344 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) {
345 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique());
346 fAvailableSecondaryCommandBuffers[i]->unrefAndAbandon();
347 }
348 fAvailableSecondaryCommandBuffers.reset();
287 349
288 // loop over all render pass sets to make sure we destroy all the internal V kRenderPasses 350 // 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) { 351 for (int i = 0; i < fRenderPassArray.count(); ++i) {
290 fRenderPassArray[i].abandonResources(); 352 fRenderPassArray[i].abandonResources();
291 } 353 }
292 fRenderPassArray.reset(); 354 fRenderPassArray.reset();
293 355
294 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re setting the hash. 356 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re setting the hash.
295 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); 357 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers);
296 for (; !iter.done(); ++iter) { 358 for (; !iter.done(); ++iter) {
297 (*iter).unrefAndAbandon(); 359 (*iter).unrefAndAbandon();
298 } 360 }
299 fSamplers.reset(); 361 fSamplers.reset();
300 362
301 fPipelineStateCache->abandon(); 363 fPipelineStateCache->abandon();
302 364
303 fPipelineCache = VK_NULL_HANDLE; 365 fPipelineCache = VK_NULL_HANDLE;
304 366
305 fUniformDescLayout = VK_NULL_HANDLE; 367 fUniformDescLayout = VK_NULL_HANDLE;
306 fUniformDescPool->unrefAndAbandon(); 368 fUniformDescPool->unrefAndAbandon();
307 369
308 #ifdef SK_TRACE_VK_RESOURCES 370 #ifdef SK_TRACE_VK_RESOURCES
371 if (GrVkResource::fTrace.count()) {
372 SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&GrVkResource::fTrace) ;
373 for (; !iter.done(); ++iter) {
374 (*iter).dumpInfo();
375 }
376 }
309 SkASSERT(0 == GrVkResource::fTrace.count()); 377 SkASSERT(0 == GrVkResource::fTrace.count());
310 #endif 378 #endif
311 } 379 }
312 380
313 //////////////////////////////////////////////////////////////////////////////// 381 ////////////////////////////////////////////////////////////////////////////////
314 382
315 GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet( 383 GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet(
316 const GrVkG pu* gpu, 384 const GrVkG pu* gpu,
317 const GrVkR enderTarget& target) 385 const GrVkR enderTarget& target)
318 : fLastReturnedIndex(0) { 386 : fLastReturnedIndex(0) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 424 }
357 425
358 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { 426 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() {
359 for (int i = 0; i < fRenderPasses.count(); ++i) { 427 for (int i = 0; i < fRenderPasses.count(); ++i) {
360 if (fRenderPasses[i]) { 428 if (fRenderPasses[i]) {
361 fRenderPasses[i]->unrefAndAbandon(); 429 fRenderPasses[i]->unrefAndAbandon();
362 fRenderPasses[i] = nullptr; 430 fRenderPasses[i] = nullptr;
363 } 431 }
364 } 432 }
365 } 433 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkResourceProvider.h ('k') | src/gpu/vk/GrVkSampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698