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

Unified Diff: src/gpu/vk/GrVkResourceProvider.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/GrVkResourceProvider.cpp
diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp
index abe07bdd0455e9218d757a044eb5cfdb7574b496..d1c6f09e939384f6b478eab2a50fc5bfdb86063d 100644
--- a/src/gpu/vk/GrVkResourceProvider.cpp
+++ b/src/gpu/vk/GrVkResourceProvider.cpp
@@ -9,10 +9,12 @@
#include "GrTextureParams.h"
#include "GrVkCommandBuffer.h"
+#include "GrVkGLSLSampler.h"
#include "GrVkPipeline.h"
#include "GrVkRenderTarget.h"
#include "GrVkSampler.h"
#include "GrVkUniformBuffer.h"
+#include "GrVkUniformHandler.h"
#include "GrVkUtil.h"
#ifdef SK_TRACE_VK_RESOURCES
@@ -22,8 +24,7 @@ uint32_t GrVkResource::fKeyCounter = 0;
GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu)
: fGpu(gpu)
- , fPipelineCache(VK_NULL_HANDLE)
- , fCurrentUniformDescCount(0) {
+ , fPipelineCache(VK_NULL_HANDLE) {
fPipelineStateCache = new PipelineStateCache(gpu);
}
@@ -57,12 +58,16 @@ void GrVkResourceProvider::initUniformDescObjects() {
dsUniformLayoutCreateInfo.bindingCount = 2;
dsUniformLayoutCreateInfo.pBindings = dsUniBindings;
+ VkDescriptorSetLayout uniformDescLayout;
GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), CreateDescriptorSetLayout(fGpu->device(),
&dsUniformLayoutCreateInfo,
nullptr,
- &fUniformDescLayout));
+ &uniformDescLayout));
- this->getDescSetHandle(0, fUniformDescLayout, &fUniformDSHandle);
+ fDescriptorSetManagers.emplace_back(fGpu, uniformDescLayout,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2);
+ SkASSERT(1 == fDescriptorSetManagers.count());
+ fUniformDSHandle = GrVkDescriptorSetManager::Handle(0);
}
void GrVkResourceProvider::init() {
@@ -190,31 +195,91 @@ sk_sp<GrVkPipelineState> GrVkResourceProvider::findOrCreateCompatiblePipelineSta
return fPipelineStateCache->refPipelineState(pipeline, proc, primitiveType, renderPass);
}
+VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) {
+ VkShaderStageFlags flags = 0;
-void GrVkResourceProvider::getDescSetHandle(uint32_t numSamplers, VkDescriptorSetLayout layout,
- GrVkDescriptorSetManager::Handle* handle) {
+ if (visibility & kVertex_GrShaderFlag) {
+ flags |= VK_SHADER_STAGE_VERTEX_BIT;
+ }
+ if (visibility & kGeometry_GrShaderFlag) {
+ flags |= VK_SHADER_STAGE_GEOMETRY_BIT;
+ }
+ if (visibility & kFragment_GrShaderFlag) {
+ flags |= VK_SHADER_STAGE_FRAGMENT_BIT;
+ }
+ return flags;
+}
+
+void GrVkResourceProvider::getSamplerDescriptorSetHandle(const GrVkUniformHandler& uniformHandler,
+ GrVkDescriptorSetManager::Handle* handle) {
SkASSERT(handle);
for (int i = 0; i < fDescriptorSetManagers.count(); ++i) {
- if (fDescriptorSetManagers[i].isCompatible(numSamplers)) {
+ if (fDescriptorSetManagers[i].isCompatible(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ &uniformHandler)) {
*handle = GrVkDescriptorSetManager::Handle(i);
return;
}
}
// Failed to find a DescSetManager, we must create a new one;
- VkDescriptorType type = numSamplers ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
- : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ uint32_t numSamplers = (uint32_t)uniformHandler.numSamplers();
+
+ SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings(
+ new VkDescriptorSetLayoutBinding[numSamplers]);
+ for (uint32_t i = 0; i < numSamplers; ++i) {
+ const GrVkGLSLSampler& sampler =
+ static_cast<const GrVkGLSLSampler&>(uniformHandler.getSampler(i));
+ SkASSERT(sampler.binding() == i);
+ dsSamplerBindings[i].binding = sampler.binding();
+ dsSamplerBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
+ dsSamplerBindings[i].descriptorCount = 1;
+ dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(sampler.visibility());
+ dsSamplerBindings[i].pImmutableSamplers = nullptr;
+ }
- fDescriptorSetManagers.emplace_back(fGpu, layout, type, numSamplers);
+ VkDescriptorSetLayoutCreateInfo dsSamplerLayoutCreateInfo;
+ memset(&dsSamplerLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo));
+ dsSamplerLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
+ dsSamplerLayoutCreateInfo.pNext = nullptr;
+ dsSamplerLayoutCreateInfo.flags = 0;
+ dsSamplerLayoutCreateInfo.bindingCount = numSamplers;
+ // Setting to nullptr fixes an error in the param checker validation layer. Even though
+ // bindingCount is 0 (which is valid), it still tries to validate pBindings unless it is null.
+ dsSamplerLayoutCreateInfo.pBindings = numSamplers ? dsSamplerBindings.get() : nullptr;
+
+ VkDescriptorSetLayout dsLayout;
+ GR_VK_CALL_ERRCHECK(fGpu->vkInterface(),
+ CreateDescriptorSetLayout(fGpu->device(),
+ &dsSamplerLayoutCreateInfo,
+ nullptr,
+ &dsLayout));
+ fDescriptorSetManagers.emplace_back(fGpu, dsLayout, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ numSamplers, &uniformHandler);
*handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1);
}
+VkDescriptorSetLayout GrVkResourceProvider::getUniformDSLayout() const {
+ SkASSERT(fUniformDSHandle.isValid());
+ return fDescriptorSetManagers[fUniformDSHandle.toIndex()].layout();
+}
+
+VkDescriptorSetLayout GrVkResourceProvider::getSamplerDSLayout(
+ const GrVkDescriptorSetManager::Handle& handle) const {
+ SkASSERT(handle.isValid());
+ return fDescriptorSetManagers[handle.toIndex()].layout();
+}
+
const GrVkDescriptorSet* GrVkResourceProvider::getUniformDescriptorSet() {
SkASSERT(fUniformDSHandle.isValid());
return fDescriptorSetManagers[fUniformDSHandle.toIndex()].getDescriptorSet(fGpu,
fUniformDSHandle);
}
+const GrVkDescriptorSet* GrVkResourceProvider::getSamplerDescriptorSet(
+ const GrVkDescriptorSetManager::Handle& handle) {
+ SkASSERT(handle.isValid());
+ return fDescriptorSetManagers[handle.toIndex()].getDescriptorSet(fGpu, handle);
+}
void GrVkResourceProvider::recycleDescriptorSet(const GrVkDescriptorSet* descSet,
const GrVkDescriptorSetManager::Handle& handle) {
@@ -326,13 +391,6 @@ void GrVkResourceProvider::destroyResources() {
GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipelineCache, nullptr));
fPipelineCache = VK_NULL_HANDLE;
- if (fUniformDescLayout) {
- GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device(),
- fUniformDescLayout,
- nullptr));
- fUniformDescLayout = VK_NULL_HANDLE;
- }
-
// We must release/destroy all command buffers and pipeline states before releasing the
// GrVkDescriptorSetManagers
for (int i = 0; i < fDescriptorSetManagers.count(); ++i) {

Powered by Google App Engine
This is Rietveld 408576698