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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/vk/GrVkResourceProvider.h ('k') | src/gpu/vk/GrVkSampler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkResourceProvider.cpp
diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp
index 4f6c7927c752b58ebd4c6d89de36d76230cc3e3e..19a2f7d87fe8a0468dd7aaae8a33d8ac90c1fc16 100644
--- a/src/gpu/vk/GrVkResourceProvider.cpp
+++ b/src/gpu/vk/GrVkResourceProvider.cpp
@@ -221,8 +221,16 @@ void GrVkResourceProvider::getUniformDescriptorSet(VkDescriptorSet* ds,
*outPool = fUniformDescPool;
}
-GrVkPrimaryCommandBuffer* GrVkResourceProvider::createPrimaryCommandBuffer() {
- GrVkPrimaryCommandBuffer* cmdBuffer = GrVkPrimaryCommandBuffer::Create(fGpu, fGpu->cmdPool());
+GrVkPrimaryCommandBuffer* GrVkResourceProvider::findOrCreatePrimaryCommandBuffer() {
+ GrVkPrimaryCommandBuffer* cmdBuffer = nullptr;
+ int count = fAvailableCommandBuffers.count();
+ if (count > 0) {
+ cmdBuffer = fAvailableCommandBuffers[count -1];
+ SkASSERT(cmdBuffer->finished(fGpu));
+ fAvailableCommandBuffers.removeShuffle(count - 1);
+ } else {
+ cmdBuffer = GrVkPrimaryCommandBuffer::Create(fGpu, fGpu->cmdPool());
+ }
fActiveCommandBuffers.push_back(cmdBuffer);
cmdBuffer->ref();
return cmdBuffer;
@@ -231,20 +239,53 @@ GrVkPrimaryCommandBuffer* GrVkResourceProvider::createPrimaryCommandBuffer() {
void GrVkResourceProvider::checkCommandBuffers() {
for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) {
if (fActiveCommandBuffers[i]->finished(fGpu)) {
- fActiveCommandBuffers[i]->unref(fGpu);
+ GrVkPrimaryCommandBuffer* cmdBuffer = fActiveCommandBuffers[i];
+ cmdBuffer->reset(fGpu);
+ fAvailableCommandBuffers.push_back(cmdBuffer);
fActiveCommandBuffers.removeShuffle(i);
}
}
}
+GrVkSecondaryCommandBuffer* GrVkResourceProvider::findOrCreateSecondaryCommandBuffer() {
+ GrVkSecondaryCommandBuffer* cmdBuffer = nullptr;
+ int count = fAvailableSecondaryCommandBuffers.count();
+ if (count > 0) {
+ cmdBuffer = fAvailableSecondaryCommandBuffers[count-1];
+ fAvailableSecondaryCommandBuffers.removeShuffle(count - 1);
+ } else {
+ cmdBuffer = GrVkSecondaryCommandBuffer::Create(fGpu, fGpu->cmdPool());
+ }
+ return cmdBuffer;
+}
+
+void GrVkResourceProvider::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* cb) {
+ cb->reset(fGpu);
+ fAvailableSecondaryCommandBuffers.push_back(cb);
+}
+
void GrVkResourceProvider::destroyResources() {
- // release our current command buffers
+ // release our active command buffers
for (int i = 0; i < fActiveCommandBuffers.count(); ++i) {
SkASSERT(fActiveCommandBuffers[i]->finished(fGpu));
SkASSERT(fActiveCommandBuffers[i]->unique());
fActiveCommandBuffers[i]->unref(fGpu);
}
fActiveCommandBuffers.reset();
+ // release our available command buffers
+ for (int i = 0; i < fAvailableCommandBuffers.count(); ++i) {
+ SkASSERT(fAvailableCommandBuffers[i]->finished(fGpu));
+ SkASSERT(fAvailableCommandBuffers[i]->unique());
+ fAvailableCommandBuffers[i]->unref(fGpu);
+ }
+ fAvailableCommandBuffers.reset();
+
+ // release our available secondary command buffers
+ for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) {
+ SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique());
+ fAvailableSecondaryCommandBuffers[i]->unref(fGpu);
+ }
+ fAvailableSecondaryCommandBuffers.reset();
// loop over all render pass sets to make sure we destroy all the internal VkRenderPasses
for (int i = 0; i < fRenderPassArray.count(); ++i) {
@@ -273,17 +314,38 @@ void GrVkResourceProvider::destroyResources() {
fUniformDescPool->unref(fGpu);
#ifdef SK_TRACE_VK_RESOURCES
+ if (GrVkResource::fTrace.count()) {
+ SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&GrVkResource::fTrace);
+ for (; !iter.done(); ++iter) {
+ (*iter).dumpInfo();
+ }
+ }
SkASSERT(0 == GrVkResource::fTrace.count());
#endif
}
void GrVkResourceProvider::abandonResources() {
- // release our current command buffers
+ // release our active command buffers
for (int i = 0; i < fActiveCommandBuffers.count(); ++i) {
SkASSERT(fActiveCommandBuffers[i]->finished(fGpu));
+ SkASSERT(fActiveCommandBuffers[i]->unique());
fActiveCommandBuffers[i]->unrefAndAbandon();
}
fActiveCommandBuffers.reset();
+ // release our available command buffers
+ for (int i = 0; i < fAvailableCommandBuffers.count(); ++i) {
+ SkASSERT(fAvailableCommandBuffers[i]->finished(fGpu));
+ SkASSERT(fAvailableCommandBuffers[i]->unique());
+ fAvailableCommandBuffers[i]->unrefAndAbandon();
+ }
+ fAvailableCommandBuffers.reset();
+
+ // release our available secondary command buffers
+ for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) {
+ SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique());
+ fAvailableSecondaryCommandBuffers[i]->unrefAndAbandon();
+ }
+ fAvailableSecondaryCommandBuffers.reset();
// loop over all render pass sets to make sure we destroy all the internal VkRenderPasses
for (int i = 0; i < fRenderPassArray.count(); ++i) {
@@ -306,6 +368,12 @@ void GrVkResourceProvider::abandonResources() {
fUniformDescPool->unrefAndAbandon();
#ifdef SK_TRACE_VK_RESOURCES
+ if (GrVkResource::fTrace.count()) {
+ SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&GrVkResource::fTrace);
+ for (; !iter.done(); ++iter) {
+ (*iter).dumpInfo();
+ }
+ }
SkASSERT(0 == GrVkResource::fTrace.count());
#endif
}
« 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