Commit 834a3a10 by Jamie Madill Committed by Commit Bot

Vulkan: Add driver uniforms set.

This will be used to specify the applied Vulkan. We will use this to implement OpenGL line rasterization rules. Bug: angleproject:2717 Change-Id: I3395bf620a01c4b84b19a00037d05f148e5523f3 Reviewed-on: https://chromium-review.googlesource.com/1120151 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarLuc Ferron <lucferron@chromium.org>
parent 534343ab
...@@ -54,7 +54,9 @@ ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer) ...@@ -54,7 +54,9 @@ ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer)
mTexturesDirty(false), mTexturesDirty(false),
mVertexArrayBindingHasChanged(false), mVertexArrayBindingHasChanged(false),
mClearColorMask(kAllColorChannelsMask), mClearColorMask(kAllColorChannelsMask),
mFlipYForCurrentSurface(false) mFlipYForCurrentSurface(false),
mDriverUniformsBuffer(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, sizeof(DriverUniforms) * 16),
mDriverUniformsDescriptorSet(VK_NULL_HANDLE)
{ {
memset(&mClearColorValue, 0, sizeof(mClearColorValue)); memset(&mClearColorValue, 0, sizeof(mClearColorValue));
memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue)); memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue));
...@@ -66,7 +68,9 @@ ContextVk::~ContextVk() ...@@ -66,7 +68,9 @@ ContextVk::~ContextVk()
void ContextVk::onDestroy(const gl::Context *context) void ContextVk::onDestroy(const gl::Context *context)
{ {
mDriverUniformsSetLayout.reset();
mIncompleteTextures.onDestroy(context); mIncompleteTextures.onDestroy(context);
mDriverUniformsBuffer.destroy(getDevice());
for (vk::DynamicDescriptorPool &descriptorPool : mDynamicDescriptorPools) for (vk::DynamicDescriptorPool &descriptorPool : mDynamicDescriptorPools)
{ {
...@@ -89,6 +93,7 @@ gl::Error ContextVk::initialize() ...@@ -89,6 +93,7 @@ gl::Error ContextVk::initialize()
VkDescriptorPoolSize uniformPoolSize = { VkDescriptorPoolSize uniformPoolSize = {
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
GetUniformBufferDescriptorCount() * vk::kDefaultDescriptorPoolMaxSets}; GetUniformBufferDescriptorCount() * vk::kDefaultDescriptorPoolMaxSets};
ANGLE_TRY( ANGLE_TRY(
mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(getDevice(), uniformPoolSize)); mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(getDevice(), uniformPoolSize));
...@@ -98,6 +103,11 @@ gl::Error ContextVk::initialize() ...@@ -98,6 +103,11 @@ gl::Error ContextVk::initialize()
ANGLE_TRY(mDynamicDescriptorPools[kTextureDescriptorSetIndex].init(getDevice(), ANGLE_TRY(mDynamicDescriptorPools[kTextureDescriptorSetIndex].init(getDevice(),
imageSamplerPoolSize)); imageSamplerPoolSize));
VkDescriptorPoolSize driverUniformsPoolSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
vk::kDefaultDescriptorPoolMaxSets};
ANGLE_TRY(mDynamicDescriptorPools[kDriverUniformsDescriptorSetIndex].init(
getDevice(), driverUniformsPoolSize));
mPipelineDesc.reset(new vk::PipelineDesc()); mPipelineDesc.reset(new vk::PipelineDesc());
mPipelineDesc->initDefaults(); mPipelineDesc->initDefaults();
...@@ -439,6 +449,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt ...@@ -439,6 +449,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
mPipelineDesc->updateViewport(framebufferVk, glState.getViewport(), mPipelineDesc->updateViewport(framebufferVk, glState.getViewport(),
glState.getNearPlane(), glState.getFarPlane(), glState.getNearPlane(), glState.getFarPlane(),
isViewportFlipEnabled()); isViewportFlipEnabled());
ANGLE_TRY(updateDriverUniforms());
break; break;
} }
case gl::State::DIRTY_BIT_DEPTH_RANGE: case gl::State::DIRTY_BIT_DEPTH_RANGE:
...@@ -826,8 +837,76 @@ VkColorComponentFlags ContextVk::getClearColorMask() const ...@@ -826,8 +837,76 @@ VkColorComponentFlags ContextVk::getClearColorMask() const
{ {
return mClearColorMask; return mClearColorMask;
} }
const FeaturesVk &ContextVk::getFeatures() const const FeaturesVk &ContextVk::getFeatures() const
{ {
return mRenderer->getFeatures(); return mRenderer->getFeatures();
} }
vk::Error ContextVk::updateDriverUniforms()
{
if (!mDriverUniformsBuffer.valid())
{
size_t minAlignment = static_cast<size_t>(
mRenderer->getPhysicalDeviceProperties().limits.minUniformBufferOffsetAlignment);
mDriverUniformsBuffer.init(minAlignment, mRenderer);
}
// Release any previously retained buffers.
mDriverUniformsBuffer.releaseRetainedBuffers(mRenderer);
const gl::Rectangle &glViewport = mState.getState().getViewport();
// Allocate a new region in the dynamic buffer.
uint8_t *ptr = nullptr;
VkBuffer buffer = VK_NULL_HANDLE;
uint32_t offset = 0;
bool newBufferAllocated = false;
ANGLE_TRY(mDriverUniformsBuffer.allocate(mRenderer, sizeof(DriverUniforms), &ptr, &buffer,
&offset, &newBufferAllocated));
// Copy and flush to the device.
DriverUniforms *driverUniforms = reinterpret_cast<DriverUniforms *>(ptr);
driverUniforms->viewport[0] = static_cast<float>(glViewport.x);
driverUniforms->viewport[1] = static_cast<float>(glViewport.y);
driverUniforms->viewport[2] = static_cast<float>(glViewport.width);
driverUniforms->viewport[2] = static_cast<float>(glViewport.height);
ANGLE_TRY(mDriverUniformsBuffer.flush(getDevice()));
// Get the descriptor set layout.
if (!mDriverUniformsSetLayout.valid())
{
vk::DescriptorSetLayoutDesc desc;
desc.update(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1);
ANGLE_TRY(mRenderer->getDescriptorSetLayout(desc, &mDriverUniformsSetLayout));
}
// Allocate a new descriptor set.
ANGLE_TRY(mDynamicDescriptorPools[kDriverUniformsDescriptorSetIndex].allocateSets(
this, mDriverUniformsSetLayout.get().ptr(), 1, &mDriverUniformsDescriptorSet));
// Update the driver uniform descriptor set.
VkDescriptorBufferInfo bufferInfo;
bufferInfo.buffer = buffer;
bufferInfo.offset = offset;
bufferInfo.range = sizeof(DriverUniforms);
VkWriteDescriptorSet writeInfo;
writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeInfo.pNext = nullptr;
writeInfo.dstSet = mDriverUniformsDescriptorSet;
writeInfo.dstBinding = 0;
writeInfo.dstArrayElement = 0;
writeInfo.descriptorCount = 1;
writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
writeInfo.pImageInfo = nullptr;
writeInfo.pTexelBufferView = nullptr;
writeInfo.pBufferInfo = &bufferInfo;
vkUpdateDescriptorSets(getDevice(), 1, &writeInfo, 0, nullptr);
return vk::NoError();
}
} // namespace rx } // namespace rx
...@@ -178,6 +178,8 @@ class ContextVk : public ContextImpl ...@@ -178,6 +178,8 @@ class ContextVk : public ContextImpl
void updateScissor(const gl::State &glState); void updateScissor(const gl::State &glState);
vk::Error updateDriverUniforms();
RendererVk *mRenderer; RendererVk *mRenderer;
vk::PipelineAndSerial *mCurrentPipeline; vk::PipelineAndSerial *mCurrentPipeline;
gl::PrimitiveMode mCurrentDrawMode; gl::PrimitiveMode mCurrentDrawMode;
...@@ -204,6 +206,15 @@ class ContextVk : public ContextImpl ...@@ -204,6 +206,15 @@ class ContextVk : public ContextImpl
// If the current surface bound to this context wants to have all rendering flipped vertically. // If the current surface bound to this context wants to have all rendering flipped vertically.
// Updated on calls to onMakeCurrent. // Updated on calls to onMakeCurrent.
bool mFlipYForCurrentSurface; bool mFlipYForCurrentSurface;
// For shader uniforms such as gl_DepthRange and the viewport size.
struct DriverUniforms
{
std::array<float, 4> viewport;
};
vk::DynamicBuffer mDriverUniformsBuffer;
VkDescriptorSet mDriverUniformsDescriptorSet;
vk::BindingPointer<vk::DescriptorSetLayout> mDriverUniformsSetLayout;
}; };
} // namespace rx } // namespace rx
......
...@@ -474,7 +474,7 @@ class DescriptorSetLayoutDesc final ...@@ -474,7 +474,7 @@ class DescriptorSetLayoutDesc final
// The following are for caching descriptor set layouts. Limited to max two descriptor set layouts // The following are for caching descriptor set layouts. Limited to max two descriptor set layouts
// and two push constants. One push constant per shader stage. This can be extended in the future. // and two push constants. One push constant per shader stage. This can be extended in the future.
constexpr size_t kMaxDescriptorSetLayouts = 2; constexpr size_t kMaxDescriptorSetLayouts = 3;
constexpr size_t kMaxPushConstantRanges = 2; constexpr size_t kMaxPushConstantRanges = 2;
struct PackedPushConstantRange struct PackedPushConstantRange
...@@ -649,10 +649,11 @@ class PipelineLayoutCache final : angle::NonCopyable ...@@ -649,10 +649,11 @@ class PipelineLayoutCache final : angle::NonCopyable
}; };
// Some descriptor set and pipeline layout constants. // Some descriptor set and pipeline layout constants.
constexpr uint32_t kVertexUniformsBindingIndex = 0; constexpr uint32_t kVertexUniformsBindingIndex = 0;
constexpr uint32_t kFragmentUniformsBindingIndex = 1; constexpr uint32_t kFragmentUniformsBindingIndex = 1;
constexpr uint32_t kUniformsDescriptorSetIndex = 0; constexpr uint32_t kUniformsDescriptorSetIndex = 0;
constexpr uint32_t kTextureDescriptorSetIndex = 1; constexpr uint32_t kTextureDescriptorSetIndex = 1;
constexpr uint32_t kDriverUniformsDescriptorSetIndex = 2;
} // namespace rx } // namespace rx
......
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