Index: src/gpu/vk/GrVkResourceProvider.cpp |
diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp |
index abe07bdd0455e9218d757a044eb5cfdb7574b496..b1817cf3ea2e7ba1b626bdfb4fe71ab9a71986a4 100644 |
--- a/src/gpu/vk/GrVkResourceProvider.cpp |
+++ b/src/gpu/vk/GrVkResourceProvider.cpp |
@@ -9,6 +9,7 @@ |
#include "GrTextureParams.h" |
#include "GrVkCommandBuffer.h" |
+#include "GrVkGLSLSampler.h" |
#include "GrVkPipeline.h" |
#include "GrVkRenderTarget.h" |
#include "GrVkSampler.h" |
@@ -22,8 +23,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); |
} |
@@ -33,38 +33,6 @@ GrVkResourceProvider::~GrVkResourceProvider() { |
delete fPipelineStateCache; |
} |
-void GrVkResourceProvider::initUniformDescObjects() { |
- // Create Uniform Buffer Descriptor |
- // The vertex uniform buffer will have binding 0 and the fragment binding 1. |
- VkDescriptorSetLayoutBinding dsUniBindings[2]; |
- memset(&dsUniBindings, 0, 2 * sizeof(VkDescriptorSetLayoutBinding)); |
- dsUniBindings[0].binding = GrVkUniformHandler::kVertexBinding; |
- dsUniBindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
- dsUniBindings[0].descriptorCount = 1; |
- dsUniBindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
- dsUniBindings[0].pImmutableSamplers = nullptr; |
- dsUniBindings[1].binding = GrVkUniformHandler::kFragBinding; |
- dsUniBindings[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
- dsUniBindings[1].descriptorCount = 1; |
- dsUniBindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
- dsUniBindings[1].pImmutableSamplers = nullptr; |
- |
- VkDescriptorSetLayoutCreateInfo dsUniformLayoutCreateInfo; |
- memset(&dsUniformLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo)); |
- dsUniformLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
- dsUniformLayoutCreateInfo.pNext = nullptr; |
- dsUniformLayoutCreateInfo.flags = 0; |
- dsUniformLayoutCreateInfo.bindingCount = 2; |
- dsUniformLayoutCreateInfo.pBindings = dsUniBindings; |
- |
- GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), CreateDescriptorSetLayout(fGpu->device(), |
- &dsUniformLayoutCreateInfo, |
- nullptr, |
- &fUniformDescLayout)); |
- |
- this->getDescSetHandle(0, fUniformDescLayout, &fUniformDSHandle); |
-} |
- |
void GrVkResourceProvider::init() { |
VkPipelineCacheCreateInfo createInfo; |
memset(&createInfo, 0, sizeof(VkPipelineCacheCreateInfo)); |
@@ -81,7 +49,10 @@ void GrVkResourceProvider::init() { |
fPipelineCache = VK_NULL_HANDLE; |
} |
- this->initUniformDescObjects(); |
+ // Init uniform descriptor objects |
+ fDescriptorSetManagers.emplace_back(fGpu, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); |
+ SkASSERT(1 == fDescriptorSetManagers.count()); |
+ fUniformDSHandle = GrVkDescriptorSetManager::Handle(0); |
} |
GrVkPipeline* GrVkResourceProvider::createPipeline(const GrPipeline& pipeline, |
@@ -190,31 +161,44 @@ sk_sp<GrVkPipelineState> GrVkResourceProvider::findOrCreateCompatiblePipelineSta |
return fPipelineStateCache->refPipelineState(pipeline, proc, primitiveType, renderPass); |
} |
- |
-void GrVkResourceProvider::getDescSetHandle(uint32_t numSamplers, VkDescriptorSetLayout layout, |
- GrVkDescriptorSetManager::Handle* handle) { |
+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; |
- |
- fDescriptorSetManagers.emplace_back(fGpu, layout, type, numSamplers); |
+ fDescriptorSetManagers.emplace_back(fGpu, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, |
+ &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 +310,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) { |