Commit 89ade79a by Jamie Madill Committed by Commit Bot

Vulkan: Clean up ScopedDescriptorSetUpdates.

Matches style guide requirement for types before members. Also moves the implementation of the class entirely into the cpp file. Moves the method implementation in ContextVk so we can more easily alter member variables. Unrelated cleanup done while working on consolidating RenderPasses. Bug: angleproject:4911 Change-Id: Ibe4273fc609b494840f1e86584bcee5bc31397d5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2331950 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCharlie Lao <cclao@google.com>
parent fba96e90
......@@ -285,6 +285,33 @@ EventName GetTraceEventName(const char *title, uint32_t counter)
}
} // anonymous namespace
ANGLE_INLINE void ContextVk::flushDescriptorSetUpdates()
{
if (mWriteDescriptorSets.empty())
{
ASSERT(mDescriptorBufferInfos.empty());
ASSERT(mDescriptorImageInfos.empty());
return;
}
vkUpdateDescriptorSets(getDevice(), static_cast<uint32_t>(mWriteDescriptorSets.size()),
mWriteDescriptorSets.data(), 0, nullptr);
mWriteDescriptorSets.clear();
mDescriptorBufferInfos.clear();
mDescriptorImageInfos.clear();
}
// ContextVk::ScopedDescriptorSetUpdates implementation.
class ContextVk::ScopedDescriptorSetUpdates final : angle::NonCopyable
{
public:
ANGLE_INLINE ScopedDescriptorSetUpdates(ContextVk *contextVk) : mContextVk(contextVk) {}
ANGLE_INLINE ~ScopedDescriptorSetUpdates() { mContextVk->flushDescriptorSetUpdates(); }
private:
ContextVk *mContextVk;
};
ContextVk::DriverUniformsDescriptorSet::DriverUniformsDescriptorSet()
: descriptorSet(VK_NULL_HANDLE), dynamicOffset(0)
{}
......@@ -632,9 +659,6 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk
mRenderPassCounter(0),
mContextPriority(renderer->getDriverPriority(GetContextPriority(state))),
mCurrentIndirectBuffer(nullptr),
mBufferInfos(),
mImageInfos(),
mWriteInfos(),
mShareGroupVk(vk::GetImpl(state.getShareGroup()))
{
ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::ContextVk");
......@@ -726,9 +750,9 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk
mPipelineDirtyBitsMask.reset(gl::State::DIRTY_BIT_TEXTURE_BINDINGS);
// Reserve reasonable amount of spaces so that for majority of apps we don't need to grow at all
mBufferInfos.reserve(kDescriptorBufferInfosInitialSize);
mImageInfos.reserve(kDescriptorImageInfosInitialSize);
mWriteInfos.reserve(kDescriptorWriteInfosInitialSize);
mDescriptorBufferInfos.reserve(kDescriptorBufferInfosInitialSize);
mDescriptorImageInfos.reserve(kDescriptorImageInfosInitialSize);
mWriteDescriptorSets.reserve(kDescriptorWriteInfosInitialSize);
}
ContextVk::~ContextVk() = default;
......@@ -3751,12 +3775,12 @@ angle::Result ContextVk::updateDriverUniformsDescriptorSet(
&driverUniforms->descriptorPoolBinding, &driverUniforms->descriptorSet));
// Update the driver uniform descriptor set.
VkDescriptorBufferInfo &bufferInfo = allocBufferInfo();
VkDescriptorBufferInfo &bufferInfo = allocDescriptorBufferInfo();
bufferInfo.buffer = buffer->getBuffer().getHandle();
bufferInfo.offset = 0;
bufferInfo.range = driverUniformsSize;
VkWriteDescriptorSet &writeInfo = allocWriteInfo();
VkWriteDescriptorSet &writeInfo = allocWriteDescriptorSet();
writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeInfo.dstSet = driverUniforms->descriptorSet;
writeInfo.dstBinding = 0;
......@@ -4649,74 +4673,60 @@ bool ContextVk::isRobustResourceInitEnabled() const
return mState.isRobustResourceInitEnabled();
}
VkDescriptorBufferInfo &ContextVk::allocBufferInfos(size_t count)
{
return allocInfos<VkDescriptorBufferInfo, &VkWriteDescriptorSet::pBufferInfo>(&mBufferInfos,
count);
}
VkDescriptorImageInfo &ContextVk::allocImageInfos(size_t count)
{
return allocInfos<VkDescriptorImageInfo, &VkWriteDescriptorSet::pImageInfo>(&mImageInfos,
count);
}
template <typename T, const T *VkWriteDescriptorSet::*pInfo>
T &ContextVk::allocInfos(std::vector<T> *mInfos, size_t count)
{
size_t oldSize = mInfos->size();
size_t newSize = oldSize + count;
if (newSize > mInfos->capacity())
{
// If we have reached capacity, grow the storage and patch the descriptor set with new
// buffer info pointer
growCapacity<T, pInfo>(mInfos, newSize);
}
mInfos->resize(newSize);
return (*mInfos)[oldSize];
}
template <typename T, const T *VkWriteDescriptorSet::*pInfo>
void ContextVk::growCapacity(std::vector<T> *mInfos, size_t newSize)
void ContextVk::growDesciptorCapacity(std::vector<T> *descriptorVector, size_t newSize)
{
const T *const oldInfoStart = mInfos->empty() ? nullptr : &(*mInfos)[0];
size_t newCapacity = std::max(mInfos->capacity() << 1, newSize);
mInfos->reserve(newCapacity);
const T *const oldInfoStart = descriptorVector->empty() ? nullptr : &(*descriptorVector)[0];
size_t newCapacity = std::max(descriptorVector->capacity() << 1, newSize);
descriptorVector->reserve(newCapacity);
if (oldInfoStart)
{
// patch mWriteInfo with new BufferInfo/ImageInfo pointers
for (VkWriteDescriptorSet &set : mWriteInfos)
for (VkWriteDescriptorSet &set : mWriteDescriptorSets)
{
if (set.*pInfo)
{
size_t index = set.*pInfo - oldInfoStart;
set.*pInfo = &(*mInfos)[index];
set.*pInfo = &(*descriptorVector)[index];
}
}
}
}
// ScopedDescriptorSetUpdates
ANGLE_INLINE ContextVk::ScopedDescriptorSetUpdates::ScopedDescriptorSetUpdates(ContextVk *contextVk)
: mContextVk(contextVk)
{}
ANGLE_INLINE ContextVk::ScopedDescriptorSetUpdates::~ScopedDescriptorSetUpdates()
template <typename T, const T *VkWriteDescriptorSet::*pInfo>
T *ContextVk::allocDescriptorInfos(std::vector<T> *descriptorVector, size_t count)
{
if (mContextVk->mWriteInfos.empty())
size_t oldSize = descriptorVector->size();
size_t newSize = oldSize + count;
if (newSize > descriptorVector->capacity())
{
ASSERT(mContextVk->mBufferInfos.empty());
ASSERT(mContextVk->mImageInfos.empty());
return;
// If we have reached capacity, grow the storage and patch the descriptor set with new
// buffer info pointer
growDesciptorCapacity<T, pInfo>(descriptorVector, newSize);
}
descriptorVector->resize(newSize);
return &(*descriptorVector)[oldSize];
}
VkDescriptorBufferInfo *ContextVk::allocDescriptorBufferInfos(size_t count)
{
return allocDescriptorInfos<VkDescriptorBufferInfo, &VkWriteDescriptorSet::pBufferInfo>(
&mDescriptorBufferInfos, count);
}
vkUpdateDescriptorSets(mContextVk->getDevice(),
static_cast<uint32_t>(mContextVk->mWriteInfos.size()),
mContextVk->mWriteInfos.data(), 0, nullptr);
mContextVk->mWriteInfos.clear();
mContextVk->mBufferInfos.clear();
mContextVk->mImageInfos.clear();
VkDescriptorImageInfo *ContextVk::allocDescriptorImageInfos(size_t count)
{
return allocDescriptorInfos<VkDescriptorImageInfo, &VkWriteDescriptorSet::pImageInfo>(
&mDescriptorImageInfos, count);
}
VkWriteDescriptorSet *ContextVk::allocWriteDescriptorSets(size_t count)
{
size_t oldSize = mWriteDescriptorSets.size();
size_t newSize = oldSize + count;
mWriteDescriptorSets.resize(newSize);
return &mWriteDescriptorSets[oldSize];
}
BufferSerial ContextVk::generateBufferSerial()
......
......@@ -577,18 +577,13 @@ class ContextVk : public ContextImpl, public vk::Context
void recycleCommandBuffer(vk::CommandBufferHelper *commandBuffer);
// DescriptorSet writes
VkDescriptorBufferInfo &allocBufferInfo() { return allocBufferInfos(1); }
VkDescriptorBufferInfo &allocBufferInfos(size_t count);
VkDescriptorImageInfo &allocImageInfo() { return allocImageInfos(1); }
VkDescriptorImageInfo &allocImageInfos(size_t count);
VkWriteDescriptorSet &allocWriteInfo() { return allocWriteInfos(1); }
VkWriteDescriptorSet &allocWriteInfos(size_t count)
{
size_t oldSize = mWriteInfos.size();
size_t newSize = oldSize + count;
mWriteInfos.resize(newSize);
return mWriteInfos[oldSize];
}
VkDescriptorBufferInfo *allocDescriptorBufferInfos(size_t count);
VkDescriptorImageInfo *allocDescriptorImageInfos(size_t count);
VkWriteDescriptorSet *allocWriteDescriptorSets(size_t count);
VkDescriptorBufferInfo &allocDescriptorBufferInfo() { return *allocDescriptorBufferInfos(1); }
VkDescriptorImageInfo &allocDescriptorImageInfo() { return *allocDescriptorImageInfos(1); }
VkWriteDescriptorSet &allocWriteDescriptorSet() { return *allocWriteDescriptorSets(1); }
vk::DynamicBuffer *getDefaultUniformStorage() { return &mDefaultUniformStorage; }
// For testing only.
......@@ -681,6 +676,8 @@ class ContextVk : public ContextImpl, public vk::Context
double cpuTimestampS;
};
class ScopedDescriptorSetUpdates;
angle::Result setupDraw(const gl::Context *context,
gl::PrimitiveMode mode,
GLint firstVertexOrInvalid,
......@@ -852,6 +849,7 @@ class ContextVk : public ContextImpl, public vk::Context
bool hasRecordedCommands();
void dumpCommandStreamDiagnostics();
angle::Result flushOutsideRenderPassCommands();
void flushDescriptorSetUpdates();
ANGLE_INLINE void onRenderPassFinished()
{
......@@ -879,9 +877,9 @@ class ContextVk : public ContextImpl, public vk::Context
// DescriptorSet writes
template <typename T, const T *VkWriteDescriptorSet::*pInfo>
T &allocInfos(std::vector<T> *mInfos, size_t count);
T *allocDescriptorInfos(std::vector<T> *descriptorVector, size_t count);
template <typename T, const T *VkWriteDescriptorSet::*pInfo>
void growCapacity(std::vector<T> *mInfos, size_t newSize);
void growDesciptorCapacity(std::vector<T> *descriptorVector, size_t newSize);
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mGraphicsDirtyBitHandlers;
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mComputeDirtyBitHandlers;
......@@ -1057,18 +1055,9 @@ class ContextVk : public ContextImpl, public vk::Context
const vk::BufferHelper *mCurrentIndirectBuffer;
// Storage for vkUpdateDescriptorSets
std::vector<VkDescriptorBufferInfo> mBufferInfos;
std::vector<VkDescriptorImageInfo> mImageInfos;
std::vector<VkWriteDescriptorSet> mWriteInfos;
class ScopedDescriptorSetUpdates final : angle::NonCopyable
{
public:
ScopedDescriptorSetUpdates(ContextVk *contextVk);
~ScopedDescriptorSetUpdates();
private:
ContextVk *mContextVk;
};
std::vector<VkDescriptorBufferInfo> mDescriptorBufferInfos;
std::vector<VkDescriptorImageInfo> mDescriptorImageInfos;
std::vector<VkWriteDescriptorSet> mWriteDescriptorSets;
ShareGroupVk *mShareGroupVk;
......
......@@ -878,8 +878,8 @@ void ProgramExecutableVk::updateDefaultUniformsDescriptorSet(
return;
}
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteInfo();
VkDescriptorBufferInfo &bufferInfo = contextVk->allocBufferInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteDescriptorSet();
VkDescriptorBufferInfo &bufferInfo = contextVk->allocDescriptorBufferInfo();
if (!defaultUniformBlock.uniformData.empty())
{
......@@ -968,8 +968,8 @@ void ProgramExecutableVk::updateBuffersDescriptorSet(ContextVk *contextVk,
"VkDeviceSize too small");
ASSERT(bufferBinding.getSize() >= 0);
VkDescriptorBufferInfo &bufferInfo = contextVk->allocBufferInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteInfo();
VkDescriptorBufferInfo &bufferInfo = contextVk->allocDescriptorBufferInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteDescriptorSet();
BufferVk *bufferVk = vk::GetImpl(bufferBinding.get());
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
......@@ -1038,8 +1038,8 @@ void ProgramExecutableVk::updateAtomicCounterBuffersDescriptorSet(
continue;
}
VkDescriptorBufferInfo &bufferInfo = contextVk->allocBufferInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteInfo();
VkDescriptorBufferInfo &bufferInfo = contextVk->allocDescriptorBufferInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteDescriptorSet();
BufferVk *bufferVk = vk::GetImpl(bufferBinding.get());
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
......@@ -1062,8 +1062,8 @@ void ProgramExecutableVk::updateAtomicCounterBuffersDescriptorSet(
vk::BufferHelper &emptyBuffer = contextVk->getEmptyBuffer();
emptyBuffer.retain(&contextVk->getResourceUseList());
size_t count = (~writtenBindings).count();
VkDescriptorBufferInfo *bufferInfos = &contextVk->allocBufferInfos(count);
VkWriteDescriptorSet *writeInfos = &contextVk->allocWriteInfos(count);
VkDescriptorBufferInfo *bufferInfos = contextVk->allocDescriptorBufferInfos(count);
VkWriteDescriptorSet *writeInfos = contextVk->allocWriteDescriptorSets(count);
size_t writeCount = 0;
for (size_t binding : ~writtenBindings)
{
......@@ -1138,8 +1138,8 @@ angle::Result ProgramExecutableVk::updateImagesDescriptorSet(
// TODO(syoussefi): Support image data reinterpretation by using binding.format.
// http://anglebug.com/3563
VkDescriptorImageInfo &imageInfo = contextVk->allocImageInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteInfo();
VkDescriptorImageInfo &imageInfo = contextVk->allocDescriptorImageInfo();
VkWriteDescriptorSet &writeInfo = contextVk->allocWriteDescriptorSet();
imageInfo.sampler = VK_NULL_HANDLE;
imageInfo.imageView = imageView->getHandle();
......@@ -1329,8 +1329,8 @@ angle::Result ProgramExecutableVk::updateTexturesDescriptorSet(ContextVk *contex
mappedSamplerNameToArrayOffset[mappedSamplerName] += arraySize;
}
VkDescriptorImageInfo *imageInfos = &contextVk->allocImageInfos(arraySize);
VkWriteDescriptorSet *writeInfos = &contextVk->allocWriteInfos(arraySize);
VkDescriptorImageInfo *imageInfos = contextVk->allocDescriptorImageInfos(arraySize);
VkWriteDescriptorSet *writeInfos = contextVk->allocWriteDescriptorSets(arraySize);
for (uint32_t arrayElement = 0; arrayElement < arraySize; ++arrayElement)
{
GLuint textureUnit = samplerBinding.boundTextureUnits[arrayElement];
......
......@@ -195,8 +195,9 @@ void TransformFeedbackVk::initDescriptorSet(ContextVk *contextVk,
if (!contextVk->getFeatures().emulateTransformFeedback.enabled)
return;
VkDescriptorBufferInfo *descriptorBufferInfo = &contextVk->allocBufferInfos(xfbBufferCount);
vk::BufferHelper *emptyBuffer = &contextVk->getEmptyBuffer();
VkDescriptorBufferInfo *descriptorBufferInfo =
contextVk->allocDescriptorBufferInfos(xfbBufferCount);
vk::BufferHelper *emptyBuffer = &contextVk->getEmptyBuffer();
for (size_t bufferIndex = 0; bufferIndex < xfbBufferCount; ++bufferIndex)
{
......@@ -224,7 +225,8 @@ void TransformFeedbackVk::updateDescriptorSet(ContextVk *contextVk,
ASSERT(programState.getTransformFeedbackBufferMode() != GL_INTERLEAVED_ATTRIBS ||
xfbBufferCount == 1);
VkDescriptorBufferInfo *descriptorBufferInfo = &contextVk->allocBufferInfos(xfbBufferCount);
VkDescriptorBufferInfo *descriptorBufferInfo =
contextVk->allocDescriptorBufferInfos(xfbBufferCount);
// Update buffer descriptor binding info for output buffers
for (size_t bufferIndex = 0; bufferIndex < xfbBufferCount; ++bufferIndex)
......@@ -290,7 +292,7 @@ void TransformFeedbackVk::writeDescriptorSet(ContextVk *contextVk,
const std::string bufferName = GetXfbBufferName(0);
ShaderInterfaceVariableInfo &info = variableInfoMap[gl::ShaderType::Vertex][bufferName];
VkWriteDescriptorSet &writeDescriptorInfo = contextVk->allocWriteInfo();
VkWriteDescriptorSet &writeDescriptorInfo = contextVk->allocWriteDescriptorSet();
writeDescriptorInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorInfo.dstSet = descSet;
writeDescriptorInfo.dstBinding = info.binding;
......
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