Commit 6ea1b416 by Luc Ferron Committed by Commit Bot

Vulkan: Reallocate only the right uniform descriptor set when needed

Bug: angleproject:2421 Change-Id: Ibdd8beee8103062a566b8caa23cdd9b8ac35d3a8 Reviewed-on: https://chromium-review.googlesource.com/974105 Commit-Queue: Luc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 13b708f2
......@@ -236,7 +236,7 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
// TODO(jmadill): Can probably use more dirty bits here.
ANGLE_TRY(programVk->updateUniforms(this));
programVk->updateTexturesDescriptorSet(this);
ANGLE_TRY(programVk->updateTexturesDescriptorSet(this));
// Bind the graphics descriptor sets.
// TODO(jmadill): Handle multiple command buffers.
......
......@@ -267,7 +267,6 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext,
mFragmentModuleSerial = renderer->issueProgramSerial();
}
ANGLE_TRY(allocateDescriptorSets(contextVk));
ANGLE_TRY(initDefaultUniformBlocks(glContext));
if (!mState.getSamplerUniformRange().empty())
......@@ -650,23 +649,25 @@ Serial ProgramVk::getFragmentModuleSerial() const
return mFragmentModuleSerial;
}
vk::Error ProgramVk::allocateDescriptorSets(ContextVk *contextVk)
vk::Error ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descriptorSetIndex)
{
RendererVk *renderer = contextVk->getRenderer();
// Write out to a new a descriptor set.
DynamicDescriptorPool *dynamicDescriptorPool = contextVk->getDynamicDescriptorPool();
const auto &descriptorSetLayouts = renderer->getGraphicsDescriptorSetLayouts();
uint32_t descriptorSetCount = static_cast<uint32_t>(descriptorSetLayouts.size());
mDescriptorSets.resize(descriptorSetCount, VK_NULL_HANDLE);
uint32_t potentialNewCount = descriptorSetIndex + 1;
if (potentialNewCount > mDescriptorSets.size())
{
mDescriptorSets.resize(potentialNewCount, VK_NULL_HANDLE);
}
const VkDescriptorSetLayout *descriptorSetLayout =
descriptorSetLayouts[descriptorSetIndex].ptr();
// TODO(lucferron): Its wasteful to reallocate the texture descriptor sets when we only
// care about the uniforms.
// http://anglebug.com/2421
ANGLE_TRY(dynamicDescriptorPool->allocateDescriptorSets(
contextVk, descriptorSetLayouts[0].ptr(), descriptorSetCount, &mDescriptorSets[0]));
ANGLE_TRY(dynamicDescriptorPool->allocateDescriptorSets(contextVk, descriptorSetLayout, 1,
&mDescriptorSets[descriptorSetIndex]));
return vk::NoError();
}
......@@ -721,7 +722,7 @@ vk::Error ProgramVk::updateUniforms(ContextVk *contextVk)
{
// We need to reinitialize the descriptor sets if we newly allocated buffers since we can't
// modify the descriptor sets once initialized.
ANGLE_TRY(allocateDescriptorSets(contextVk));
ANGLE_TRY(allocateDescriptorSet(contextVk, UniformBufferIndex));
ANGLE_TRY(updateDefaultUniformsDescriptorSet(contextVk));
}
......@@ -800,13 +801,15 @@ const gl::RangeUI &ProgramVk::getUsedDescriptorSetRange() const
return mUsedDescriptorSetRange;
}
void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
vk::Error ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
{
if (mState.getSamplerBindings().empty() || !mDirtyTextures)
{
return;
return vk::NoError();
}
ANGLE_TRY(allocateDescriptorSet(contextVk, TextureIndex));
ASSERT(mUsedDescriptorSetRange.contains(1));
VkDescriptorSet descriptorSet = mDescriptorSets[1];
......@@ -862,6 +865,7 @@ void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
vkUpdateDescriptorSets(device, imageCount, writeDescriptorInfo.data(), 0, nullptr);
mDirtyTextures = false;
return vk::NoError();
}
void ProgramVk::invalidateTextures()
......
......@@ -14,6 +14,7 @@
#include "libANGLE/Constants.h"
#include "libANGLE/renderer/ProgramImpl.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/StreamingBuffer.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
......@@ -123,7 +124,7 @@ class ProgramVk : public ProgramImpl
// or Textures.
const gl::RangeUI &getUsedDescriptorSetRange() const;
void updateTexturesDescriptorSet(ContextVk *contextVk);
vk::Error updateTexturesDescriptorSet(ContextVk *contextVk);
void invalidateTextures();
// For testing only.
......@@ -131,7 +132,7 @@ class ProgramVk : public ProgramImpl
private:
vk::Error reset(ContextVk *contextVk);
vk::Error allocateDescriptorSets(ContextVk *contextVk);
vk::Error allocateDescriptorSet(ContextVk *contextVk, uint32_t descriptorSetIndex);
gl::Error initDefaultUniformBlocks(const gl::Context *glContext);
vk::Error updateDefaultUniformsDescriptorSet(ContextVk *contextVk);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment