Commit ebf7299e by Jamie Madill Committed by Commit Bot

Vulkan: Minimal dirty bits for ContextVk.

Currently this won't speed up performance much, if at all, since we don't even really support state changes. It sets the stage for using a pipeline cache later, with better state change support. It also makes implementing descriptor sets for Textures a bit simpler, since we can just update descriptor sets when the dirty bits tell us of a Texture change. Add cache structures to VertexArrayVk and ContextVk so we only need to update the structures before we create a new pipeline. When we support pipeline caching, we will most likely be updating a compact representation for fast cache query. BUG=angleproject:1898 BUG=angleproject:2167 Change-Id: Id545f2c67c06d8b6e8b7eb63ca70464f6b9a51f6 Reviewed-on: https://chromium-review.googlesource.com/713586 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent b9cb7f60
...@@ -155,6 +155,22 @@ class ContextVk : public ContextImpl, public ResourceVk ...@@ -155,6 +155,22 @@ class ContextVk : public ContextImpl, public ResourceVk
RendererVk *mRenderer; RendererVk *mRenderer;
vk::Pipeline mCurrentPipeline; vk::Pipeline mCurrentPipeline;
GLenum mCurrentDrawMode; GLenum mCurrentDrawMode;
// Keep CreateInfo structures cached so that we can quickly update them when creating
// updated pipelines. When we move to a pipeline cache, we will want to use a more compact
// structure that we can use to query the pipeline cache in the Renderer.
// TODO(jmadill): Update this when we move to a pipeline cache.
VkPipelineShaderStageCreateInfo mCurrentShaderStages[2];
VkPipelineVertexInputStateCreateInfo mCurrentVertexInputState;
VkPipelineInputAssemblyStateCreateInfo mCurrentInputAssemblyState;
VkViewport mCurrentViewportVk;
VkRect2D mCurrentScissorVk;
VkPipelineViewportStateCreateInfo mCurrentViewportState;
VkPipelineRasterizationStateCreateInfo mCurrentRasterState;
VkPipelineMultisampleStateCreateInfo mCurrentMultisampleState;
VkPipelineColorBlendAttachmentState mCurrentBlendAttachmentState;
VkPipelineColorBlendStateCreateInfo mCurrentBlendState;
VkGraphicsPipelineCreateInfo mCurrentPipelineInfo;
}; };
} // namespace rx } // namespace rx
......
...@@ -104,9 +104,6 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext, ...@@ -104,9 +104,6 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext,
mLinkedVertexModule.retain(device, std::move(vertexModule)); mLinkedVertexModule.retain(device, std::move(vertexModule));
mLinkedFragmentModule.retain(device, std::move(fragmentModule)); mLinkedFragmentModule.retain(device, std::move(fragmentModule));
// TODO(jmadill): Use pipeline cache.
context->invalidateCurrentPipeline();
return true; return true;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "libANGLE/renderer/vulkan/BufferVk.h" #include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/ContextVk.h" #include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/formatutilsvk.h"
namespace rx namespace rx
{ {
...@@ -21,8 +22,11 @@ namespace rx ...@@ -21,8 +22,11 @@ namespace rx
VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state) VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state)
: VertexArrayImpl(state), : VertexArrayImpl(state),
mCurrentVertexBufferHandlesCache(state.getMaxAttribs(), VK_NULL_HANDLE), mCurrentVertexBufferHandlesCache(state.getMaxAttribs(), VK_NULL_HANDLE),
mCurrentVkBuffersCache(state.getMaxAttribs(), nullptr) mCurrentVkBuffersCache(state.getMaxAttribs(), nullptr),
mCurrentVertexDescsValid(false)
{ {
mCurrentVertexBindingDescs.reserve(state.getMaxAttribs());
mCurrentVertexAttribDescs.reserve(state.getMaxAttribs());
} }
void VertexArrayVk::destroy(const gl::Context *context) void VertexArrayVk::destroy(const gl::Context *context)
...@@ -39,6 +43,9 @@ void VertexArrayVk::syncState(const gl::Context *context, ...@@ -39,6 +43,9 @@ void VertexArrayVk::syncState(const gl::Context *context,
auto contextVk = GetImplAs<ContextVk>(context); auto contextVk = GetImplAs<ContextVk>(context);
contextVk->invalidateCurrentPipeline(); contextVk->invalidateCurrentPipeline();
// Invalidate the vertex descriptions.
invalidateVertexDescriptions();
// Rebuild current attribute buffers cache. This will fail horribly if the buffer changes. // Rebuild current attribute buffers cache. This will fail horribly if the buffer changes.
// TODO(jmadill): Handle buffer storage changes. // TODO(jmadill): Handle buffer storage changes.
const auto &attribs = mState.getVertexAttributes(); const auto &attribs = mState.getVertexAttributes();
...@@ -53,6 +60,7 @@ void VertexArrayVk::syncState(const gl::Context *context, ...@@ -53,6 +60,7 @@ void VertexArrayVk::syncState(const gl::Context *context,
const auto &attrib = attribs[attribIndex]; const auto &attrib = attribs[attribIndex];
const auto &binding = bindings[attrib.bindingIndex]; const auto &binding = bindings[attrib.bindingIndex];
if (attrib.enabled) if (attrib.enabled)
{ {
gl::Buffer *bufferGL = binding.getBuffer().get(); gl::Buffer *bufferGL = binding.getBuffer().get();
...@@ -90,4 +98,66 @@ void VertexArrayVk::updateCurrentBufferSerials(const gl::AttributesMask &activeA ...@@ -90,4 +98,66 @@ void VertexArrayVk::updateCurrentBufferSerials(const gl::AttributesMask &activeA
} }
} }
void VertexArrayVk::invalidateVertexDescriptions()
{
mCurrentVertexDescsValid = false;
mCurrentVertexBindingDescs.clear();
mCurrentVertexAttribDescs.clear();
}
void VertexArrayVk::updateVertexDescriptions(const gl::Context *context)
{
if (mCurrentVertexDescsValid)
{
return;
}
const auto &attribs = mState.getVertexAttributes();
const auto &bindings = mState.getVertexBindings();
const gl::Program *programGL = context->getGLState().getProgram();
for (auto attribIndex : programGL->getActiveAttribLocationsMask())
{
const auto &attrib = attribs[attribIndex];
const auto &binding = bindings[attrib.bindingIndex];
if (attrib.enabled)
{
VkVertexInputBindingDescription bindingDesc;
bindingDesc.binding = static_cast<uint32_t>(mCurrentVertexBindingDescs.size());
bindingDesc.stride = static_cast<uint32_t>(gl::ComputeVertexAttributeTypeSize(attrib));
bindingDesc.inputRate = (binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE
: VK_VERTEX_INPUT_RATE_VERTEX);
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib);
VkVertexInputAttributeDescription attribDesc;
attribDesc.binding = bindingDesc.binding;
attribDesc.format = vk::GetNativeVertexFormat(vertexFormatType);
attribDesc.location = static_cast<uint32_t>(attribIndex);
attribDesc.offset =
static_cast<uint32_t>(ComputeVertexAttributeOffset(attrib, binding));
mCurrentVertexBindingDescs.push_back(bindingDesc);
mCurrentVertexAttribDescs.push_back(attribDesc);
}
else
{
UNIMPLEMENTED();
}
}
mCurrentVertexDescsValid = true;
}
const std::vector<VkVertexInputBindingDescription> &VertexArrayVk::getVertexBindingDescs() const
{
return mCurrentVertexBindingDescs;
}
const std::vector<VkVertexInputAttributeDescription> &VertexArrayVk::getVertexAttribDescs() const
{
return mCurrentVertexAttribDescs;
}
} // namespace rx } // namespace rx
...@@ -30,9 +30,21 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -30,9 +30,21 @@ class VertexArrayVk : public VertexArrayImpl
void updateCurrentBufferSerials(const gl::AttributesMask &activeAttribsMask, Serial serial); void updateCurrentBufferSerials(const gl::AttributesMask &activeAttribsMask, Serial serial);
void invalidateVertexDescriptions();
void updateVertexDescriptions(const gl::Context *context);
const std::vector<VkVertexInputBindingDescription> &getVertexBindingDescs() const;
const std::vector<VkVertexInputAttributeDescription> &getVertexAttribDescs() const;
private: private:
std::vector<VkBuffer> mCurrentVertexBufferHandlesCache; std::vector<VkBuffer> mCurrentVertexBufferHandlesCache;
std::vector<BufferVk *> mCurrentVkBuffersCache; std::vector<BufferVk *> mCurrentVkBuffersCache;
// Keep a cache of binding and attribute descriptions for easy pipeline updates.
// TODO(jmadill): Update this when we support pipeline caching.
bool mCurrentVertexDescsValid;
std::vector<VkVertexInputBindingDescription> mCurrentVertexBindingDescs;
std::vector<VkVertexInputAttributeDescription> mCurrentVertexAttribDescs;
}; };
} // 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