aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2016-09-20 12:39:25 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-20 12:39:25 -0700
commit594739c7924f46e1632d2f97a9b0822082b1169d (patch)
tree2ad43463b6dbdc1db0b3c1bbaca4694173b44ac6 /src/gpu/vk
parent0ecd91695fdc730ff0f1a56681c32ff3d7fea28f (diff)
Use STDArray to for tracked resources in vulkan command buffer
This is a minor speed improvement to help with the number of times we are freeing and re-allocating the tracked resource arrays BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2338963004 Review-Url: https://codereview.chromium.org/2338963004
Diffstat (limited to 'src/gpu/vk')
-rw-r--r--src/gpu/vk/GrVkCommandBuffer.cpp15
-rw-r--r--src/gpu/vk/GrVkCommandBuffer.h25
2 files changed, 29 insertions, 11 deletions
diff --git a/src/gpu/vk/GrVkCommandBuffer.cpp b/src/gpu/vk/GrVkCommandBuffer.cpp
index 317b735391..41a7bb51d7 100644
--- a/src/gpu/vk/GrVkCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkCommandBuffer.cpp
@@ -66,12 +66,21 @@ void GrVkCommandBuffer::reset(GrVkGpu* gpu) {
for (int i = 0; i < fTrackedResources.count(); ++i) {
fTrackedResources[i]->unref(gpu);
}
- fTrackedResources.reset();
-
for (int i = 0; i < fTrackedRecycledResources.count(); ++i) {
fTrackedRecycledResources[i]->recycle(const_cast<GrVkGpu*>(gpu));
}
- fTrackedRecycledResources.reset();
+
+ if (++fNumResets > kNumRewindResetsBeforeFullReset) {
+ fTrackedResources.reset();
+ fTrackedRecycledResources.reset();
+ fTrackedResources.setReserve(kInitialTrackedResourcesCount);
+ fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount);
+ fNumResets = 0;
+ } else {
+ fTrackedResources.rewind();
+ fTrackedRecycledResources.rewind();
+ }
+
this->invalidateState();
diff --git a/src/gpu/vk/GrVkCommandBuffer.h b/src/gpu/vk/GrVkCommandBuffer.h
index 67b09c7a82..e593b2d542 100644
--- a/src/gpu/vk/GrVkCommandBuffer.h
+++ b/src/gpu/vk/GrVkCommandBuffer.h
@@ -114,31 +114,33 @@ public:
// command buffer finishes execution
void addResource(const GrVkResource* resource) {
resource->ref();
- fTrackedResources.push_back(resource);
+ fTrackedResources.append(1, &resource);
}
// Add ref-counted resource that will be tracked and released when this command buffer finishes
// execution. When it is released, it will signal that the resource can be recycled for reuse.
void addRecycledResource(const GrVkRecycledResource* resource) {
resource->ref();
- fTrackedRecycledResources.push_back(resource);
+ fTrackedRecycledResources.append(1, &resource);
}
void reset(GrVkGpu* gpu);
protected:
GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp = VK_NULL_HANDLE)
- : fTrackedResources(kInitialTrackedResourcesCount)
- , fTrackedRecycledResources(kInitialTrackedResourcesCount)
- , fIsActive(false)
+ : fIsActive(false)
, fActiveRenderPass(rp)
, fCmdBuffer(cmdBuffer)
, fBoundVertexBufferIsValid(false)
- , fBoundIndexBufferIsValid(false) {
+ , fBoundIndexBufferIsValid(false)
+ , fNumResets(0) {
+ fTrackedResources.setReserve(kInitialTrackedResourcesCount);
+ fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount);
this->invalidateState();
}
- SkTArray<const GrVkResource*, true> fTrackedResources;
- SkTArray<const GrVkRecycledResource*, true> fTrackedRecycledResources;
+
+ SkTDArray<const GrVkResource*> fTrackedResources;
+ SkTDArray<const GrVkRecycledResource*> fTrackedRecycledResources;
// Tracks whether we are in the middle of a command buffer begin/end calls and thus can add
// new commands to the buffer;
@@ -166,6 +168,13 @@ private:
VkBuffer fBoundIndexBuffer;
bool fBoundIndexBufferIsValid;
+ // When resetting the command buffer, we remove the tracked resources from their arrays, and
+ // we prefer to not free all the memory every time so usually we just rewind. However, to avoid
+ // all arrays growing to the max size, after so many resets we'll do a full reset of the tracked
+ // resource arrays.
+ static const int kNumRewindResetsBeforeFullReset = 8;
+ int fNumResets;
+
// Cached values used for dynamic state updates
VkViewport fCachedViewport;
VkRect2D fCachedScissor;