Vulkan: Store Pipeline/DS Layouts in ProgramVk.
We can keep a shared reference to the Pipeline and Descriptor Set
layouts in the Program. This ensures they are not in use when they are
deleted. Note that they are allowed to be deleted as long as no command
buffers are currently recording with them. If the Program is deleted
then there should be no further commands using these layouts.
Bug: angleproject:2462
Change-Id: I75161b3ce1ee8eae33dd6becee79b4262b844cdd
Reviewed-on: https://chromium-review.googlesource.com/1089807
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/ProgramVk.cpp b/src/libANGLE/renderer/vulkan/ProgramVk.cpp
index 36a809e..7346b4d 100644
--- a/src/libANGLE/renderer/vulkan/ProgramVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ProgramVk.cpp
@@ -172,6 +172,12 @@
VkDevice device = contextVk->getDevice();
+ for (auto &descriptorSetLayout : mDescriptorSetLayouts)
+ {
+ descriptorSetLayout.reset();
+ }
+ mPipelineLayout.reset();
+
for (auto &uniformBlock : mDefaultUniformBlocks)
{
uniformBlock.storage.destroy(device);
@@ -266,10 +272,40 @@
if (!mState.getSamplerUniformRange().empty())
{
// Ensure the descriptor set range includes the textures at position 1.
- mUsedDescriptorSetRange.extend(1);
+ mUsedDescriptorSetRange.extend(kTextureDescriptorSetIndex);
mDirtyTextures = true;
}
+ // Store a reference to the pipeline and descriptor set layouts. This will create them if they
+ // don't already exist in the cache.
+ vk::DescriptorSetLayoutDesc uniformsSetDesc;
+ uniformsSetDesc.update(kVertexUniformsBindingIndex, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
+ 1);
+ uniformsSetDesc.update(kFragmentUniformsBindingIndex, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
+ 1);
+
+ ANGLE_TRY(renderer->getDescriptorSetLayout(
+ uniformsSetDesc, &mDescriptorSetLayouts[kUniformsDescriptorSetIndex]));
+
+ const uint32_t maxTextures = renderer->getMaxActiveTextures();
+
+ vk::DescriptorSetLayoutDesc texturesSetDesc;
+ for (uint32_t textureIndex = 0; textureIndex < maxTextures; ++textureIndex)
+ {
+ // TODO(jmadll): Sampler arrays. http://anglebug.com/2462
+ texturesSetDesc.update(textureIndex, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1);
+ }
+
+ ANGLE_TRY(renderer->getDescriptorSetLayout(texturesSetDesc,
+ &mDescriptorSetLayouts[kTextureDescriptorSetIndex]));
+
+ vk::PipelineLayoutDesc pipelineLayoutDesc;
+ pipelineLayoutDesc.updateDescriptorSetLayout(kUniformsDescriptorSetIndex, uniformsSetDesc);
+ pipelineLayoutDesc.updateDescriptorSetLayout(kTextureDescriptorSetIndex, texturesSetDesc);
+
+ ANGLE_TRY(
+ renderer->getPipelineLayout(pipelineLayoutDesc, mDescriptorSetLayouts, &mPipelineLayout));
+
return true;
}
@@ -701,8 +737,6 @@
vk::Error ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descriptorSetIndex)
{
- RendererVk *renderer = contextVk->getRenderer();
-
// Write out to a new a descriptor set.
vk::DynamicDescriptorPool *dynamicDescriptorPool = contextVk->getDynamicDescriptorPool();
@@ -713,8 +747,7 @@
}
const vk::DescriptorSetLayout &descriptorSetLayout =
- renderer->getGraphicsDescriptorSetLayout(descriptorSetIndex);
-
+ mDescriptorSetLayouts[descriptorSetIndex].get();
ANGLE_TRY(dynamicDescriptorPool->allocateDescriptorSets(contextVk, descriptorSetLayout.ptr(), 1,
&mDescriptorSets[descriptorSetIndex]));
return vk::NoError();
@@ -925,6 +958,11 @@
mDirtyTextures = true;
}
+const vk::PipelineLayout &ProgramVk::getPipelineLayout() const
+{
+ return mPipelineLayout.get();
+}
+
void ProgramVk::setDefaultUniformBlocksMinSizeForTesting(size_t minSize)
{
for (DefaultUniformBlock &block : mDefaultUniformBlocks)