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, ...@@ -236,7 +236,7 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
// TODO(jmadill): Can probably use more dirty bits here. // TODO(jmadill): Can probably use more dirty bits here.
ANGLE_TRY(programVk->updateUniforms(this)); ANGLE_TRY(programVk->updateUniforms(this));
programVk->updateTexturesDescriptorSet(this); ANGLE_TRY(programVk->updateTexturesDescriptorSet(this));
// Bind the graphics descriptor sets. // Bind the graphics descriptor sets.
// TODO(jmadill): Handle multiple command buffers. // TODO(jmadill): Handle multiple command buffers.
......
...@@ -267,7 +267,6 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext, ...@@ -267,7 +267,6 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext,
mFragmentModuleSerial = renderer->issueProgramSerial(); mFragmentModuleSerial = renderer->issueProgramSerial();
} }
ANGLE_TRY(allocateDescriptorSets(contextVk));
ANGLE_TRY(initDefaultUniformBlocks(glContext)); ANGLE_TRY(initDefaultUniformBlocks(glContext));
if (!mState.getSamplerUniformRange().empty()) if (!mState.getSamplerUniformRange().empty())
...@@ -650,23 +649,25 @@ Serial ProgramVk::getFragmentModuleSerial() const ...@@ -650,23 +649,25 @@ Serial ProgramVk::getFragmentModuleSerial() const
return mFragmentModuleSerial; return mFragmentModuleSerial;
} }
vk::Error ProgramVk::allocateDescriptorSets(ContextVk *contextVk) vk::Error ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descriptorSetIndex)
{ {
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
// Write out to a new a descriptor set. // Write out to a new a descriptor set.
DynamicDescriptorPool *dynamicDescriptorPool = contextVk->getDynamicDescriptorPool(); DynamicDescriptorPool *dynamicDescriptorPool = contextVk->getDynamicDescriptorPool();
const auto &descriptorSetLayouts = renderer->getGraphicsDescriptorSetLayouts(); 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 ANGLE_TRY(dynamicDescriptorPool->allocateDescriptorSets(contextVk, descriptorSetLayout, 1,
// care about the uniforms. &mDescriptorSets[descriptorSetIndex]));
// http://anglebug.com/2421
ANGLE_TRY(dynamicDescriptorPool->allocateDescriptorSets(
contextVk, descriptorSetLayouts[0].ptr(), descriptorSetCount, &mDescriptorSets[0]));
return vk::NoError(); return vk::NoError();
} }
...@@ -721,7 +722,7 @@ vk::Error ProgramVk::updateUniforms(ContextVk *contextVk) ...@@ -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 // We need to reinitialize the descriptor sets if we newly allocated buffers since we can't
// modify the descriptor sets once initialized. // modify the descriptor sets once initialized.
ANGLE_TRY(allocateDescriptorSets(contextVk)); ANGLE_TRY(allocateDescriptorSet(contextVk, UniformBufferIndex));
ANGLE_TRY(updateDefaultUniformsDescriptorSet(contextVk)); ANGLE_TRY(updateDefaultUniformsDescriptorSet(contextVk));
} }
...@@ -800,13 +801,15 @@ const gl::RangeUI &ProgramVk::getUsedDescriptorSetRange() const ...@@ -800,13 +801,15 @@ const gl::RangeUI &ProgramVk::getUsedDescriptorSetRange() const
return mUsedDescriptorSetRange; return mUsedDescriptorSetRange;
} }
void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk) vk::Error ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
{ {
if (mState.getSamplerBindings().empty() || !mDirtyTextures) if (mState.getSamplerBindings().empty() || !mDirtyTextures)
{ {
return; return vk::NoError();
} }
ANGLE_TRY(allocateDescriptorSet(contextVk, TextureIndex));
ASSERT(mUsedDescriptorSetRange.contains(1)); ASSERT(mUsedDescriptorSetRange.contains(1));
VkDescriptorSet descriptorSet = mDescriptorSets[1]; VkDescriptorSet descriptorSet = mDescriptorSets[1];
...@@ -862,6 +865,7 @@ void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk) ...@@ -862,6 +865,7 @@ void ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
vkUpdateDescriptorSets(device, imageCount, writeDescriptorInfo.data(), 0, nullptr); vkUpdateDescriptorSets(device, imageCount, writeDescriptorInfo.data(), 0, nullptr);
mDirtyTextures = false; mDirtyTextures = false;
return vk::NoError();
} }
void ProgramVk::invalidateTextures() void ProgramVk::invalidateTextures()
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libANGLE/Constants.h" #include "libANGLE/Constants.h"
#include "libANGLE/renderer/ProgramImpl.h" #include "libANGLE/renderer/ProgramImpl.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/StreamingBuffer.h" #include "libANGLE/renderer/vulkan/StreamingBuffer.h"
#include "libANGLE/renderer/vulkan/vk_utils.h" #include "libANGLE/renderer/vulkan/vk_utils.h"
...@@ -123,7 +124,7 @@ class ProgramVk : public ProgramImpl ...@@ -123,7 +124,7 @@ class ProgramVk : public ProgramImpl
// or Textures. // or Textures.
const gl::RangeUI &getUsedDescriptorSetRange() const; const gl::RangeUI &getUsedDescriptorSetRange() const;
void updateTexturesDescriptorSet(ContextVk *contextVk); vk::Error updateTexturesDescriptorSet(ContextVk *contextVk);
void invalidateTextures(); void invalidateTextures();
// For testing only. // For testing only.
...@@ -131,7 +132,7 @@ class ProgramVk : public ProgramImpl ...@@ -131,7 +132,7 @@ class ProgramVk : public ProgramImpl
private: private:
vk::Error reset(ContextVk *contextVk); 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); gl::Error initDefaultUniformBlocks(const gl::Context *glContext);
vk::Error updateDefaultUniformsDescriptorSet(ContextVk *contextVk); 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