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

Unified Diff: src/gpu/vk/GrVkUniformBuffer.cpp

Issue 2159333002: Recycle small uniform buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« src/gpu/vk/GrVkResourceProvider.cpp ('K') | « src/gpu/vk/GrVkUniformBuffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkUniformBuffer.cpp
diff --git a/src/gpu/vk/GrVkUniformBuffer.cpp b/src/gpu/vk/GrVkUniformBuffer.cpp
index 022e2e33bdd10f978d49d6b622539b74db679d19..e080bfaa3403e639cdde7d2522e96339694390f6 100644
--- a/src/gpu/vk/GrVkUniformBuffer.cpp
+++ b/src/gpu/vk/GrVkUniformBuffer.cpp
@@ -8,24 +8,56 @@
#include "GrVkUniformBuffer.h"
#include "GrVkGpu.h"
-
-GrVkUniformBuffer* GrVkUniformBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
+GrVkUniformBuffer* GrVkUniformBuffer::Create(GrVkGpu* gpu, size_t size) {
if (0 == size) {
return nullptr;
}
+ const GrVkResource* resource = nullptr;
+ if (size <= GrVkUniformBuffer::kStandardSize) {
+ resource = gpu->resourceProvider().findOrCreateStandardUniformBufferResource();
+ } else {
+ resource = CreateResource(gpu, size);
+ }
+ if (!resource) {
+ return nullptr;
+ }
+
GrVkBuffer::Desc desc;
- desc.fDynamic = dynamic;
+ desc.fDynamic = true;
desc.fType = GrVkBuffer::kUniform_Type;
desc.fSizeInBytes = size;
+ GrVkUniformBuffer* buffer = new GrVkUniformBuffer(gpu, desc,
+ (const GrVkBuffer::Resource*) resource);
+ if (!buffer) {
+ // this will destroy anything we got from the resource provider,
+ // but this avoids a conditional
+ resource->unref(gpu);
+ }
+ return buffer;
+}
- const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc);
- if (!bufferResource) {
+const GrVkResource* GrVkUniformBuffer::CreateResource(GrVkGpu* gpu, size_t size) {
+ if (0 == size) {
return nullptr;
}
+ GrVkBuffer::Desc desc;
+ desc.fDynamic = true;
+ desc.fType = GrVkBuffer::kUniform_Type;
+ desc.fSizeInBytes = size;
- GrVkUniformBuffer* buffer = new GrVkUniformBuffer(desc, bufferResource);
- if (!buffer) {
- bufferResource->unref(gpu);
+ return GrVkBuffer::Create(gpu, desc);
+}
+
+void GrVkUniformBuffer::release(const GrVkGpu* gpu) {
+ if (this->size() <= GrVkUniformBuffer::kStandardSize) {
+ (void)fGpu->resourceProvider().recycleStandardUniformBufferResource(this->resource());
}
- return buffer;
-}
+ this->vkRelease(gpu);
+}
+
+void GrVkUniformBuffer::abandon() {
+ if (this->size() <= GrVkUniformBuffer::kStandardSize) {
+ (void)fGpu->resourceProvider().recycleStandardUniformBufferResource(this->resource());
+ }
+ this->vkAbandon();
+}
« src/gpu/vk/GrVkResourceProvider.cpp ('K') | « src/gpu/vk/GrVkUniformBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698