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

Unified Diff: src/gpu/vk/GrVkDescriptorSetManager.h

Issue 2163673002: Setup system in Vulkan to reuse VkDescriptorSet allocations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit 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/GrVkDescriptorSet.cpp ('k') | src/gpu/vk/GrVkDescriptorSetManager.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkDescriptorSetManager.h
diff --git a/src/gpu/vk/GrVkDescriptorSetManager.h b/src/gpu/vk/GrVkDescriptorSetManager.h
new file mode 100644
index 0000000000000000000000000000000000000000..33a7720ab34cb38d4eaae1f03c3d6cf64f2b35e3
--- /dev/null
+++ b/src/gpu/vk/GrVkDescriptorSetManager.h
@@ -0,0 +1,97 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#ifndef GrVkDescriptorSetManager_DEFINED
+#define GrVkDescriptorSetManager_DEFINED
+
+#include "GrResourceHandle.h"
+#include "GrVkDescriptorPool.h"
+#include "SkRefCnt.h"
+#include "SkTArray.h"
+#include "vk/GrVkDefines.h"
+
+class GrVkDescriptorSet;
+class GrVkGpu;
+
+/**
+ * This class handles the allocation of descriptor sets for a given VkDescriptorSetLayout. It will
+ * try to reuse previously allocated descriptor sets if they are no longer in use by other objects.
+ */
+class GrVkDescriptorSetManager {
+public:
+ GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle);
+
+ GrVkDescriptorSetManager(GrVkGpu* gpu,
+ VkDescriptorSetLayout layout,
+ VkDescriptorType,
+ uint32_t samplerCount);
+ ~GrVkDescriptorSetManager() {}
+
+ void abandon();
+ void release(const GrVkGpu* gpu);
+
+ const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle);
+
+ void recycleDescriptorSet(const GrVkDescriptorSet*);
+
+ int isCompatible(uint32_t numSamplers) const { return numSamplers == fNumSamplerBindings; }
+
+private:
+ struct DescriptorPoolManager {
+ DescriptorPoolManager(VkDescriptorSetLayout layout, VkDescriptorType type,
+ uint32_t samplerCount, GrVkGpu* gpu)
+ : fDescLayout(layout)
+ , fDescType(type)
+ , fCurrentDescriptorCount(0)
+ , fPool(nullptr) {
+ if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type) {
+ fDescCountPerSet = kNumUniformDescPerSet;
+ } else {
+ SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
+ fDescCountPerSet = samplerCount;
+ }
+
+ SkASSERT(fDescCountPerSet < kStartNumDescriptors);
+ fMaxDescriptors = kStartNumDescriptors;
+ SkASSERT(fMaxDescriptors > 0);
+ this->getNewPool(gpu);
+ }
+
+ ~DescriptorPoolManager() {
+ SkASSERT(!fDescLayout);
+ SkASSERT(!fPool);
+ }
+
+ void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds);
+
+ void freeGPUResources(const GrVkGpu* gpu);
+ void abandonGPUResources();
+
+ VkDescriptorSetLayout fDescLayout; // Not owned by this class
+ VkDescriptorType fDescType;
+ uint32_t fDescCountPerSet;
+ uint32_t fMaxDescriptors;
+ uint32_t fCurrentDescriptorCount;
+ GrVkDescriptorPool* fPool;
+
+ private:
+ enum {
+ kNumUniformDescPerSet = 2,
+ kMaxDescriptors = 1024,
+ kStartNumDescriptors = 16, // must be less than kMaxUniformDescriptors
+ };
+
+ void getNewPool(GrVkGpu* gpu);
+ };
+
+ DescriptorPoolManager fPoolManager;
+ SkTArray<const GrVkDescriptorSet*> fFreeSets;
+ // If the number of bindings is 0 we assume this is for uniform buffers
+ uint32_t fNumSamplerBindings;
+};
+
+#endif
« no previous file with comments | « src/gpu/vk/GrVkDescriptorSet.cpp ('k') | src/gpu/vk/GrVkDescriptorSetManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698