diff options
author | egdaniel <egdaniel@google.com> | 2016-07-29 10:46:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-29 10:46:06 -0700 |
commit | 31bc7df59b2cafeaf13bc3cd44a1a3ba3c54308e (patch) | |
tree | 69ef979022f970b4ef6074f67c51614280a18b2f /src | |
parent | f6593a68d9a8dbe01f4a3578874bedbfbebe55e5 (diff) |
Properly recycle uniform buffers in vulkan
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2195713002
Review-Url: https://codereview.chromium.org/2195713002
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/vk/GrVkBuffer.cpp | 4 | ||||
-rw-r--r-- | src/gpu/vk/GrVkBuffer.h | 15 | ||||
-rw-r--r-- | src/gpu/vk/GrVkPipelineState.cpp | 6 | ||||
-rw-r--r-- | src/gpu/vk/GrVkUniformBuffer.cpp | 12 | ||||
-rw-r--r-- | src/gpu/vk/GrVkUniformBuffer.h | 3 |
5 files changed, 30 insertions, 10 deletions
diff --git a/src/gpu/vk/GrVkBuffer.cpp b/src/gpu/vk/GrVkBuffer.cpp index 75f3901b4e..a03ea0cc41 100644 --- a/src/gpu/vk/GrVkBuffer.cpp +++ b/src/gpu/vk/GrVkBuffer.cpp @@ -180,8 +180,8 @@ bool GrVkBuffer::vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInByt if (!fResource->unique()) { // in use by the command buffer, so we need to create a new one - fResource->unref(gpu); - fResource = Create(gpu, fDesc); + fResource->recycle(gpu); + fResource = this->createResource(gpu, fDesc); if (createdNewBuffer) { *createdNewBuffer = true; } diff --git a/src/gpu/vk/GrVkBuffer.h b/src/gpu/vk/GrVkBuffer.h index b400e09916..bb529b3f73 100644 --- a/src/gpu/vk/GrVkBuffer.h +++ b/src/gpu/vk/GrVkBuffer.h @@ -25,11 +25,11 @@ public: SkASSERT(!fResource); } - VkBuffer buffer() const { return fResource->fBuffer; } - const GrVkAlloc& alloc() const { return fResource->fAlloc; } - const GrVkResource* resource() const { return fResource; } - size_t size() const { return fDesc.fSizeInBytes; } - VkDeviceSize offset() const { return fOffset; } + VkBuffer buffer() const { return fResource->fBuffer; } + const GrVkAlloc& alloc() const { return fResource->fAlloc; } + const GrVkRecycledResource* resource() const { return fResource; } + size_t size() const { return fDesc.fSizeInBytes; } + VkDeviceSize offset() const { return fOffset; } void addMemoryBarrier(const GrVkGpu* gpu, VkAccessFlags srcAccessMask, @@ -94,6 +94,11 @@ protected: void vkRelease(const GrVkGpu* gpu); private: + virtual const Resource* createResource(GrVkGpu* gpu, + const Desc& descriptor) { + return Create(gpu, descriptor); + } + void validate() const; bool vkIsMapped() const; diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp index 5b3fa8f056..2dd691cf29 100644 --- a/src/gpu/vk/GrVkPipelineState.cpp +++ b/src/gpu/vk/GrVkPipelineState.cpp @@ -382,13 +382,13 @@ void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) { commandBuffer.addRecycledResource(fSamplerDescriptorSet); } - if (fVertexUniformBuffer.get()) { - commandBuffer.addResource(fVertexUniformBuffer->resource()); + commandBuffer.addRecycledResource(fVertexUniformBuffer->resource()); } if (fFragmentUniformBuffer.get()) { - commandBuffer.addResource(fFragmentUniformBuffer->resource()); + commandBuffer.addRecycledResource(fFragmentUniformBuffer->resource()); } + for (int i = 0; i < fSamplers.count(); ++i) { commandBuffer.addResource(fSamplers[i]); } diff --git a/src/gpu/vk/GrVkUniformBuffer.cpp b/src/gpu/vk/GrVkUniformBuffer.cpp index c3899b01b9..ac013f7dfe 100644 --- a/src/gpu/vk/GrVkUniformBuffer.cpp +++ b/src/gpu/vk/GrVkUniformBuffer.cpp @@ -82,6 +82,18 @@ const GrVkResource* GrVkUniformBuffer::CreateResource(GrVkGpu* gpu, size_t size) return resource; } +const GrVkBuffer::Resource* GrVkUniformBuffer::createResource(GrVkGpu* gpu, + const GrVkBuffer::Desc& descriptor) { + const GrVkResource* vkResource; + if (descriptor.fSizeInBytes <= GrVkUniformBuffer::kStandardSize) { + GrVkResourceProvider& provider = gpu->resourceProvider(); + vkResource = provider.findOrCreateStandardUniformBufferResource(); + } else { + vkResource = CreateResource(gpu, descriptor.fSizeInBytes); + } + return (const GrVkBuffer::Resource*) vkResource; +} + void GrVkUniformBuffer::Resource::onRecycle(GrVkGpu* gpu) const { if (fAlloc.fSize <= GrVkUniformBuffer::kStandardSize) { gpu->resourceProvider().recycleStandardUniformBufferResource(this); diff --git a/src/gpu/vk/GrVkUniformBuffer.h b/src/gpu/vk/GrVkUniformBuffer.h index 7aa3af6f8d..d2d9f3230c 100644 --- a/src/gpu/vk/GrVkUniformBuffer.h +++ b/src/gpu/vk/GrVkUniformBuffer.h @@ -45,6 +45,9 @@ private: typedef GrVkBuffer::Resource INHERITED; }; + const GrVkBuffer::Resource* createResource(GrVkGpu* gpu, + const GrVkBuffer::Desc& descriptor) override; + GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc, const GrVkUniformBuffer::Resource* resource) : INHERITED(desc, resource) |