Track resources on GrVkCommandBuffer as sk_sps.

Bug: skia:11136
Change-Id: I4234cdcbcfba524e030c510ae0a4ce1616c0b94e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350029
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2021-01-05 16:42:49 -05:00 committed by Skia Commit-Bot
parent 99c4c8331f
commit d15176dbab
2 changed files with 16 additions and 15 deletions

View File

@ -60,21 +60,18 @@ void GrVkCommandBuffer::releaseResources() {
SkASSERT(!fIsActive);
for (int i = 0; i < fTrackedResources.count(); ++i) {
fTrackedResources[i]->notifyFinishedWithWorkOnGpu();
fTrackedResources[i]->unref();
}
fTrackedResources.reset();
for (int i = 0; i < fTrackedRecycledResources.count(); ++i) {
fTrackedRecycledResources[i]->notifyFinishedWithWorkOnGpu();
fTrackedRecycledResources[i]->recycle();
}
if (++fNumResets > kNumRewindResetsBeforeFullReset) {
fTrackedResources.reset();
fTrackedRecycledResources.reset();
fTrackedResources.setReserve(kInitialTrackedResourcesCount);
fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount);
fNumResets = 0;
} else {
fTrackedResources.rewind();
fTrackedRecycledResources.rewind();
}
@ -282,7 +279,7 @@ void GrVkCommandBuffer::bindPipeline(const GrVkGpu* gpu, sk_sp<const GrVkPipelin
GR_VK_CALL(gpu->vkInterface(), CmdBindPipeline(fCmdBuffer,
VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline->pipeline()));
this->addResource(pipeline.get());
this->addResource(std::move(pipeline));
}
void GrVkCommandBuffer::drawIndexed(const GrVkGpu* gpu,

View File

@ -107,11 +107,14 @@ public:
// Add ref-counted resource that will be tracked and released when this command buffer finishes
// execution
void addResource(const GrManagedResource* resource) {
void addResource(sk_sp<const GrManagedResource> resource) {
SkASSERT(resource);
resource->ref();
resource->notifyQueuedForWorkOnGpu();
fTrackedResources.append(1, &resource);
fTrackedResources.push_back(std::move(resource));
}
void addResource(const GrManagedResource* resource) {
this->addResource(sk_ref_sp(resource));
SkASSERT(resource);
}
// Add ref-counted resource that will be tracked and released when this command buffer finishes
@ -140,7 +143,6 @@ protected:
GrVkCommandBuffer(VkCommandBuffer cmdBuffer, bool isWrapped = false)
: fCmdBuffer(cmdBuffer)
, fIsWrapped(isWrapped) {
fTrackedResources.setReserve(kInitialTrackedResourcesCount);
fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount);
this->invalidateState();
}
@ -151,9 +153,14 @@ protected:
void submitPipelineBarriers(const GrVkGpu* gpu, bool forSelfDependency = false);
SkTDArray<const GrManagedResource*> fTrackedResources;
SkTDArray<const GrRecycledResource*> fTrackedRecycledResources;
SkSTArray<16, sk_sp<const GrBuffer>> fTrackedGpuBuffers;
private:
static constexpr int kInitialTrackedResourcesCount = 32;
protected:
SkSTArray<kInitialTrackedResourcesCount, sk_sp<const GrManagedResource>> fTrackedResources;
SkTDArray<const GrRecycledResource*> fTrackedRecycledResources;
SkSTArray<16, sk_sp<const GrBuffer>> fTrackedGpuBuffers;
SkSTArray<16, gr_cb<const GrSurface>> fTrackedGpuSurfaces;
// Tracks whether we are in the middle of a command buffer begin/end calls and thus can add
@ -168,9 +175,6 @@ protected:
VkCommandBuffer fCmdBuffer;
private:
static const int kInitialTrackedResourcesCount = 32;
virtual void onReleaseResources() {}
virtual void onFreeGPUData(const GrVkGpu* gpu) const = 0;