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

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

Issue 2172873003: Reuse sampler descriptor set allocations in Vulkan (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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
Index: src/gpu/vk/GrVkDescriptorSetManager.cpp
diff --git a/src/gpu/vk/GrVkDescriptorSetManager.cpp b/src/gpu/vk/GrVkDescriptorSetManager.cpp
index 51138e1a079814852f9aacd11671654989384e5e..703f2fde128d58febe8e85e67af48fdd670c6bf5 100644
--- a/src/gpu/vk/GrVkDescriptorSetManager.cpp
+++ b/src/gpu/vk/GrVkDescriptorSetManager.cpp
@@ -10,13 +10,29 @@
#include "GrVkDescriptorPool.h"
#include "GrVkDescriptorSet.h"
#include "GrVkGpu.h"
+#include "GrVkUniformHandler.h"
+#include "glsl/GrGLSLSampler.h"
GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu,
VkDescriptorSetLayout layout,
VkDescriptorType type,
- uint32_t samplerCount)
- : fPoolManager(layout, type, samplerCount, gpu)
- , fNumSamplerBindings(samplerCount) {
+ uint32_t descCountPerSet,
+ const GrVkUniformHandler* uniformHandler)
+ : fPoolManager(layout, type, descCountPerSet, gpu) {
+ if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
+ SkASSERT(uniformHandler);
+ SkASSERT((int)descCountPerSet == uniformHandler->numSamplers());
+ for (int i = 0; i < uniformHandler->numSamplers(); ++i) {
+ fBindingVisibilities.push_back(uniformHandler->getSampler(i).visibility());
+ }
+ } else {
+ SkASSERT(type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
+ SkASSERT(2 == descCountPerSet);
+ // We set the visibility of the first binding to the vertex shader and the second to the
+ // fragment shader.
+ fBindingVisibilities.push_back(kVertex_GrShaderFlag);
+ fBindingVisibilities.push_back(kFragment_GrShaderFlag);
+ }
}
const GrVkDescriptorSet* GrVkDescriptorSetManager::getDescriptorSet(GrVkGpu* gpu,
@@ -59,6 +75,28 @@ void GrVkDescriptorSetManager::abandon() {
fFreeSets.reset();
}
+VkDescriptorSetLayout GrVkDescriptorSetManager::layout() const { return fPoolManager.fDescLayout; }
jvanverth1 2016/07/25 19:12:56 Put in .h file?
egdaniel 2016/07/26 13:33:19 Done.
+
+bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type,
+ const GrVkUniformHandler* uniHandler) const {
+ SkASSERT(uniHandler);
+ if (type != fPoolManager.fDescType) {
+ return false;
+ }
+
+ if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
+ if (fBindingVisibilities.count() != uniHandler->numSamplers()) {
+ return false;
+ }
+ for (int i = 0; i < uniHandler->numSamplers(); ++i) {
+ if (uniHandler->getSampler(i).visibility() != fBindingVisibilities[i]) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
////////////////////////////////////////////////////////////////////////////////
void GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(GrVkGpu* gpu) {
@@ -101,9 +139,11 @@ void GrVkDescriptorSetManager::DescriptorPoolManager::getNewDescriptorSet(GrVkGp
}
void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(const GrVkGpu* gpu) {
- // The layout should be owned by the class which owns the DescriptorSetManager so it will
- // take care of destroying it.
- fDescLayout = VK_NULL_HANDLE;
+ if (fDescLayout) {
+ GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorSetLayout(gpu->device(), fDescLayout,
jvanverth1 2016/07/25 19:12:56 Is there any way to create this in the DescriptorP
egdaniel 2016/07/26 13:33:19 Done.
+ nullptr));
+ fDescLayout = VK_NULL_HANDLE;
+ }
if (fPool) {
fPool->unref(gpu);

Powered by Google App Engine
This is Rietveld 408576698