Commit 12f38c49 by Jamie Madill Committed by Commit Bot

Vulkan: Use dynamic buffer for driver uniform updates.

This should reduce the number of descriptor sets we need to allocate. We only allocate a new descriptor set when the underlying buffer is reallocated. We pass in the buffer offset via the dynamic offsets parameter. Bug: angleproject:3504 Change-Id: I40d031cd7295a8d002caff4f331f4a311f07505c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1646757 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTobin Ehlis <tobine@google.com>
parent 9520a246
...@@ -175,6 +175,7 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk ...@@ -175,6 +175,7 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk
mFlipYForCurrentSurface(false), mFlipYForCurrentSurface(false),
mDriverUniformsBuffer(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, sizeof(DriverUniforms) * 16, true), mDriverUniformsBuffer(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, sizeof(DriverUniforms) * 16, true),
mDriverUniformsDescriptorSet(VK_NULL_HANDLE), mDriverUniformsDescriptorSet(VK_NULL_HANDLE),
mDriverUniformsDynamicOffset(0),
mDefaultAttribBuffers{{INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, mDefaultAttribBuffers{{INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT,
INIT, INIT, INIT, INIT}}, INIT, INIT, INIT, INIT}},
mLastCompletedQueueSerial(renderer->nextSerial()), mLastCompletedQueueSerial(renderer->nextSerial()),
...@@ -273,7 +274,7 @@ angle::Result ContextVk::initialize() ...@@ -273,7 +274,7 @@ angle::Result ContextVk::initialize()
{ {
TRACE_EVENT0("gpu.angle", "ContextVk::initialize"); TRACE_EVENT0("gpu.angle", "ContextVk::initialize");
VkDescriptorPoolSize driverSetSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}; VkDescriptorPoolSize driverSetSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1};
ANGLE_TRY(mDriverUniformsDescriptorPool.init(this, &driverSetSize, 1)); ANGLE_TRY(mDriverUniformsDescriptorPool.init(this, &driverSetSize, 1));
ANGLE_TRY(mQueryPools[gl::QueryType::AnySamples].init(this, VK_QUERY_TYPE_OCCLUSION, ANGLE_TRY(mQueryPools[gl::QueryType::AnySamples].init(this, VK_QUERY_TYPE_OCCLUSION,
...@@ -643,9 +644,9 @@ angle::Result ContextVk::handleDirtyDescriptorSets(const gl::Context *context, ...@@ -643,9 +644,9 @@ angle::Result ContextVk::handleDirtyDescriptorSets(const gl::Context *context,
ANGLE_TRY(mProgram->updateDescriptorSets(this, commandBuffer)); ANGLE_TRY(mProgram->updateDescriptorSets(this, commandBuffer));
// Bind the graphics descriptor sets. // Bind the graphics descriptor sets.
commandBuffer->bindGraphicsDescriptorSets(mProgram->getPipelineLayout(), commandBuffer->bindGraphicsDescriptorSets(
kDriverUniformsDescriptorSetIndex, 1, mProgram->getPipelineLayout(), kDriverUniformsDescriptorSetIndex, 1,
&mDriverUniformsDescriptorSet, 0, nullptr); &mDriverUniformsDescriptorSet, 1, &mDriverUniformsDynamicOffset);
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1925,13 +1926,16 @@ angle::Result ContextVk::handleDirtyDriverUniforms(const gl::Context *context, ...@@ -1925,13 +1926,16 @@ angle::Result ContextVk::handleDirtyDriverUniforms(const gl::Context *context,
static_cast<float>(mDrawFramebuffer->getState().getDimensions().height) * 0.5f; static_cast<float>(mDrawFramebuffer->getState().getDimensions().height) * 0.5f;
// Allocate a new region in the dynamic buffer. // Allocate a new region in the dynamic buffer.
uint8_t *ptr = nullptr; uint8_t *ptr;
VkBuffer buffer = VK_NULL_HANDLE; VkBuffer buffer;
VkDeviceSize offset = 0; VkDeviceSize offset;
bool newBuffer;
ANGLE_TRY(mDriverUniformsBuffer.allocate(this, sizeof(DriverUniforms), &ptr, &buffer, &offset, ANGLE_TRY(mDriverUniformsBuffer.allocate(this, sizeof(DriverUniforms), &ptr, &buffer, &offset,
nullptr)); &newBuffer));
float scaleY = isViewportFlipEnabledForDrawFBO() ? -1.0f : 1.0f; float scaleY = isViewportFlipEnabledForDrawFBO() ? -1.0f : 1.0f;
mDriverUniformsDynamicOffset = static_cast<uint32_t>(offset);
float depthRangeNear = mState.getNearPlane(); float depthRangeNear = mState.getNearPlane();
float depthRangeFar = mState.getFarPlane(); float depthRangeFar = mState.getFarPlane();
float depthRangeDiff = depthRangeFar - depthRangeNear; float depthRangeDiff = depthRangeFar - depthRangeNear;
...@@ -1949,29 +1953,32 @@ angle::Result ContextVk::handleDirtyDriverUniforms(const gl::Context *context, ...@@ -1949,29 +1953,32 @@ angle::Result ContextVk::handleDirtyDriverUniforms(const gl::Context *context,
ANGLE_TRY(mDriverUniformsBuffer.flush(this)); ANGLE_TRY(mDriverUniformsBuffer.flush(this));
// Allocate a new descriptor set. if (newBuffer)
ANGLE_TRY(mDriverUniformsDescriptorPool.allocateSets(this, mDriverUniformsSetLayout.get().ptr(), {
1, &mDriverUniformsDescriptorPoolBinding, // Allocate a new descriptor set.
&mDriverUniformsDescriptorSet)); ANGLE_TRY(mDriverUniformsDescriptorPool.allocateSets(
this, mDriverUniformsSetLayout.get().ptr(), 1, &mDriverUniformsDescriptorPoolBinding,
// Update the driver uniform descriptor set. &mDriverUniformsDescriptorSet));
VkDescriptorBufferInfo bufferInfo = {};
bufferInfo.buffer = buffer; // Update the driver uniform descriptor set.
bufferInfo.offset = offset; VkDescriptorBufferInfo bufferInfo = {};
bufferInfo.range = sizeof(DriverUniforms); bufferInfo.buffer = buffer;
bufferInfo.offset = 0;
VkWriteDescriptorSet writeInfo = {}; bufferInfo.range = sizeof(DriverUniforms);
writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeInfo.dstSet = mDriverUniformsDescriptorSet; VkWriteDescriptorSet writeInfo = {};
writeInfo.dstBinding = 0; writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeInfo.dstArrayElement = 0; writeInfo.dstSet = mDriverUniformsDescriptorSet;
writeInfo.descriptorCount = 1; writeInfo.dstBinding = 0;
writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; writeInfo.dstArrayElement = 0;
writeInfo.pImageInfo = nullptr; writeInfo.descriptorCount = 1;
writeInfo.pTexelBufferView = nullptr; writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
writeInfo.pBufferInfo = &bufferInfo; writeInfo.pImageInfo = nullptr;
writeInfo.pTexelBufferView = nullptr;
vkUpdateDescriptorSets(getDevice(), 1, &writeInfo, 0, nullptr); writeInfo.pBufferInfo = &bufferInfo;
vkUpdateDescriptorSets(getDevice(), 1, &writeInfo, 0, nullptr);
}
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -2426,7 +2433,7 @@ angle::Result ContextVk::generateSurfaceSemaphores(SignalSemaphoreVector *signal ...@@ -2426,7 +2433,7 @@ angle::Result ContextVk::generateSurfaceSemaphores(SignalSemaphoreVector *signal
vk::DescriptorSetLayoutDesc ContextVk::getDriverUniformsDescriptorSetDesc() const vk::DescriptorSetLayoutDesc ContextVk::getDriverUniformsDescriptorSetDesc() const
{ {
vk::DescriptorSetLayoutDesc desc; vk::DescriptorSetLayoutDesc desc;
desc.update(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL_GRAPHICS); desc.update(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_ALL_GRAPHICS);
return desc; return desc;
} }
} // namespace rx } // namespace rx
...@@ -465,6 +465,7 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::CommandBuff ...@@ -465,6 +465,7 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::CommandBuff
vk::DynamicBuffer mDriverUniformsBuffer; vk::DynamicBuffer mDriverUniformsBuffer;
VkDescriptorSet mDriverUniformsDescriptorSet; VkDescriptorSet mDriverUniformsDescriptorSet;
uint32_t mDriverUniformsDynamicOffset;
vk::BindingPointer<vk::DescriptorSetLayout> mDriverUniformsSetLayout; vk::BindingPointer<vk::DescriptorSetLayout> mDriverUniformsSetLayout;
vk::RefCountedDescriptorPoolBinding mDriverUniformsDescriptorPoolBinding; vk::RefCountedDescriptorPoolBinding mDriverUniformsDescriptorPoolBinding;
......
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